Marc Lehmann wrote:
On Sun, Nov 04, 2007 at 09:56:44PM -0800, Scott Lamb <[EMAIL PROTECTED]> 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

Thanks for these ideas,

#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)

main(int argc, char **argv)
    struct event ev;
    int sts;
    const char *method;

    /* Initialize, hopefully with select method */
    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) {
        return (errno == EBADF) ? EXIT_SUCCESS : EXIT_FAILURE;

    return EXIT_FAILURE;
Libevent-users mailing list

Reply via email to