X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Feventl.c;h=f9f0dc21a5aa19f3267fdcc6544e22a2155e91cf;hb=88f96194d5a63278eb57b32c814019dab51da9ff;hp=3b57d6458ca3520d27f8e2f3e134978265a951a2;hpb=b73890ede1ee6eeb8a07937733871077df6f15b9;p=pazpar2-moved-to-github.git diff --git a/src/eventl.c b/src/eventl.c index 3b57d64..f9f0dc2 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 @@ -70,7 +71,8 @@ iochan_man_t iochan_man_create(int no_threads) man->sel_thread = 0; /* can't create sel_thread yet because we may fork */ man->sel_fd = -1; man->no_threads = no_threads; - man->log_level = YLOG_DEBUG; + man->log_level = yaz_log_module_level("iochan"); + return man; } @@ -113,9 +115,6 @@ IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, new_iochan->fd = fd; new_iochan->flags = 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; @@ -150,7 +149,7 @@ static void run_fun(iochan_man_t man, IOCHAN p) { if (man->sel_thread) { - yaz_log(man->log_level, "eventl: add fun chan=%p name=%s event=%d", + yaz_log(man->log_level, "eventl: work add chan=%p name=%s event=%d", p, p->name ? p->name : "", p->this_event); p->thread_users++; sel_thread_add(man->sel_thread, p); @@ -167,7 +166,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); @@ -181,16 +180,10 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) { if (p->thread_users > 0) continue; - if (p->maskfun) - p->flags = (*p->maskfun)(p); - if (p->socketfun) - p->fd = (*p->socketfun)(p); if (p->max_idle && p->max_idle < to.tv_sec) 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) @@ -235,9 +228,15 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) } } } + if (man->log_level) + { + int no = 0; + for (p = *iochans; p; p = p->next) + no++; + yaz_log(man->log_level, "%d channels", no); + } for (p = *iochans; p; p = p->next) { - int force_event = p->force_event; time_t now = time(0); if (p->destroyed) @@ -251,29 +250,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; - yaz_log(YLOG_DEBUG, "Eventl input event"); 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; - yaz_log(YLOG_DEBUG, "Eventl output event"); 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; @@ -310,6 +305,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