Marc Lehmann schmorp at schmorp.de
Mon Jul 6 17:34:09 CEST 2015

On Mon, Jul 06, 2015 at 01:09:47PM +0000, "Morand, Guy" <Guy.Morand at comet.ch> wrote:
> However, to monitor a GPIO line, I need to get the  EXCEPTION event from select or the POLLPRI from poll. Unfortunately this event doesn't seem to be implemented in libev and I can't use it out of the box. 
> Before trying to change something, I wanted to see with you if there is there any reasons for no implementing this event? What are the constraints and the limitations?

The reasons are that these events are not well defined and not portable
- exceptional events can only work with the select backend for
example. Libev (by choice) doesn't implement functionality that works only
on some platforms, with some backends, or some kernels, it is supposed to
be portable.

As for well defined, I guess your case is a good example: there really
isn't anything called "urgent data" (pollpri) or "exceptional event"
(select) about a GPIO line. Also, if POLLPRI is set then POLLOUT must
also always be set (if urgent data is available, then read will not
block). So overall, the driver you use is already buggy and abuses POLLPRI
functionality when it probably should use read or write notifications.

As for backends/portability between them, if you have to use POLLPRI for
example, you *need* to use poll(), which libev can't, in general, do for
you (POLLPRI is not the same as select's exception set, so it would have
to crash or otherwise fail if poll is unavailable).

On the plus side, libev (unlike most event libs) also allows you to add
those event sources yourself in a reasonably straightforward way, for
example by spawning another thread and using ev_async to signal those
events to the main thread, which could then act directly or use poll to
find out more, so there should always be a way to work around driver
idiosyncrasies or use platform-specific event sources.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list