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

Comparing rxvt-unicode/src/iom.C (file contents):
Revision 1.8 by pcg, Fri Jan 16 22:11:09 2004 UTC vs.
Revision 1.10 by pcg, Sat Jan 17 14:10:40 2004 UTC

1/* 1/*
2 iom.C -- generic I/O multiplexor 2 iom.C -- generic I/O multiplexor
3 Copyright (C) 2003 Marc Lehmann <pcg@goof.com> 3 Copyright (C) 2003, 2004 Marc Lehmann <pcg@goof.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/ 18*/
19 19
20#include "../config.h"
21
22#include <cstdio> 20#include <cstdio>
23#include <cstdlib> 21#include <cstdlib>
24#include <cerrno> 22#include <cerrno>
25 23
26#include <sys/select.h> 24#include <sys/select.h>
29#include "iom.h" 27#include "iom.h"
30 28
31// TSTAMP_MAX must still fit into a positive struct timeval 29// TSTAMP_MAX must still fit into a positive struct timeval
32#define TSTAMP_MAX (double)(1UL<<31) 30#define TSTAMP_MAX (double)(1UL<<31)
33 31
32// this is a dummy time watcher to ensure that the first
33// time watcher is _always_ valid, this gets rid of a lot
34// of null-pointer-checks
35// (must come _before_ iom is being defined)
36static struct tw0 : time_watcher {
37 void cb (time_watcher &w)
38 {
39 // should never get called
40 // reached end-of-time, or tstamp has a bogus definition,
41 // or compiler initilization order broken, or somethine else :)
42 abort ();
43 }
44
45 tw0()
46 : time_watcher (this, &tw0::cb)
47 { }
48} tw0;
49
34tstamp NOW; 50tstamp NOW;
35static bool iom_valid; 51static bool iom_valid;
36io_manager iom; 52io_manager iom;
37 53
38template<class watcher> 54template<class watcher>
39void io_manager::reg (watcher *w, simplevec<watcher *> &queue) 55void io_manager::reg (watcher *w, io_manager_vec<watcher> &queue)
40{ 56{
41 if (!iom_valid) 57 if (!iom_valid)
42 abort (); 58 abort ();
43 59
44 if (!w->active) 60 if (!w->active)
47 w->active = queue.size (); 63 w->active = queue.size ();
48 } 64 }
49} 65}
50 66
51template<class watcher> 67template<class watcher>
52void io_manager::unreg (watcher *w, simplevec<watcher *> &queue) 68void io_manager::unreg (watcher *w, io_manager_vec<watcher> &queue)
53{ 69{
54 if (!iom_valid) 70 if (!iom_valid)
55 return; 71 return;
56 72
57 if (w->active) 73 if (w->active)
142 tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); 158 tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000);
143 to = &tval; 159 to = &tval;
144 } 160 }
145 break; 161 break;
146 } 162 }
147 else if (next->at >= 0) 163 else
148 { 164 {
149 unreg (next); 165 unreg (next);
150 next->call (*next); 166 next->call (*next);
151 } 167 }
152 } 168 }
167 FD_ZERO (&rfd); 183 FD_ZERO (&rfd);
168 FD_ZERO (&wfd); 184 FD_ZERO (&wfd);
169 185
170 int fds = 0; 186 int fds = 0;
171 187
172 for (io_watcher **i = iow.end (); i-- > iow.begin (); ) 188 for (io_manager_vec<io_watcher>::iterator i = iow.end (); i-- > iow.begin (); )
173 if (*i) 189 if (*i)
174 { 190 {
175 if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd); 191 if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd);
176 if ((*i)->events & EVENT_WRITE) FD_SET ((*i)->fd, &wfd); 192 if ((*i)->events & EVENT_WRITE) FD_SET ((*i)->fd, &wfd);
177 193
224 break; 240 break;
225#endif 241#endif
226 } 242 }
227} 243}
228 244
229// this is a dummy time watcher to ensure that the first
230// time watcher is _always_ valid, this gets rid of a lot
231// of null-pointer-checks
232static struct tw0 : time_watcher {
233 void cb (time_watcher &w)
234 {
235 // should never get called
236 // reached end-of-time, or tstamp has a bogus definition :)
237 abort ();
238 }
239
240 tw0()
241 : time_watcher (this, &tw0::cb)
242 { }
243} tw0;
244
245io_manager::io_manager () 245io_manager::io_manager ()
246{ 246{
247 iom_valid = true; 247 iom_valid = true;
248 248
249#if IOM_TIME 249#if IOM_TIME
250 set_now (); 250 set_now ();
251 251
252 tw0.start (TSTAMP_MAX); 252 tw0.start (TSTAMP_MAX);
253 printf ("abort, %f but inly on %f\n", NOW, tw0.at);
253#endif 254#endif
254} 255}
255 256
256io_manager::~io_manager () 257io_manager::~io_manager ()
257{ 258{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines