which kind of signal i've to handle in a AF_INET socket, both server and client side?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
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()
orpoll()
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.