This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Documentation of eventfd_write and eventfd_read?


On Fri, Jan 31, 2014 at 11:55 AM, Hei Chan <structurechart@yahoo.com> wrote:
> Hi,
>
> I am looking for the documentation of eventfd_write() and eventfd_read().
>
> I downloaded the manual of glibc and grepped for eventfd_write/read but I don't see any.

These interface *should* be documented but they are not.

Patches welcome.

> If the manual doesn't exist, I have 2 questions:
> 1. eventfd_write()'s 2nd argument can't be zero?  It seems like when it is zero, epoll_wait() never returns for that event.
> 2. will there be any side effect if I call eventfd_write(), epoll_wait() returns for that event, but I don't eventfd_read() to consume that event?
>

See Additional glibc features:
http://man7.org/linux/man-pages/man2/eventfd.2.html
~~~
   Additional glibc features
       The GNU C library defines an additional type, and two functions that
       attempt to abstract some of the details of reading and writing on an
       eventfd file descriptor:

           typedef uint64_t eventfd_t;

           int eventfd_read(int fd, eventfd_t *value);
           int eventfd_write(int fd, eventfd_t value);

       The functions perform the read and write operations on an eventfd
       file descriptor, returning 0 if the correct number of bytes was
       transferred, or -1 otherwise.
~~~

1. The value of eventfd_write's 2nd argument can be zero.

The implementation in glibc looks like this:

int
eventfd_write (int fd, eventfd_t value)
{
  return __write (fd, &value,
          sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
}

2. If you don't read the event then it's still there waiting for you
to read it. I surmise that eventually the internal write buffer will
fill up if you don't issue a read and the writes will start to block.

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]