--- rxvt-unicode/src/iom.C 2003/11/26 10:42:34 1.4 +++ rxvt-unicode/src/iom.C 2003/12/19 06:17:03 1.7 @@ -107,6 +107,24 @@ } #endif +#if IOM_IDLE +idle_watcher::~idle_watcher () +{ + if (iom_valid) + iom.unreg (this); +} + +void io_manager::reg (idle_watcher *w) +{ + reg (w, iw); +} + +void io_manager::unreg (idle_watcher *w) +{ + unreg (w, iw); +} +#endif + #if IOM_TIME inline void set_now (void) { @@ -126,36 +144,49 @@ for (;;) { -#if IOM_CHECK - for (int i = 0; i < cw.size (); ++i) - cw[i]->call (*cw[i]); -#endif - -#if IOM_TIME - time_watcher *w; + struct timeval *to = 0; + struct timeval tval; - for (;;) +#if IOM_IDLE + if (iw.size ()) { - w = tw[0]; - - for (time_watcher **i = tw.begin (); i < tw.end (); ++i) - if ((*i)->at < w->at) - w = *i; - - if (w->at > NOW) - break; - - // call it - w->call (*w); + tval.tv_sec = 0; + tval.tv_usec = 0; + to = &tval; + } + else +#endif + { +#if IOM_TIME + time_watcher *w; - if (w->at < 0) - unreg (w); + for (;tw.size ();) + { + w = tw[0]; + + for (time_watcher **i = tw.begin (); i < tw.end (); ++i) + if ((*i)->at < w->at) + w = *i; + + if (w->at > NOW) + { + double diff = w->at - NOW; + tval.tv_sec = (int)diff; + tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); + to = &tval; + break; + } + else if (w->at >= 0) + w->call (*w); + else + unreg (w); + } +#endif } - double diff = w->at - NOW; - struct timeval to; - to.tv_sec = (int)diff; - to.tv_usec = (int)((diff - to.tv_sec) * 1000000); +#if IOM_CHECK + for (int i = 0; i < cw.size (); ++i) + cw[i]->call (*cw[i]); #endif #if IOM_IO @@ -171,14 +202,15 @@ if ((*w)->events & EVENT_READ ) FD_SET ((*w)->fd, &rfd); if ((*w)->events & EVENT_WRITE) FD_SET ((*w)->fd, &wfd); - if ((*w)->fd > fds) fds = (*w)->fd; + if ((*w)->fd >= fds) fds = (*w)->fd + 1; } + if (!to && !fds) + break; // no events + + fds = select (fds, &rfd, &wfd, 0, to); # if IOM_TIME - fds = select (fds + 1, &rfd, &wfd, 0, &to); set_now (); -# else - fds = select (fds + 1, &rfd, &wfd, 0, 0); # endif if (fds > 0) @@ -194,28 +226,31 @@ if (revents) w->call (*w, revents); } - } +#if IOM_IDLE + else if (iw.size ()) + for (int i = 0; i < iw.size (); ++i) + iw[i]->call (*iw[i]); +#endif + #elif IOM_TIME + if (!to) + break; + select (0, 0, 0, 0, &to); set_now (); +#else + break; #endif -} - -void io_manager::idle_cb (time_watcher &w) -{ - w.at = NOW + 1000000000; + } } io_manager::io_manager () { +#if IOM_TIME set_now (); +#endif iom_valid = true; - -#if IOM_TIME - idle = new time_watcher (this, &io_manager::idle_cb); - idle->start (0); -#endif } io_manager::~io_manager ()