comparison src/event/modules/ngx_select_module.c @ 106:45f7329b4bd0 NGINX_0_3_0

nginx 0.3.0 *) Change: the 10-days live time limit of worker process was eliminated. The limit was introduced because of millisecond timers overflow.
author Igor Sysoev <http://sysoev.ru>
date Fri, 07 Oct 2005 00:00:00 +0400
parents 71c46860eb55
children 408f195b3482
comparison
equal deleted inserted replaced
105:531d62c2a28d 106:45f7329b4bd0
263 263
264 static ngx_int_t 264 static ngx_int_t
265 ngx_select_process_events(ngx_cycle_t *cycle) 265 ngx_select_process_events(ngx_cycle_t *cycle)
266 { 266 {
267 int ready, nready; 267 int ready, nready;
268 ngx_uint_t i, found, lock, expire; 268 ngx_uint_t i, found, lock;
269 ngx_err_t err; 269 ngx_err_t err;
270 ngx_msec_t timer; 270 ngx_msec_t timer, delta;
271 ngx_event_t *ev; 271 ngx_event_t *ev;
272 ngx_connection_t *c; 272 ngx_connection_t *c;
273 ngx_epoch_msec_t delta;
274 struct timeval tv, *tp; 273 struct timeval tv, *tp;
275 #if (NGX_HAVE_SELECT_CHANGE_TIMEOUT) 274 #if (NGX_HAVE_SELECT_CHANGE_TIMEOUT)
276 static ngx_epoch_msec_t deltas = 0; 275 static ngx_msec_t deltas = 0;
277 #endif 276 #endif
278 277
279 for ( ;; ) { 278 timer = ngx_event_find_timer();
280 timer = ngx_event_find_timer();
281
282 if (timer != 0) {
283 break;
284 }
285
286 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
287 "select expired timer");
288
289 ngx_event_expire_timers((ngx_msec_t)
290 (ngx_elapsed_msec - ngx_old_elapsed_msec));
291 }
292
293 ngx_old_elapsed_msec = ngx_elapsed_msec;
294
295 expire = 1;
296 279
297 #if !(NGX_WIN32) 280 #if !(NGX_WIN32)
298 281
299 if (ngx_accept_mutex) { 282 if (ngx_accept_mutex) {
300 if (ngx_accept_disabled > 0) { 283 if (ngx_accept_disabled > 0) {
308 if (ngx_accept_mutex_held == 0 291 if (ngx_accept_mutex_held == 0
309 && (timer == NGX_TIMER_INFINITE 292 && (timer == NGX_TIMER_INFINITE
310 || timer > ngx_accept_mutex_delay)) 293 || timer > ngx_accept_mutex_delay))
311 { 294 {
312 timer = ngx_accept_mutex_delay; 295 timer = ngx_accept_mutex_delay;
313 expire = 0;
314 } 296 }
315 } 297 }
316 } 298 }
317 299
318 if (max_fd == -1) { 300 if (max_fd == -1) {
345 } 327 }
346 #endif 328 #endif
347 329
348 if (timer == NGX_TIMER_INFINITE) { 330 if (timer == NGX_TIMER_INFINITE) {
349 tp = NULL; 331 tp = NULL;
350 expire = 0;
351 332
352 } else { 333 } else {
353 tv.tv_sec = timer / 1000; 334 tv.tv_sec = (long) (timer / 1000);
354 tv.tv_usec = (timer % 1000) * 1000; 335 tv.tv_usec = (long) ((timer % 1000) * 1000);
355 tp = &tv; 336 tp = &tv;
356 } 337 }
357 338
358 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 339 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
359 "select timer: %d", timer); 340 "select timer: %M", timer);
360 341
361 work_read_fd_set = master_read_fd_set; 342 work_read_fd_set = master_read_fd_set;
362 work_write_fd_set = master_write_fd_set; 343 work_write_fd_set = master_write_fd_set;
363 344
364 #if 1 345 #if 1
384 } 365 }
385 366
386 #if (NGX_HAVE_SELECT_CHANGE_TIMEOUT) 367 #if (NGX_HAVE_SELECT_CHANGE_TIMEOUT)
387 368
388 if (timer != NGX_TIMER_INFINITE) { 369 if (timer != NGX_TIMER_INFINITE) {
389 delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000); 370 delta = timer - ((ngx_msec_t) tv.tv_sec * 1000 + tv.tv_usec / 1000);
390 371
391 /* 372 /*
392 * learn the real time and update the cached time 373 * learn the real time and update the cached time
393 * if the sum of the last deltas overcomes 1 second 374 * if the sum of the last deltas overcomes 1 second
394 */ 375 */
397 if (deltas > 1000) { 378 if (deltas > 1000) {
398 ngx_gettimeofday(&tv); 379 ngx_gettimeofday(&tv);
399 ngx_time_update(tv.tv_sec); 380 ngx_time_update(tv.tv_sec);
400 deltas = tv.tv_usec / 1000; 381 deltas = tv.tv_usec / 1000;
401 382
402 ngx_elapsed_msec = (ngx_epoch_msec_t) tv.tv_sec * 1000 383 ngx_current_time = (ngx_msec_t) tv.tv_sec * 1000
403 + tv.tv_usec / 1000 - ngx_start_msec; 384 + tv.tv_usec / 1000;
404 } else { 385 } else {
405 ngx_elapsed_msec += delta; 386 ngx_current_time += delta;
406 } 387 }
407 388
408 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 389 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
409 "select timer: %d, delta: %d", timer, (int) delta); 390 "select timer: %M, delta: %M", timer, delta);
410 391
411 } else { 392 } else {
412 delta = 0; 393 deltas = 0;
394
413 ngx_gettimeofday(&tv); 395 ngx_gettimeofday(&tv);
414 ngx_time_update(tv.tv_sec); 396 ngx_time_update(tv.tv_sec);
415 397
416 ngx_elapsed_msec = (ngx_epoch_msec_t) tv.tv_sec * 1000 398 delta = ngx_current_time;
417 + tv.tv_usec / 1000 - ngx_start_msec; 399 ngx_current_time = (ngx_msec_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
418 400
419 if (ready == 0) { 401 if (ready == 0) {
420 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 402 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
421 "select() returned no events without timeout"); 403 "select() returned no events without timeout");
422 ngx_accept_mutex_unlock(); 404 ngx_accept_mutex_unlock();
427 #else /* !(NGX_HAVE_SELECT_CHANGE_TIMEOUT) */ 409 #else /* !(NGX_HAVE_SELECT_CHANGE_TIMEOUT) */
428 410
429 ngx_gettimeofday(&tv); 411 ngx_gettimeofday(&tv);
430 ngx_time_update(tv.tv_sec); 412 ngx_time_update(tv.tv_sec);
431 413
432 delta = ngx_elapsed_msec; 414 delta = ngx_current_time;
433 ngx_elapsed_msec = (ngx_epoch_msec_t) tv.tv_sec * 1000 415 ngx_current_time = (ngx_msec_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
434 + tv.tv_usec / 1000 - ngx_start_msec;
435 416
436 if (timer != NGX_TIMER_INFINITE) { 417 if (timer != NGX_TIMER_INFINITE) {
437 delta = ngx_elapsed_msec - delta; 418 delta = ngx_current_time - delta;
438 419
439 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 420 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
440 "select timer: %d, delta: %d", timer, (int) delta); 421 "select timer: %M, delta: %M", timer, delta);
441 422
442 } else { 423 } else {
443 if (ready == 0) { 424 if (ready == 0) {
444 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 425 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
445 "select() returned no events without timeout"); 426 "select() returned no events without timeout");
592 573
593 if (ready != nready) { 574 if (ready != nready) {
594 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "select ready != events"); 575 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "select ready != events");
595 } 576 }
596 577
597 if (expire && delta) { 578 ngx_event_expire_timers();
598 ngx_event_expire_timers((ngx_msec_t) delta);
599 }
600 579
601 if (!ngx_threaded) { 580 if (!ngx_threaded) {
602 ngx_event_process_posted(cycle); 581 ngx_event_process_posted(cycle);
603 } 582 }
604 583