which kind of signal i've to handle in a AF_INET socket, both server and client side?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Depending on how you're doing what you're doing, you may have to handle SIG_PIPE
, which can happen when the connection is arbitrarily broken.
You should not have to handle any other signals.
If you are using select()
or poll()
or (personal preference) epoll()
you should check for errors (eg, POLLHUP
) before you check for read/write availability.
You should also always check the return value of read()/write()/send()/recv()
. If there's an error, they return -1, but if they return 0, that means the other end disconnected. Ie, a read of 0 does just mean 0 bytes were read but the connection is still good. It isn't. Close the socket. This is stipulated by POSIX.