Mercurial > hg > nginx
comparison src/event/modules/ngx_sigio_module.c @ 247:008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 01 Feb 2004 08:10:52 +0000 |
parents | 6753e8cdaa2c |
children |
comparison
equal
deleted
inserted
replaced
246:6753e8cdaa2c | 247:008276b9e061 |
---|---|
11 | 11 |
12 #if (TEST_BUILD_SIGIO) | 12 #if (TEST_BUILD_SIGIO) |
13 | 13 |
14 #define F_SETSIG 10 | 14 #define F_SETSIG 10 |
15 | 15 |
16 #define POLL_IN POLLIN | |
17 #define POLL_OUT POLLOUT | |
18 | |
16 #endif | 19 #endif |
17 | 20 |
18 | 21 |
19 typedef struct { | 22 typedef struct { |
20 int signal; | 23 int signo; |
21 } ngx_sigio_conf_t; | 24 } ngx_sigio_conf_t; |
22 | 25 |
23 | 26 |
24 static int ngx_sigio_init(ngx_cycle_t *cycle); | 27 static int ngx_sigio_init(ngx_cycle_t *cycle); |
25 static void ngx_sigio_done(ngx_cycle_t *cycle); | 28 static void ngx_sigio_done(ngx_cycle_t *cycle); |
42 | 45 |
43 {ngx_string("sigio_signal"), | 46 {ngx_string("sigio_signal"), |
44 NGX_EVENT_CONF|NGX_CONF_TAKE1, | 47 NGX_EVENT_CONF|NGX_CONF_TAKE1, |
45 ngx_conf_set_num_slot, | 48 ngx_conf_set_num_slot, |
46 0, | 49 0, |
47 offsetof(ngx_sigio_conf_t, signal), | 50 offsetof(ngx_sigio_conf_t, signo), |
48 NULL}, | 51 NULL}, |
49 | 52 |
50 ngx_null_command | 53 ngx_null_command |
51 }; | 54 }; |
52 | 55 |
85 ngx_sigio_conf_t *sgcf; | 88 ngx_sigio_conf_t *sgcf; |
86 | 89 |
87 sgcf = ngx_event_get_conf(cycle->conf_ctx, ngx_sigio_module); | 90 sgcf = ngx_event_get_conf(cycle->conf_ctx, ngx_sigio_module); |
88 | 91 |
89 sigemptyset(&set); | 92 sigemptyset(&set); |
90 sigaddset(&set, sgcf->signal); | 93 sigaddset(&set, sgcf->signo); |
91 sigaddset(&set, SIGIO); | 94 sigaddset(&set, SIGIO); |
92 | 95 |
93 if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { | 96 if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { |
94 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | 97 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
95 "sigprocmask() failed"); | 98 "sigprocmask() failed"); |
142 ngx_sigio_conf_t *sgcf; | 145 ngx_sigio_conf_t *sgcf; |
143 | 146 |
144 sgcf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_sigio_module); | 147 sgcf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_sigio_module); |
145 | 148 |
146 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | 149 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
147 "sigio add connection: fd:%d signo:%d", c->fd, sgcf->signal); | 150 "sigio add connection: fd:%d signo:%d", c->fd, sgcf->signo); |
148 | 151 |
149 if (fcntl(c->fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC) == -1) { | 152 if (fcntl(c->fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC) == -1) { |
150 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, | 153 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, |
151 "fcntl(O_RDWR|O_NONBLOCK|O_ASYNC) failed"); | 154 "fcntl(O_RDWR|O_NONBLOCK|O_ASYNC) failed"); |
152 return NGX_ERROR; | 155 return NGX_ERROR; |
153 } | 156 } |
154 | 157 |
155 if (fcntl(c->fd, F_SETSIG, sgcf->signal) == -1) { | 158 if (fcntl(c->fd, F_SETSIG, sgcf->signo) == -1) { |
156 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, | 159 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, |
157 "fcntl(F_SETSIG) failed"); | 160 "fcntl(F_SETSIG) failed"); |
158 return NGX_ERROR; | 161 return NGX_ERROR; |
159 } | 162 } |
160 | 163 |
197 ngx_err_t err; | 200 ngx_err_t err; |
198 ngx_cycle_t **cycle; | 201 ngx_cycle_t **cycle; |
199 siginfo_t si; | 202 siginfo_t si; |
200 struct timeval tv; | 203 struct timeval tv; |
201 struct timespec ts; | 204 struct timespec ts; |
205 struct sigaction sa; | |
202 ngx_connection_t *c; | 206 ngx_connection_t *c; |
203 ngx_epoch_msec_t delta; | 207 ngx_epoch_msec_t delta; |
204 ngx_sigio_conf_t *sgcf; | 208 ngx_sigio_conf_t *sgcf; |
205 | 209 |
206 timer = ngx_event_find_timer(); | 210 timer = ngx_event_find_timer(); |
244 "sigio timer: %d, delta: %d", timer, (int) delta); | 248 "sigio timer: %d, delta: %d", timer, (int) delta); |
245 } | 249 } |
246 | 250 |
247 sgcf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_sigio_module); | 251 sgcf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_sigio_module); |
248 | 252 |
249 if (signo == sgcf->signal) { | 253 if (signo == sgcf->signo) { |
250 | 254 |
251 /* STUB: old_cycles */ | 255 /* STUB: old_cycles */ |
252 c = &ngx_connections[si.si_fd]; | 256 c = &ngx_cycle->connections[si.si_fd]; |
253 | 257 |
254 if (si.si_band & EPOLLIN) { | 258 if (si.si_band & POLL_IN) { |
259 if (!c->read->active) { | |
260 continue; | |
261 } | |
262 | |
263 c->read->ready = 1; | |
264 c->read->event_handler(c->read); | |
265 } | |
266 | |
267 if (si.si_band & POLL_OUT) { | |
255 if (!c->read->active) { | 268 if (!c->read->active) { |
256 continue; | 269 continue; |
257 } | 270 } |
258 | 271 |
259 c->read->ready = 1; | 272 c->read->ready = 1; |
262 | 275 |
263 } else if (signo == SIGIO) { | 276 } else if (signo == SIGIO) { |
264 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 277 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
265 "signal queue overflowed: " | 278 "signal queue overflowed: " |
266 "SIGIO, fd:%d, band:%d", si.si_fd, si.si_band); | 279 "SIGIO, fd:%d, band:%d", si.si_fd, si.si_band); |
280 | |
281 ngx_memzero(&sa, sizeof(struct sigaction)); | |
282 sa.sa_sigaction = SIG_DFL; | |
283 sigemptyset(&sa.sa_mask); | |
284 if (sigaction(sgcf->signo, &sa, NULL) == -1) { | |
285 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | |
286 "sigaction queue overflowed: " | |
287 "SIGIO, fd:%d, band:%d", si.si_fd, si.si_band); | |
288 } | |
267 | 289 |
268 } else { | 290 } else { |
269 ngx_log_error(NGX_LOG_ALERT, log, 0, | 291 ngx_log_error(NGX_LOG_ALERT, log, 0, |
270 timer ? "sigtimedwait() returned unexpected signal: %d": | 292 timer ? "sigtimedwait() returned unexpected signal: %d": |
271 "sigwaitinfo() returned unexpected signal: %d", | 293 "sigwaitinfo() returned unexpected signal: %d", |
348 | 370 |
349 static char *ngx_sigio_init_conf(ngx_cycle_t *cycle, void *conf) | 371 static char *ngx_sigio_init_conf(ngx_cycle_t *cycle, void *conf) |
350 { | 372 { |
351 ngx_sigio_conf_t *sgcf = conf; | 373 ngx_sigio_conf_t *sgcf = conf; |
352 | 374 |
353 ngx_conf_init_unsigned_value(sgcf->signal, SIGRTMIN); | 375 /* LinuxThreads uses the first 3 RT signals */ |
376 ngx_conf_init_unsigned_value(sgcf->signo, SIGRTMIN + 10); | |
354 | 377 |
355 return NGX_CONF_OK; | 378 return NGX_CONF_OK; |
356 } | 379 } |