--- gvpe/src/iom.C 2004/01/17 14:08:57 1.14 +++ gvpe/src/iom.C 2004/03/28 01:53:33 1.19 @@ -21,9 +21,17 @@ #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 @@ -33,19 +41,20 @@ // 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) +static struct tw0 : time_watcher { - // should never get called - // reached end-of-time, or tstamp has a bogus definition, - // or compiler initilization order broken, or somethine else :) - abort (); - } + 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; + tw0 () + : time_watcher (this, &tw0::cb) + { }} +tw0; tstamp NOW; static bool iom_valid; @@ -59,6 +68,9 @@ if (!w->active) { +#if IOM_CHECK + queue.activity = true; +#endif queue.push_back (w); w->active = queue.size (); } @@ -90,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 @@ -135,6 +147,7 @@ } else #endif + { #if IOM_TIME time_watcher *next; @@ -155,7 +168,7 @@ { double diff = next->at - NOW; tval.tv_sec = (int)diff; - tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); + tval.tv_usec = (int) ((diff - tval.tv_sec) * 1000000); to = &tval; } break; @@ -167,18 +180,28 @@ } } #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 - fd_set rfd, wfd, efd; + fd_set rfd, wfd; FD_ZERO (&rfd); FD_ZERO (&wfd); @@ -197,7 +220,7 @@ if (!to && !fds) //TODO: also check idle_watchers and check_watchers break; // no events - fds = select (fds, &rfd, &wfd, &efd, to); + fds = select (fds, &rfd, &wfd, NULL, to); # if IOM_TIME set_now (); # endif @@ -239,6 +262,7 @@ #else break; #endif + } } @@ -250,7 +274,6 @@ set_now (); tw0.start (TSTAMP_MAX); - printf ("abort, %f but inly on %f\n", NOW, tw0.at); #endif }