which kind of signal i’ve to handle in a AF_INET socket, both server and client side?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.