Skip to content

Commit

Permalink
Uberdetailed debug information about event loop operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dechamps committed Jul 4, 2014
1 parent 132ba09 commit f17f57d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/event.c
Expand Up @@ -24,6 +24,7 @@
#include "net.h"
#include "utils.h"
#include "xalloc.h"
#include "logger.h"

struct timeval now;

Expand Down Expand Up @@ -67,8 +68,11 @@ static splay_tree_t io_tree = {.compare = (splay_compare_t)io_compare};
static splay_tree_t timeout_tree = {.compare = (splay_compare_t)timeout_compare};

void io_add(io_t *io, io_cb_t cb, void *data, int fd, int flags) {
if(io->cb)
logger(DEBUG_META, LOG_NOTICE, "io_add(%x, %x, %x, %d, %d)", io, cb, data, fd, flags);
if(io->cb) {
logger(DEBUG_META, LOG_NOTICE, "io_add() ignored because of io->cb");
return;
}

io->fd = fd;
#ifdef HAVE_MINGW
Expand Down Expand Up @@ -97,11 +101,16 @@ void io_add_event(io_t *io, io_cb_t cb, void *data, WSAEVENT event) {
#endif

void io_set(io_t *io, int flags) {
if (flags == io->flags)
logger(DEBUG_META, LOG_NOTICE, "io_set(%x, %d)", io, flags);
if (flags == io->flags) {
logger(DEBUG_META, LOG_NOTICE, "io_set() ignored because no-op");
return;
}
io->flags = flags;
if (io->fd == -1)
if (io->fd == -1) {
logger(DEBUG_META, LOG_NOTICE, "io_set() ignored because no fd");
return;
}

#ifndef HAVE_MINGW
if(flags & IO_READ)
Expand All @@ -125,8 +134,11 @@ void io_set(io_t *io, int flags) {
}

void io_del(io_t *io) {
if(!io->cb)
logger(DEBUG_META, LOG_NOTICE, "io_del(%x)", io);
if(!io->cb) {
logger(DEBUG_META, LOG_NOTICE, "io_del() ignored because no io->cb");
return;
}

io_set(io, 0);
#ifdef HAVE_MINGW
Expand All @@ -135,6 +147,8 @@ void io_del(io_t *io) {
event_count--;
#endif

if (!splay_search(&io_tree, io))
logger(DEBUG_META, LOG_NOTICE, "io_del() called with unknown io");
splay_unlink_node(&io_tree, &io->node);
io->cb = NULL;
}
Expand Down Expand Up @@ -256,6 +270,7 @@ bool event_loop(void) {
fd_set writable;

while(running) {
logger(DEBUG_META, LOG_NOTICE, "event_loop() freezing FD sets");
memcpy(&readable, &readfds, sizeof readable);
memcpy(&writable, &writefds, sizeof writable);
struct timeval diff;
Expand Down

0 comments on commit f17f57d

Please sign in to comment.