How to inform the server when a client is interrupted?
How to 开发者_运维知识库inform the server if a client is interrupted, and then close the socket?
If the other end of a socket is closed, your end will be marked as readable and return 0
from read
- this is the "end of file" indication.
If you try to write
to such a socket, you will recieve the SIGPIPE
signal, and the write
will return error with errno set to EPIPE
("Broken Pipe"). You must be prepared to handle this event, because the other end can close the socket at any time.
You need TCP_KEEPALIVE
精彩评论