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);
|
2015-05-20 20:51:56 +08:00
|
|
|
static ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle, ngx_uint_t all);
|
2005-09-23 19:02:22 +08:00
|
|
|
static void ngx_close_accepted_connection(ngx_connection_t *c);
|
2016-01-21 00:52:12 +08:00
|
|
|
#if (NGX_DEBUG)
|
|
|
|
static void ngx_debug_accepted_connection(ngx_event_conf_t *ecf,
|
|
|
|
ngx_connection_t *c);
|
|
|
|
#endif
|
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
|
|
|
|
2015-04-23 19:17:40 +08:00
|
|
|
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
|
|
|
|
2013-09-05 00:48:28 +08:00
|
|
|
if (s == (ngx_socket_t) -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) {
|
2015-05-20 20:51:56 +08:00
|
|
|
if (ngx_disable_accept_events((ngx_cycle_t *) ngx_cycle, 1)
|
2012-05-11 21:33:06 +08:00
|
|
|
!= 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;
|
|
|
|
}
|
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
c->type = SOCK_STREAM;
|
|
|
|
|
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
|
|
|
|
2015-04-22 23:57:32 +08:00
|
|
|
/* set a blocking mode for iocp and non-blocking mode for others */
|
2003-05-21 21:28:21 +08:00
|
|
|
|
|
|
|
if (ngx_inherited_nonblocking) {
|
2015-04-22 23:57:32 +08:00
|
|
|
if (ngx_event_flags & NGX_USE_IOCP_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 {
|
2015-04-23 19:17:40 +08:00
|
|
|
if (!(ngx_event_flags & NGX_USE_IOCP_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;
|
2013-12-09 14:14:51 +08:00
|
|
|
c->local_socklen = ls->socklen;
|
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
|
|
|
|
2015-04-23 19:17:40 +08:00
|
|
|
if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
|
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
|
|
|
|
|
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)
|
|
|
|
{
|
2016-01-21 00:52:12 +08:00
|
|
|
ngx_str_t addr;
|
|
|
|
u_char text[NGX_SOCKADDR_STRLEN];
|
2004-04-08 23:58:25 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
ngx_debug_accepted_connection(ecf, c);
|
|
|
|
|
|
|
|
if (log->log_level & NGX_LOG_DEBUG_EVENT) {
|
|
|
|
addr.data = text;
|
|
|
|
addr.len = ngx_sock_ntop(c->sockaddr, c->socklen, text,
|
|
|
|
NGX_SOCKADDR_STRLEN, 1);
|
|
|
|
|
|
|
|
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,
|
|
|
|
"*%uA accept: %V fd:%d", c->number, &addr, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-04-30 06:02:18 +08:00
|
|
|
#endif
|
2004-04-08 23:58:25 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) {
|
|
|
|
if (ngx_add_conn(c) == NGX_ERROR) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
2012-04-30 06:02:18 +08:00
|
|
|
}
|
2016-01-21 00:52:12 +08:00
|
|
|
}
|
2012-04-30 06:02:18 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
log->data = NULL;
|
|
|
|
log->handler = NULL;
|
2012-04-30 06:02:18 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
ls->handler(c);
|
|
|
|
|
|
|
|
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
|
|
|
|
ev->available--;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (ev->available);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if !(NGX_WIN32)
|
|
|
|
|
|
|
|
void
|
|
|
|
ngx_event_recvmsg(ngx_event_t *ev)
|
|
|
|
{
|
|
|
|
ssize_t n;
|
|
|
|
ngx_log_t *log;
|
|
|
|
ngx_err_t err;
|
|
|
|
ngx_event_t *rev, *wev;
|
|
|
|
struct iovec iov[1];
|
|
|
|
struct msghdr msg;
|
|
|
|
ngx_listening_t *ls;
|
|
|
|
ngx_event_conf_t *ecf;
|
|
|
|
ngx_connection_t *c, *lc;
|
|
|
|
u_char sa[NGX_SOCKADDRLEN];
|
|
|
|
static u_char buffer[65535];
|
|
|
|
|
|
|
|
#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
|
|
|
|
|
|
|
|
#if (NGX_HAVE_IP_RECVDSTADDR)
|
|
|
|
u_char msg_control[CMSG_SPACE(sizeof(struct in_addr))];
|
|
|
|
#elif (NGX_HAVE_IP_PKTINFO)
|
|
|
|
u_char msg_control[CMSG_SPACE(sizeof(struct in_pktinfo))];
|
2012-04-30 06:02:18 +08:00
|
|
|
#endif
|
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
#if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)
|
|
|
|
u_char msg_control6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
|
2012-04-30 06:02:18 +08:00
|
|
|
#endif
|
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ev->timedout) {
|
|
|
|
if (ngx_enable_accept_events((ngx_cycle_t *) ngx_cycle) != NGX_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev->timedout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module);
|
|
|
|
|
|
|
|
if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) {
|
|
|
|
ev->available = ecf->multi_accept;
|
|
|
|
}
|
|
|
|
|
|
|
|
lc = ev->data;
|
|
|
|
ls = lc->listening;
|
|
|
|
ev->ready = 0;
|
|
|
|
|
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
|
|
|
|
"recvmsg on %V, ready: %d", &ls->addr_text, ev->available);
|
|
|
|
|
|
|
|
do {
|
|
|
|
ngx_memzero(&msg, sizeof(struct msghdr));
|
|
|
|
|
|
|
|
iov[0].iov_base = (void *) buffer;
|
|
|
|
iov[0].iov_len = sizeof(buffer);
|
|
|
|
|
|
|
|
msg.msg_name = &sa;
|
|
|
|
msg.msg_namelen = sizeof(sa);
|
|
|
|
msg.msg_iov = iov;
|
|
|
|
msg.msg_iovlen = 1;
|
|
|
|
|
|
|
|
#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
|
|
|
|
|
|
|
|
if (ls->wildcard) {
|
|
|
|
|
|
|
|
#if (NGX_HAVE_IP_RECVDSTADDR || NGX_HAVE_IP_PKTINFO)
|
|
|
|
if (ls->sockaddr->sa_family == AF_INET) {
|
|
|
|
msg.msg_control = &msg_control;
|
|
|
|
msg.msg_controllen = sizeof(msg_control);
|
2004-04-08 23:58:25 +08:00
|
|
|
}
|
2016-01-21 00:52:12 +08:00
|
|
|
#endif
|
2012-04-30 06:02:18 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
#if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)
|
|
|
|
if (ls->sockaddr->sa_family == AF_INET6) {
|
|
|
|
msg.msg_control = &msg_control6;
|
|
|
|
msg.msg_controllen = sizeof(msg_control6);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
n = recvmsg(lc->fd, &msg, 0);
|
|
|
|
|
|
|
|
if (n == -1) {
|
|
|
|
err = ngx_socket_errno;
|
|
|
|
|
|
|
|
if (err == NGX_EAGAIN) {
|
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err,
|
|
|
|
"recvmsg() not ready");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_ALERT, ev->log, err, "recvmsg() failed");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (NGX_STAT_STUB)
|
|
|
|
(void) ngx_atomic_fetch_add(ngx_stat_accepted, 1);
|
|
|
|
#endif
|
2012-04-30 06:02:18 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
|
|
|
|
if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) {
|
|
|
|
ngx_log_error(NGX_LOG_ALERT, ev->log, 0,
|
|
|
|
"recvmsg() truncated data");
|
2012-04-30 06:02:18 +08:00
|
|
|
continue;
|
2004-04-08 23:58:25 +08:00
|
|
|
}
|
2016-01-21 00:52:12 +08:00
|
|
|
#endif
|
2004-04-08 23:58:25 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
ngx_accept_disabled = ngx_cycle->connection_n / 8
|
|
|
|
- ngx_cycle->free_connection_n;
|
2014-05-22 04:16:09 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
c = ngx_get_connection(lc->fd, ev->log);
|
|
|
|
if (c == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->shared = 1;
|
|
|
|
c->type = SOCK_DGRAM;
|
|
|
|
c->socklen = msg.msg_namelen;
|
|
|
|
|
|
|
|
#if (NGX_STAT_STUB)
|
|
|
|
(void) ngx_atomic_fetch_add(ngx_stat_active, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
c->pool = ngx_create_pool(ls->pool_size, ev->log);
|
|
|
|
if (c->pool == NULL) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
2004-04-08 23:58:25 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
c->sockaddr = ngx_palloc(c->pool, c->socklen);
|
|
|
|
if (c->sockaddr == NULL) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
2014-05-22 04:16:09 +08:00
|
|
|
}
|
2016-01-21 00:52:12 +08:00
|
|
|
|
|
|
|
ngx_memcpy(c->sockaddr, msg.msg_name, c->socklen);
|
|
|
|
|
|
|
|
log = ngx_palloc(c->pool, sizeof(ngx_log_t));
|
|
|
|
if (log == NULL) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*log = ls->log;
|
|
|
|
|
|
|
|
c->send = ngx_udp_send;
|
|
|
|
|
|
|
|
c->log = log;
|
|
|
|
c->pool->log = log;
|
|
|
|
|
|
|
|
c->listening = ls;
|
|
|
|
c->local_sockaddr = ls->sockaddr;
|
|
|
|
c->local_socklen = ls->socklen;
|
|
|
|
|
|
|
|
#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
|
|
|
|
|
|
|
|
if (ls->wildcard) {
|
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
struct sockaddr *sockaddr;
|
|
|
|
|
|
|
|
sockaddr = ngx_palloc(c->pool, c->local_socklen);
|
|
|
|
if (sockaddr == NULL) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_memcpy(sockaddr, c->local_sockaddr, c->local_socklen);
|
|
|
|
c->local_sockaddr = sockaddr;
|
|
|
|
|
|
|
|
for (cmsg = CMSG_FIRSTHDR(&msg);
|
|
|
|
cmsg != NULL;
|
|
|
|
cmsg = CMSG_NXTHDR(&msg, cmsg))
|
|
|
|
{
|
|
|
|
|
|
|
|
#if (NGX_HAVE_IP_RECVDSTADDR)
|
|
|
|
|
|
|
|
if (cmsg->cmsg_level == IPPROTO_IP
|
|
|
|
&& cmsg->cmsg_type == IP_RECVDSTADDR
|
|
|
|
&& sockaddr->sa_family == AF_INET)
|
|
|
|
{
|
|
|
|
struct in_addr *addr;
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
addr = (struct in_addr *) CMSG_DATA(cmsg);
|
|
|
|
sin = (struct sockaddr_in *) sockaddr;
|
|
|
|
sin->sin_addr = *addr;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif (NGX_HAVE_IP_PKTINFO)
|
|
|
|
|
|
|
|
if (cmsg->cmsg_level == IPPROTO_IP
|
|
|
|
&& cmsg->cmsg_type == IP_PKTINFO
|
|
|
|
&& sockaddr->sa_family == AF_INET)
|
|
|
|
{
|
|
|
|
struct in_pktinfo *pkt;
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
pkt = (struct in_pktinfo *) CMSG_DATA(cmsg);
|
|
|
|
sin = (struct sockaddr_in *) sockaddr;
|
|
|
|
sin->sin_addr = pkt->ipi_addr;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-05-22 04:16:09 +08:00
|
|
|
#endif
|
2006-07-11 21:20:19 +08:00
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
#if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)
|
|
|
|
|
|
|
|
if (cmsg->cmsg_level == IPPROTO_IPV6
|
|
|
|
&& cmsg->cmsg_type == IPV6_PKTINFO
|
|
|
|
&& sockaddr->sa_family == AF_INET6)
|
|
|
|
{
|
|
|
|
struct in6_pktinfo *pkt6;
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
pkt6 = (struct in6_pktinfo *) CMSG_DATA(cmsg);
|
|
|
|
sin6 = (struct sockaddr_in6 *) sockaddr;
|
|
|
|
sin6->sin6_addr = pkt6->ipi6_addr;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
c->buffer = ngx_create_temp_buf(c->pool, n);
|
|
|
|
if (c->buffer == NULL) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->buffer->last = ngx_cpymem(c->buffer->last, buffer, n);
|
|
|
|
|
|
|
|
rev = c->read;
|
|
|
|
wev = c->write;
|
|
|
|
|
|
|
|
wev->ready = 1;
|
|
|
|
|
|
|
|
rev->log = log;
|
|
|
|
wev->log = log;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: MT: - ngx_atomic_fetch_add()
|
|
|
|
* or protection by critical section or light mutex
|
|
|
|
*
|
|
|
|
* TODO: MP: - allocated in a shared memory
|
|
|
|
* - ngx_atomic_fetch_add()
|
|
|
|
* or protection by critical section or light mutex
|
|
|
|
*/
|
|
|
|
|
|
|
|
c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1);
|
|
|
|
|
|
|
|
#if (NGX_STAT_STUB)
|
|
|
|
(void) ngx_atomic_fetch_add(ngx_stat_handled, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ls->addr_ntop) {
|
|
|
|
c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len);
|
|
|
|
if (c->addr_text.data == NULL) {
|
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
|
|
|
}
|
2016-01-21 00:52:12 +08:00
|
|
|
|
|
|
|
c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->socklen,
|
|
|
|
c->addr_text.data,
|
|
|
|
ls->addr_text_max_len, 0);
|
|
|
|
if (c->addr_text.len == 0) {
|
|
|
|
ngx_close_accepted_connection(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (NGX_DEBUG)
|
|
|
|
{
|
|
|
|
ngx_str_t addr;
|
|
|
|
u_char text[NGX_SOCKADDR_STRLEN];
|
|
|
|
|
|
|
|
ngx_debug_accepted_connection(ecf, c);
|
|
|
|
|
|
|
|
if (log->log_level & NGX_LOG_DEBUG_EVENT) {
|
|
|
|
addr.data = text;
|
|
|
|
addr.len = ngx_sock_ntop(c->sockaddr, c->socklen, text,
|
|
|
|
NGX_SOCKADDR_STRLEN, 1);
|
|
|
|
|
|
|
|
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0,
|
|
|
|
"*%uA recvmsg: %V fd:%d n:%z",
|
|
|
|
c->number, &addr, c->fd, n);
|
|
|
|
}
|
|
|
|
|
2003-03-04 14:33:48 +08:00
|
|
|
}
|
2016-01-21 00:52:12 +08:00
|
|
|
#endif
|
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) {
|
2016-01-21 00:52:12 +08:00
|
|
|
ev->available -= n;
|
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
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
#endif
|
|
|
|
|
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");
|
|
|
|
|
2015-04-23 19:17:40 +08:00
|
|
|
if (ngx_accept_mutex_held && 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
|
|
|
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) {
|
2015-05-20 20:51:56 +08:00
|
|
|
if (ngx_disable_accept_events(cycle, 0) == NGX_ERROR) {
|
2004-03-31 23:26:46 +08:00
|
|
|
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
|
|
|
|
2015-05-20 20:51:56 +08:00
|
|
|
if (c == NULL || c->read->active) {
|
2012-05-11 21:33:06 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-04-23 19:17:40 +08:00
|
|
|
if (ngx_add_event(c->read, NGX_READ_EVENT, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
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
|
2015-05-20 20:51:56 +08:00
|
|
|
ngx_disable_accept_events(ngx_cycle_t *cycle, ngx_uint_t all)
|
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
|
|
|
|
2015-05-20 20:51:56 +08:00
|
|
|
if (c == NULL || !c->read->active) {
|
2005-09-23 19:02:22 +08:00
|
|
|
continue;
|
|
|
|
}
|
2004-04-15 01:44:28 +08:00
|
|
|
|
2015-05-20 20:51:56 +08:00
|
|
|
#if (NGX_HAVE_REUSEPORT)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do not disable accept on worker's own sockets
|
|
|
|
* when disabling accept events due to accept mutex
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ls[i].reuseport && !all) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-04-23 19:17:40 +08:00
|
|
|
if (ngx_del_event(c->read, NGX_READ_EVENT, NGX_DISABLE_EVENT)
|
|
|
|
== NGX_ERROR)
|
|
|
|
{
|
|
|
|
return NGX_ERROR;
|
2004-03-31 23:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-01-21 00:52:12 +08:00
|
|
|
if (!c->shared && ngx_close_socket(fd) == -1) {
|
2005-09-23 19:02:22 +08:00
|
|
|
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
|
|
|
}
|
2016-01-21 00:52:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
#if (NGX_DEBUG)
|
|
|
|
|
|
|
|
static void
|
|
|
|
ngx_debug_accepted_connection(ngx_event_conf_t *ecf, ngx_connection_t *c)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
cidr = ecf->debug_connection.elts;
|
|
|
|
for (i = 0; i < ecf->debug_connection.nelts; i++) {
|
|
|
|
if (cidr[i].family != (ngx_uint_t) c->sockaddr->sa_family) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
next:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|