X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=libmainloop%2Fselect.c;fp=libmainloop%2Fselect.c;h=14070aabe6814a94a3e21838fcd8e34081c90155;hp=f8410a5b846c46b318deb3d1a039576c0b0b6618;hb=29aae1975d46f66b97a2b873f1875eded8c6fbc3;hpb=1a1da7f91ce0772210023d766e616aa0362c8d8d diff --git a/libmainloop/select.c b/libmainloop/select.c index f8410a5..14070aa 100644 --- a/libmainloop/select.c +++ b/libmainloop/select.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -100,13 +101,13 @@ void mainloop_select() int nfds=0; int ret=0; - FD_ZERO(&rfds); - - set_input_fds(&rfds, &nfds); #ifdef _POSIX_SELECT { sigset_t oldmask; + + FD_ZERO(&rfds); + set_input_fds(&rfds, &nfds); mainloop_block_signals(&oldmask); @@ -118,18 +119,26 @@ void mainloop_select() #else #warning "pselect() unavailable -- using dirty hacks" { - struct timeval tv_={0, 0}, *tv=&tv_; + struct timeval tv={0, 0}; /* If there are timers, make sure we return from select with * some delay, if the timer signal happens right before * entering select(). Race conditions with other signals * we'll just have to ignore without pselect(). */ - if(!libmainloop_get_timeout(tv)) - tv=NULL; + do{ + FD_ZERO(&rfds); + set_input_fds(&rfds, &nfds); - if(!mainloop_unhandled_signals()) - ret=select(nfds+1, &rfds, NULL, NULL, tv); + bool to=libmainloop_get_timeout(&tv); + + if(mainloop_unhandled_signals()){ + ret=0; + break; + } + + ret=select(nfds+1, &rfds, NULL, NULL, to ? &tv : NULL); + }while(ret<0 && errno==EINTR && !mainloop_unhandled_signals()); } #endif if(ret>0)