Read from TCP socket with broken connection.

Sergei Organov osv at javad.ru
Tue Apr 10 18:08:14 UTC 2001


When a socket was connected but remote host has closed connection, how
subsequent read/write operations should behave? My observation is that read()
returns 0 and doesn't set 'errno'. Is it correct behavior?

If yes, then how do I distinguish between reading from such a socket and
reading from connected socked that results in time-out with zero bytes
received? Or, alternatively, how to detect that remote host has closed
connection? 

I've tried to use 'getpeername' to detect that connection is closed, but for
no avail.

Thanks in advance,
Sergei.




More information about the users mailing list