ÇUnix套接字。信号处理 [英] C unix sockets. Signals to handle
问题描述
我在一个插座AF_INET处理哪一种信号,服务器和客户端?
which kind of signal i've to handle in a AF_INET socket, both server and client side?
推荐答案
根据你如何做你正在做什么,你的可能的必须处理 SIG_PIPE
,它可以发生在连接任意打破。
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.
如果您使用的是选择()
或调查()
或(个人preference)的epoll()
您应该检查错误(例如, POLLHUP
)的前的您检查读/写可用性。
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.
您也应该检查的返回值的read()/写()/发送()/的recv()
。如果有错误,它们返回-1,但如果他们返回0,这意味着另一端断开。也就是说,0读不只是意味着0字节宣读但连接还是不错的。事实并非如此。关闭套接字。这是通过POSIX规定。
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.
这篇关于ÇUnix套接字。信号处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!