comparison src/event/modules/ngx_select_module.c @ 315:39b6f2df45c0

nginx-0.0.3-2004-04-14-21:44:28 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 14 Apr 2004 17:44:28 +0000
parents d71c87d11b16
children a0beefedaf94
comparison
equal deleted inserted replaced
314:d71c87d11b16 315:39b6f2df45c0
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 work_read_fd_set = master_read_fd_set;
267 work_write_fd_set = master_write_fd_set;
268
269 timer = ngx_event_find_timer(); 266 timer = ngx_event_find_timer();
270 ngx_old_elapsed_msec = ngx_elapsed_msec; 267 ngx_old_elapsed_msec = ngx_elapsed_msec;
271 268
272 if (timer) { 269 expire = 1;
273 tv.tv_sec = timer / 1000; 270
274 tv.tv_usec = (timer % 1000) * 1000; 271 #if !(WIN32)
275 tp = &tv; 272
276 expire = 1; 273 if (ngx_accept_mutex) {
277 274 if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) {
278 } else { 275 return NGX_ERROR;
279 tp = NULL; 276 }
280 expire = 0; 277
281 } 278 if (ngx_accept_mutex_held == 0
279 && (timer == 0 || timer > ngx_accept_mutex_delay))
280 {
281 timer = ngx_accept_mutex_delay;
282 expire = 0;
283 }
284 }
285
286 if (max_fd == -1) {
287 for (i = 0; i < nevents; i++) {
288 c = event_index[i]->data;
289 if (max_fd < c->fd) {
290 max_fd = c->fd;
291 }
292 }
293
294 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
295 "change max_fd: %d", max_fd);
296 }
297
298 #endif
282 299
283 #if (NGX_DEBUG) 300 #if (NGX_DEBUG)
284 for (i = 0; i < nevents; i++) { 301 for (i = 0; i < nevents; i++) {
285 ev = event_index[i]; 302 ev = event_index[i];
286 c = ev->data; 303 c = ev->data;
287 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 304 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
288 "select event: fd:%d wr:%d", c->fd,ev->write); 305 "select event: fd:%d wr:%d", c->fd, ev->write);
289 } 306 }
290 #endif 307 #endif
291 308
292 #if !(WIN32) 309 if (timer == -1) {
293 310 tv.tv_sec = 0;
294 if (max_fd == -1) { 311 tv.tv_usec = 0;
295 for (i = 0; i < nevents; i++) { 312 tp = &tv;
296 c = event_index[i]->data; 313
297 if (max_fd < c->fd) { 314 } else if (timer) {
298 max_fd = c->fd; 315 tv.tv_sec = timer / 1000;
299 } 316 tv.tv_usec = (timer % 1000) * 1000;
300 } 317 tp = &tv;
301 318
302 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 319 } else {
303 "change max_fd: %d", max_fd); 320 tp = NULL;
304 } 321 expire = 0;
305 322 }
306 if (ngx_accept_mutex) {
307 if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) {
308 return NGX_ERROR;
309 }
310
311 if (ngx_accept_mutex_held == 0 && timer > ngx_accept_mutex_delay) {
312 timer = ngx_accept_mutex_delay;
313 expire = 0;
314 }
315 }
316
317 #endif
318 323
319 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 324 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
320 "select timer: %d", timer); 325 "select timer: %d", timer);
326
327 work_read_fd_set = master_read_fd_set;
328 work_write_fd_set = master_write_fd_set;
329
330 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
331 "select read fd_set: %08X", *(int *) &work_read_fd_set);
321 332
322 #if (WIN32) 333 #if (WIN32)
323 ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp); 334 ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp);
324 #else 335 #else
325 ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tp); 336 ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tp);
357 ngx_time_update(tv.tv_sec); 368 ngx_time_update(tv.tv_sec);
358 369
359 if (ready == 0) { 370 if (ready == 0) {
360 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 371 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
361 "select() returned no events without timeout"); 372 "select() returned no events without timeout");
373 ngx_accept_mutex_unlock();
362 return NGX_ERROR; 374 return NGX_ERROR;
363 } 375 }
364 } 376 }
365 377
366 #else /* !(HAVE_SELECT_CHANGE_TIMEOUT) */ 378 #else /* !(HAVE_SELECT_CHANGE_TIMEOUT) */
379 391
380 } else { 392 } else {
381 if (ready == 0) { 393 if (ready == 0) {
382 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 394 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
383 "select() returned no events without timeout"); 395 "select() returned no events without timeout");
396 ngx_accept_mutex_unlock();
384 return NGX_ERROR; 397 return NGX_ERROR;
385 } 398 }
386 } 399 }
387 400
388 #endif /* HAVE_SELECT_CHANGE_TIMEOUT */ 401 #endif /* HAVE_SELECT_CHANGE_TIMEOUT */
395 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, "select() failed"); 408 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, "select() failed");
396 #else 409 #else
397 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, 410 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
398 cycle->log, err, "select() failed"); 411 cycle->log, err, "select() failed");
399 #endif 412 #endif
413 ngx_accept_mutex_unlock();
400 return NGX_ERROR; 414 return NGX_ERROR;
401 } 415 }
402 416
403 417
404 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { 418 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {