<div class="gmail_quote"><div>My apologies for taking so long to reply, OSCON has been taking up all my time this week.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div>I *might* be able to modify the "readSocket()" function to better handle this case, but I don't want to risk inadvertently messing up higher-level code that uses this function by mishandling cases when "recvfrom()" might return zero in a *non*-error situation.</div>
<div><br></div><div>In the situation that you are concerned about - recvfrom() returning "zero if the connection is TCP and the peer has closed its half side of the connection" - what is the value of "errno" in this case? (If it's something non-zero, then I should be able to update "readSocket()" to add a test for this.)</div>
</div></blockquote><div><br></div><div>By design, errno is only set when the return value is negative. Socket close (EOF) is not considered an error, and is indicated instead by a zero return value. This is the only use of a zero return value for TCP sockets on POSIX.</div>
<div><br></div><div>Here's an example of Apache HTTPD relying on zero return value to detect socket close/EOF (taken from <a href="http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sendrecv.c?view=markup">http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sendrecv.c?view=markup</a> )</div>
<div><br></div><div><span class="Apple-style-span" style="font-family:Times;font-size:medium"><pre style="word-wrap:break-word;white-space:pre-wrap">apr_status_t apr_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock,
apr_int32_t flags, char *buf,
apr_size_t *len)
{</pre><pre style="word-wrap:break-word;white-space:pre-wrap">// ...snip...</pre></span><span class="Apple-style-span" style="font-family:Times;font-size:medium"><pre style="word-wrap:break-word;white-space:pre-wrap"> do {
rv = recvfrom(sock->socketdes, buf, (*len), flags,
(struct sockaddr*)&from->sa, &from->salen);
} while (rv == -1 && errno == EINTR);<br></pre><pre style="word-wrap:break-word;white-space:pre-wrap">// ...snip...</pre></span><span class="Apple-style-span" style="font-family:Times;font-size:medium"><pre style="word-wrap:break-word;white-space:pre-wrap">
if (rv == 0 && sock->type == SOCK_STREAM) {
return APR_EOF;
}
return APR_SUCCESS;
}</pre></span><br></div></div>