Re: How long does read(2) wait before an EAGAIN is thrown?
- From: "lovecreatesbea...@xxxxxxxxx" <lovecreatesbeauty@xxxxxxxxx>
- Date: Sun, 22 Jun 2008 20:00:32 -0700 (PDT)
On Jun 20, 7:04 pm, David Schwartz <dav...@xxxxxxxxxxxxx> wrote:
On Jun 19, 7:02 am, "lovecreatesbea...@xxxxxxxxx"
<lovecreatesbea...@xxxxxxxxx> wrote:
For example, I send a greeting message to smtp-server, and expect to
read an SMTP ``250'' response. How long time does read() wait before a
slow 250 arrives, if this runs on non-blocking i/o?
// greeting
sbuf = "HELO " + server + "\n";
cout << sbuf;
if (write(sock, sbuf.c_str(), sbuf.size()) < 0){
perror("write()");
exit(1);
}
if (read(sock, buf, BUFSIZ) < 0){ /* How Long wait */
if ((len = read(sock, buf, sizeof buf - 1)) < 0){
perror("read()");
exit(1);
}
buf[len] = '\0';
cout << buf;
sbuf = buf;
if (sbuf.find("250") == string::npos){
cerr << "HELO mail action failed" << endl;
exit(1);
}
You seem to have made TCP mistake number 1, you've forgotten to
implement the SMTP protocol! (Hint: It's a line-based protocol. Where
is your code to receive a line?)
Do I read a line in line-based protocol way like this:
#define ONE_BYTE 1
while (read(sock, buf, ONE_BYTE) > 0){
/*store data in a file for the sake of the
amount of data exceeds that of buf*/
ret = fputc(*buf, fp);
if (ret == EOF)
exit(EXIT_FAILURE);
/*line-based protocol read, maybe \r\n*/
if (*buf == '\n')
break;
}
Can you please elaborate on this.
.
- Follow-Ups:
- Re: How long does read(2) wait before an EAGAIN is thrown?
- From: David Schwartz
- Re: How long does read(2) wait before an EAGAIN is thrown?
- References:
- How long does read(2) wait before an EAGAIN is thrown?
- From: lovecreatesbea...@xxxxxxxxx
- Re: How long does read(2) wait before an EAGAIN is thrown?
- From: David Schwartz
- How long does read(2) wait before an EAGAIN is thrown?
- Prev by Date: Re: How long does read(2) wait before an EAGAIN is thrown?
- Next by Date: MACROS on traceroute
- Previous by thread: Re: How long does read(2) wait before an EAGAIN is thrown?
- Next by thread: Re: How long does read(2) wait before an EAGAIN is thrown?
- Index(es):
Relevant Pages
|