Mercurial > hg > nginx
comparison src/event/ngx_event_accept.c @ 419:47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 09 Sep 2004 15:40:48 +0000 |
parents | 6f3b20c1ac50 |
children | bd39260a1383 |
comparison
equal
deleted
inserted
replaced
418:cf072d26d6d6 | 419:47709bff4468 |
---|---|
9 int flag; | 9 int flag; |
10 u_char *name; | 10 u_char *name; |
11 } ngx_accept_log_ctx_t; | 11 } ngx_accept_log_ctx_t; |
12 | 12 |
13 | 13 |
14 static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log); | |
14 static size_t ngx_accept_log_error(void *data, char *buf, size_t len); | 15 static size_t ngx_accept_log_error(void *data, char *buf, size_t len); |
15 | 16 |
16 | 17 |
17 void ngx_event_accept(ngx_event_t *ev) | 18 void ngx_event_accept(ngx_event_t *ev) |
18 { | 19 { |
136 "accept() on %s returned socket #%d while " | 137 "accept() on %s returned socket #%d while " |
137 "only %d connections was configured, " | 138 "only %d connections was configured, " |
138 "closing the connection", | 139 "closing the connection", |
139 ls->listening->addr_text.data, s, ecf->connections); | 140 ls->listening->addr_text.data, s, ecf->connections); |
140 | 141 |
141 if (ngx_close_socket(s) == -1) { | 142 ngx_close_accepted_socket(s, log); |
142 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, | |
143 ngx_close_socket_n "failed"); | |
144 } | |
145 | |
146 ngx_destroy_pool(pool); | 143 ngx_destroy_pool(pool); |
147 return; | 144 return; |
148 } | 145 } |
149 | 146 |
150 /* set a blocking mode for aio and non-blocking mode for the others */ | 147 /* set a blocking mode for aio and non-blocking mode for the others */ |
153 if ((ngx_event_flags & NGX_USE_AIO_EVENT)) { | 150 if ((ngx_event_flags & NGX_USE_AIO_EVENT)) { |
154 if (ngx_blocking(s) == -1) { | 151 if (ngx_blocking(s) == -1) { |
155 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, | 152 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, |
156 ngx_blocking_n " failed"); | 153 ngx_blocking_n " failed"); |
157 | 154 |
158 if (ngx_close_socket(s) == -1) { | 155 ngx_close_accepted_socket(s, log); |
159 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, | |
160 ngx_close_socket_n " failed"); | |
161 } | |
162 | |
163 ngx_destroy_pool(pool); | 156 ngx_destroy_pool(pool); |
164 return; | 157 return; |
165 } | 158 } |
166 } | 159 } |
167 | 160 |
169 if (!(ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT))) { | 162 if (!(ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT))) { |
170 if (ngx_nonblocking(s) == -1) { | 163 if (ngx_nonblocking(s) == -1) { |
171 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, | 164 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, |
172 ngx_nonblocking_n " failed"); | 165 ngx_nonblocking_n " failed"); |
173 | 166 |
174 if (ngx_close_socket(s) == -1) { | 167 ngx_close_accepted_socket(s, log); |
175 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, | |
176 ngx_close_socket_n " failed"); | |
177 } | |
178 | |
179 ngx_destroy_pool(pool); | 168 ngx_destroy_pool(pool); |
180 return; | 169 return; |
181 } | 170 } |
182 } | 171 } |
183 } | 172 } |
284 #endif | 273 #endif |
285 | 274 |
286 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, | 275 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
287 "accept: fd:%d c:%d", s, c->number); | 276 "accept: fd:%d c:%d", s, c->number); |
288 | 277 |
278 if (c->listening->addr_ntop) { | |
279 c->addr_text.data = ngx_palloc(c->pool, | |
280 c->listening->addr_text_max_len); | |
281 if (c->addr_text.data == NULL) { | |
282 ngx_close_accepted_socket(s, log); | |
283 ngx_destroy_pool(pool); | |
284 return; | |
285 } | |
286 | |
287 c->addr_text.len = ngx_sock_ntop(c->listening->family, c->sockaddr, | |
288 c->addr_text.data, | |
289 c->listening->addr_text_max_len); | |
290 if (c->addr_text.len == 0) { | |
291 ngx_close_accepted_socket(s, log); | |
292 ngx_destroy_pool(pool); | |
293 return; | |
294 } | |
295 } | |
296 | |
289 #if (NGX_DEBUG) | 297 #if (NGX_DEBUG) |
290 { | 298 { |
291 | 299 |
292 uint32_t *addr; | 300 uint32_t *addr; |
293 in_addr_t i; | 301 in_addr_t i; |
305 } | 313 } |
306 #endif | 314 #endif |
307 | 315 |
308 if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) { | 316 if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) { |
309 if (ngx_add_conn(c) == NGX_ERROR) { | 317 if (ngx_add_conn(c) == NGX_ERROR) { |
310 if (ngx_close_socket(s) == -1) { | 318 ngx_close_accepted_socket(s, log); |
311 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, | |
312 ngx_close_socket_n " failed"); | |
313 } | |
314 | |
315 ngx_destroy_pool(pool); | 319 ngx_destroy_pool(pool); |
316 return; | 320 return; |
317 } | 321 } |
318 } | 322 } |
319 | 323 |
438 | 442 |
439 return NGX_OK; | 443 return NGX_OK; |
440 } | 444 } |
441 | 445 |
442 | 446 |
447 static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log) | |
448 { | |
449 if (ngx_close_socket(s) == -1) { | |
450 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, | |
451 ngx_close_socket_n " failed"); | |
452 } | |
453 } | |
454 | |
455 | |
443 static size_t ngx_accept_log_error(void *data, char *buf, size_t len) | 456 static size_t ngx_accept_log_error(void *data, char *buf, size_t len) |
444 { | 457 { |
445 ngx_accept_log_ctx_t *ctx = data; | 458 ngx_accept_log_ctx_t *ctx = data; |
446 | 459 |
447 return ngx_snprintf(buf, len, " while accept() on %s", ctx->name); | 460 return ngx_snprintf(buf, len, " while accept() on %s", ctx->name); |