Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

recv fails with read of 0 bytes continously

47 views
Skip to first unread message

invy

unread,
Jul 3, 2007, 8:37:32 AM7/3/07
to
Hi,
I have implemented a select-recv loop for a server. My
problem is recv is always failing with reading of 0 bytes. The select
returns success and after reading the data the loop is going to select
then again it returns success and recv reads 0 byte. Please advice me
on this issue.

Peter Duniho

unread,
Jul 3, 2007, 12:02:58 PM7/3/07
to

recv() returns 0 when the connection of a connection-oriented socket has
been closed. It also returns 0 when a zero-length datagram is received,
for connectionless sockets.

The usual case is the first scenario and is normal. When you receive 0
bytes, your connection is closed and you should close the socket and
discard it.

Note that select() will indicate the socket is readable, since it is. The
return value of 0 isn't a failure; it's a normal, successful read that
tells you something specific about the state of the socket.

Pete

0 new messages