--- rxvt-unicode/src/iom.C 2004/01/16 22:11:09 1.8 +++ rxvt-unicode/src/iom.C 2004/02/01 01:34:41 1.13 @@ -1,6 +1,6 @@ /* iom.C -- generic I/O multiplexor - Copyright (C) 2003 Marc Lehmann + Copyright (C) 2003, 2004 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,39 +17,67 @@ Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "../config.h" - #include #include #include -#include #include +#if 1 // older unices need these includes for select(2) +# include +# include +#endif + +// if the BSDs would at least be marginally POSIX-compatible.. *sigh* +// until that happens, sys/select.h must come last +#include + #include "iom.h" // TSTAMP_MAX must still fit into a positive struct timeval #define TSTAMP_MAX (double)(1UL<<31) +// this is a dummy time watcher to ensure that the first +// time watcher is _always_ valid, this gets rid of a lot +// of null-pointer-checks +// (must come _before_ iom is being defined) +static struct tw0 : time_watcher + { + void cb (time_watcher &w) + { + // should never get called + // reached end-of-time, or tstamp has a bogus definition, + // or compiler initilization order broken, or somethine else :) + abort (); + } + + tw0() + : time_watcher (this, &tw0::cb) + { }} +tw0; + tstamp NOW; static bool iom_valid; io_manager iom; template -void io_manager::reg (watcher *w, simplevec &queue) +void io_manager::reg (watcher *w, io_manager_vec &queue) { if (!iom_valid) abort (); if (!w->active) { +#if IOM_CHECK + queue.activity = true; +#endif queue.push_back (w); w->active = queue.size (); } } template -void io_manager::unreg (watcher *w, simplevec &queue) +void io_manager::unreg (watcher *w, io_manager_vec &queue) { if (!iom_valid) return; @@ -74,7 +102,7 @@ #endif #if IOM_IO -void io_manager::reg (io_watcher *w) { reg (w, iow); } +void io_manager::reg (io_watcher *w) { reg (w, iow); } void io_manager::unreg (io_watcher *w) { unreg (w, iow); } #endif @@ -119,6 +147,7 @@ } else #endif + { #if IOM_TIME time_watcher *next; @@ -144,21 +173,31 @@ } break; } - else if (next->at >= 0) + else { unreg (next); next->call (*next); } } #endif + } #if IOM_CHECK + tw.activity = false; + for (int i = cw.size (); i--; ) if (!cw[i]) cw.erase_unordered (i); else cw[i]->call (*cw[i]); + + if (tw.activity) + { + tval.tv_sec = 0; + tval.tv_usec = 0; + to = &tval; + } #endif #if IOM_IO @@ -169,7 +208,7 @@ int fds = 0; - for (io_watcher **i = iow.end (); i-- > iow.begin (); ) + for (io_manager_vec::iterator i = iow.end (); i-- > iow.begin (); ) if (*i) { if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd); @@ -223,25 +262,10 @@ #else break; #endif + } } -// this is a dummy time watcher to ensure that the first -// time watcher is _always_ valid, this gets rid of a lot -// of null-pointer-checks -static struct tw0 : time_watcher { - void cb (time_watcher &w) - { - // should never get called - // reached end-of-time, or tstamp has a bogus definition :) - abort (); - } - - tw0() - : time_watcher (this, &tw0::cb) - { } -} tw0; - io_manager::io_manager () { iom_valid = true;