Re: How long does read(2) wait before an EAGAIN is thrown?



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.
.



Relevant Pages

  • Why SMTP Sucks...mh003
    ... This document is an outline of why spam is more of a problem in SMTP ... the features of SMTP which enable spam. ... spam problem being worse in SMTP than in any other protocol. ...
    (soc.culture.greek)
  • Re: Which is correct?
    ... SMTP This protocol is asynchronous email-based replication that can be used ... be installed on domain controllers using this site link. ...
    (microsoft.public.cert.exam.mcsa)
  • Re: SPAM - More info please
    ... This happens because of a misconfigured SMTP server. ... POP (Post Office Protocol) is a client end protocol. ... IMAP (internet Mail Access Protocol) is another client end protocol. ...
    (Security-Basics)
  • Error Messages on windows email, cannot receive or send email
    ... Protocol: SMTP, Server Response: '552 5.2.3 DATA size exceeds maximum ...
    (microsoft.public.windows.vista.mail)
  • Re: Exchange SMTP
    ... POP3 is a protocol used to retrieve mail from your ISP's mail server /* ... Outlook Express for Windows folk) connects to the mail server on port ... SMTP on the other hand is a protocol used to send mail /* Outgoing ... SMTP which is what Exchange is designed to use best. ...
    (microsoft.public.windows.server.sbs)