diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-09-09 19:40:48 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-09-09 19:40:48 +0400 |
commit | 2e6ba93fa79cadf9ed2256992d7c8c4d512f2b1f (patch) | |
tree | 50dd328ad6dbd0d9a22a561f2f335ebfe098f1d0 /src/event | |
parent | 0d9da9b6c3c4842eade3034e6e1f3ea140d08d6d (diff) |
nginx-0.0.10-2004-09-09-19:40:48 import
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/ngx_event_accept.c | 53 | ||||
-rw-r--r-- | src/event/ngx_event_connect.h | 18 |
2 files changed, 42 insertions, 29 deletions
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index d84d8c542..10f24a6ad 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -11,6 +11,7 @@ typedef struct { } ngx_accept_log_ctx_t; +static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log); static size_t ngx_accept_log_error(void *data, char *buf, size_t len); @@ -138,11 +139,7 @@ void ngx_event_accept(ngx_event_t *ev) "closing the connection", ls->listening->addr_text.data, s, ecf->connections); - if (ngx_close_socket(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, - ngx_close_socket_n "failed"); - } - + ngx_close_accepted_socket(s, log); ngx_destroy_pool(pool); return; } @@ -155,11 +152,7 @@ void ngx_event_accept(ngx_event_t *ev) ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, ngx_blocking_n " failed"); - if (ngx_close_socket(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, - ngx_close_socket_n " failed"); - } - + ngx_close_accepted_socket(s, log); ngx_destroy_pool(pool); return; } @@ -171,11 +164,7 @@ void ngx_event_accept(ngx_event_t *ev) ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, ngx_nonblocking_n " failed"); - if (ngx_close_socket(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, - ngx_close_socket_n " failed"); - } - + ngx_close_accepted_socket(s, log); ngx_destroy_pool(pool); return; } @@ -286,6 +275,25 @@ void ngx_event_accept(ngx_event_t *ev) ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, "accept: fd:%d c:%d", s, c->number); + if (c->listening->addr_ntop) { + c->addr_text.data = ngx_palloc(c->pool, + c->listening->addr_text_max_len); + if (c->addr_text.data == NULL) { + ngx_close_accepted_socket(s, log); + ngx_destroy_pool(pool); + return; + } + + c->addr_text.len = ngx_sock_ntop(c->listening->family, c->sockaddr, + c->addr_text.data, + c->listening->addr_text_max_len); + if (c->addr_text.len == 0) { + ngx_close_accepted_socket(s, log); + ngx_destroy_pool(pool); + return; + } + } + #if (NGX_DEBUG) { @@ -307,11 +315,7 @@ void ngx_event_accept(ngx_event_t *ev) if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) { if (ngx_add_conn(c) == NGX_ERROR) { - if (ngx_close_socket(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, - ngx_close_socket_n " failed"); - } - + ngx_close_accepted_socket(s, log); ngx_destroy_pool(pool); return; } @@ -440,6 +444,15 @@ ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle) } +static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log) +{ + if (ngx_close_socket(s) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, + ngx_close_socket_n " failed"); + } +} + + static size_t ngx_accept_log_error(void *data, char *buf, size_t len) { ngx_accept_log_ctx_t *ctx = data; diff --git a/src/event/ngx_event_connect.h b/src/event/ngx_event_connect.h index 01299f12b..8a3e17fdf 100644 --- a/src/event/ngx_event_connect.h +++ b/src/event/ngx_event_connect.h @@ -13,20 +13,20 @@ typedef struct { in_addr_t addr; ngx_str_t host; - int port; + in_port_t port; ngx_str_t addr_port_text; - int fails; + ngx_int_t fails; time_t accessed; } ngx_peer_t; typedef struct { - int current; - int number; - int max_fails; - int fail_timeout; - int last_cached; + ngx_int_t current; + ngx_int_t number; + ngx_int_t max_fails; + ngx_int_t fail_timeout; + ngx_int_t last_cached; /* ngx_mutex_t *mutex; */ ngx_connection_t **cached; @@ -37,8 +37,8 @@ typedef struct { typedef struct { ngx_peers_t *peers; - int cur_peer; - int tries; + ngx_int_t cur_peer; + ngx_int_t tries; ngx_connection_t *connection; #if (NGX_THREADS) |