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: Hei Chan <structurechart at yahoo dot com>
- To: Carlos O'Donell <carlos at systemhalted dot org>
- Cc: "libc-help at sourceware dot org" <libc-help at sourceware dot org>
- Date: Fri, 31 Jan 2014 21:54:05 -0800 (PST)
- 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> <CAE2sS1g-Fct7OG9TconTrPLQH3kFE-WTqdXtY+JXihLV=vXP=Q at mail dot gmail dot com>
- Reply-to: Hei Chan <structurechart at yahoo dot com>
Hi Carlos,
Thanks for your reply.
Yes, that manpage is the only "document" I have found online, and it doesn't describe whether there is any side effect when 2nd argument of eventfd_write() is zero.
The implementation you included doesn't seem to suggest so.
Sounds like a bug that epoll_wait() doesn't return when eventfd_write() is called with zero as the 2nd argument?
I am on glibc 2.12.
I have searched glibc's bugzilla, and I don't see any ticket mentioned eventfd_write().
Any input is welcome.
On Saturday, February 1, 2014 9:09 AM, Carlos O'Donell <carlos@systemhalted.org> wrote:
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.