Socket: constantly getting POLLHUP for half closing

I wrote a socket server running on Linux, but it is probably not linux specificix.

I use poll()to check the status of clients. After sending the request, my clients make an active (half) close. The server is constantly receiving POLLHUPand POLLERRdue to client closure. I also see POLLRDHUP, so I know that in fact half is closed, and the / reset connection is not closed. My problem is that I always get these events, although I already knew from a previous survey that I was half-closed.

How can I disable this so that I no longer receive this event? I tried to do extra read()and do shutdown(fd, SHUT_RD), but it doesn't seem to help. I do not want to pollwake up for an event that I have already processed.

+1
source share
2 answers

Stop, including fd in readfds, set as soon as you get half closure. There was nothing left to read except half-closed. From now on, you may only be interested in events that are writable.

+3
source

Just ignore the POLLHUPreturn flags. Existing code, if correct, will do what you want.

, poll() ( EJP-), , . , ; , , ( TCP-).

"" , poll() . poll() read() , , close(). POLLHUP .

, , POLLHUP. ( ) (.. read()), poll(), ​​ "", (). , ( , POLLHUP), .

0

Source: https://habr.com/ru/post/1528801/


All Articles