[Libevent-users] announcing libev, towards a faster and more
featureful libevent
Scott Lamb
slamb at slamb.org
Mon Nov 5 12:50:54 EST 2007
Marc Lehmann wrote:
> On Sun, Nov 04, 2007 at 09:56:44PM -0800, Scott Lamb <slamb at slamb.org> wrote:
>>> returning from event_loop, leaving the app unclear on what has happened
>>> and what to do.
>>>
>>> In any case, you can get the same behaviour as libevent by calling unloop
>>> in case of an error, so the interface is strictly more powerful.
>> Another reason this is undesirable: to get the libevent behavior, I'd
>> have to have this logic in *every callback* to get the same behavior.
>
> Hmm, one could actually roll this into the libevent compatibility
> layer. I'll think about this (didn't occur to me before).
>
> Note, however, that I think the libevent interface is undesirable, as it
> leaves me unclear on what happened and no reasonable way to recover (e.g.
> in the case of EBADF in select).
No, as I said before, libevent retains errno. I've attached a
demonstration program. If it doesn't return 0 when run against your
libevent emulation layer, your code is broken.
> Also, with libevent, you would need similar logic around each call to
> event_add/del and so on, because those can all fail in libevent, so its just
> a different place, really.
It's not just a different place - it's where the failure happened.
>
> (And I do think I will provide an oom-error handler for this specific
> case, as it is about the only generic error that isn't specific to some
> watcher).
>
> Thanks for these ideas,
>
-------------- next part --------------
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <event.h>
#include <errno.h>
#include <string.h>
const int BADFD = 64;
static void
cb(int fd, short events, void *cbarg)
{
}
int
main(int argc, char **argv)
{
struct event ev;
int sts;
const char *method;
/* Initialize, hopefully with select method */
putenv("EVENT_NOKQUEUE=yes");
putenv("EVENT_NODEVPOLL=yes");
putenv("EVENT_NOPOLL=yes");
putenv("EVENT_NOEPOLL=yes");
putenv("EVENT_NORTSIG=yes");
putenv("EVENT_NODEVPORT=yes");
event_init();
method = event_get_method();
if (strcmp(method, "select") != 0)
return EXIT_FAILURE;
/* add a bad descriptor */
close(BADFD); /* just to be sure */
event_set(&ev, BADFD, EV_READ|EV_PERSIST, cb, NULL);
sts = event_add(&ev, NULL);
if (sts != 0)
return EXIT_FAILURE;
/* try dispatching */
sts = event_dispatch();
if (sts != 0) {
perror("event_dispatch");
return (errno == EBADF) ? EXIT_SUCCESS : EXIT_FAILURE;
}
return EXIT_FAILURE;
}
More information about the Libevent-users
mailing list