diff --git a/event.c b/event.c index 91485cef..5c383f62 100644 --- a/event.c +++ b/event.c @@ -1391,9 +1391,9 @@ static void evthread_ignore_fd(int fd, short what, void *arg) { struct event_base *base = arg; - int buf[128]; + char buf[128]; - /* we draining the socket */ + /* we're draining the socket */ while (recv(fd, buf, sizeof(buf), 0) != -1) ; @@ -1448,3 +1448,34 @@ evthread_set_lock_create_callbacks(struct event_base *base, /* now, let's allocate our lock */ base->th_base_lock = (*alloc_fn)(); } + +void +event_base_dump_events(struct event_base *base, FILE *output) +{ + struct event *e; + int i; + fprintf(output, "Inserted events:\n"); + TAILQ_FOREACH(e, &base->eventqueue, ev_next) { + fprintf(output, " %p [fd %ld]%s%s%s%s%s\n", + (void*)e, (long)e->ev_fd, + (e->ev_events&EV_READ)?" Read":"", + (e->ev_events&EV_WRITE)?" Write":"", + (e->ev_events&EV_SIGNAL)?" Signal":"", + (e->ev_events&EV_TIMEOUT)?" Timeout":"", + (e->ev_events&EV_PERSIST)?" Persist":""); + + } + for (i = 0; i < base->nactivequeues; ++i) { + if (TAILQ_EMPTY(base->activequeues[i])) + continue; + fprintf(output, "Active events [priority %d]:\n", i); + TAILQ_FOREACH(e, &base->eventqueue, ev_next) { + fprintf(output, " %p [fd %ld]%s%s%s%s\n", + (void*)e, (long)e->ev_fd, + (e->ev_res&EV_READ)?" Read active":"", + (e->ev_res&EV_WRITE)?" Write active":"", + (e->ev_res&EV_SIGNAL)?" Signal active":"", + (e->ev_res&EV_TIMEOUT)?" Timeout active":""); + } + } +} diff --git a/include/event2/event.h b/include/event2/event.h index 563b2d1b..e837197b 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -45,6 +45,8 @@ extern "C" { #include #endif +#include + /* For int types. */ #include @@ -538,6 +540,8 @@ void event_set_mem_functions(void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz), void (*free_fn)(void *ptr)); +void event_base_dump_events(struct event_base *, FILE *); + #ifdef __cplusplus } #endif