Using non-blocking (20 ms cycle) TCP connection in linux, I got a problem:
-
when I close socket from the server side [close(sd) or shutdown(sd,2);close(sd)], the client poll() receives no POLLHUP event.
-
when server is killed from shell, POLLHUP is received.
How can I inform client in a cycle or two?
A TCP disconnect is signalled with POLLIN, and a read() will return 0 in the case of a graceful shutdown, or -1 and an appropriate error (errno being anything but EINTR/EWOULDBLOCK).
There are platforms where it might be signaled with POLLHUP, so you might want to handle that case too.