1 | /* |
1 | /* |
2 | iom.C -- generic I/O multiplexor |
2 | iom.C -- generic I/O multiplexer |
3 | Copyright (C) 2003, 2004 Marc Lehmann <pcg@goof.com> |
3 | Copyright (C) 2003, 2004 Marc Lehmann <gvpe@schmorp.de> |
4 | |
4 | |
|
|
5 | This file is part of GVPE. |
|
|
6 | |
5 | This program is free software; you can redistribute it and/or modify |
7 | GVPE is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
9 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
10 | (at your option) any later version. |
9 | |
11 | |
10 | This program is distributed in the hope that it will be useful, |
12 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
15 | GNU General Public License for more details. |
14 | |
16 | |
15 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
18 | along with gvpe; if not, write to the Free Software |
17 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
20 | */ |
|
|
21 | |
|
|
22 | #include "iom.h" |
19 | |
23 | |
20 | #include <cstdio> |
24 | #include <cstdio> |
21 | #include <cstdlib> |
25 | #include <cstdlib> |
22 | #include <cerrno> |
26 | #include <cerrno> |
23 | |
27 | |
24 | #include <sys/time.h> |
28 | #include <sys/time.h> |
25 | |
29 | |
|
|
30 | #include <assert.h> |
|
|
31 | |
26 | #if 1 // older unices need these includes for select(2) |
32 | #if 1 // older unices need these includes for select (2) |
27 | # include <unistd.h> |
33 | # include <unistd.h> |
28 | # include <sys/types.h> |
34 | # include <sys/types.h> |
|
|
35 | # include <time.h> |
|
|
36 | #endif |
|
|
37 | |
|
|
38 | // for IOM_SIG |
|
|
39 | #if IOM_SIG |
|
|
40 | # include <csignal> |
|
|
41 | # include <fcntl.h> |
29 | #endif |
42 | #endif |
30 | |
43 | |
31 | // if the BSDs would at least be marginally POSIX-compatible.. *sigh* |
44 | // if the BSDs would at least be marginally POSIX-compatible.. *sigh* |
32 | // until that happens, sys/select.h must come last |
45 | // until that happens, sys/select.h must come last |
33 | #include <sys/select.h> |
46 | #include <sys/select.h> |
34 | |
47 | |
35 | #include "iom.h" |
48 | #define TIMEVAL timeval |
|
|
49 | #define TV_FRAC tv_usec |
|
|
50 | #define TV_MULT 1000000L |
36 | |
51 | |
37 | // TSTAMP_MAX must still fit into a positive struct timeval |
52 | #if IOM_IO |
38 | #define TSTAMP_MAX (double)(1UL<<31) |
53 | static io_manager_vec<io_watcher> iow; |
|
|
54 | #endif |
|
|
55 | #if IOM_CHECK |
|
|
56 | static io_manager_vec<check_watcher> cw; |
|
|
57 | #endif |
|
|
58 | #if IOM_TIME |
|
|
59 | static io_manager_vec<time_watcher> tw; |
|
|
60 | #endif |
|
|
61 | #if IOM_IDLE |
|
|
62 | static io_manager_vec<idle_watcher> iw; |
|
|
63 | #endif |
|
|
64 | #if IOM_SIG |
|
|
65 | static int sigpipe[2]; // signal signalling pipe |
|
|
66 | static sigset_t sigs; |
|
|
67 | struct sig_vec : io_manager_vec<sig_watcher> { |
|
|
68 | int pending; |
|
|
69 | sig_vec () |
|
|
70 | : pending (false) |
|
|
71 | { } |
|
|
72 | }; |
|
|
73 | static vector<sig_vec *> sw; |
|
|
74 | #endif |
39 | |
75 | |
40 | // this is a dummy time watcher to ensure that the first |
76 | // this is a dummy time watcher to ensure that the first |
41 | // time watcher is _always_ valid, this gets rid of a lot |
77 | // time watcher is _always_ valid, this gets rid of a lot |
42 | // of null-pointer-checks |
78 | // of null-pointer-checks |
43 | // (must come _before_ iom is being defined) |
79 | // (must come _before_ iom is being defined) |
… | |
… | |
45 | { |
81 | { |
46 | void cb (time_watcher &w) |
82 | void cb (time_watcher &w) |
47 | { |
83 | { |
48 | // should never get called |
84 | // should never get called |
49 | // reached end-of-time, or tstamp has a bogus definition, |
85 | // reached end-of-time, or tstamp has a bogus definition, |
50 | // or compiler initilization order broken, or somethine else :) |
86 | // or compiler initialisation order broken, or something else :) |
51 | abort (); |
87 | abort (); |
52 | } |
88 | } |
53 | |
89 | |
54 | tw0() |
90 | tw0 () |
55 | : time_watcher (this, &tw0::cb) |
91 | : time_watcher (this, &tw0::cb) |
56 | { }} |
92 | { } |
57 | tw0; |
93 | } tw0; |
58 | |
94 | |
59 | tstamp NOW; |
95 | tstamp NOW; |
|
|
96 | |
|
|
97 | #if IOM_TIME |
|
|
98 | tstamp io_manager::now () |
|
|
99 | { |
|
|
100 | struct timeval tv; |
|
|
101 | |
|
|
102 | gettimeofday (&tv, 0); |
|
|
103 | return (tstamp)tv.tv_sec + (tstamp)tv.tv_usec / 1000000.; |
|
|
104 | } |
|
|
105 | |
|
|
106 | void io_manager::set_now () |
|
|
107 | { |
|
|
108 | NOW = now (); |
|
|
109 | } |
|
|
110 | #endif |
|
|
111 | |
60 | static bool iom_valid; |
112 | static bool iom_valid; |
61 | io_manager iom; |
113 | |
|
|
114 | // used for initialisation only |
|
|
115 | static struct init { |
|
|
116 | init () |
|
|
117 | { |
|
|
118 | #if IOM_SIG |
|
|
119 | sigemptyset (&sigs); |
|
|
120 | |
|
|
121 | if (pipe (sigpipe)) |
|
|
122 | { |
|
|
123 | perror ("io_manager: unable to create signal pipe, aborting."); |
|
|
124 | abort (); |
|
|
125 | } |
|
|
126 | |
|
|
127 | fcntl (sigpipe[0], F_SETFL, O_NONBLOCK); fcntl (sigpipe[0], F_SETFD, FD_CLOEXEC); |
|
|
128 | fcntl (sigpipe[1], F_SETFL, O_NONBLOCK); fcntl (sigpipe[1], F_SETFD, FD_CLOEXEC); |
|
|
129 | #endif |
|
|
130 | |
|
|
131 | iom_valid = true; |
|
|
132 | |
|
|
133 | #if IOM_TIME |
|
|
134 | io_manager::set_now (); |
|
|
135 | |
|
|
136 | tw0.start (TSTAMP_MAX); |
|
|
137 | #endif |
|
|
138 | } |
|
|
139 | |
|
|
140 | static void required (); |
|
|
141 | } init; |
|
|
142 | |
|
|
143 | void |
|
|
144 | init::required () |
|
|
145 | { |
|
|
146 | if (!iom_valid) |
|
|
147 | { |
|
|
148 | write (2, "io_manager: early registration attempt, aborting.\n", |
|
|
149 | sizeof ("io_manager: early registration attempt, aborting.\n") - 1); |
|
|
150 | abort (); |
|
|
151 | } |
|
|
152 | } |
62 | |
153 | |
63 | template<class watcher> |
154 | template<class watcher> |
64 | void io_manager::reg (watcher *w, io_manager_vec<watcher> &queue) |
155 | void io_manager::reg (watcher &w, io_manager_vec<watcher> &queue) |
65 | { |
156 | { |
66 | if (!iom_valid) |
157 | init::required (); |
67 | abort (); |
|
|
68 | |
158 | |
69 | if (!w->active) |
159 | if (!w.active) |
70 | { |
160 | { |
71 | #if IOM_CHECK |
|
|
72 | queue.activity = true; |
|
|
73 | #endif |
|
|
74 | queue.push_back (w); |
161 | queue.push_back (&w); |
75 | w->active = queue.size (); |
162 | w.active = queue.size (); |
76 | } |
163 | } |
77 | } |
164 | } |
78 | |
165 | |
79 | template<class watcher> |
166 | template<class watcher> |
80 | void io_manager::unreg (watcher *w, io_manager_vec<watcher> &queue) |
167 | void io_manager::unreg (watcher &w, io_manager_vec<watcher> &queue) |
81 | { |
168 | { |
82 | if (!iom_valid) |
169 | if (!iom_valid) |
83 | return; |
170 | return; |
84 | |
171 | |
85 | if (w->active) |
172 | if (w.active) |
86 | { |
173 | { |
87 | queue [w->active - 1] = 0; |
174 | queue [w.active - 1] = 0; |
88 | w->active = 0; |
175 | w.active = 0; |
89 | } |
176 | } |
90 | } |
177 | } |
91 | |
178 | |
92 | #if IOM_TIME |
179 | #if IOM_TIME |
93 | void time_watcher::trigger () |
180 | void time_watcher::trigger () |
94 | { |
181 | { |
95 | call (*this); |
182 | call (*this); |
96 | |
183 | io_manager::reg (*this); |
97 | iom.reg (this); |
|
|
98 | } |
184 | } |
99 | |
185 | |
100 | void io_manager::reg (time_watcher *w) { reg (w, tw); } |
186 | void io_manager::reg (time_watcher &w) { io_manager::reg (w, tw); } |
101 | void io_manager::unreg (time_watcher *w) { unreg (w, tw); } |
187 | void io_manager::unreg (time_watcher &w) { io_manager::unreg (w, tw); } |
102 | #endif |
188 | #endif |
103 | |
189 | |
104 | #if IOM_IO |
190 | #if IOM_IO |
105 | void io_manager::reg (io_watcher *w) { reg (w, iow); } |
191 | void io_manager::reg (io_watcher &w) { io_manager::reg (w, iow); } |
106 | void io_manager::unreg (io_watcher *w) { unreg (w, iow); } |
192 | void io_manager::unreg (io_watcher &w) { io_manager::unreg (w, iow); } |
107 | #endif |
193 | #endif |
108 | |
194 | |
109 | #if IOM_CHECK |
195 | #if IOM_CHECK |
110 | void io_manager::reg (check_watcher *w) { reg (w, cw); } |
196 | void io_manager::reg (check_watcher &w) { io_manager::reg (w, cw); } |
111 | void io_manager::unreg (check_watcher *w) { unreg (w, cw); } |
197 | void io_manager::unreg (check_watcher &w) { io_manager::unreg (w, cw); } |
112 | #endif |
198 | #endif |
113 | |
199 | |
114 | #if IOM_IDLE |
200 | #if IOM_IDLE |
115 | void io_manager::reg (idle_watcher *w) { reg (w, iw); } |
201 | void io_manager::reg (idle_watcher &w) { io_manager::reg (w, iw); } |
116 | void io_manager::unreg (idle_watcher *w) { unreg (w, iw); } |
202 | void io_manager::unreg (idle_watcher &w) { io_manager::unreg (w, iw); } |
117 | #endif |
203 | #endif |
118 | |
204 | |
119 | #if IOM_TIME |
205 | #if IOM_SIG |
120 | inline void set_now (void) |
206 | static void |
|
|
207 | sighandler (int signum) |
121 | { |
208 | { |
122 | struct timeval tv; |
209 | sw [signum - 1]->pending = true; |
123 | |
210 | |
124 | gettimeofday (&tv, 0); |
211 | // we use a pipe for signal notifications, as most current |
125 | |
212 | // OSes (Linux...) do not implement pselect correctly. ugh. |
126 | NOW = (tstamp)tv.tv_sec + (tstamp)tv.tv_usec / 1000000; |
213 | char ch = signum; // actual content not used |
127 | #endif |
214 | write (sigpipe[1], &ch, 1); |
128 | } |
215 | } |
|
|
216 | |
|
|
217 | void io_manager::reg (sig_watcher &w) |
|
|
218 | { |
|
|
219 | assert (0 < w.signum); |
|
|
220 | |
|
|
221 | sw.reserve (w.signum); |
|
|
222 | |
|
|
223 | while (sw.size () < w.signum) // pathetic |
|
|
224 | sw.push_back (0); |
|
|
225 | |
|
|
226 | sig_vec *&sv = sw[w.signum - 1]; |
|
|
227 | |
|
|
228 | if (!sv) |
|
|
229 | { |
|
|
230 | sv = new sig_vec; |
|
|
231 | |
|
|
232 | sigaddset (&sigs, w.signum); |
|
|
233 | sigprocmask (SIG_BLOCK, &sigs, NULL); |
|
|
234 | |
|
|
235 | struct sigaction sa; |
|
|
236 | sa.sa_handler = sighandler; |
|
|
237 | sigfillset (&sa.sa_mask); |
|
|
238 | sa.sa_flags = SA_RESTART; |
|
|
239 | |
|
|
240 | if (sigaction (w.signum, &sa, 0)) |
|
|
241 | { |
|
|
242 | perror ("io_manager: error while installing signal handler, ignoring."); |
|
|
243 | abort (); |
|
|
244 | } |
|
|
245 | |
|
|
246 | } |
|
|
247 | |
|
|
248 | io_manager::reg (w, *sv); |
|
|
249 | } |
|
|
250 | |
|
|
251 | void io_manager::unreg (sig_watcher &w) |
|
|
252 | { |
|
|
253 | if (!w.active) |
|
|
254 | return; |
|
|
255 | |
|
|
256 | assert (0 < w.signum && w.signum <= sw.size ()); |
|
|
257 | |
|
|
258 | io_manager::unreg (w, *sw[w.signum - 1]); |
|
|
259 | } |
|
|
260 | |
|
|
261 | void sig_watcher::start (int signum) |
|
|
262 | { |
|
|
263 | stop (); |
|
|
264 | this->signum = signum; |
|
|
265 | io_manager::reg (*this); |
|
|
266 | } |
|
|
267 | #endif |
129 | |
268 | |
130 | void io_manager::loop () |
269 | void io_manager::loop () |
131 | { |
270 | { |
|
|
271 | init::required (); |
|
|
272 | |
132 | #if IOM_TIME |
273 | #if IOM_TIME |
133 | set_now (); |
274 | set_now (); |
134 | #endif |
275 | #endif |
135 | |
276 | |
136 | for (;;) |
277 | for (;;) |
137 | { |
278 | { |
138 | struct timeval *to = 0; |
|
|
139 | struct timeval tval; |
|
|
140 | |
279 | |
141 | #if IOM_IDLE |
280 | #if IOM_TIME |
142 | if (iw.size ()) |
281 | // call pending time watchers |
143 | { |
282 | { |
144 | tval.tv_sec = 0; |
283 | bool activity; |
145 | tval.tv_usec = 0; |
284 | |
146 | to = &tval; |
|
|
147 | } |
285 | do |
148 | else |
|
|
149 | #endif |
|
|
150 | |
|
|
151 | { |
|
|
152 | #if IOM_TIME |
|
|
153 | time_watcher *next; |
|
|
154 | |
|
|
155 | for (;;) |
|
|
156 | { |
286 | { |
157 | next = tw[0]; // the first time-watcher must exist at ALL times |
287 | activity = false; |
158 | |
288 | |
159 | for (int i = tw.size (); i--; ) |
289 | for (int i = tw.size (); i--; ) |
160 | if (!tw[i]) |
290 | if (!tw[i]) |
161 | tw.erase_unordered (i); |
291 | tw.erase_unordered (i); |
162 | else if (tw[i]->at < next->at) |
292 | else if (tw[i]->at <= NOW) |
163 | next = tw[i]; |
|
|
164 | |
|
|
165 | if (next->at > NOW) |
|
|
166 | { |
293 | { |
167 | if (next != tw[0]) |
294 | time_watcher &w = *tw[i]; |
168 | { |
295 | |
169 | double diff = next->at - NOW; |
|
|
170 | tval.tv_sec = (int)diff; |
|
|
171 | tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); |
|
|
172 | to = &tval; |
|
|
173 | } |
|
|
174 | break; |
296 | unreg (w); |
|
|
297 | w.call (w); |
|
|
298 | |
|
|
299 | activity = true; |
175 | } |
300 | } |
176 | else |
|
|
177 | { |
|
|
178 | unreg (next); |
|
|
179 | next->call (*next); |
|
|
180 | } |
|
|
181 | } |
301 | } |
182 | #endif |
302 | while (activity); |
183 | |
|
|
184 | } |
303 | } |
|
|
304 | #endif |
185 | |
305 | |
186 | #if IOM_CHECK |
306 | #if IOM_CHECK |
187 | tw.activity = false; |
307 | // call all check watchers |
188 | |
|
|
189 | for (int i = cw.size (); i--; ) |
308 | for (int i = cw.size (); i--; ) |
190 | if (!cw[i]) |
309 | if (!cw[i]) |
191 | cw.erase_unordered (i); |
310 | cw.erase_unordered (i); |
192 | else |
311 | else |
193 | cw[i]->call (*cw[i]); |
312 | cw[i]->call (*cw[i]); |
|
|
313 | #endif |
194 | |
314 | |
195 | if (tw.activity) |
315 | struct TIMEVAL *to = 0; |
|
|
316 | struct TIMEVAL tval; |
|
|
317 | |
|
|
318 | #if IOM_IDLE |
|
|
319 | if (iw.size ()) |
196 | { |
320 | { |
197 | tval.tv_sec = 0; |
321 | tval.tv_sec = 0; |
198 | tval.tv_usec = 0; |
322 | tval.TV_FRAC = 0; |
199 | to = &tval; |
323 | to = &tval; |
200 | } |
324 | } |
|
|
325 | else |
201 | #endif |
326 | #endif |
202 | |
327 | { |
203 | #if IOM_IO |
328 | #if IOM_TIME |
|
|
329 | // find earliest active watcher |
|
|
330 | time_watcher *next = tw[0]; // the first time-watcher must exist at ALL times |
|
|
331 | |
|
|
332 | for (io_manager_vec<time_watcher>::const_iterator i = tw.end (); i-- > tw.begin (); ) |
|
|
333 | if (*i && (*i)->at < next->at) |
|
|
334 | next = *i; |
|
|
335 | |
|
|
336 | if (next->at > NOW && next != tw[0]) |
|
|
337 | { |
|
|
338 | double diff = next->at - NOW; |
|
|
339 | tval.tv_sec = (int)diff; |
|
|
340 | tval.TV_FRAC = (int) ((diff - tval.tv_sec) * TV_MULT); |
|
|
341 | to = &tval; |
|
|
342 | } |
|
|
343 | } |
|
|
344 | #endif |
|
|
345 | |
|
|
346 | #if IOM_IO || IOM_SIG |
204 | fd_set rfd, wfd, efd; |
347 | fd_set rfd, wfd; |
205 | |
348 | |
206 | FD_ZERO (&rfd); |
349 | FD_ZERO (&rfd); |
207 | FD_ZERO (&wfd); |
350 | FD_ZERO (&wfd); |
208 | |
351 | |
209 | int fds = 0; |
352 | int fds = 0; |
210 | |
353 | |
|
|
354 | # if IOM_IO |
211 | for (io_manager_vec<io_watcher>::iterator i = iow.end (); i-- > iow.begin (); ) |
355 | for (io_manager_vec<io_watcher>::const_iterator i = iow.end (); i-- > iow.begin (); ) |
212 | if (*i) |
356 | if (*i) |
213 | { |
357 | { |
214 | if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd); |
358 | if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd); |
215 | if ((*i)->events & EVENT_WRITE) FD_SET ((*i)->fd, &wfd); |
359 | if ((*i)->events & EVENT_WRITE) FD_SET ((*i)->fd, &wfd); |
216 | |
360 | |
217 | if ((*i)->fd >= fds) fds = (*i)->fd + 1; |
361 | if ((*i)->fd >= fds) fds = (*i)->fd + 1; |
218 | } |
362 | } |
|
|
363 | # endif |
219 | |
364 | |
220 | if (!to && !fds) //TODO: also check idle_watchers and check_watchers |
365 | if (!to && !fds) //TODO: also check idle_watchers and check_watchers? |
221 | break; // no events |
366 | break; // no events |
222 | |
367 | |
|
|
368 | # if IOM_SIG |
|
|
369 | FD_SET (sigpipe[0], &rfd); |
|
|
370 | if (sigpipe[0] >= fds) fds = sigpipe[0] + 1; |
|
|
371 | # endif |
|
|
372 | |
|
|
373 | # if IOM_SIG |
|
|
374 | // there is no race, as we use a pipe for signals, so select |
|
|
375 | // will return if a signal is caught. |
|
|
376 | sigprocmask (SIG_UNBLOCK, &sigs, NULL); |
|
|
377 | # endif |
223 | fds = select (fds, &rfd, &wfd, &efd, to); |
378 | fds = select (fds, &rfd, &wfd, NULL, to); |
|
|
379 | # if IOM_SIG |
|
|
380 | sigprocmask (SIG_BLOCK, &sigs, NULL); |
|
|
381 | # endif |
|
|
382 | |
224 | # if IOM_TIME |
383 | # if IOM_TIME |
|
|
384 | { |
|
|
385 | // update time, try to compensate for gross non-monotonic time changes |
|
|
386 | tstamp diff = NOW; |
225 | set_now (); |
387 | set_now (); |
|
|
388 | diff = NOW - diff; |
|
|
389 | |
|
|
390 | if (diff < 0) |
|
|
391 | for (io_manager_vec<time_watcher>::const_iterator i = tw.end (); i-- > tw.begin (); ) |
|
|
392 | if (*i) |
|
|
393 | (*i)->at += diff; |
|
|
394 | } |
226 | # endif |
395 | # endif |
227 | |
396 | |
228 | if (fds > 0) |
397 | if (fds > 0) |
229 | for (int i = iow.size (); i--; ) |
398 | { |
230 | if (!iow[i]) |
399 | # if IOM_SIG |
231 | iow.erase_unordered (i); |
400 | if (FD_ISSET (sigpipe[0], &rfd)) |
232 | else |
|
|
233 | { |
401 | { |
234 | short revents = iow[i]->events; |
402 | char ch; |
235 | |
403 | |
236 | if (!FD_ISSET (iow[i]->fd, &rfd)) revents &= ~EVENT_READ; |
404 | while (read (sigpipe[0], &ch, 1) > 0) |
237 | if (!FD_ISSET (iow[i]->fd, &wfd)) revents &= ~EVENT_WRITE; |
405 | ; |
238 | |
406 | |
239 | if (revents) |
407 | for (vector<sig_vec *>::iterator svp = sw.end (); svp-- > sw.begin (); ) |
240 | iow[i]->call (*iow[i], revents); |
408 | if (*svp && (*svp)->pending) |
|
|
409 | { |
|
|
410 | sig_vec &sv = **svp; |
|
|
411 | for (int i = sv.size (); i--; ) |
|
|
412 | if (!sv[i]) |
|
|
413 | sv.erase_unordered (i); |
|
|
414 | else |
|
|
415 | sv[i]->call (*sv[i]); |
|
|
416 | |
|
|
417 | sv.pending = false; |
|
|
418 | } |
241 | } |
419 | } |
|
|
420 | # endif |
|
|
421 | |
|
|
422 | # if IOM_IO |
|
|
423 | for (int i = iow.size (); i--; ) |
|
|
424 | if (!iow[i]) |
|
|
425 | iow.erase_unordered (i); |
|
|
426 | else |
|
|
427 | { |
|
|
428 | io_watcher &w = *iow[i]; |
|
|
429 | short revents = w.events; |
|
|
430 | |
|
|
431 | if (!FD_ISSET (w.fd, &rfd)) revents &= ~EVENT_READ; |
|
|
432 | if (!FD_ISSET (w.fd, &wfd)) revents &= ~EVENT_WRITE; |
|
|
433 | |
|
|
434 | if (revents) |
|
|
435 | w.call (w, revents); |
|
|
436 | } |
|
|
437 | #endif |
|
|
438 | } |
242 | else if (fds < 0 && errno != EINTR) |
439 | else if (fds < 0 && errno != EINTR) |
243 | { |
440 | { |
244 | perror ("Error while waiting for I/O or time event"); |
441 | perror ("io_manager: fatal error while waiting for I/O or time event, aborting."); |
245 | abort (); |
442 | abort (); |
246 | } |
443 | } |
247 | #if IOM_IDLE |
444 | #if IOM_IDLE |
248 | else |
445 | else |
249 | for (int i = iw.size (); i--; ) |
446 | for (int i = iw.size (); i--; ) |
… | |
… | |
260 | select (0, 0, 0, 0, &to); |
457 | select (0, 0, 0, 0, &to); |
261 | set_now (); |
458 | set_now (); |
262 | #else |
459 | #else |
263 | break; |
460 | break; |
264 | #endif |
461 | #endif |
265 | |
|
|
266 | } |
462 | } |
267 | } |
463 | } |
268 | |
464 | |
269 | io_manager::io_manager () |
|
|
270 | { |
|
|
271 | iom_valid = true; |
|
|
272 | |
|
|
273 | #if IOM_TIME |
|
|
274 | set_now (); |
|
|
275 | |
|
|
276 | tw0.start (TSTAMP_MAX); |
|
|
277 | #endif |
|
|
278 | } |
|
|
279 | |
|
|
280 | io_manager::~io_manager () |
|
|
281 | { |
|
|
282 | iom_valid = false; |
|
|
283 | } |
|
|
284 | |
|
|