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
|
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>
|
|
|
|
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
/* the buffer size is enough to hold "struct sockaddr_un" */
|
|
|
|
#define NGX_SOCKLEN 512
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
2005-09-23 19:02:22 +08:00
|
|
|
char sa[NGX_SOCKLEN];
|
2003-05-29 21:02:09 +08:00
|
|
|
|
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 {
|
2006-09-25 22:34:29 +08:00
|
|
|
socklen = NGX_SOCKLEN;
|
2003-05-20 23:37:55 +08:00
|
|
|
|
2006-09-25 22:34:29 +08:00
|
|
|
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
|
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
|
|
|
|
2006-02-23 03:41:39 +08:00
|
|
|
ngx_log_error((err == NGX_ECONNABORTED) ? NGX_LOG_ERR:
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
NGX_LOG_ALERT,
|
2005-09-23 19:02:22 +08:00
|
|
|
ev->log, err, "accept() failed");
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-29 21:02:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-15 03:39:54 +08:00
|
|
|
#if (NGX_STAT_STUB)
|
2005-10-12 21:50:36 +08:00
|
|
|
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)
|
|
|
|
ngx_atomic_fetch_add(ngx_stat_active, 1);
|
|
|
|
#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
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
c->listening = ls;
|
2006-09-25 22:34:29 +08:00
|
|
|
c->socklen = 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
|
|
|
|
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)
|
2005-10-12 21:50:36 +08:00
|
|
|
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
|
|
|
|
2008-08-22 03:24:07 +08:00
|
|
|
c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->addr_text.data,
|
2005-09-23 19:02:22 +08:00
|
|
|
ls->addr_text_max_len);
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
in_addr_t i;
|
2006-07-11 21:20:19 +08:00
|
|
|
ngx_event_debug_t *dc;
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
struct sockaddr_in *sin;
|
2004-04-08 23:58:25 +08:00
|
|
|
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
sin = (struct sockaddr_in *) sa;
|
2006-07-11 21:20:19 +08:00
|
|
|
dc = ecf->debug_connection.elts;
|
2004-04-08 23:58:25 +08:00
|
|
|
for (i = 0; i < ecf->debug_connection.nelts; i++) {
|
2006-07-11 21:20:19 +08:00
|
|
|
if ((sin->sin_addr.s_addr & dc[i].mask) == dc[i].addr) {
|
2004-04-08 23:58:25 +08:00
|
|
|
log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
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)
|
2005-10-12 21:50:36 +08:00
|
|
|
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
|
|
|
}
|