Mercurial > hg > nginx
comparison src/event/ngx_event_accept.c @ 493:975f62e77f02 release-0.1.21
nginx-0.1.21-RELEASE import
*) Bugfix: the ngx_http_stub_status_module showed incorrect statistics
if "rtsig" method was used or if several worker process ran on SMP.
*) Bugfix: nginx could not be built by the icc compiler on Linux or if
the zlib-1.2.x library was building from sources.
*) Bugfix: nginx could not be built on NetBSD 2.0.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 22 Feb 2005 14:40:13 +0000 |
parents | 31ff3e943e16 |
children | fc9909c369b2 |
comparison
equal
deleted
inserted
replaced
492:a3fac9a5aa5b | 493:975f62e77f02 |
---|---|
5 | 5 |
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 #include <nginx.h> | |
11 | 10 |
12 | 11 |
13 static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log); | 12 static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log); |
14 static u_char *ngx_accept_log_error(ngx_log_t *log, u_char *buf, size_t len); | 13 static u_char *ngx_accept_log_error(ngx_log_t *log, u_char *buf, size_t len); |
15 | 14 |
16 | 15 |
17 void ngx_event_accept(ngx_event_t *ev) | 16 void |
17 ngx_event_accept(ngx_event_t *ev) | |
18 { | 18 { |
19 ngx_uint_t instance, accepted; | 19 ngx_uint_t instance, accepted; |
20 socklen_t len; | 20 socklen_t len; |
21 struct sockaddr *sa; | 21 struct sockaddr *sa; |
22 ngx_err_t err; | 22 ngx_err_t err; |
51 if (pool == NULL) { | 51 if (pool == NULL) { |
52 | 52 |
53 /* | 53 /* |
54 * Create the pool before accept() to avoid the copying of | 54 * Create the pool before accept() to avoid the copying of |
55 * the sockaddr. Although accept() can fail it is uncommon | 55 * the sockaddr. Although accept() can fail it is uncommon |
56 * case and besides the pool can be got from the free pool list | 56 * case and besides the pool can be got from the free pool list. |
57 */ | 57 */ |
58 | 58 |
59 if (!(pool = ngx_create_pool(ls->listening->pool_size, ev->log))) { | 59 if (!(pool = ngx_create_pool(ls->listening->pool_size, ev->log))) { |
60 return; | 60 return; |
61 } | 61 } |
115 ngx_destroy_pool(pool); | 115 ngx_destroy_pool(pool); |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 #if (NGX_STAT_STUB) | 119 #if (NGX_STAT_STUB) |
120 (*ngx_stat_accepted)++; | 120 ngx_atomic_inc(ngx_stat_accepted); |
121 #endif | 121 #endif |
122 | 122 |
123 ngx_accept_disabled = (ngx_uint_t) s + NGX_ACCEPT_THRESHOLD | 123 ngx_accept_disabled = (ngx_uint_t) s + NGX_ACCEPT_THRESHOLD |
124 - ecf->connections; | 124 - ecf->connections; |
125 | 125 |
137 ngx_destroy_pool(pool); | 137 ngx_destroy_pool(pool); |
138 return; | 138 return; |
139 } | 139 } |
140 | 140 |
141 #if (NGX_STAT_STUB) | 141 #if (NGX_STAT_STUB) |
142 (*ngx_stat_active)++; | 142 ngx_atomic_inc(ngx_stat_active); |
143 #endif | 143 #endif |
144 | 144 |
145 /* set a blocking mode for aio and non-blocking mode for others */ | 145 /* set a blocking mode for aio and non-blocking mode for others */ |
146 | 146 |
147 if (ngx_inherited_nonblocking) { | 147 if (ngx_inherited_nonblocking) { |
232 | 232 |
233 wev->write = 1; | 233 wev->write = 1; |
234 wev->ready = 1; | 234 wev->ready = 1; |
235 | 235 |
236 if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT)) { | 236 if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT)) { |
237 /* epoll, rtsig, aio, iocp */ | 237 /* rtsig, aio, iocp */ |
238 rev->ready = 1; | 238 rev->ready = 1; |
239 } | 239 } |
240 | 240 |
241 if (ev->deferred_accept) { | 241 if (ev->deferred_accept) { |
242 rev->ready = 1; | 242 rev->ready = 1; |
334 | 334 |
335 } while (ev->available); | 335 } while (ev->available); |
336 } | 336 } |
337 | 337 |
338 | 338 |
339 ngx_int_t ngx_trylock_accept_mutex(ngx_cycle_t *cycle) | 339 ngx_int_t |
340 ngx_trylock_accept_mutex(ngx_cycle_t *cycle) | |
340 { | 341 { |
341 if (*ngx_accept_mutex == 0 | 342 if (*ngx_accept_mutex == 0 |
342 && ngx_atomic_cmp_set(ngx_accept_mutex, 0, ngx_pid)) | 343 && ngx_atomic_cmp_set(ngx_accept_mutex, 0, ngx_pid)) |
343 { | 344 { |
344 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | 345 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
366 | 367 |
367 return NGX_OK; | 368 return NGX_OK; |
368 } | 369 } |
369 | 370 |
370 | 371 |
371 ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle) | 372 ngx_int_t |
373 ngx_enable_accept_events(ngx_cycle_t *cycle) | |
372 { | 374 { |
373 ngx_uint_t i; | 375 ngx_uint_t i; |
374 ngx_listening_t *s; | 376 ngx_listening_t *s; |
375 | 377 |
376 s = cycle->listening.elts; | 378 s = cycle->listening.elts; |
398 | 400 |
399 return NGX_OK; | 401 return NGX_OK; |
400 } | 402 } |
401 | 403 |
402 | 404 |
403 ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle) | 405 ngx_int_t |
406 ngx_disable_accept_events(ngx_cycle_t *cycle) | |
404 { | 407 { |
405 ngx_uint_t i; | 408 ngx_uint_t i; |
406 ngx_listening_t *s; | 409 ngx_listening_t *s; |
407 | 410 |
408 s = cycle->listening.elts; | 411 s = cycle->listening.elts; |
440 | 443 |
441 return NGX_OK; | 444 return NGX_OK; |
442 } | 445 } |
443 | 446 |
444 | 447 |
445 static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log) | 448 static void |
449 ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log) | |
446 { | 450 { |
447 if (ngx_close_socket(s) == -1) { | 451 if (ngx_close_socket(s) == -1) { |
448 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, | 452 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, |
449 ngx_close_socket_n " failed"); | 453 ngx_close_socket_n " failed"); |
450 } | 454 } |
451 } | 455 } |
452 | 456 |
453 | 457 |
454 static u_char *ngx_accept_log_error(ngx_log_t *log, u_char *buf, size_t len) | 458 static u_char * |
459 ngx_accept_log_error(ngx_log_t *log, u_char *buf, size_t len) | |
455 { | 460 { |
456 return ngx_snprintf(buf, len, " while accept() on %V", log->data); | 461 return ngx_snprintf(buf, len, " while accept() on %V", log->data); |
457 } | 462 } |