X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Feventl.c;h=499239143dd6463d5bc02a78a0f6b69512f8bced;hb=e785ffaab91fa3671aa61088154d8bbf84a8d5bb;hp=48c1abdbb7cf54e94ac0ea2e5825d3e9fddec1bc;hpb=e94bb57662a692dd4c0502dfb4569bfa8b811d03;p=pazpar2-moved-to-github.git diff --git a/src/eventl.c b/src/eventl.c index 48c1abd..4992391 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #endif +#include #include #include @@ -116,7 +117,6 @@ IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, new_iochan->fun = cb; new_iochan->socketfun = NULL; new_iochan->maskfun = NULL; - new_iochan->force_event = 0; new_iochan->last_event = new_iochan->max_idle = 0; new_iochan->next = NULL; new_iochan->man = 0; @@ -168,7 +168,7 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) IOCHAN p, *nextp; fd_set in, out, except; int res, max; - static struct timeval nullto = {0, 0}, to; + static struct timeval to; struct timeval *timeout; FD_ZERO(&in); @@ -190,8 +190,6 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) to.tv_sec = p->max_idle; if (p->fd < 0) continue; - if (p->force_event) - timeout = &nullto; /* polling select */ if (p->flags & EVENT_INPUT) FD_SET(p->fd, &in); if (p->flags & EVENT_OUTPUT) @@ -245,7 +243,6 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) } for (p = *iochans; p; p = p->next) { - int force_event = p->force_event; time_t now = time(0); if (p->destroyed) @@ -259,27 +256,25 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) continue; } p->this_event = 0; - p->force_event = 0; - if ((p->max_idle && now - p->last_event > p->max_idle) - || force_event == EVENT_TIMEOUT) + if (p->max_idle && now - p->last_event > p->max_idle) { p->last_event = now; p->this_event |= EVENT_TIMEOUT; } if (p->fd >= 0) { - if (FD_ISSET(p->fd, &in) || force_event == EVENT_INPUT) + if (FD_ISSET(p->fd, &in)) { p->last_event = now; p->this_event |= EVENT_INPUT; } - if (FD_ISSET(p->fd, &out) || force_event == EVENT_OUTPUT) + if (FD_ISSET(p->fd, &out)) { p->last_event = now; p->this_event |= EVENT_OUTPUT; } - if (FD_ISSET(p->fd, &except) || force_event == EVENT_EXCEPT) + if (FD_ISSET(p->fd, &except)) { p->last_event = now; p->this_event |= EVENT_EXCEPT; @@ -316,6 +311,18 @@ void iochan_man_events(iochan_man_t man) event_loop(man, &man->channel_list); } +void pazpar2_sleep(double d) +{ +#ifdef WIN32 + Sleep( (DWORD) (d * 1000)); +#else + struct timeval tv; + tv.tv_sec = floor(d); + tv.tv_usec = (d - floor(d)) * 1000000; + select(0, 0, 0, 0, &tv); +#endif +} + /* * Local variables: * c-basic-offset: 4