nginx-0.0.11-2004-09-22-20:18:21 import

This commit is contained in:
Igor Sysoev 2004-09-22 16:18:21 +00:00
parent f1602634ad
commit 85080d09ad
9 changed files with 203 additions and 21 deletions

View File

@ -645,21 +645,23 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
ngx_flag_t flag;
ngx_str_t *value;
ngx_str_t *value;
ngx_flag_t *fp;
ngx_conf_post_t *post;
fp = (ngx_flag_t *) (p + cmd->offset);
if (*(ngx_flag_t *) (p + cmd->offset) != NGX_CONF_UNSET) {
if (*fp != NGX_CONF_UNSET) {
return "is duplicate";
}
value = cf->args->elts;
if (ngx_strcasecmp(value[1].data, "on") == 0) {
flag = 1;
*fp = 1;
} else if (ngx_strcasecmp(value[1].data, "off") == 0) {
flag = 0;
*fp = 0;
} else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@ -669,7 +671,10 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
*(ngx_flag_t *) (p + cmd->offset) = flag;
if (cmd->post) {
post = cmd->post;
return post->post_handler(cf, post, fp);
}
return NGX_CONF_OK;
}

View File

@ -5,6 +5,9 @@
void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin)
{
#if (NGX_HAVE_ATOMIC_OPS)
ngx_uint_t tries;
tries = 0;
@ -26,4 +29,15 @@ void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin)
}
}
}
#else
#if (NGX_THREADS)
#error ngx_spinlock() or ngx_atomic_cmp_set() are not defined !
#endif
#endif
}

View File

@ -45,6 +45,7 @@ static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd,
static void *ngx_event_create_conf(ngx_cycle_t *cycle);
static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf);
static char *ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data);
static ngx_uint_t ngx_event_max_module;
@ -113,6 +114,9 @@ ngx_module_t ngx_events_module = {
static ngx_str_t event_core_name = ngx_string("event_core");
static ngx_conf_post_t ngx_accept_mutex_post = { ngx_accept_mutex_check } ;
static ngx_command_t ngx_event_core_commands[] = {
{ ngx_string("connections"),
@ -141,7 +145,7 @@ static ngx_command_t ngx_event_core_commands[] = {
ngx_conf_set_flag_slot,
0,
offsetof(ngx_event_conf_t, accept_mutex),
NULL },
&ngx_accept_mutex_post },
{ ngx_string("accept_mutex_delay"),
NGX_EVENT_CONF|NGX_CONF_TAKE1,
@ -777,3 +781,20 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
return NGX_CONF_OK;
}
static char *ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data)
{
#if !(NGX_HAVE_ATOMIC_OPS)
ngx_flag_t *fp = data;
*fp = 0;
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"accept_mutex\" is not supported, ignored");
#endif
return NGX_CONF_OK;
}

View File

