ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/iom.C
(Generate patch)

Comparing gvpe/src/iom.C (file contents):
Revision 1.17 by pcg, Thu Jan 29 23:17:39 2004 UTC vs.
Revision 1.18 by pcg, Sun Mar 28 01:43:50 2004 UTC

21#include <cstdlib> 21#include <cstdlib>
22#include <cerrno> 22#include <cerrno>
23 23
24#include <sys/time.h> 24#include <sys/time.h>
25 25
26#if 1 // older unices need these includes for select(2) 26#if 1 // older unices need these includes for select (2)
27# include <unistd.h> 27# include <unistd.h>
28# include <sys/types.h> 28# include <sys/types.h>
29#endif 29#endif
30 30
31// if the BSDs would at least be marginally POSIX-compatible.. *sigh* 31// if the BSDs would at least be marginally POSIX-compatible.. *sigh*
39 39
40// this is a dummy time watcher to ensure that the first 40// this is a dummy time watcher to ensure that the first
41// time watcher is _always_ valid, this gets rid of a lot 41// time watcher is _always_ valid, this gets rid of a lot
42// of null-pointer-checks 42// of null-pointer-checks
43// (must come _before_ iom is being defined) 43// (must come _before_ iom is being defined)
44static struct tw0 : time_watcher { 44static struct tw0 : time_watcher
45 void cb (time_watcher &w)
46 { 45 {
46 void cb (time_watcher &w)
47 {
47 // should never get called 48 // should never get called
48 // reached end-of-time, or tstamp has a bogus definition, 49 // reached end-of-time, or tstamp has a bogus definition,
49 // or compiler initilization order broken, or somethine else :) 50 // or compiler initilization order broken, or somethine else :)
50 abort (); 51 abort ();
51 } 52 }
52 53
53 tw0() 54 tw0 ()
54 : time_watcher (this, &tw0::cb) 55 : time_watcher (this, &tw0::cb)
55 { } 56 { }}
56} tw0; 57tw0;
57 58
58tstamp NOW; 59tstamp NOW;
59static bool iom_valid; 60static bool iom_valid;
60io_manager iom; 61io_manager iom;
61 62
99void io_manager::reg (time_watcher *w) { reg (w, tw); } 100void io_manager::reg (time_watcher *w) { reg (w, tw); }
100void io_manager::unreg (time_watcher *w) { unreg (w, tw); } 101void io_manager::unreg (time_watcher *w) { unreg (w, tw); }
101#endif 102#endif
102 103
103#if IOM_IO 104#if IOM_IO
104void io_manager::reg (io_watcher *w) { reg (w, iow); } 105void io_manager::reg (io_watcher *w) { reg (w, iow); }
105void io_manager::unreg (io_watcher *w) { unreg (w, iow); } 106void io_manager::unreg (io_watcher *w) { unreg (w, iow); }
106#endif 107#endif
107 108
108#if IOM_CHECK 109#if IOM_CHECK
109void io_manager::reg (check_watcher *w) { reg (w, cw); } 110void io_manager::reg (check_watcher *w) { reg (w, cw); }
144 tval.tv_usec = 0; 145 tval.tv_usec = 0;
145 to = &tval; 146 to = &tval;
146 } 147 }
147 else 148 else
148#endif 149#endif
150
149 { 151 {
150#if IOM_TIME 152#if IOM_TIME
151 time_watcher *next; 153 time_watcher *next;
152 154
153 for (;;) 155 for (;;)
164 { 166 {
165 if (next != tw[0]) 167 if (next != tw[0])
166 { 168 {
167 double diff = next->at - NOW; 169 double diff = next->at - NOW;
168 tval.tv_sec = (int)diff; 170 tval.tv_sec = (int)diff;
169 tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); 171 tval.tv_usec = (int) ((diff - tval.tv_sec) * 1000000);
170 to = &tval; 172 to = &tval;
171 } 173 }
172 break; 174 break;
173 } 175 }
174 else 176 else
176 unreg (next); 178 unreg (next);
177 next->call (*next); 179 next->call (*next);
178 } 180 }
179 } 181 }
180#endif 182#endif
183
181 } 184 }
182 185
183#if IOM_CHECK 186#if IOM_CHECK
184 tw.activity = false; 187 tw.activity = false;
185 188
196 to = &tval; 199 to = &tval;
197 } 200 }
198#endif 201#endif
199 202
200#if IOM_IO 203#if IOM_IO
201 fd_set rfd, wfd, efd; 204 fd_set rfd, wfd;
202 205
203 FD_ZERO (&rfd); 206 FD_ZERO (&rfd);
204 FD_ZERO (&wfd); 207 FD_ZERO (&wfd);
205 208
206 int fds = 0; 209 int fds = 0;
257 select (0, 0, 0, 0, &to); 260 select (0, 0, 0, 0, &to);
258 set_now (); 261 set_now ();
259#else 262#else
260 break; 263 break;
261#endif 264#endif
265
262 } 266 }
263} 267}
264 268
265io_manager::io_manager () 269io_manager::io_manager ()
266{ 270{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines