apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Norris <...@cataclysm.cx>
Subject Re: PATCH: Determine how many bytes are waiting to be read from a socket
Date Fri, 05 Mar 2004 00:44:57 GMT
On Thu, Mar 04, 2004 at 06:04:05PM -0600, Scott Lamb wrote:
> On Mar 4, 2004, at 4:51 PM, Robert Norris wrote:
> >I use this to determine if the peer has closed the connection. In that
> >case, the socket goes readable, and this function reports 0 bytes
> >waiting.
> I don't think this is correct. select() and similar functions can 
> return spuriously, at least on some platforms[*]. I would imagine this 
> would return 0 in such a case, and the socket would not have closed. 
> Why not just do the read and see if it returns 0?

The connection is only closed if the socket is readable and there's no
bytes waiting. The results of select()/poll() are undefined unless they
return successfully.

Just doing the read is no good - I'm writing an event notifier and I
only want to actually read the data if there is data waiting (otherwise
my abstraction breaks).


Robert Norris                                       GPG: 1024D/FC18E6C2
Email+Jabber: rob@cataclysm.cx                Web: http://cataclysm.cx/

View raw message