Mercurial > hg > nginx
comparison src/event/ngx_event_accept.c @ 257:70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 11 Feb 2004 17:08:49 +0000 |
parents | b6793bc5034b |
children | d30f2c39caae |
comparison
equal
deleted
inserted
replaced
256:8e39cab6abd5 | 257:70e1c7d2b83d |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 #include <nginx.h> | 5 #include <nginx.h> |
6 | |
7 | |
8 typedef struct { | |
9 int flag; | |
10 char *name; | |
11 } ngx_accept_log_ctx_t; | |
6 | 12 |
7 | 13 |
8 static size_t ngx_accept_log_error(void *data, char *buf, size_t len); | 14 static size_t ngx_accept_log_error(void *data, char *buf, size_t len); |
9 | 15 |
10 | 16 |
18 ngx_pool_t *pool; | 24 ngx_pool_t *pool; |
19 ngx_socket_t s; | 25 ngx_socket_t s; |
20 ngx_event_t *rev, *wev; | 26 ngx_event_t *rev, *wev; |
21 ngx_connection_t *c, *ls; | 27 ngx_connection_t *c, *ls; |
22 ngx_event_conf_t *ecf; | 28 ngx_event_conf_t *ecf; |
29 ngx_accept_log_ctx_t *ctx; | |
23 | 30 |
24 ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module); | 31 ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module); |
25 | 32 |
26 if (ngx_event_flags & (NGX_USE_EDGE_EVENT|NGX_USE_SIGIO_EVENT)) { | 33 if (ngx_event_flags & (NGX_USE_EDGE_EVENT|NGX_USE_SIGIO_EVENT)) { |
27 ev->available = 1; | 34 ev->available = 1; |
30 ev->available = ecf->multi_accept; | 37 ev->available = ecf->multi_accept; |
31 } | 38 } |
32 | 39 |
33 ls = ev->data; | 40 ls = ev->data; |
34 | 41 |
35 ngx_log_debug(ev->log, "accept on %s ready: %d" _ | 42 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
36 ls->listening->addr_text.data _ | 43 "accept on %s, ready: %d", |
37 ev->available); | 44 ls->listening->addr_text.data, ev->available); |
38 | 45 |
39 ev->ready = 0; | 46 ev->ready = 0; |
40 accepted = 0; | 47 accepted = 0; |
41 pool = NULL; | 48 pool = NULL; |
42 | 49 |
66 } | 73 } |
67 | 74 |
68 ngx_memcpy(log, ls->log, sizeof(ngx_log_t)); | 75 ngx_memcpy(log, ls->log, sizeof(ngx_log_t)); |
69 pool->log = log; | 76 pool->log = log; |
70 | 77 |
71 log->data = ls->listening->addr_text.data; | 78 if (!(ctx = ngx_palloc(pool, sizeof(ngx_accept_log_ctx_t)))) { |
79 ngx_destroy_pool(pool); | |
80 return; | |
81 } | |
82 | |
83 /* -1 disable logging the connection number */ | |
84 ctx->flag = -1; | |
85 ctx->name = ls->listening->addr_text.data; | |
86 | |
87 log->data = ctx; | |
72 log->handler = ngx_accept_log_error; | 88 log->handler = ngx_accept_log_error; |
73 | 89 |
74 len = ls->listening->socklen; | 90 len = ls->listening->socklen; |
75 | 91 |
76 s = accept(ls->fd, sa, &len); | 92 s = accept(ls->fd, sa, &len); |
231 c->log = log; | 247 c->log = log; |
232 rev->log = log; | 248 rev->log = log; |
233 wev->log = log; | 249 wev->log = log; |
234 | 250 |
235 /* | 251 /* |
236 * In the multithreaded model the connection counter is updated by | 252 * TODO: MT: - atomic increment (x86: lock xadd) |
237 * the main thread only that accept()s connections. | 253 * or protection by critical section or mutex |
238 * | 254 * |
239 * TODO: MP: - allocated in a shared memory | 255 * TODO: MP: - allocated in a shared memory |
240 * - atomic increment (x86: lock xadd) | 256 * - atomic increment (x86: lock xadd) |
241 * or protection by critical section or mutex | 257 * or protection by critical section or mutex |
242 */ | 258 */ |
277 } | 293 } |
278 | 294 |
279 | 295 |
280 static size_t ngx_accept_log_error(void *data, char *buf, size_t len) | 296 static size_t ngx_accept_log_error(void *data, char *buf, size_t len) |
281 { | 297 { |
282 char *sock = data; | 298 ngx_accept_log_ctx_t *ctx = data; |
283 | 299 |
284 return ngx_snprintf(buf, len, " while accept() on %s", sock); | 300 return ngx_snprintf(buf, len, " while accept() on %s", ctx->name); |
285 } | 301 } |