This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Documentation of eventfd_write and eventfd_read?
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Hei Chan <structurechart at yahoo dot com>
- Cc: "libc-help at sourceware dot org" <libc-help at sourceware dot org>
- Date: Fri, 31 Jan 2014 20:09:19 -0500
- Subject: Re: Documentation of eventfd_write and eventfd_read?
- Authentication-results: sourceware.org; auth=none
- References: <1391187311 dot 91829 dot YahooMailNeo at web165005 dot mail dot bf1 dot yahoo dot com>
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.