Linux FD sets user expectations

Imagine having a library that runs a server socket and manages epoll fd with all clients. Since everything should be non-blocking, control is transferred to the user, who may want to make a choice on different fds, including the one that notifies the library.

The user is currently specifying callbacks. The user can then call the service procedure, which evaluates epoll and calls these callbacks to avoid constantly calling the service procedure and instead do other things that the user can expect on epoll fd.

What is the correct way to set fd to a user without looking at epoll fd? For me, the best solution would be to create a second read-only file descriptor that will become readable if epoll becomes readable. Is it possible?

I am aware of a possible solution using a service flow, but I would prefer it if I could do this without adding complexity due to synchronization.

Another possible solution would be eventfd and a thread that will poll epoll fd and then fire eventfd. But that seems to be the top.

+5
source share

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


All Articles