X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=lib%2Fmtio-select.c;h=26e6785273d71deb7a3408a164818cb5d0bdf5c4;hp=6536c95a1599cd5c6a80422b30bea4556679ed23;hb=9d32586e59d7053a53e54860cbcfbb9c23f59e8a;hpb=aa06d1b36cfaa0610205cf49003277e6a12c874b diff --git a/lib/mtio-select.c b/lib/mtio-select.c index 6536c95..26e6785 100644 --- a/lib/mtio-select.c +++ b/lib/mtio-select.c @@ -32,6 +32,7 @@ #include static struct blocker *blockers; +static int exitstatus; struct blocker { struct blocker *n, *p; @@ -72,7 +73,7 @@ int block(int fd, int ev, time_t to) return(rv); } -void ioloop(void) +int ioloop(void) { int ret; fd_set rfds, wfds, efds; @@ -82,6 +83,7 @@ void ioloop(void) int maxfd; int ev; + exitstatus = 0; while(blockers != NULL) { FD_ZERO(&rfds); FD_ZERO(&wfds); @@ -100,6 +102,8 @@ void ioloop(void) if((bl->to != 0) && ((timeout == 0) || (timeout > bl->to))) timeout = bl->to; } + if(exitstatus) + return(exitstatus); toval.tv_sec = timeout - now; toval.tv_usec = 0; ret = select(maxfd + 1, &rfds, &wfds, &efds, timeout?(&toval):NULL); @@ -110,21 +114,28 @@ void ioloop(void) * probably is. */ sleep(1); } - } - now = time(NULL); - for(bl = blockers; bl; bl = nbl) { - nbl = bl->n; - ev = 0; - if(FD_ISSET(bl->fd, &rfds)) - ev |= EV_READ; - if(FD_ISSET(bl->fd, &wfds)) - ev |= EV_WRITE; - if(FD_ISSET(bl->fd, &efds)) - ev = -1; - if((ev < 0) || (ev & bl->ev)) - resume(bl->th, ev); - else if((bl->to != 0) && (bl->to <= now)) - resume(bl->th, 0); + } else { + now = time(NULL); + for(bl = blockers; bl; bl = nbl) { + nbl = bl->n; + ev = 0; + if(FD_ISSET(bl->fd, &rfds)) + ev |= EV_READ; + if(FD_ISSET(bl->fd, &wfds)) + ev |= EV_WRITE; + if(FD_ISSET(bl->fd, &efds)) + ev = -1; + if((ev < 0) || (ev & bl->ev)) + resume(bl->th, ev); + else if((bl->to != 0) && (bl->to <= now)) + resume(bl->th, 0); + } } } + return(0); +} + +void exitioloop(int status) +{ + exitstatus = status; }