2002-08-07 00:39:45 +08:00
|
|
|
|
2004-09-28 16:34:51 +08:00
|
|
|
/*
|
2004-09-30 00:00:49 +08:00
|
|
|
* Copyright (C) Igor Sysoev
|
2012-01-18 23:07:43 +08:00
|
|
|
* Copyright (C) Nginx, Inc.
|
2004-09-28 16:34:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
#include <ngx_config.h>
|
2002-08-26 23:18:19 +08:00
|
|
|
#include <ngx_core.h>
|
2002-08-07 00:39:45 +08:00
|
|
|
#include <ngx_event.h>
|
|
|
|
|
|
|
|
|
nginx-0.3.8-RELEASE import
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; the bug had
appeared in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
2005-11-10 01:25:55 +08:00
|
|
|
static ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle);
|
|
|
|
static ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle);
|
2005-09-23 19:02:22 +08:00
|
|
|
static void ngx_close_accepted_connection(ngx_connection_t *c);
|
2003-11-20 00:26:41 +08:00
|
|
|
|
|
|
|
|
2005-02-22 22:40:13 +08:00
|
|
|
void
|
|
|
|
ngx_event_accept(ngx_event_t *ev)
|
2002-08-07 00:39:45 +08:00
|
|
|
{
|
2006-09-25 22:34:29 +08:00
|
|
|
socklen_t socklen;
|
2005-01-25 20:27:35 +08:00
|
|
|
ngx_err_t err;
|
|
|
|
ngx_log_t *log;
|
2012-05-11 21:33:06 +08:00
|
|
|
ngx_uint_t level;
|
2005-01-25 20:27:35 +08:00
|
|
|
ngx_socket_t s;
|
|
|
|
ngx_event_t *rev, *wev;
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_listening_t *ls;
|
|
|
|
ngx_connection_t *c, *lc;
|
2005-01-25 20:27:35 +08:00
|
|
|
ngx_event_conf_t *ecf;
|
2009-02-21 15:02:02 +08:00
|
|
|
u_char sa[NGX_SOCKADDRLEN];
|
2010-12-02 18:05:41 +08:00
|
|
|
#if (NGX_HAVE_ACCEPT4)
|
|
|
|
static ngx_uint_t use_accept4 = 1;
|
|
|
|
#endif
|
2003-05-29 21:02:09 +08:00
|
|
|
|
2012-05-11 21:33:06 +08:00
|
|
|
if (ev->timedout) {
|
|
|
|
if (ngx_enable_accept_events((ngx_cycle_t *) ngx_cycle) != NGX_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev->timedout = 0;
|
|
|
|
}
|
|
|
|
|
2003-07-07 14:11:50 +08:00
|
|
|
ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module);
|
2003-01-30 15:28:09 +08:00
|
|
|
|
2004-07-07 23:01:00 +08:00
|
|
|
if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
|
2004-02-03 05:19:52 +08:00
|
|
|
ev->available = 1;
|
|
|
|
|
2004-10-21 23:34:38 +08:00
|
|
|
} else if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) {
|
2004-02-03 05:19:52 +08:00
|
|
|
ev->available = ecf->multi_accept;
|
|
|
|
}
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
lc = ev->data;
|
|
|
|
ls = lc->listening;
|
|
|
|
ev->ready = 0;
|
2002-12-15 14:25:09 +08:00
|
|
|
|
2004-02-12 01:08:49 +08:00
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
|
2005-09-23 19:02:22 +08:00
|
|
|
"accept on %V, ready: %d", &ls->addr_text, ev->available);
|
2003-01-30 15:28:09 +08:00
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
do {
|
2009-02-21 15:02:02 +08:00
|
|
|
socklen = NGX_SOCKADDRLEN;
|
2003-05-20 23:37:55 +08:00
|
|
|
|
2010-11-25 18:15:04 +08:00
|
|
|
#if (NGX_HAVE_ACCEPT4)
|
2010-12-02 18:05:41 +08:00
|
|
|
if (use_accept4) {
|
|
|
|
s = accept4(lc->fd, (struct sockaddr *) sa, &socklen,
|
|
|
|
SOCK_NONBLOCK);
|
|
|
|
} else {
|
|
|
|
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
|
|
|
|
}
|
2010-11-25 18:15:04 +08:00
|
|
|
#else
|
2006-09-25 22:34:29 +08:00
|
|
|
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
|
2010-11-25 18:15:04 +08:00
|
|
|
#endif
|
2004-12-21 20:30:30 +08:00
|
|
|
|
2003-01-30 15:28:09 +08:00
|
|
|
if (s == -1) {
|
2002-08-07 00:39:45 +08:00
|
|
|
err = ngx_socket_errno;
|
2003-01-30 15:28:09 +08:00
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
if (err == NGX_EAGAIN) {
|
2006-09-26 20:20:12 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err,
|
|
|
|
"accept() not ready");
|
2003-05-14 00:02:32 +08:00
|
|
|
return;
|
2002-08-07 00:39:45 +08:00
|
|
|
}
|
2002-08-26 23:18:19 +08:00
|
|
|
|
2012-05-11 21:33:06 +08:00
|
|
|
level = NGX_LOG_ALERT;
|
|
|
|
|
|
|
|
if (err == NGX_ECONNABORTED) {
|
|
|
|
level = NGX_LOG_ERR;
|
|
|
|
|
|
|
|
} else if (err == NGX_EMFILE || err == NGX_ENFILE) {
|
|
|
|
level = NGX_LOG_CRIT;
|
|
|
|
}
|
|
|
|
|
2010-12-02 22:20:51 +08:00
|
|
|
#if (NGX_HAVE_ACCEPT4)
|
2012-05-11 21:33:06 +08:00
|
|
|
ngx_log_error(level, ev->log, err,
|
2010-12-02 18:05:41 +08:00
|
|
|
use_accept4 ? "accept4() failed" : "accept() failed");
|
|
|
|
|
|
|
|
if (use_accept4 && err == NGX_ENOSYS) {
|
|
|
|
use_accept4 = 0;
|
|
|
|
ngx_inherited_nonblocking = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2010-12-02 22:20:51 +08:00
|
|
|
#else
|
2012-05-11 21:33:06 +08:00
|
|
|
ngx_log_error(level, ev->log, err, "accept() failed");
|
2010-12-02 18:05:41 +08:00
|
|
|
#endif
|
2003-05-29 21:02:09 +08:00
|
|
|
|
2004-02-03 05:19:52 +08:00
|
|
|
if (err == NGX_ECONNABORTED) {
|
2004-10-21 23:34:38 +08:00
|
|
|
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
|
2004-02-03 05:19:52 +08:00
|
|
|
ev->available--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev->available) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-11 21:33:06 +08:00
|
|
|
if (err == NGX_EMFILE || err == NGX_ENFILE) {
|
|
|
|
if (ngx_disable_accept_events((ngx_cycle_t *) ngx_cycle)
|
|
|
|
!= NGX_OK)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ngx_use_accept_mutex) {
|
|
|
|
if (ngx_accept_mutex_held) {
|
|
|
|
ngx_shmtx_unlock(&ngx_accept_mutex);
|
|
|
|
ngx_accept_mutex_held = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_accept_disabled = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ngx_add_timer(ev, ecf->accept_mutex_delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-29 21:02:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-15 03:39:54 +08:00
|
|
|
#if (NGX_STAT_STUB)
|
2009-06-18 21:14:51 +08:00
|
|
|
(void) ngx_atomic_fetch_add(ngx_stat_accepted, 1);
|
2004-09-15 03:39:54 +08:00
|
|
|
#endif
|
2004-04-22 02:54:33 +08:00
|
|
|
|
2008-09-19 20:47:13 +08:00
|
|
|
ngx_accept_disabled = ngx_cycle->connection_n / 8
|
2005-09-23 19:02:22 +08:00
|
|
|
- ngx_cycle->free_connection_n;
|
|
|
|
|
|
|
|
c = ngx_get_connection(s, ev->log);
|
|
|
|
|
|
|
|
if (c == NULL) {
|
|
|
|
if (ngx_close_socket(s) == -1) {
|
|
|
|
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,
|
|
|
|
ngx_close_socket_n " failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-04-18 03:55:41 +08:00
|
|
|
#if (NGX_STAT_STUB)
|
2009-06-18 21:14:51 +08:00
|
|
|
(void) ngx_atomic_fetch_add(ngx_stat_active, 1);
|
2006-04-18 03:55:41 +08:00
|
|
|
#endif
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
c->pool = ngx_create_pool(ls->pool_size, ev->log);
|
|
|
|
if (c->pool == NULL) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
|
|
|
}
|
2003-07-21 05:15:59 +08:00
|
|
|
|
2006-09-25 22:34:29 +08:00
|
|
|
c->sockaddr = ngx_palloc(c->pool, socklen);
|
2005-09-23 19:02:22 +08:00
|
|
|
if (c->sockaddr == NULL) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
|
|
|
}
|
2003-05-29 21:02:09 +08:00
|
|
|
|
2006-09-25 22:34:29 +08:00
|
|
|
ngx_memcpy(c->sockaddr, sa, socklen);
|
2003-05-29 21:02:09 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
log = ngx_palloc(c->pool, sizeof(ngx_log_t));
|
|
|
|
if (log == NULL) {
|
|
|
|
ngx_close_accepted_connection(c);
|
2003-05-14 00:02:32 +08:00
|
|
|
return;
|
2002-08-07 00:39:45 +08:00
|
|
|
}
|
2002-08-26 23:18:19 +08:00
|
|
|
|
2005-02-09 22:31:07 +08:00
|
|
|
/* set a blocking mode for aio and non-blocking mode for others */
|
2003-05-21 21:28:21 +08:00
|
|
|
|
|
|
|
if (ngx_inherited_nonblocking) {
|
2005-09-23 19:02:22 +08:00
|
|
|
if (ngx_event_flags & NGX_USE_AIO_EVENT) {
|
2003-05-21 21:28:21 +08:00
|
|
|
if (ngx_blocking(s) == -1) {
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,
|
2003-11-20 00:26:41 +08:00
|
|
|
ngx_blocking_n " failed");
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_close_accepted_connection(c);
|
2003-05-21 21:28:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-02-07 01:21:13 +08:00
|
|
|
}
|
|
|
|
|
2003-05-21 21:28:21 +08:00
|
|
|
} else {
|
2004-06-07 03:49:18 +08:00
|
|
|
if (!(ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT))) {
|
2003-05-21 21:28:21 +08:00
|
|
|
if (ngx_nonblocking(s) == -1) {
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,
|
2003-11-20 00:26:41 +08:00
|
|
|
ngx_nonblocking_n " failed");
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_close_accepted_connection(c);
|
2003-05-21 21:28:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-02-07 01:21:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
*log = ls->log;
|
2003-06-11 23:28:34 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
c->recv = ngx_recv;
|
|
|
|
c->send = ngx_send;
|
2005-11-15 21:30:52 +08:00
|
|
|
c->recv_chain = ngx_recv_chain;
|
2005-09-23 19:02:22 +08:00
|
|
|
c->send_chain = ngx_send_chain;
|
2003-06-11 23:28:34 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
c->log = log;
|
|
|
|
c->pool->log = log;
|
2002-12-15 14:25:09 +08:00
|
|
|
|
2006-09-25 22:34:29 +08:00
|
|
|
c->socklen = socklen;
|
2009-02-21 15:02:02 +08:00
|
|
|
c->listening = ls;
|
|
|
|
c->local_sockaddr = ls->sockaddr;
|
2003-05-12 23:52:24 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
c->unexpected_eof = 1;
|
2004-07-07 14:15:04 +08:00
|
|
|
|
2009-10-26 19:43:32 +08:00
|
|
|
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
|
|
if (c->sockaddr->sa_family == AF_UNIX) {
|
|
|
|
c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
|
|
|
|
c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED;
|
|
|
|
#if (NGX_SOLARIS)
|
|
|
|
/* Solaris's sendfilev() supports AF_NCA, AF_INET, and AF_INET6 */
|
|
|
|
c->sendfile = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
rev = c->read;
|
|
|
|
wev = c->write;
|
2002-08-26 23:18:19 +08:00
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
wev->ready = 1;
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2004-07-07 23:01:00 +08:00
|
|
|
if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT)) {
|
2005-02-22 22:40:13 +08:00
|
|
|
/* rtsig, aio, iocp */
|
2003-10-29 16:30:44 +08:00
|
|
|
rev->ready = 1;
|
2003-02-07 01:21:13 +08:00
|
|
|
}
|
|
|
|
|
2004-01-30 05:45:01 +08:00
|
|
|
if (ev->deferred_accept) {
|
|
|
|
rev->ready = 1;
|
2005-06-16 02:33:41 +08:00
|
|
|
#if (NGX_HAVE_KQUEUE)
|
|
|
|
rev->available = 1;
|
|
|
|
#endif
|
2004-01-30 05:45:01 +08:00
|
|
|
}
|
|
|
|
|
2003-11-20 00:26:41 +08:00
|
|
|
rev->log = log;
|
|
|
|
wev->log = log;
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2003-12-09 04:48:12 +08:00
|
|
|
/*
|
2005-10-12 21:50:36 +08:00
|
|
|
* TODO: MT: - ngx_atomic_fetch_add()
|
2004-02-24 04:57:12 +08:00
|
|
|
* or protection by critical section or light mutex
|
2003-12-09 04:48:12 +08:00
|
|
|
*
|
|
|
|
* TODO: MP: - allocated in a shared memory
|
2005-10-12 21:50:36 +08:00
|
|
|
* - ngx_atomic_fetch_add()
|
2004-02-24 04:57:12 +08:00
|
|
|
* or protection by critical section or light mutex
|
2003-12-09 04:48:12 +08:00
|
|
|
*/
|
2003-12-19 16:15:11 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1);
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2005-02-24 20:29:09 +08:00
|
|
|
#if (NGX_STAT_STUB)
|
2009-06-18 21:14:51 +08:00
|
|
|
(void) ngx_atomic_fetch_add(ngx_stat_handled, 1);
|
2005-02-24 20:29:09 +08:00
|
|
|
#endif
|
|
|
|
|
2004-06-28 02:01:57 +08:00
|
|
|
#if (NGX_THREADS)
|
|
|
|
rev->lock = &c->lock;
|
|
|
|
wev->lock = &c->lock;
|
2004-07-07 14:15:04 +08:00
|
|
|
rev->own_lock = &c->lock;
|
|
|
|
wev->own_lock = &c->lock;
|
2004-06-28 02:01:57 +08:00
|
|
|
#endif
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
if (ls->addr_ntop) {
|
2008-06-17 23:00:30 +08:00
|
|
|
c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len);
|
2004-09-09 23:40:48 +08:00
|
|
|
if (c->addr_text.data == NULL) {
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_close_accepted_connection(c);
|
2004-09-09 23:40:48 +08:00
|
|
|
return;
|
|
|
|
}
|
2005-11-15 21:30:52 +08:00
|
|
|
|
2013-07-11 20:07:25 +08:00
|
|
|
c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->socklen,
|
|
|
|
c->addr_text.data,
|
2009-02-21 15:02:02 +08:00
|
|
|
ls->addr_text_max_len, 0);
|
2004-09-09 23:40:48 +08:00
|
|
|
if (c->addr_text.len == 0) {
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_close_accepted_connection(c);
|
2004-09-09 23:40:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-08 23:58:25 +08:00
|
|
|
#if (NGX_DEBUG)
|
|
|
|
{
|
|
|
|
|
2012-04-30 06:02:18 +08:00
|
|
|
struct sockaddr_in *sin;
|
|
|
|
ngx_cidr_t *cidr;
|
|
|
|
ngx_uint_t i;
|
|
|
|
#if (NGX_HAVE_INET6)
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
ngx_uint_t n;
|
|
|
|
#endif
|
2004-04-08 23:58:25 +08:00
|
|
|
|
2012-04-30 06:02:18 +08:00
|
|
|
cidr = ecf->debug_connection.elts;
|
2004-04-08 23:58:25 +08:00
|
|
|
for (i = 0; i < ecf->debug_connection.nelts; i++) {
|
2013-09-05 00:48:23 +08:00
|
|
|
if (cidr[i].family != (ngx_uint_t) c->sockaddr->sa_family) {
|
2012-04-30 06:02:18 +08:00
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cidr[i].family) {
|
|
|
|
|
|
|
|
#if (NGX_HAVE_INET6)
|
|
|
|
case AF_INET6:
|
|
|
|
sin6 = (struct sockaddr_in6 *) c->sockaddr;
|
|
|
|
for (n = 0; n < 16; n++) {
|
|
|
|
if ((sin6->sin6_addr.s6_addr[n]
|
|
|
|
& cidr[i].u.in6.mask.s6_addr[n])
|
|
|
|
!= cidr[i].u.in6.addr.s6_addr[n])
|
|
|
|
{
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
|
|
case AF_UNIX:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default: /* AF_INET */
|
|
|
|
sin = (struct sockaddr_in *) c->sockaddr;
|
|
|
|
if ((sin->sin_addr.s_addr & cidr[i].u.in.mask)
|
|
|
|
!= cidr[i].u.in.addr)
|
|
|
|
{
|
|
|
|
goto next;
|
|
|
|
}
|
2004-04-08 23:58:25 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-04-30 06:02:18 +08:00
|
|
|
|
|
|
|
log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
next:
|
|
|
|
continue;
|
2004-04-08 23:58:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-07-11 21:20:19 +08:00
|
|
|
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,
|
|
|
|
"*%d accept: %V fd:%d", c->number, &c->addr_text, s);
|
|
|
|
|
2004-07-07 23:01:00 +08:00
|
|
|
if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) {
|
2003-05-29 21:02:09 +08:00
|
|
|
if (ngx_add_conn(c) == NGX_ERROR) {
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_close_accepted_connection(c);
|
2003-05-14 00:02:32 +08:00
|
|
|
return;
|
2003-03-04 14:33:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-20 00:26:41 +08:00
|
|
|
log->data = NULL;
|
|
|
|
log->handler = NULL;
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
ls->handler(c);
|
2002-08-07 00:39:45 +08:00
|
|
|
|
2004-10-21 23:34:38 +08:00
|
|
|
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
|
2002-08-07 00:39:45 +08:00
|
|
|
ev->available--;
|
2003-01-30 15:28:09 +08:00
|
|
|
}
|
2003-11-20 00:26:41 +08:00
|
|
|
|
2002-08-07 00:39:45 +08:00
|
|
|
} while (ev->available);
|
|
|
|
}
|
2003-11-20 00:26:41 +08:00
|
|
|
|
|
|
|
|
2005-02-22 22:40:13 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_trylock_accept_mutex(ngx_cycle_t *cycle)
|
2004-03-31 23:26:46 +08:00
|
|
|
{
|
2006-02-08 23:33:12 +08:00
|
|
|
if (ngx_shmtx_trylock(&ngx_accept_mutex)) {
|
|
|
|
|
2004-03-31 23:26:46 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
|
|
|
"accept mutex locked");
|
|
|
|
|
2006-09-26 20:20:12 +08:00
|
|
|
if (ngx_accept_mutex_held
|
|
|
|
&& ngx_accept_events == 0
|
|
|
|
&& !(ngx_event_flags & NGX_USE_RTSIG_EVENT))
|
|
|
|
{
|
nginx-0.3.8-RELEASE import
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; the bug had
appeared in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
2005-11-10 01:25:55 +08:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
2004-03-31 23:26:46 +08:00
|
|
|
|
nginx-0.3.8-RELEASE import
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; the bug had
appeared in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
2005-11-10 01:25:55 +08:00
|
|
|
if (ngx_enable_accept_events(cycle) == NGX_ERROR) {
|
2006-02-08 23:33:12 +08:00
|
|
|
ngx_shmtx_unlock(&ngx_accept_mutex);
|
nginx-0.3.8-RELEASE import
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; the bug had
appeared in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
2005-11-10 01:25:55 +08:00
|
|
|
return NGX_ERROR;
|
2004-03-31 23:26:46 +08:00
|
|
|
}
|
|
|
|
|
2006-09-26 20:20:12 +08:00
|
|
|
ngx_accept_events = 0;
|
nginx-0.3.8-RELEASE import
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; the bug had
appeared in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
2005-11-10 01:25:55 +08:00
|
|
|
ngx_accept_mutex_held = 1;
|
|
|
|
|
2004-03-31 23:26:46 +08:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2006-09-26 20:20:12 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
|
|
|
"accept mutex lock failed: %ui", ngx_accept_mutex_held);
|
|
|
|
|
2004-04-01 14:21:13 +08:00
|
|
|
if (ngx_accept_mutex_held) {
|
2004-03-31 23:26:46 +08:00
|
|
|
if (ngx_disable_accept_events(cycle) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-04-01 14:21:13 +08:00
|
|
|
ngx_accept_mutex_held = 0;
|
2004-03-31 23:26:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
nginx-0.3.8-RELEASE import
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; the bug had
appeared in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
2005-11-10 01:25:55 +08:00
|
|
|
static ngx_int_t
|
2005-02-22 22:40:13 +08:00
|
|
|
ngx_enable_accept_events(ngx_cycle_t *cycle)
|
2004-03-31 23:26:46 +08:00
|
|
|
{
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_uint_t i;
|
|
|
|
ngx_listening_t *ls;
|
|
|
|
ngx_connection_t *c;
|
2004-03-31 23:26:46 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
ls = cycle->listening.elts;
|
2004-03-31 23:26:46 +08:00
|
|
|
for (i = 0; i < cycle->listening.nelts; i++) {
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
c = ls[i].connection;
|
2004-03-31 23:26:46 +08:00
|
|
|
|
2012-05-11 21:33:06 +08:00
|
|
|
if (c->read->active) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-06-07 03:49:18 +08:00
|
|
|
if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
|
nginx-0.3.8-RELEASE import
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; the bug had
appeared in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
2005-11-10 01:25:55 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
if (ngx_add_conn(c) == NGX_ERROR) {
|
2004-03-31 23:26:46 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2005-09-23 19:02:22 +08:00
|
|
|
if (ngx_add_event(c->read, NGX_READ_EVENT, 0) == NGX_ERROR) {
|
2004-03-31 23:26:46 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
nginx-0.3.8-RELEASE import
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; the bug had
appeared in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
2005-11-10 01:25:55 +08:00
|
|
|
static ngx_int_t
|
2005-02-22 22:40:13 +08:00
|
|
|
ngx_disable_accept_events(ngx_cycle_t *cycle)
|
2004-03-31 23:26:46 +08:00
|
|
|
{
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_uint_t i;
|
|
|
|
ngx_listening_t *ls;
|
|
|
|
ngx_connection_t *c;
|
2004-03-31 23:26:46 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
ls = cycle->listening.elts;
|
2004-03-31 23:26:46 +08:00
|
|
|
for (i = 0; i < cycle->listening.nelts; i++) {
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
c = ls[i].connection;
|
2004-03-31 23:26:46 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
if (!c->read->active) {
|
|
|
|
continue;
|
|
|
|
}
|
2004-04-15 01:44:28 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
|
|
|
|
if (ngx_del_conn(c, NGX_DISABLE_EVENT) == NGX_ERROR) {
|
2004-03-31 23:26:46 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2005-09-23 19:02:22 +08:00
|
|
|
if (ngx_del_event(c->read, NGX_READ_EVENT, NGX_DISABLE_EVENT)
|
|
|
|
== NGX_ERROR)
|
2004-03-31 23:26:46 +08:00
|
|
|
{
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-22 22:40:13 +08:00
|
|
|
static void
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_close_accepted_connection(ngx_connection_t *c)
|
2004-09-09 23:40:48 +08:00
|
|
|
{
|
2005-09-23 19:02:22 +08:00
|
|
|
ngx_socket_t fd;
|
|
|
|
|
|
|
|
ngx_free_connection(c);
|
|
|
|
|
|
|
|
fd = c->fd;
|
|
|
|
c->fd = (ngx_socket_t) -1;
|
|
|
|
|
|
|
|
if (ngx_close_socket(fd) == -1) {
|
|
|
|
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno,
|
2004-09-09 23:40:48 +08:00
|
|
|
ngx_close_socket_n " failed");
|
|
|
|
}
|
2005-02-24 20:29:09 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
if (c->pool) {
|
|
|
|
ngx_destroy_pool(c->pool);
|
|
|
|
}
|
|
|
|
|
2005-02-24 20:29:09 +08:00
|
|
|
#if (NGX_STAT_STUB)
|
2009-06-18 21:14:51 +08:00
|
|
|
(void) ngx_atomic_fetch_add(ngx_stat_active, -1);
|
2005-02-24 20:29:09 +08:00
|
|
|
#endif
|
2004-09-09 23:40:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
u_char *
|
2005-02-22 22:40:13 +08:00
|
|
|
ngx_accept_log_error(ngx_log_t *log, u_char *buf, size_t len)
|
2003-11-20 00:26:41 +08:00
|
|
|
{
|
2005-09-23 19:02:22 +08:00
|
|
|
return ngx_snprintf(buf, len, " while accepting new connection on %V",
|
|
|
|
log->data);
|
2003-11-20 00:26:41 +08:00
|
|
|
}
|