From 72f2e367705393703e1159c2db6435e90b593a26 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 22 Jul 2003 19:53:10 +0000 Subject: [PATCH] nginx-0.0.1-2003-07-22-23:53:10 import --- src/event/modules/ngx_select_module.c | 2 +- src/event/ngx_event_accept.c | 2 +- src/event/ngx_event_connect.c | 74 +++++++++++++++++---------- src/event/ngx_event_connect.h | 4 +- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c index 7bcdd678b..1f8a5d98e 100644 --- a/src/event/modules/ngx_select_module.c +++ b/src/event/modules/ngx_select_module.c @@ -428,7 +428,7 @@ static char *ngx_select_init_conf(ngx_cycle_t *cycle, void *conf) ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); - /* disable warnings: the default FD_SETSIZE is 1024U in FreeBSD 5.x */ + /* disable warning: the default FD_SETSIZE is 1024U in FreeBSD 5.x */ if ((unsigned) ecf->connections > FD_SETSIZE) { return "maximum number of connections " diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index f9fdd5730..e9469753d 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -66,7 +66,7 @@ ngx_log_debug(ev->log, "ADDR %s" _ ls->listening->addr_text.data); return; } - /* disable warnings: Win32 SOCKET is u_int while UNIX socket is int */ + /* disable warning: Win32 SOCKET is u_int while UNIX socket is int */ if ((unsigned) s >= (unsigned) ecf->connections) { diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index a44ff0607..70e864b78 100644 --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -4,9 +4,27 @@ int ngx_event_connect_peer(ngx_peer_connecttion_t *pc) { - time_t now; + time_t now; + ngx_socket_t s; - /* TODO: cached connection */ + /* ngx_lock_mutex(pc->peers->mutex); */ + + if (pc->peers->last_cached) { + + /* cached connection */ + + pc->connection = pc->peers->cached[pc->peers->last_cached] + pc->peers->last_cached--; + + /* ngx_unlock_mutex(pc->peers->mutex); */ + + pc->cached = 1; + return NGX_OK; + } + + /* ngx_unlock_mutex(pc->peers->mutex); */ + + pc->cached = 0; now = ngx_time(); @@ -71,26 +89,24 @@ int ngx_event_connect_peer(ngx_peer_connecttion_t *pc) } } - - - + pc->addr_port_text = peer->addr_port_text; s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0); if (s == -1) { - ngx_log_error(NGX_LOG_ALERT, cp->log, ngx_socket_errno, + ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, ngx_socket_n " failed"); return NGX_ERROR; } - if (cp->rcvbuf) { + if (pc->rcvbuf) { if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, - (const void *) &cp->rcvbuf, sizeof(int)) == -1) { - ngx_log_error(NGX_LOG_ALERT, cp->log, ngx_socket_errno, + (const void *) &pc->rcvbuf, sizeof(int)) == -1) { + ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, "setsockopt(SO_RCVBUF) failed"); if (ngx_close_socket(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, cp->log, ngx_socket_errno, + ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, ngx_close_socket_n " failed"); } @@ -99,11 +115,11 @@ int ngx_event_connect_peer(ngx_peer_connecttion_t *pc) } if (ngx_nonblocking(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, cn->log, ngx_socket_errno, + ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, ngx_nonblocking_n " failed"); if (ngx_close_socket(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, cn->log, ngx_socket_errno, + ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, ngx_close_socket_n " failed"); } @@ -111,17 +127,17 @@ int ngx_event_connect_peer(ngx_peer_connecttion_t *pc) } #if (WIN32) - /* - * Winsock assignes a socket number divisible by 4 - * so to find a connection we divide a socket number by 4. - */ + /* + * Winsock assignes a socket number divisible by 4 + * so to find a connection we divide a socket number by 4. + */ - if (s % 4) { - ngx_log_error(NGX_LOG_EMERG, cp->log, 0, - ngx_socket_n - " created socket %d, not divisible by 4", s); - exit(1); - } + if (s % 4) { + ngx_log_error(NGX_LOG_EMERG, pc->log, 0, + ngx_socket_n + " created socket %d, not divisible by 4", s); + exit(1); + } c = &ngx_cycle->connections[s / 4]; rev = &ngx_cycle->read_events[s / 4]; @@ -148,9 +164,15 @@ int ngx_event_connect_peer(ngx_peer_connecttion_t *pc) rev->instance = wev->instance = !instance; - !!!!!!!!!!!!!!! - - rev->log = wev->log = c->log = cn->log; + rev->log = wev->log = c->log = pc->log; c->fd = s; - wev->close_handler = rev->close_handler = ngx_event_close_connection; + + pc->connection = c; + + if (ngx_add_conn) { + if (ngx_add_conn(c) == NGX_ERROR) { + return NGX_ERROR; + } + } + } diff --git a/src/event/ngx_event_connect.h b/src/event/ngx_event_connect.h index c4cf0c528..714ef6f59 100644 --- a/src/event/ngx_event_connect.h +++ b/src/event/ngx_event_connect.h @@ -11,7 +11,7 @@ typedef struct { u_int32_t addr; ngx_str_t host; int port; - ngx_str_t addr_port_name; + ngx_str_t addr_port_text; int fails; time_t accessed; @@ -38,6 +38,8 @@ typedef struct { ngx_connection_t *connection; + int rcvbuf; + unsigned cached:1; } ngx_peer_connection_t;