Fwd: Re: [ale] OT:  C not C++ Question
    Benjamin Scherrey 
    scherrey at proteus-tech.com
       
    Sun Dec 29 01:40:21 EST 2002
    
    
  
Forgot an important bit of your code...
----------  Forwarded Message  ----------
Subject: Re: [ale] OT:  C not C++ Question
Date: Sun, 29 Dec 2002 01:34:35 -0500
From: Benjamin Scherrey <scherrey at proteus-tech.com>
To: ale at ale.org
To: ale at ale.org
Can you not establish a pointer to a BufferedInputStream outside of
the while loop, use it within the loop, then delete it outside when
completed? You don't make clear the implications of
BufferedInputStream_new() but its a good general rule that one should
not try to write C++/java code within C. I've intermixed some code
for you...
On Saturday 28 December 2002 11:20 pm, cfowler wrote:
> Example Code:
> int
> main(int argc, char **argv)
> {
>         Socket *sock;
>         String *tmp;
>         InputStream *is;
>         OutputStream *os;
>         BufferedInputStream *bis;
>         String *to = String_new("<chuck at cehuber.org>");
>         String *from = String_new("<cfowler at opsup.com>");
>         int code;
>
>         if((sock = Socket_new("192.168.1.254", 25)) == NULL)
>                 err("Could not create Socket");
>
>         if((Socket_connect(sock)) == -1)
>                 err("Could not make conenction");
>
>         //Now we have a conenction lets get out streams
>         is = Socket_getInputStream(sock);
>         os = Socket_getOutputStream(sock);
>
>         // Create our buffered input stream
>         bis = BufferedInputStream_new(is);
>
>         tmp = BufferedInputStream_readLine(bis);
>         printf("Got: [%s]\n", String_getChars(tmp));
>         String_dispose(tmp);
>
>         tmp = String_new("Helo localhost.localdomain\r\n");
>         sendCmd(sock, tmp, &code);
>         String_dispose(tmp);
>
>         tmp = String_new_1("MAIL FROM: %s\r\n",
> String_getChars(from)); sendCmd(sock, tmp, &code);
>         String_dispose(tmp);
>
>         tmp = String_new_1("RCPT TO: %s\r\n", String_getChars(to));
>         sendCmd(sock, tmp, &code);
>         String_dispose(tmp);
>
>         tmp = String_new("DATA\r\n");
>         sendCmd(sock, tmp, &code);
>         String_dispose(tmp);
>
>         InputStream_dispose(is);
>         is = InputStream_new(NULL);
>         InputStream_setFd(is, 0); // Set FD to STDIN
>         bis = BufferedInputStream_new(is);
	BufferedInputStream* tbis = 0;
>         while(true) {
>                 tmp = BufferedInputStream_readLine(bis);
>
>                 if(String_startsWith(tmp, ".") == true) {
>                         String_append(tmp, "\r\n");
>                         OutputStream_write_1(os, tmp);
			tbis = BufferedInputStream_new( Socket_getInputStream(sock));
/*
>                         tmp = BufferedInputStream_readLine(
>
> BufferedInputStream_new(
>
> Socket_getInputStream(sock)));
*/
			// Forgot this important bit...
			tmp = BufferedInputStream_readLine( tbis );
		
>                         printf("Got: [%s]\n",
> String_getChars(tmp)); String_dispose(tmp);
			BufferedInputStream_dispose(tbis);
			tbis = 0;
>                         break;
>                 }
>
>                 String_append(tmp, "\r\n");
>                 OutputStream_write_1(os, tmp);
>
>         }
>
>
>         // Clean up
>         String_dispose(to);
>         String_dispose(from);
>         BufferedInputStream_dispose(bis);
	if( tbis )
	{
		BufferedInputStream_dispose(tbis);
	}
>         InputStream_dispose(is);
>         OutputStream_dispose(os);
>         Socket_dispose(sock);
>
> }
	So why won't the above work?
		Ben Scherrey
-------------------------------------------------------
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
    
    
More information about the Ale
mailing list