On 9/26/2013 9:36 AM, Quoth Chris Verges:
However, if I physically remove the network interface -- such as yanking the USB adapter out of its socket -- the TCP session stills reports as ESTABLISHED via netstat and the application receives no read error.
I'm at a bit of a loss how this is possible when the underlying OS shows that the interface no longer exists yet the socket is blocking away happily. Has anyone else experienced similar symptoms? Any advice?
This is normal for TCP connections. If you only have outstanding read operations you cannot detect non-graceful shutdowns. However the next time you attempt to write to the socket you will get a disconnection error. One strategy you can use is to have a timer that periodically writes a "null message" (whatever that happens to be according to the application protocol in use) if nothing else has been written to the port recently (ie. reset the timer whenever you do a write). You'll want to set the timer long enough to not waste bandwidth or get in the way of normal communication but short enough that you can detect disconnection within a reasonable time. Exactly how long that will be depends on your use case. :)