@ -96,6 +96,13 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
NULL },
{ ngx_string("client_large_buffers"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
ngx_conf_set_bufs_slot,
NGX_HTTP_SRV_CONF_OFFSET,
offsetof(ngx_http_core_srv_conf_t, client_large_buffers),
NULL },
{ ngx_string("large_client_header"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
@ -1247,6 +1254,15 @@ static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf)
ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)),
NGX_CONF_ERROR);
/*
set by ngx_pcalloc():
conf->client_large_buffers.num = 0;
*/
ngx_init_array(cscf->locations, cf->pool,
5, sizeof(void *), NGX_CONF_ERROR);
ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t),
@ -1326,6 +1342,8 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
prev->client_header_timeout, 60000);
ngx_conf_merge_size_value(conf->client_header_buffer_size,
prev->client_header_buffer_size, 1024);
ngx_conf_merge_bufs_value(conf->client_large_buffers,
prev->client_large_buffers, 4, ngx_pagesize);
ngx_conf_merge_value(conf->large_client_header,
prev->large_client_header, 1);
ngx_conf_merge_unsigned_value(conf->restrict_host_names,
@ -1543,7 +1561,7 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_OK;
}
ls->port = port;
ls->port = (in_port_t) port;
ls->addr = inet_addr((const char *) addr);
if (ls->addr == INADDR_NONE) {

View File

@ -66,6 +66,8 @@ typedef struct {
size_t request_pool_size;
size_t client_header_buffer_size;
ngx_bufs_t client_large_buffers;
ngx_msec_t post_accept_timeout;
ngx_msec_t client_header_timeout;

View File

@ -12,6 +12,8 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev);
static void ngx_http_process_request_line(ngx_event_t *rev);
static void ngx_http_process_request_headers(ngx_event_t *rev);
static ssize_t ngx_http_read_request_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_alloc_header_buf(ngx_http_request_t *r,
ngx_uint_t request_line);
static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r);
static void ngx_http_set_write_handler(ngx_http_request_t *r);
@ -935,6 +937,25 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
if (r->header_in->last == r->header_in->end) {
#if 1
/* ngx_http_alloc_large_header_buffer() */
rc = ngx_http_alloc_header_buf(r, 0);
if (rc == NGX_ERROR) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
}
if (rc == NGX_DECLINED) {
ngx_http_client_error(r, NGX_HTTP_PARSE_TOO_LONG_HEADER,
NGX_HTTP_BAD_REQUEST);
return;
}
#endif
#if 0
/*
* if the large client headers are enabled then
* we need to compact r->header_in buf
@ -964,6 +985,7 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
NGX_HTTP_BAD_REQUEST);
return;
}
#endif
}
}
}
@ -1023,6 +1045,92 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
}
#if 1
static ngx_int_t ngx_http_alloc_header_buf(ngx_http_request_t *r,
ngx_uint_t request_line)
{
u_char *old, *new;
ngx_int_t offset;
ngx_buf_t *b;
ngx_http_connection_t *hc;
ngx_http_core_srv_conf_t *cscf;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http alloc large header buffer");
old = request_line ? r->request_start : r->header_name_start;
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
if ((size_t) (r->header_in->pos - old) >= cscf->client_large_buffers.size) {
return NGX_DECLINED;
}
hc = r->http_connection;
if (hc->nfree) {
b = hc->free[--hc->nfree];
} else if (hc->nbusy < cscf->client_large_buffers.num) {
if (hc->busy == NULL) {
hc->busy = ngx_palloc(r->connection->pool,
cscf->client_large_buffers.num * sizeof(ngx_buf_t *));
if (hc->busy == NULL) {
return NGX_ERROR;
}
}
b = ngx_create_temp_buf(r->connection->pool,
cscf->client_large_buffers.size);
if (b == NULL) {
return NGX_ERROR;
}
} else {
return NGX_DECLINED;
}
hc->busy[hc->nbusy++] = b;
new = b->start;
ngx_memcpy(new, old, r->header_in->last - old);
b->pos = new + (r->header_in->pos - old);
b->last = new + (r->header_in->last - old);
if (request_line) {
r->request_start = new;
r->request_end = new + (r->request_end - old);
r->uri_start = new + (r->uri_start - old);
r->uri_end = new + (r->uri_end - old);
if (r->uri_ext) {
r->uri_ext = new + (r->uri_ext - old);
}
if (r->args_start) {
r->args_start = new + (r->args_start - old);
}
} else {
r->header_name_start = new;
r->header_name_end = new + (r->header_name_end - old);
r->header_start = new + (r->header_start - old);
r->header_end = new + (r->header_end - old);
}
r->header_in = b;
return NGX_OK;
}
#endif
static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
{
u_char *ua, *user_agent;

View File

@ -221,10 +221,10 @@ typedef struct {
ngx_http_request_t *request;
ngx_buf_t **busy;
ngx_uint_t nbusy;
ngx_int_t nbusy;
ngx_buf_t **free;
ngx_uint_t nfree;
ngx_int_t nfree;
ngx_uint_t pipeline; /* unsigned pipeline:1; */
} ngx_http_connection_t;

View File

@ -8,6 +8,8 @@
#if ( __i386__ || __amd64__ )
#define NGX_HAVE_ATOMIC_OPS 1
typedef volatile uint32_t ngx_atomic_t;
#if (NGX_SMP)
@ -33,6 +35,8 @@ static ngx_inline uint32_t ngx_atomic_inc(ngx_atomic_t *value)
}
#if 0
static ngx_inline uint32_t ngx_atomic_dec(ngx_atomic_t *value)
{
uint32_t old;
@ -48,6 +52,8 @@ static ngx_inline uint32_t ngx_atomic_dec(ngx_atomic_t *value)
return old;
}
#endif
static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
ngx_atomic_t old,
@ -70,6 +76,8 @@ static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
#elif ( __sparc__ )
#define NGX_HAVE_ATOMIC_OPS 1
typedef volatile uint32_t ngx_atomic_t;
@ -99,11 +107,6 @@ static ngx_inline uint32_t ngx_atomic_inc(ngx_atomic_t *value)
}
/* STUB */
#define ngx_atomic_dec(x) (*(x))--;
/**/
static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
ngx_atomic_t old,
ngx_atomic_t set)
@ -121,13 +124,18 @@ static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
#else
#define NGX_HAVE_ATOMIC_OPS 0
typedef volatile uint32_t ngx_atomic_t;
/* STUB */
#define ngx_atomic_inc(x) ++(*(x));
#define ngx_atomic_dec(x) --(*(x));
#define ngx_atomic_cmp_set(lock, old, set) 1
/**/
#define ngx_atomic_inc(x) ++(*(x));
static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
ngx_atomic_t old,
ngx_atomic_t set)
{
return 1;
}
#endif

View File

@ -6,17 +6,23 @@
#include <ngx_core.h>
#define NGX_HAVE_ATOMIC_OPS 1
#define ngx_atomic_inc(p) InterlockedIncrement((long *) p)
#define ngx_atomic_dec(p) InterlockedDecrement((long *) p)
#if defined( __WATCOMC__ ) || defined( __BORLANDC__ )
/* the new SDK headers */
#define ngx_atomic_cmp_set(lock, old, set) \
(InterlockedCompareExchange((long *) lock, set, old) == old)
#else
/* the old MS VC6.0SP2 SDK headers */
#define ngx_atomic_cmp_set(lock, old, set) \
(InterlockedCompareExchange((void **) lock, (void *) set, (void *) old) \
== (void *) old)