aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-04-01 16:20:53 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-04-01 16:20:53 +0000
commitdbb27765706e2d2f35b0af57c317b58d2d9d6ec9 (patch)
tree69760523cc77e8244f0f1d5c3c0247544a1179b9 /src
parent205dc145c5d22613826927d6ae8ccd3a69d0e907 (diff)
downloadnginx-dbb27765706e2d2f35b0af57c317b58d2d9d6ec9.tar.gz
nginx-dbb27765706e2d2f35b0af57c317b58d2d9d6ec9.zip
nginx-0.0.3-2004-04-01-20:20:53 import
Diffstat (limited to 'src')
-rw-r--r--src/core/ngx_connection.c3
-rw-r--r--src/event/modules/ngx_kqueue_module.c2
-rw-r--r--src/event/ngx_event.c68
-rw-r--r--src/event/ngx_event.h9
-rw-r--r--src/event/ngx_event_accept.c5
-rw-r--r--src/event/ngx_event_timer.h19
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c10
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.h1
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c6
-rw-r--r--src/http/ngx_http_core_module.c10
-rw-r--r--src/http/ngx_http_core_module.h1
-rw-r--r--src/http/ngx_http_request.h1
-rw-r--r--src/http/ngx_http_request_body.c15
-rw-r--r--src/http/ngx_http_write_filter.c5
-rw-r--r--src/os/unix/ngx_files.c14
-rw-r--r--src/os/unix/ngx_files.h3
-rw-r--r--src/os/unix/ngx_process_cycle.c18
-rw-r--r--src/os/unix/ngx_readv_chain.c2
18 files changed, 129 insertions, 63 deletions
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index a7c02c8f8..8dedbd10e 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -212,6 +212,9 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
return;
}
+ ngx_accept_mutex_held = 0;
+ ngx_accept_mutex = NULL;
+
ls = cycle->listening.elts;
for (i = 0; i < cycle->listening.nelts; i++) {
fd = ls[i].fd;
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index 8d37d0187..9f0cd1857 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -375,7 +375,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
return NGX_ERROR;
}
-#if 0
+#if 1
if (ngx_accept_mutex_held == 0 && timer == 0) {
/* STUB */ timer = 500;
}
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index 5678c8489..b50b8739c 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -28,7 +28,8 @@ extern ngx_event_module_t ngx_epoll_module_ctx;
#include <ngx_aio_module.h>
#endif
-static int ngx_event_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle);
static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd,
@@ -39,11 +40,16 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle);
static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf);
-int ngx_event_flags;
-ngx_event_actions_t ngx_event_actions;
+static ngx_uint_t ngx_event_max_module;
+ngx_uint_t ngx_event_flags;
+ngx_event_actions_t ngx_event_actions;
+
+
+ngx_atomic_t *ngx_accept_mutex_ptr;
+ngx_atomic_t *ngx_accept_mutex;
+ngx_uint_t ngx_accept_mutex_held;
-static int ngx_event_max_module;
ngx_thread_volatile ngx_event_t *ngx_posted_events;
#if (NGX_THREADS)
@@ -101,6 +107,13 @@ static ngx_command_t ngx_event_core_commands[] = {
offsetof(ngx_event_conf_t, multi_accept),
NULL },
+ { ngx_string("accept_mutex"),
+ NGX_EVENT_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_flag_slot,
+ 0,
+ offsetof(ngx_event_conf_t, accept_mutex),
+ NULL },
+
ngx_null_command
};
@@ -119,18 +132,50 @@ ngx_module_t ngx_event_core_module = {
&ngx_event_core_module_ctx, /* module context */
ngx_event_core_commands, /* module directives */
NGX_EVENT_MODULE, /* module type */
- NULL, /* init module */
- ngx_event_init /* init child */
+ ngx_event_module_init, /* init module */
+ ngx_event_process_init /* init process */
};
-static int ngx_event_init(ngx_cycle_t *cycle)
+static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
+{
+ ngx_core_conf_t *ccf;
+ ngx_event_conf_t *ecf;
+
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+ if (ccf->master == 0) {
+ return NGX_OK;
+ }
+
+ ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
+
+ if (ecf->accept_mutex == 0) {
+ return NGX_OK;
+ }
+
+ ngx_accept_mutex_ptr = mmap(NULL, sizeof(ngx_atomic_t),
+ PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_SHARED, -1, 0);
+
+ if (ngx_accept_mutex_ptr == NULL) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "mmap(MAP_ANON|MAP_SHARED) failed");
+ return NGX_ERROR;
+ }
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
{
ngx_uint_t m, i;
ngx_socket_t fd;
ngx_event_t *rev, *wev;
ngx_listening_t *s;
ngx_connection_t *c;
+ ngx_core_conf_t *ccf;
ngx_event_conf_t *ecf;
ngx_event_module_t *module;
#if (WIN32)
@@ -138,6 +183,13 @@ static int ngx_event_init(ngx_cycle_t *cycle)
#endif
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+ if (ccf->worker_processes > 1 && ngx_accept_mutex_ptr) {
+ ngx_accept_mutex = ngx_accept_mutex_ptr;
+ ngx_accept_mutex_held = 1;
+ }
+
#if (NGX_THREADS)
if (!(ngx_posted_events_mutex = ngx_mutex_init(cycle->log, 0))) {
return NGX_ERROR;
@@ -470,6 +522,7 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle)
ecf->connections = NGX_CONF_UNSET;
ecf->use = NGX_CONF_UNSET;
ecf->multi_accept = NGX_CONF_UNSET;
+ ecf->accept_mutex = NGX_CONF_UNSET;
ecf->name = (void *) NGX_CONF_UNSET;
return ecf;
@@ -542,6 +595,7 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
cycle->connection_n = ecf->connections;
ngx_conf_init_value(ecf->multi_accept, 0);
+ ngx_conf_init_value(ecf->accept_mutex, 1);
return NGX_CONF_OK;
}
diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h
index 69a08cd8a..7fa1a9365 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -374,9 +374,12 @@ extern ngx_event_actions_t ngx_event_actions;
typedef struct {
- int connections;
- int use;
+ ngx_int_t connections;
+ ngx_int_t use;
+
ngx_flag_t multi_accept;
+ ngx_flag_t accept_mutex;
+
u_char *name;
} ngx_event_conf_t;
@@ -407,7 +410,7 @@ extern ngx_uint_t ngx_accept_mutex_held;
}
-extern int ngx_event_flags;
+extern ngx_uint_t ngx_event_flags;
extern ngx_module_t ngx_events_module;
extern ngx_module_t ngx_event_core_module;
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c
index d1942d581..41794bea9 100644
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -14,11 +14,6 @@ typedef struct {
static size_t ngx_accept_log_error(void *data, char *buf, size_t len);
-ngx_atomic_t *ngx_accept_mutex_ptr;
-ngx_atomic_t *ngx_accept_mutex;
-ngx_uint_t ngx_accept_mutex_held;
-
-
void ngx_event_accept(ngx_event_t *ev)
{
ngx_uint_t instance, rinstance, winstance, accepted;
diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h
index 21f261f88..0eae57043 100644
--- a/src/event/ngx_event_timer.h
+++ b/src/event/ngx_event_timer.h
@@ -67,17 +67,28 @@ ngx_inline static void ngx_event_del_timer(ngx_event_t *ev)
ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
{
- if (ev->timer_set) {
- ngx_del_timer(ev);
- }
+ ngx_int_t key;
- ev->rbtree_key = (ngx_int_t)
+ key = (ngx_int_t)
(ngx_elapsed_msec / NGX_TIMER_RESOLUTION * NGX_TIMER_RESOLUTION
+ timer) / NGX_TIMER_RESOLUTION;
#if 0
(ngx_elapsed_msec + timer) / NGX_TIMER_RESOLUTION;
#endif
+ if (ev->timer_set) {
+ if (key - ev->rbtree_key < 50) {
+ ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
+ "event timer: %d, old: %d, new: %d",
+ ngx_event_ident(ev->data), ev->rbtree_key, key);
+ return;
+ }
+
+ ngx_del_timer(ev);
+ }
+
+ ev->rbtree_key = key;
+
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
"event timer add: %d: %d",
ngx_event_ident(ev->data), ev->rbtree_key);
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 8f0336a9b..0dba23f9b 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -60,13 +60,6 @@ static ngx_command_t ngx_http_proxy_commands[] = {
0,
NULL },
- { ngx_string("proxy_request_buffer_size"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_proxy_loc_conf_t, request_buffer_size),
- NULL },
-
{ ngx_string("proxy_connect_timeout"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
@@ -781,7 +774,6 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
*/
- conf->request_buffer_size = NGX_CONF_UNSET_SIZE;
conf->connect_timeout = NGX_CONF_UNSET_MSEC;
conf->send_timeout = NGX_CONF_UNSET_MSEC;
@@ -822,8 +814,6 @@ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
ngx_http_proxy_loc_conf_t *prev = parent;
ngx_http_proxy_loc_conf_t *conf = child;
- ngx_conf_merge_size_value(conf->request_buffer_size,
- prev->request_buffer_size, 8192);
ngx_conf_merge_msec_value(conf->connect_timeout,
prev->connect_timeout, 60000);
ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 30000);
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index d204cac59..853aa7617 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -48,7 +48,6 @@ typedef struct {
typedef struct {
- size_t request_buffer_size;
size_t header_buffer_size;
size_t busy_buffers_size;
size_t max_temp_file_size;
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 00a078009..bd4befd76 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -86,7 +86,6 @@ int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p)
tf->warn = "a client request body is buffered to a temporary file";
/* tf->persistent = 0; */
- rb->buf_size = p->lcf->request_buffer_size;
rb->handler = ngx_http_proxy_init_upstream;
rb->data = p;
/* rb->bufs = NULL; */
@@ -1179,7 +1178,10 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
ep->temp_file->file.log = r->connection->log;
ep->temp_file->path = p->lcf->temp_path;
ep->temp_file->pool = r->pool;
- if (!p->cachable) {
+
+ if (p->cachable) {
+ ep->temp_file->persistent = 1;
+ } else {
ep->temp_file->warn = "an upstream response is buffered "
"to a temporary file";
}
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 1f449e239..3ae61829f 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -149,6 +149,13 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
NULL },
+ { ngx_string("client_body_buffer_size"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_size_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
+ NULL },
+
{ ngx_string("client_body_timeout"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
@@ -1181,6 +1188,7 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
*/
lcf->client_max_body_size = NGX_CONF_UNSET_SIZE;
+ lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
lcf->sendfile = NGX_CONF_UNSET;
lcf->tcp_nopush = NGX_CONF_UNSET;
@@ -1261,6 +1269,8 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_size_value(conf->client_max_body_size,
prev->client_max_body_size, 10 * 1024 * 1024);
+ ngx_conf_merge_size_value(conf->client_body_buffer_size,
+ prev->client_body_buffer_size, 8192);
ngx_conf_merge_msec_value(conf->client_body_timeout,
prev->client_body_timeout, 60000);
ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 3af3ed480..130106bae 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -124,6 +124,7 @@ typedef struct {
size_t client_max_body_size; /* client_max_body_size */
size_t send_lowat; /* send_lowat */
size_t discarded_buffer_size; /* discarded_buffer_size */
+ size_t client_body_buffer_size; /* client_body_buffer_size */
ngx_msec_t client_body_timeout; /* client_body_timeout */
ngx_msec_t send_timeout; /* send_timeout */
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index a3161531f..5e127e8fc 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -155,7 +155,6 @@ typedef struct {
ngx_chain_t *bufs;
ngx_hunk_t *buf;
size_t rest;
- size_t buf_size;
void (*handler) (void *data);
void *data;
} ngx_http_request_body_t;
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index 9f1260c6f..c4aada505 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -11,10 +11,10 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r);
ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r)
{
- ssize_t size;
- ngx_hunk_t *h;
- ngx_chain_t *cl;
-
+ ssize_t size;
+ ngx_hunk_t *h;
+ ngx_chain_t *cl;
+ ngx_http_core_loc_conf_t *clcf;
size = r->header_in->last - r->header_in->pos;
@@ -47,15 +47,18 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r)
}
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
r->request_body->rest = r->headers_in.content_length_n - size;
if (r->request_body->rest
- < r->request_body->buf_size + (r->request_body->buf_size >> 2))
+ < clcf->client_body_buffer_size
+ + (clcf->client_body_buffer_size >> 2))
{
size = r->request_body->rest;
} else {
- size = r->request_body->buf_size;
+ size = clcf->client_body_buffer_size;
}
ngx_test_null(r->request_body->buf, ngx_create_temp_hunk(r->pool, size),
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 1091d75be..5fa144fbc 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -62,7 +62,7 @@ ngx_module_t ngx_http_write_filter_module = {
ngx_http_write_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_write_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -82,7 +82,8 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
sizeof(ngx_http_write_filter_ctx_t), NGX_ERROR);
}
- size = flush = 0;
+ size = 0;
+ flush = 0;
last = 0;
ll = &ctx->out;
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index fbbddc6ab..da452e3fe 100644
--- a/src/os/unix/ngx_files.c
+++ b/src/os/unix/ngx_files.c
@@ -101,6 +101,20 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
}
+int ngx_open_tempfile(u_char *name, ngx_uint_t persistent)
+{
+ ngx_fd_t fd;
+
+ fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR, 0600);
+
+ if (fd != -1 && !persistent) {
+ unlink((const char *) name);
+ }
+
+ return fd;
+}
+
+
ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
off_t offset, ngx_pool_t *pool)
{
diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h
index 9952a7448..afc5367a3 100644
--- a/src/os/unix/ngx_files.h
+++ b/src/os/unix/ngx_files.h
@@ -30,8 +30,7 @@
#define ngx_delete_file_n "unlink()"
-#define ngx_open_tempfile(name, persistent) \
- open((const char *) name, O_CREAT|O_EXCL|O_RDWR, 0600)
+int ngx_open_tempfile(u_char *name, ngx_uint_t persistent);
#define ngx_open_tempfile_n "open()"
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 090733adb..1ae4deeb6 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -65,17 +65,6 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
signo = 0;
live = 0;
- ngx_accept_mutex_ptr = mmap(NULL, sizeof(ngx_atomic_t),
- PROT_READ|PROT_WRITE,
- MAP_ANON|MAP_SHARED, -1, 0);
-
- if (ngx_accept_mutex_ptr == NULL) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "mmap(MAP_ANON|MAP_SHARED) failed");
- /* fatal */
- exit(2);
- }
-
for ( ;; ) {
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle");
@@ -378,11 +367,6 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
- if (ccf->worker_processes > 1) {
- ngx_accept_mutex = ngx_accept_mutex_ptr;
- ngx_accept_mutex_held = 1;
- }
-
if (ccf->group != (gid_t) NGX_CONF_UNSET) {
if (setuid(ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
@@ -485,8 +469,6 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
ngx_close_listening_sockets(cycle);
- ngx_accept_mutex = NULL;
-
for ( ;; ) {
if (ngx_event_timer_rbtree == &ngx_event_timer_sentinel) {
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exiting");
diff --git a/src/os/unix/ngx_readv_chain.c b/src/os/unix/ngx_readv_chain.c
index 9aee56404..3ec3b2761 100644
--- a/src/os/unix/ngx_readv_chain.c
+++ b/src/os/unix/ngx_readv_chain.c
@@ -68,7 +68,7 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "readv: %d:%d", io.nelts, iov->iov_len);
+ "readv: %d, last:%d", io.nelts, iov->iov_len);
rev = c->read;