X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsimple-watch.c;h=06be1d6f8eb28baf6f14261ae5609da919708430;hb=6031c7a7c36452ce88469591993416fd80370ffd;hp=e0b1467d91b66c9c25116a18e2482f00ae90370d;hpb=70dc9df7e75ce18ae620cf0c4d88c66eee155960;p=catta diff --git a/src/simple-watch.c b/src/simple-watch.c index e0b1467..06be1d6 100644 --- a/src/simple-watch.c +++ b/src/simple-watch.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "fdutil.h" // catta_set_nonblock #include "internal.h" // closesocket @@ -112,9 +113,10 @@ static void clear_wakeup(CattaSimplePoll *s) { s->wakeup_issued = 0; - for(;;) + for(;;) { if (readpipe(s->wakeup_pipe[0], c, sizeof(c)) != sizeof(c)) break; + } } static CattaWatch* watch_new(const CattaPoll *api, int fd, CattaWatchEvent event, CattaWatchCallback callback, void *userdata) { @@ -311,13 +313,16 @@ CattaSimplePoll *catta_simple_poll_new(void) { winsock_init(); // on Windows, pipe uses sockets; no-op on other platforms if (pipe(s->wakeup_pipe) < 0) { - catta_free(s); - winsock_exit(); - return NULL; + catta_log_error(__FILE__": pipe() failed: %s", errnostrsocket()); + goto fail; } - catta_set_nonblock(s->wakeup_pipe[0]); - catta_set_nonblock(s->wakeup_pipe[1]); + if (catta_set_nonblock(s->wakeup_pipe[0]) < 0 || + catta_set_nonblock(s->wakeup_pipe[1]) < 0) + { + catta_log_error(__FILE__": O_NONBLOCK failed: %s", errnostrsocket()); + goto fail; + } s->api.userdata = s; @@ -352,6 +357,11 @@ CattaSimplePoll *catta_simple_poll_new(void) { CATTA_LLIST_HEAD_INIT(CattaTimeout, s->timeouts); return s; + +fail: + catta_free(s); + winsock_exit(); + return NULL; } void catta_simple_poll_free(CattaSimplePoll *s) { @@ -543,7 +553,7 @@ int catta_simple_poll_dispatch(CattaSimplePoll *s) { assert(s->state == STATE_RAN); s->state = STATE_DISPATCHING; - /* We execute only on callback in every iteration */ + /* We execute only one callback in every iteration */ /* Check whether the wakeup time has been reached now */ if ((next_timeout = find_next_timeout(s))) {