X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsimple-watch.c;h=06be1d6f8eb28baf6f14261ae5609da919708430;hb=4ca82ce280a465ccefe7fb8549d83ec78bb190d6;hp=2992d87108075144468a4110f469b90770515129;hpb=ba535ad98bd65dfbefedb0902403d72ebae10c10;p=catta diff --git a/src/simple-watch.c b/src/simple-watch.c index 2992d87..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,15 +113,10 @@ static void clear_wakeup(CattaSimplePoll *s) { s->wakeup_issued = 0; - printf("(clear wake-up"); fflush(stdout); // XXX for(;;) { - int n; - ioctl(s->wakeup_pipe[0], FIONREAD, &n); - printf(" %d", n); fflush(stdout); // XXX if (readpipe(s->wakeup_pipe[0], c, sizeof(c)) != sizeof(c)) break; } - printf(")\n"); // XXX } static CattaWatch* watch_new(const CattaPoll *api, int fd, CattaWatchEvent event, CattaWatchCallback callback, void *userdata) { @@ -317,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; @@ -358,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) { @@ -521,20 +525,12 @@ int catta_simple_poll_run(CattaSimplePoll *s) { for (;;) { errno = 0; - // XXX debug - { - printf("(poll %d...", s->n_pollfds); - fflush(stdout); - } if (s->poll_func(s->pollfds, s->n_pollfds, s->prepared_timeout, s->poll_func_userdata) < 0) { - if (errno == EINTR) { - printf(" interrupted)\n"); // XXX + if (errno == EINTR) continue; - } s->state = STATE_FAILURE; - printf(" FAIL)\n"); // XXX return -1; } @@ -557,19 +553,6 @@ int catta_simple_poll_dispatch(CattaSimplePoll *s) { assert(s->state == STATE_RAN); s->state = STATE_DISPATCHING; - // XXX debug - { - int i, nready=0, nwatches=0; - for(w=s->watches; w; w=w->watches_next) - nwatches++; - for(i=0; in_pollfds; i++) - if(s->pollfds[i].revents) - nready++; - if(nready > 0 && s->pollfds[i].revents) - printf(" wake-up,"); - printf(" %d ready, %d watches)\n", nready, nwatches); - } - /* We execute only one callback in every iteration */ /* Check whether the wakeup time has been reached now */