Will select (or epoll) mark a socket as readable if there is data on the socket prior to adding the socket to the list of monitored file descriptor

StackOverflow https://stackoverflow.com/questions/18527380

  •  26-06-2022
  •  | 
  •  

Question

I’m seeking help to understand the following situation: 1. I have a TCP socket connection established the peer. 2. I added to the list of file descriptors to be monitored by select 3. select alerts me to any activity on the socket and my application processes the data sent by the peer on the socket. 4. I now remove the file descriptor associated with the socket from the list of file descriptors to be monitored by select. 5. Peer sends me some data on that socket. I do not read that data. 6. after a few seconds, I again and the file descriptor associated with the socket to the list of file descriptors to be monitored by select 7. will select now immediately let me know that the socket is readable? What, if in step 5, the peer does not send me any data but say, since a FIN. Will select still tell me that the socket is readable in summary, the question is if select(or any of its variants such as epoll) indicate that a socket is readable if there has been any activity on the socket prior to including the socket in the list of monitored file descriptors and assuming that the application has read no data from the socket

Was it helpful?

Solution

  1. will select now immediately let me know that the socket is readable?

Yes.

What, if in step 5, the peer does not send me any data but say, since a FIN. Will select still tell me that the socket is readable

Yes.

in summary, the question is if select(or any of its variants such as epoll) indicate that a socket is readable if there has been any activity on the socket prior to including the socket in the list of monitored file descriptors and assuming that the application has read no data from the socket

Yes.

NB 'Prior to including the socket in the list of monitored file descriptors' doesn't really mean anything. The operating system doesn't know when you did that. It only knows that you called select() with that list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top