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.15 by pcg, Sun Mar 28 02:07:08 2004 UTC vs.
Revision 1.16 by pcg, Fri Apr 2 14:30:06 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#include <assert.h>
27
26#if 1 // older unices need these includes for select (2) 28#if 1 // older unices need these includes for select (2)
27# include <unistd.h> 29# include <unistd.h>
28# include <sys/types.h> 30# include <sys/types.h>
29#endif 31#endif
30 32
31// if the BSDs would at least be marginally POSIX-compatible.. *sigh* 33// if the BSDs would at least be marginally POSIX-compatible.. *sigh*
32// until that happens, sys/select.h must come last 34// until that happens, sys/select.h must come last
33#include <sys/select.h> 35#include <sys/select.h>
36
37// for IOM_SIG
38#include <signal.h>
34 39
35#include "iom.h" 40#include "iom.h"
36 41
37// TSTAMP_MAX must still fit into a positive struct timeval 42// TSTAMP_MAX must still fit into a positive struct timeval
38#define TSTAMP_MAX (double)(1UL<<31) 43#define TSTAMP_MAX (double)(1UL<<31)
51 abort (); 56 abort ();
52 } 57 }
53 58
54 tw0 () 59 tw0 ()
55 : time_watcher (this, &tw0::cb) 60 : time_watcher (this, &tw0::cb)
56 { }} 61 { }
57tw0; 62 } tw0;
58 63
59tstamp NOW; 64tstamp NOW;
60static bool iom_valid; 65static bool iom_valid;
61io_manager iom; 66io_manager iom;
62 67
122 struct timeval tv; 127 struct timeval tv;
123 128
124 gettimeofday (&tv, 0); 129 gettimeofday (&tv, 0);
125 130
126 NOW = (tstamp)tv.tv_sec + (tstamp)tv.tv_usec / 1000000; 131 NOW = (tstamp)tv.tv_sec + (tstamp)tv.tv_usec / 1000000;
127#endif
128} 132}
133#endif
129 134
135#if IOM_SIG
136// race conditions galore
137
138void io_manager::sighandler (int signum)
139{
140 assert (0 < signum && signum <= iom.sw.size ());
141
142 sig_vec &sv = *iom.sw [signum - 1];
143
144 for (int i = sv.size (); i--; )
145 if (!sv[i])
146 sv.erase_unordered (i);
147 else
148 sv[i]->call (*sv[i]);
149}
150
151void io_manager::reg (sig_watcher *w)
152{
153 assert (0 < w->signum);
154
155 sw.reserve (w->signum);
156
157 sig_vec *&sv = sw [w->signum - 1];
158
159 if (!sv)
160 {
161 sv = new sig_vec;
162
163 struct sigaction sa;
164 sa.sa_handler = io_manager::sighandler;
165 sigfillset (&sa.sa_mask);
166 sa.sa_flags = 0;
167
168 if (sigaction (w->signum, &sa, 0))
169 {
170 perror ("Error while installing signal handler");
171 abort ();
172 }
173 }
174
175 reg (w, *sv);
176}
177
178void io_manager::unreg (sig_watcher *w)
179{
180 assert (0 < w->signum && w->signum <= sw.size ());
181
182 unreg (w, *sw [w->signum - 1]);
183}
184
185void sig_watcher::start (int signum)
186{
187 stop ();
188 this->signum = signum;
189 iom.reg (this);
190}
191#endif
192
130void io_manager::loop () 193void io_manager::loop ()
131{ 194{
132#if IOM_TIME 195#if IOM_TIME
133 set_now (); 196 set_now ();
134#endif 197#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines