X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsimple-watch.c;h=2992d87108075144468a4110f469b90770515129;hb=ba535ad98bd65dfbefedb0902403d72ebae10c10;hp=7719e56cb0e43b557d9f173f6b40e951dc484cad;hpb=dd315fb0f7a90a6f154cbea0e7a7c64b550164b9;p=catta diff --git a/src/simple-watch.c b/src/simple-watch.c index 7719e56..2992d87 100644 --- a/src/simple-watch.c +++ b/src/simple-watch.c @@ -100,7 +100,7 @@ void catta_simple_poll_wakeup(CattaSimplePoll *s) { char c = 'W'; assert(s); - writepipe(s->wakeup_pipe[1], &c, sizeof(c)); + (void)writepipe(s->wakeup_pipe[1], &c, sizeof(c)); s->wakeup_issued = 1; } @@ -112,9 +112,15 @@ static void clear_wakeup(CattaSimplePoll *s) { s->wakeup_issued = 0; - for(;;) + 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) { @@ -515,12 +521,20 @@ 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) + if (errno == EINTR) { + printf(" interrupted)\n"); // XXX continue; + } s->state = STATE_FAILURE; + printf(" FAIL)\n"); // XXX return -1; } @@ -543,7 +557,20 @@ int catta_simple_poll_dispatch(CattaSimplePoll *s) { assert(s->state == STATE_RAN); s->state = STATE_DISPATCHING; - /* We execute only on callback in every iteration */ + // 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 */ if ((next_timeout = find_next_timeout(s))) {