Using libev with /sys/class/gpios

Marc Lehmann schmorp at
Wed Nov 22 03:21:21 CET 2017

On Wed, Nov 22, 2017 at 01:39:13AM +0000, Deri James <deri at> wrote:
> The file /sys/class/gpio/gpio??/value is a pseudo file which reflect the current 

I assume you are talking about linux here. In general, on linux, if things
work with poll or select, they also work with libev.

> The kernel 
> actually raises an interrupt

I severely doubt the kernel raises an interrupt - either the hardware
raises an interrupt or the kernel somehow notifies the application with a
signal or an I/O readyness notification.

> when the state changes and using POLLPRI |
> POLLERR with the standard poll() routine seems to work Ok.

You can't specify poll flags with libev, because libev does not normally
use poll. You also cannot specify POLLERR at all, as this is an output flag
and specifying it would be a bug. Libev will report POLLERR as a treadyness

Have you tried polling with EV_READ and/or EV_WRITE? It would be a kernel
bug if POLLPRI is signalled but POLLIN isn't, as urgent read data is also
read data.

> Is it possible to do this with the libev library?

libev might be able to poll for the gpio events, but it cannot specify
custom poll flags simply because libev supports (and usually uses) other
mechanisms than poll.

If EV_READ/WRITE doesn't work, you likely can't make it work directly with
libev. You might be able to use epoll and poll the epoll fd with libev
though, if you have to use libev. epoll also doesn't support POLLPRI, but
it does support the (hopefully equivalent) EPOLLPRI.

If the fd really just signals POLLPRI but not POLLIN with poll, then you
might consider reporting this as a kernel bug.

      -----==-                                             |
      ----==-- _                                           |
      ---==---(_)__  __ ____  __       Marc Lehmann      +--
      --==---/ / _ \/ // /\ \/ /       pcg at      |e|
      -=====/_/_//_/\_,_/ /_/\_\       XX11-RIPE         --+
    The choice of a GNU generation                       |

More information about the libev mailing list