5

Imagine having a library that starts a server socket and manages an epoll fd with all clients. Since everything should be non blocking, control is passed to the user which may want to do a select on different fds, including the one that notifies the library.

Currently the user specifies callbacks. Then the user may call the service routine which evaluates the epoll and invokes those callbacks, to avoid constantly calling the service routine and instead do other things the user may want to wait on the epoll fd.

What is the proper way to expose a fd to the user without exposing the epoll fd ? For me a better solution would be to create a second, read-only file descriptor which becomes readable if the epoll becomes readable. Is this possible?

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

Another possible solution would be a eventfd and a thread which polls the epoll fd and then triggers the eventfd. But this seems to be over the top.

Eric Hauenstein
  • 2,557
  • 6
  • 31
  • 41
Lars M.
  • 179
  • 10
  • Is it a library meant for internal usage in a specific limited set of apps or a general purpose library to be published somewhere? – Oleg Kuralenko Jan 16 '18 at 18:21
  • Although it's development is initiated due to a private project when it's done and it's good it will be made publicly available. However I do not see how this is relevant for the question as I prefer a clean solution over an "do not access"-agreement anyways. – Lars M. Jan 16 '18 at 20:22
  • Have you thought of using a pipe and pass one end to the user to write to or read from? – amine.ahd Jan 19 '18 at 08:54
  • I assume you application is multi-threaded, one for the library and one for each client? The description of your tasks looks like some kind of a multi-drop bus demultiplexer. – Maquefel Jan 19 '18 at 17:30
  • I would like to avoid a service thread for the library. I already mentioned this possibility. – Lars M. Jan 21 '18 at 12:48

0 Answers0