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.12 by pcg, Thu Jan 29 23:26:01 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
24#include <sys/time.h>
25
26#if 1 // older unices need these includes for select(2)
27# include <unistd.h>
28# include <sys/types.h>
29#endif
30
31// if the BSDs would at least be marginally POSIX-compatible.. *sigh*
32// until that happens, sys/select.h must come last
26#include <sys/select.h> 33#include <sys/select.h>
27#include <sys/time.h>
28 34
29#include "iom.h" 35#include "iom.h"
30 36
31// TSTAMP_MAX must still fit into a positive struct timeval 37// TSTAMP_MAX must still fit into a positive struct timeval
32#define TSTAMP_MAX (double)(1UL<<31) 38#define TSTAMP_MAX (double)(1UL<<31)
39
40// this is a dummy time watcher to ensure that the first
41// time watcher is _always_ valid, this gets rid of a lot
42// of null-pointer-checks
43// (must come _before_ iom is being defined)
44static struct tw0 : time_watcher {
45 void cb (time_watcher &w)
46 {
47 // should never get called
48 // reached end-of-time, or tstamp has a bogus definition,
49 // or compiler initilization order broken, or somethine else :)
50 abort ();
51 }
52
53 tw0()
54 : time_watcher (this, &tw0::cb)
55 { }
56} tw0;
33 57
34tstamp NOW; 58tstamp NOW;
35static bool iom_valid; 59static bool iom_valid;
36io_manager iom; 60io_manager iom;
37 61
38template<class watcher> 62template<class watcher>
39void io_manager::reg (watcher *w, simplevec<watcher *> &queue) 63void io_manager::reg (watcher *w, io_manager_vec<watcher> &queue)
40{ 64{
41 if (!iom_valid) 65 if (!iom_valid)
42 abort (); 66 abort ();
43 67
44 if (!w->active) 68 if (!w->active)
45 { 69 {
70#if IOM_CHECK
71 queue.activity = true;
72#endif
46 queue.push_back (w); 73 queue.push_back (w);
47 w->active = queue.size (); 74 w->active = queue.size ();
48 } 75 }
49} 76}
50 77
51template<class watcher> 78template<class watcher>
52void io_manager::unreg (watcher *w, simplevec<watcher *> &queue) 79void io_manager::unreg (watcher *w, io_manager_vec<watcher> &queue)
53{ 80{
54 if (!iom_valid) 81 if (!iom_valid)
55 return; 82 return;
56 83
57 if (w->active) 84 if (w->active)
142 tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); 169 tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000);
143 to = &tval; 170 to = &tval;
144 } 171 }
145 break; 172 break;
146 } 173 }
147 else if (next->at >= 0) 174 else
148 { 175 {
149 unreg (next); 176 unreg (next);
150 next->call (*next); 177 next->call (*next);
151 } 178 }
152 } 179 }
153#endif 180#endif
154 } 181 }
155 182
156#if IOM_CHECK 183#if IOM_CHECK
184 tw.activity = false;
185
157 for (int i = cw.size (); i--; ) 186 for (int i = cw.size (); i--; )
158 if (!cw[i]) 187 if (!cw[i])
159 cw.erase_unordered (i); 188 cw.erase_unordered (i);
160 else 189 else
161 cw[i]->call (*cw[i]); 190 cw[i]->call (*cw[i]);
191
192 if (tw.activity)
193 {
194 tval.tv_sec = 0;
195 tval.tv_usec = 0;
196 to = &tval;
197 }
162#endif 198#endif
163 199
164#if IOM_IO 200#if IOM_IO
165 fd_set rfd, wfd, efd; 201 fd_set rfd, wfd, efd;
166 202
167 FD_ZERO (&rfd); 203 FD_ZERO (&rfd);
168 FD_ZERO (&wfd); 204 FD_ZERO (&wfd);
169 205
170 int fds = 0; 206 int fds = 0;
171 207
172 for (io_watcher **i = iow.end (); i-- > iow.begin (); ) 208 for (io_manager_vec<io_watcher>::iterator i = iow.end (); i-- > iow.begin (); )
173 if (*i) 209 if (*i)
174 { 210 {
175 if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd); 211 if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd);
176 if ((*i)->events & EVENT_WRITE) FD_SET ((*i)->fd, &wfd); 212 if ((*i)->events & EVENT_WRITE) FD_SET ((*i)->fd, &wfd);
177 213
224 break; 260 break;
225#endif 261#endif
226 } 262 }
227} 263}
228 264
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 () 265io_manager::io_manager ()
246{ 266{
247 iom_valid = true; 267 iom_valid = true;
248 268
249#if IOM_TIME 269#if IOM_TIME

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines