nginx-0.0.3-2004-04-01-20:20:53 import

This commit is contained in:
Igor Sysoev 2004-04-01 16:20:53 +00:00
parent 205dc145c5
commit dbb2776570
19 changed files with 130 additions and 64 deletions

2
auto/configure vendored
View File

@ -36,6 +36,6 @@ if [ "$PLATFORM" != win32 ]; then
. auto/unix
fi
have NGX_SMP . auto/have
have=NGX_SMP . auto/have
. auto/summary

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
static int ngx_event_max_module;
ngx_atomic_t *ngx_accept_mutex_ptr;
ngx_atomic_t *ngx_accept_mutex;
ngx_uint_t ngx_accept_mutex_held;
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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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";
}

View File

@ -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);

View File

@ -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 */

View File

@ -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;

View File

@ -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),

View File

@ -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;

View File

@ -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)
{

View File

@ -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()"

View File

@ -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");

View File

@ -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;