Question

Hi I need to have an specific file descriptor within the descriptors I am monitoring in epoll to block one descriptor is for a socket which is constantly getting broadcast messages but the user have to type an action in the keyboard that is my other descriptor this is the one I need to block because I start typing and then another broadcast message arrive and messes up with what I am writing.

Is there a way to pause an event for a file descriptor to detecting data ready or to block another file descriptor when it has the data ready?

Was it helpful?

Solution

You have a couple of ways to go.

  1. If you are using EPOLLET (edge-triggered), then your event handler on wake-up can first check if you are in the middle of handling typed input from the console. If so, it can just not read anything, but set a flag. When the typed input handler is done, it checks that flag, and manually wakes up the socket input handler to handle the data.

  2. If you are using level-triggered instead, then you can suppress th event by modifying the event set for that file descriptor to suppress the events you want to ignore. This can either be by using EPOLL_CTL_MOD with a new set of events, or by using EPOLL_CTL_DEL to unregister the file descriptor from epoll altogether. You would add back what was suppressed after you are finished with the typed input handler.

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