C unix sockets. Signals to handle

2019-06-08 18:10发布

which kind of signal i've to handle in a AF_INET socket, both server and client side?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-06-08 18:37

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.

查看更多
登录 后发表回答