
On Thu, Jan 28, 2010 at 8:30 AM, Igor R
This issue has previously been discussed in details, and IIRC, the conclusion was that the reliable method to detect peer disconnection is to try reading from the socket.
Not quite. IIRC, the conclusion was that you are hosed in this exact scenario. Basically, if you absolutely must detect this, and aren't otherwise sending data, then you need to be able to build a "heartbeat" into your protocol. You essentially must periodically send a packet (e.g. a heartbeat message). The write call will always succeed until you fill up your socket send buffer (which won't happen w/ heartbeat messages). However, the failure to write will ultimately trigger a timeout, and it will be the read call that fails. See the previous thread for the details as to what is happening at the TCP level. Jon