Skip to content

Commit

Permalink
nginx-0.0.3-2004-04-01-20:20:53 import
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsysoev committed Apr 1, 2004
1 parent 205dc14 commit dbb2776
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 64 deletions.
2 changes: 1 addition & 1 deletion auto/configure
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ if [ "$PLATFORM" != win32 ]; then
. auto/unix
fi

have NGX_SMP . auto/have
have=NGX_SMP . auto/have

. auto/summary
3 changes: 3 additions & 0 deletions src/core/ngx_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/event/modules/ngx_kqueue_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
68 changes: 61 additions & 7 deletions src/event/ngx_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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
};

Expand All @@ -119,25 +132,64 @@ 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)
ngx_iocp_conf_t *iocpcf;
#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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
9 changes: 6 additions & 3 deletions src/event/ngx_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
5 changes: 0 additions & 5 deletions src/event/ngx_event_accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 15 additions & 4 deletions src/event/ngx_event_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions src/http/modules/proxy/ngx_http_proxy_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/http/modules/proxy/ngx_http_proxy_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/http/modules/proxy/ngx_http_proxy_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; */
Expand Down Expand Up @@ -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";
}
Expand Down
10 changes: 10 additions & 0 deletions src/http/ngx_http_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/http/ngx_http_core_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 0 additions & 1 deletion src/http/ngx_http_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions src/http/ngx_http_request_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions src/http/ngx_http_write_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};


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

Expand Down
Loading

0 comments on commit dbb2776

Please sign in to comment.