comparison src/event/modules/ngx_rtsig_module.c @ 305:4b1a3a4acc60

nginx-0.0.3-2004-04-02-19:13:20 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 02 Apr 2004 15:13:20 +0000
parents 8c5bdde0d9f0
children 6b91bfbc4123
comparison
equal deleted inserted replaced
304:bcbe876f4262 305:4b1a3a4acc60
37 37
38 static int ngx_rtsig_init(ngx_cycle_t *cycle); 38 static int ngx_rtsig_init(ngx_cycle_t *cycle);
39 static void ngx_rtsig_done(ngx_cycle_t *cycle); 39 static void ngx_rtsig_done(ngx_cycle_t *cycle);
40 static int ngx_rtsig_add_connection(ngx_connection_t *c); 40 static int ngx_rtsig_add_connection(ngx_connection_t *c);
41 static int ngx_rtsig_del_connection(ngx_connection_t *c, u_int flags); 41 static int ngx_rtsig_del_connection(ngx_connection_t *c, u_int flags);
42 static int ngx_rtsig_process_events(ngx_log_t *log); 42 static int ngx_rtsig_process_events(ngx_cycle_t *cycle);
43 static int ngx_rtsig_process_overflow(ngx_log_t *log); 43 static int ngx_rtsig_process_overflow(ngx_cycle_t *cycle);
44 44
45 static void *ngx_rtsig_create_conf(ngx_cycle_t *cycle); 45 static void *ngx_rtsig_create_conf(ngx_cycle_t *cycle);
46 static char *ngx_rtsig_init_conf(ngx_cycle_t *cycle, void *conf); 46 static char *ngx_rtsig_init_conf(ngx_cycle_t *cycle, void *conf);
47 47
48 48
186 186
187 return NGX_OK; 187 return NGX_OK;
188 } 188 }
189 189
190 190
191 int ngx_rtsig_process_events(ngx_log_t *log) 191 int ngx_rtsig_process_events(ngx_cycle_t *cycle)
192 { 192 {
193 int signo; 193 int signo;
194 ngx_int_t instance, i; 194 ngx_int_t instance, i;
195 size_t n; 195 size_t n;
196 ngx_msec_t timer; 196 ngx_msec_t timer;
197 ngx_err_t err; 197 ngx_err_t err;
198 ngx_cycle_t **cycle;
199 siginfo_t si; 198 siginfo_t si;
200 struct timeval tv; 199 struct timeval tv;
201 struct timespec ts, *tp; 200 struct timespec ts, *tp;
202 struct sigaction sa; 201 struct sigaction sa;
203 ngx_connection_t *c; 202 ngx_connection_t *c;
214 213
215 } else { 214 } else {
216 tp = NULL; 215 tp = NULL;
217 } 216 }
218 217
219 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "rtsig timer: %d", timer); 218 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
219 "rtsig timer: %d", timer);
220 220
221 /* Linux sigwaitinfo() is sigtimedwait() with the NULL timeout pointer */ 221 /* Linux sigwaitinfo() is sigtimedwait() with the NULL timeout pointer */
222 222
223 signo = sigtimedwait(&set, &si, tp); 223 signo = sigtimedwait(&set, &si, tp);
224 224
234 delta = ngx_elapsed_msec; 234 delta = ngx_elapsed_msec;
235 ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec; 235 ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec;
236 236
237 if (err) { 237 if (err) {
238 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, 238 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
239 log, err, "sigtimedwait() failed"); 239 cycle->log, err, "sigtimedwait() failed");
240 return NGX_ERROR; 240 return NGX_ERROR;
241 } 241 }
242 242
243 if (timer) { 243 if (timer) {
244 delta = ngx_elapsed_msec - delta; 244 delta = ngx_elapsed_msec - delta;
245 245
246 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, 246 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
247 "rtsig timer: %d, delta: %d", timer, (int) delta); 247 "rtsig timer: %d, delta: %d", timer, (int) delta);
248 } 248 }
249 249
250 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, 250 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
251 "signo:%d fd:%d band:%X", signo, si.si_fd, si.si_band); 251 "signo:%d fd:%d band:%X", signo, si.si_fd, si.si_band);
252 252
253 rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module); 253 rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module);
254 254
255 if (signo == rtscf->signo) { 255 if (signo == rtscf->signo) {
256 256
257 /* TODO: old_cycles */ 257 /* TODO: old_cycles */
258
258 c = &ngx_cycle->connections[si.si_fd]; 259 c = &ngx_cycle->connections[si.si_fd];
259 260
260 /* TODO: stale signals */ 261 /* TODO: stale signals */
261 262
262 if (si.si_band & (POLLIN|POLLHUP|POLLERR)) { 263 if (si.si_band & (POLLIN|POLLHUP|POLLERR)) {
272 c->write->event_handler(c->write); 273 c->write->event_handler(c->write);
273 } 274 }
274 } 275 }
275 276
276 } else if (signo == SIGIO) { 277 } else if (signo == SIGIO) {
277 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 278 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
278 "signal queue overflowed: " 279 "signal queue overflowed: "
279 "SIGIO, fd:%d, band:%X", si.si_fd, si.si_band); 280 "SIGIO, fd:%d, band:%X", si.si_fd, si.si_band);
280 281
281 /* TODO: flush all the used RT signals */ 282 /* TODO: flush all the used RT signals */
282 283
283 ngx_memzero(&sa, sizeof(struct sigaction)); 284 ngx_memzero(&sa, sizeof(struct sigaction));
284 sa.sa_handler = SIG_DFL; 285 sa.sa_handler = SIG_DFL;
285 sigemptyset(&sa.sa_mask); 286 sigemptyset(&sa.sa_mask);
286 if (sigaction(rtscf->signo, &sa, NULL) == -1) { 287 if (sigaction(rtscf->signo, &sa, NULL) == -1) {
287 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 288 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
288 "sigaction(%d, SIG_DFL) failed", rtscf->signo); 289 "sigaction(%d, SIG_DFL) failed", rtscf->signo);
289 } 290 }
290 291
291 ngx_event_actions = ngx_poll_module_ctx.actions; 292 ngx_event_actions = ngx_poll_module_ctx.actions;
292 ngx_event_actions.process = ngx_rtsig_process_overflow; 293 ngx_event_actions.process = ngx_rtsig_process_overflow;
295 296
296 /* STUB: add events. WHAT to do with fcntl()s ? */ 297 /* STUB: add events. WHAT to do with fcntl()s ? */
297 298
298 299
299 } else { 300 } else {
300 ngx_log_error(NGX_LOG_ALERT, log, 0, 301 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
301 "sigtimedwait() returned unexpected signal: %d", signo); 302 "sigtimedwait() returned unexpected signal: %d", signo);
302 return NGX_ERROR; 303 return NGX_ERROR;
303 } 304 }
304 305
305 if (timer != (ngx_msec_t) -1 && delta) { 306 if (timer != (ngx_msec_t) -1 && delta) {
308 309
309 return NGX_OK; 310 return NGX_OK;
310 } 311 }
311 312
312 313
313 static int ngx_rtsig_process_overflow(ngx_log_t *log) 314 static int ngx_rtsig_process_overflow(ngx_cycle_t *cycle)
314 { 315 {
315 if (ngx_poll_module_ctx.actions.process(log) == NGX_OK) { 316 if (ngx_poll_module_ctx.actions.process(cycle) == NGX_OK) {
316 ngx_event_actions = ngx_rtsig_module_ctx.actions; 317 ngx_event_actions = ngx_rtsig_module_ctx.actions;
317 ngx_event_flags = NGX_USE_SIGIO_EVENT; 318 ngx_event_flags = NGX_USE_SIGIO_EVENT;
318 } 319 }
319 320
320 return NGX_OK; 321 return NGX_OK;