comparison src/event/modules/ngx_select_module.c @ 316:a0beefedaf94

nginx-0.0.3-2004-04-15-00:34:05 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 14 Apr 2004 20:34:05 +0000
parents 39b6f2df45c0
children 1308b98496a2
comparison
equal deleted inserted replaced
315:39b6f2df45c0 316:a0beefedaf94
261 struct timeval tv, *tp; 261 struct timeval tv, *tp;
262 #if (HAVE_SELECT_CHANGE_TIMEOUT) 262 #if (HAVE_SELECT_CHANGE_TIMEOUT)
263 static ngx_epoch_msec_t deltas = 0; 263 static ngx_epoch_msec_t deltas = 0;
264 #endif 264 #endif
265 265
266 timer = ngx_event_find_timer(); 266 for ( ;; ) {
267 timer = ngx_event_find_timer();
268
269 if (timer != 0) {
270 break;
271 }
272
273 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
274 "select expired timer");
275
276 ngx_event_expire_timers(0);
277 }
278
267 ngx_old_elapsed_msec = ngx_elapsed_msec; 279 ngx_old_elapsed_msec = ngx_elapsed_msec;
268 280
269 expire = 1; 281 expire = 1;
270 282
271 #if !(WIN32) 283 #if !(WIN32)
274 if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) { 286 if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) {
275 return NGX_ERROR; 287 return NGX_ERROR;
276 } 288 }
277 289
278 if (ngx_accept_mutex_held == 0 290 if (ngx_accept_mutex_held == 0
279 && (timer == 0 || timer > ngx_accept_mutex_delay)) 291 && (timer == NGX_TIMER_INFINITE || timer > ngx_accept_mutex_delay))
280 { 292 {
281 timer = ngx_accept_mutex_delay; 293 timer = ngx_accept_mutex_delay;
282 expire = 0; 294 expire = 0;
283 } 295 }
284 } 296 }
304 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 316 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
305 "select event: fd:%d wr:%d", c->fd, ev->write); 317 "select event: fd:%d wr:%d", c->fd, ev->write);
306 } 318 }
307 #endif 319 #endif
308 320
309 if (timer == -1) { 321 if (timer == NGX_TIMER_INFINITE) {
310 tv.tv_sec = 0; 322 tp = NULL;
311 tv.tv_usec = 0; 323 expire = 0;
312 tp = &tv; 324
313 325 } else {
314 } else if (timer) {
315 tv.tv_sec = timer / 1000; 326 tv.tv_sec = timer / 1000;
316 tv.tv_usec = (timer % 1000) * 1000; 327 tv.tv_usec = (timer % 1000) * 1000;
317 tp = &tv; 328 tp = &tv;
318
319 } else {
320 tp = NULL;
321 expire = 0;
322 } 329 }
323 330
324 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 331 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
325 "select timer: %d", timer); 332 "select timer: %d", timer);
326 333
342 err = 0; 349 err = 0;
343 } 350 }
344 351
345 #if (HAVE_SELECT_CHANGE_TIMEOUT) 352 #if (HAVE_SELECT_CHANGE_TIMEOUT)
346 353
347 if (timer) { 354 if (timer != NGX_TIMER_INFINITE) {
348 delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000); 355 delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000);
349 356
350 /* 357 /*
351 * learn the real time and update the cached time 358 * learn the real time and update the cached time
352 * if the sum of the last deltas overcomes 1 second 359 * if the sum of the last deltas overcomes 1 second
381 ngx_time_update(tv.tv_sec); 388 ngx_time_update(tv.tv_sec);
382 389
383 delta = ngx_elapsed_msec; 390 delta = ngx_elapsed_msec;
384 ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec; 391 ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec;
385 392
386 if (timer) { 393 if (timer != NGX_TIMER_INFINITE) {
387 delta = ngx_elapsed_msec - delta; 394 delta = ngx_elapsed_msec - delta;
388 395
389 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 396 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
390 "select timer: %d, delta: %d", timer, (int) delta); 397 "select timer: %d, delta: %d", timer, (int) delta);
391 398