nginx-0.0.1-2003-07-22-23:53:10 import

This commit is contained in:
Igor Sysoev 2003-07-22 19:53:10 +00:00
parent 5b8d38832b
commit 72f2e36770
4 changed files with 53 additions and 29 deletions

View File

@ -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); 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) { if ((unsigned) ecf->connections > FD_SETSIZE) {
return "maximum number of connections " return "maximum number of connections "

View File

@ -66,7 +66,7 @@ ngx_log_debug(ev->log, "ADDR %s" _ ls->listening->addr_text.data);
return; 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) { if ((unsigned) s >= (unsigned) ecf->connections) {

View File

@ -4,9 +4,27 @@
int ngx_event_connect_peer(ngx_peer_connecttion_t *pc) 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(); 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); s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
if (s == -1) { 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"); ngx_socket_n " failed");
return NGX_ERROR; return NGX_ERROR;
} }
if (cp->rcvbuf) { if (pc->rcvbuf) {
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
(const void *) &cp->rcvbuf, sizeof(int)) == -1) { (const void *) &pc->rcvbuf, sizeof(int)) == -1) {
ngx_log_error(NGX_LOG_ALERT, cp->log, ngx_socket_errno, ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
"setsockopt(SO_RCVBUF) failed"); "setsockopt(SO_RCVBUF) failed");
if (ngx_close_socket(s) == -1) { 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"); ngx_close_socket_n " failed");
} }
@ -99,11 +115,11 @@ int ngx_event_connect_peer(ngx_peer_connecttion_t *pc)
} }
if (ngx_nonblocking(s) == -1) { 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"); ngx_nonblocking_n " failed");
if (ngx_close_socket(s) == -1) { 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"); ngx_close_socket_n " failed");
} }
@ -111,17 +127,17 @@ int ngx_event_connect_peer(ngx_peer_connecttion_t *pc)
} }
#if (WIN32) #if (WIN32)
/* /*
* Winsock assignes a socket number divisible by 4 * Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4. * so to find a connection we divide a socket number by 4.
*/ */
if (s % 4) { if (s % 4) {
ngx_log_error(NGX_LOG_EMERG, cp->log, 0, ngx_log_error(NGX_LOG_EMERG, pc->log, 0,
ngx_socket_n ngx_socket_n
" created socket %d, not divisible by 4", s); " created socket %d, not divisible by 4", s);
exit(1); exit(1);
} }
c = &ngx_cycle->connections[s / 4]; c = &ngx_cycle->connections[s / 4];
rev = &ngx_cycle->read_events[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->instance = wev->instance = !instance;
!!!!!!!!!!!!!!! rev->log = wev->log = c->log = pc->log;
rev->log = wev->log = c->log = cn->log;
c->fd = s; 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;
}
}
} }

View File

@ -11,7 +11,7 @@ typedef struct {
u_int32_t addr; u_int32_t addr;
ngx_str_t host; ngx_str_t host;
int port; int port;
ngx_str_t addr_port_name; ngx_str_t addr_port_text;
int fails; int fails;
time_t accessed; time_t accessed;
@ -38,6 +38,8 @@ typedef struct {
ngx_connection_t *connection; ngx_connection_t *connection;
int rcvbuf;
unsigned cached:1; unsigned cached:1;
} ngx_peer_connection_t; } ngx_peer_connection_t;