diff options
Diffstat (limited to 'src')
33 files changed, 1490 insertions, 200 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index cd1551421..d30e12744 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -100,6 +100,13 @@ static ngx_command_t ngx_core_commands[] = { offsetof(ngx_core_conf_t, rlimit_nofile), NULL }, + { ngx_string("worker_rlimit_core"), + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + 0, + offsetof(ngx_core_conf_t, rlimit_core), + NULL }, + { ngx_string("worker_rlimit_sigpending"), NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, ngx_conf_set_num_slot, @@ -558,6 +565,7 @@ ngx_core_module_create_conf(ngx_cycle_t *cycle) ccf->debug_points = NGX_CONF_UNSET; ccf->rlimit_nofile = NGX_CONF_UNSET; + ccf->rlimit_core = NGX_CONF_UNSET; ccf->rlimit_sigpending = NGX_CONF_UNSET; ccf->user = (ngx_uid_t) NGX_CONF_UNSET_UINT; diff --git a/src/core/nginx.h b/src/core/nginx.h index 80fd49837..ce9e59654 100644 --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -8,7 +8,7 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VER "nginx/0.3.15" +#define NGINX_VER "nginx/0.3.16" #define NGINX_VAR "NGINX" #define NGX_OLDPID_EXT ".oldbin" diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h index 96569b893..d924ec5e8 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -98,8 +98,8 @@ typedef long ngx_flag_t; #define NGX_ALIGNMENT sizeof(unsigned long) /* platform word */ #endif -#define ngx_align(p) (u_char *) (((uintptr_t) p + (NGX_ALIGNMENT - 1)) \ - & ~(NGX_ALIGNMENT - 1)) +#define ngx_align(d, a) (((d) + (a - 1)) & ~(a - 1)) +#define ngx_align_ptr(p, a) (u_char *) (((uintptr_t) (p) + (a - 1)) & ~(a - 1)) #define ngx_abort abort diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index fc04e9ce6..cbf8c7ba1 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -60,6 +60,7 @@ typedef struct { ngx_int_t debug_points; ngx_int_t rlimit_nofile; + ngx_int_t rlimit_core; ngx_int_t rlimit_sigpending; int priority; diff --git a/src/core/ngx_hash.c b/src/core/ngx_hash.c index 9d41df63b..4decd42e9 100644 --- a/src/core/ngx_hash.c +++ b/src/core/ngx_hash.c @@ -8,8 +8,488 @@ #include <ngx_core.h> +void * +ngx_hash_find(ngx_hash_t *hash, ngx_uint_t key, u_char *name, size_t len) +{ + ngx_uint_t i; + ngx_hash_elt_t *elt; + +#if 0 + ngx_str_t line; + + line.len = len; + line.data = name; + ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "hf:\"%V\"", &line); +#endif + + elt = hash->buckets[key % hash->size]; + + if (elt == NULL) { + return NULL; + } + + while (elt->value) { + if (len != (size_t) elt->len) { + goto next; + } + + for (i = 0; i < len; i++) { + if (name[i] != elt->name[i]) { + goto next; + } + } + + return elt->value; + + next: + + elt = (ngx_hash_elt_t *) ngx_align_ptr(&elt->name[0] + elt->len, + sizeof(void *)); + continue; + } + + return NULL; +} + + +void * +ngx_hash_find_wildcard(ngx_hash_wildcard_t *hwc, u_char *name, size_t len) +{ + void *value; + ngx_uint_t i, n, key; + +#if 0 + ngx_str_t line; + + line.len = len; + line.data = name; + ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "wc:\"%V\"", &line); +#endif + + n = len; + + while (n) { + if (name[n - 1] == '.') { + break; + } + + n--; + } + + if (n == 0) { + return NULL; + } + + key = 0; + + for (i = n; i < len; i++) { + key = ngx_hash(key, name[i]); + } + +#if 0 + ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "key:\"%ui\"", key); +#endif + + value = ngx_hash_find(&hwc->hash, key, &name[n], len - n); + + if (value) { + if ((uintptr_t) value & 1) { + hwc = (ngx_hash_wildcard_t *) ((uintptr_t) value & (uintptr_t) ~1); + + value = ngx_hash_find_wildcard(hwc, name, n - 1); + + if (value) { + return value; + } + + return hwc->value; + } + + return value; + } + + return hwc->value; +} + + +#define NGX_HASH_ELT_SIZE(name) \ + sizeof(void *) + ngx_align((name)->key.len + 1, sizeof(void *)) + +ngx_int_t +ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts) +{ + u_char *elts; + size_t *test, len; + ngx_uint_t i, n, key, size, start, bucket_size; + ngx_hash_elt_t *elt, **buckets; + + for (n = 0; n < nelts; n++) { + if (names[n].key.len >= 255) { + ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, + "the \"%V\" value to hash is to long: %uz bytes, " + "the maximum length can be 255 bytes only", + &names[n].key, names[n].key.len); + return NGX_ERROR; + } + + if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *)) + { + ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, + "could not build the %s hash, you should " + "increase %s_bucket_size: %i", + hinit->name, hinit->name, hinit->bucket_size); + return NGX_ERROR; + } + } + + test = ngx_alloc(hinit->max_size * sizeof(ngx_uint_t), hinit->pool->log); + if (test == NULL) { + return NGX_ERROR; + } + + start = nelts / (ngx_cacheline_size / (2 * sizeof(void *)) - 1); + start = start ? start : 1; + + bucket_size = hinit->bucket_size - sizeof(void *); + + for (size = start; size < hinit->max_size; size++) { + + ngx_memzero(test, size * sizeof(ngx_uint_t)); + + for (n = 0; n < nelts; n++) { + if (names[n].key.data == NULL) { + continue; + } + + key = names[n].key_hash % size; + test[key] += NGX_HASH_ELT_SIZE(&names[n]); + +#if 0 + ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, + "%ui: %ui %ui \"%V\"", + size, key, test[key], &names[n].key); +#endif + + if (test[key] > bucket_size) { + goto next; + } + } + + goto found; + + next: + + continue; + } + + ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, + "could not build the %s hash, you should increase " + "either %s_max_size: %i or %s_bucket_size: %i", + hinit->name, hinit->name, hinit->max_size, + hinit->name, hinit->bucket_size); + + ngx_free(test); + + return NGX_ERROR; + +found: + + for (i = 0; i < size; i++) { + test[i] = sizeof(void *); + } + + for (n = 0; n < nelts; n++) { + if (names[n].key.data == NULL) { + continue; + } + + key = names[n].key_hash % size; + test[key] += NGX_HASH_ELT_SIZE(&names[n]); + } + + len = 0; + + for (i = 0; i < size; i++) { + if (test[i] == sizeof(void *)) { + continue; + } + + test[i] = ngx_align(test[i], ngx_cacheline_size); + + len += test[i]; + } + + if (hinit->hash == NULL) { + hinit->hash = ngx_pcalloc(hinit->pool, sizeof(ngx_hash_wildcard_t) + + size * sizeof(ngx_hash_elt_t *)); + if (hinit->hash == NULL) { + ngx_free(test); + return NGX_ERROR; + } + + buckets = (ngx_hash_elt_t **) + ((u_char *) hinit->hash + sizeof(ngx_hash_wildcard_t)); + + } else { + buckets = ngx_pcalloc(hinit->pool, size * sizeof(ngx_hash_elt_t *)); + if (buckets == NULL) { + ngx_free(test); + return NGX_ERROR; + } + } + + elts = ngx_palloc(hinit->pool, len + ngx_cacheline_size); + if (elts == NULL) { + ngx_free(test); + return NGX_ERROR; + } + + elts = ngx_align_ptr(elts, ngx_cacheline_size); + + for (i = 0; i < size; i++) { + if (test[i] == sizeof(void *)) { + continue; + } + + buckets[i] = (ngx_hash_elt_t *) elts; + elts += test[i]; + + } + + for (i = 0; i < size; i++) { + test[i] = 0; + } + + for (n = 0; n < nelts; n++) { + if (names[n].key.data == NULL) { + continue; + } + + key = names[n].key_hash % size; + elt = (ngx_hash_elt_t *) ((u_char *) buckets[key] + test[key]); + + elt->value = names[n].value; + elt->len = (u_char) names[n].key.len; + + for (i = 0; i < names[n].key.len; i++) { + elt->name[i] = ngx_tolower(names[n].key.data[i]); + } + + test[key] += NGX_HASH_ELT_SIZE(&names[n]); + } + + for (i = 0; i < size; i++) { + if (buckets[i] == NULL) { + continue; + } + + elt = (ngx_hash_elt_t *) ((u_char *) buckets[i] + test[i]); + + elt->value = NULL; + } + + ngx_free(test); + + hinit->hash->buckets = buckets; + hinit->hash->size = size; + +#if 0 + + for (i = 0; i < size; i++) { + ngx_str_t val; + ngx_uint_t key; + + elt = buckets[i]; + + if (elt == NULL) { + ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, + "%ui: NULL", i); + continue; + } + + while (elt->value) { + val.len = elt->len; + val.data = &elt->name[0]; + + key = hinit->key(val.data, val.len); + + ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, + "%ui: %p \"%V\" %ui", i, elt, &val, key); + + elt = (ngx_hash_elt_t *) ngx_align_ptr(&elt->name[0] + elt->len, + sizeof(void *)); + } + } + +#endif + + return NGX_OK; +} + + +ngx_int_t +ngx_hash_wildcard_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, + ngx_uint_t nelts) +{ + size_t len; + ngx_uint_t i, n; + ngx_array_t curr_names, next_names; + ngx_hash_key_t *name, *next_name; + ngx_hash_init_t h; + ngx_hash_wildcard_t *wdc; + + if (ngx_array_init(&curr_names, hinit->temp_pool, nelts, + sizeof(ngx_hash_key_t)) + != NGX_OK) + { + return NGX_ERROR; + } + + if (ngx_array_init(&next_names, hinit->temp_pool, nelts, + sizeof(ngx_hash_key_t)) + != NGX_OK) + { + return NGX_ERROR; + } + + for (n = 0; n < nelts; n = i) { + +#if 0 + ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, + "wc0: \"%V\"", &names[n].key); +#endif + + for (len = 0; len < names[n].key.len; len++) { + if (names[n].key.data[len] == '.') { + len++; + break; + } + } + + name = ngx_array_push(&curr_names); + if (name == NULL) { + return NGX_ERROR; + } + + name->key.len = len - 1; + name->key.data = names[n].key.data; + name->key_hash = hinit->key(name->key.data, name->key.len); + name->value = names[n].value; + +#if 0 + ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, + "wc1: \"%V\"", &name->key); +#endif + + next_names.nelts = 0; + + if (names[n].key.len != len) { + next_name = ngx_array_push(&next_names); + if (next_name == NULL) { + return NGX_ERROR; + } + + next_name->key.len = names[n].key.len - len; + next_name->key.data = names[n].key.data + len; + next_name->key_hash= 0; + next_name->value = names[n].value; + +#if 0 + ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, + "wc2: \"%V\"", &next_name->key); +#endif + } + + for (i = n + 1; i < nelts; i++) { + if (ngx_strncmp(names[n].key.data, names[i].key.data, len) != 0) { + break; + } + + next_name = ngx_array_push(&next_names); + if (next_name == NULL) { + return NGX_ERROR; + } + + next_name->key.len = names[i].key.len - len; + next_name->key.data = names[i].key.data + len; + next_name->key_hash= 0; + next_name->value = names[i].value; + +#if 0 + ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, + "wc2: \"%V\"", &next_name->key); +#endif + } + + if (next_names.nelts) { + h = *hinit; + h.hash = NULL; + + if (ngx_hash_wildcard_init(&h, (ngx_hash_key_t *) next_names.elts, + next_names.nelts) + != NGX_OK) + { + return NGX_ERROR; + } + + wdc = (ngx_hash_wildcard_t *) h.hash; + + if (names[n].key.len == len) { + wdc->value = names[n].value; +#if 0 + ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, + "wdc: \"%V\"", wdc->value); +#endif + } + + name->value = (void *) ((uintptr_t) wdc | 1); + } + } + + if (ngx_hash_init(hinit, (ngx_hash_key_t *) curr_names.elts, + curr_names.nelts) + != NGX_OK) + { + return NGX_ERROR; + } + + return NGX_OK; +} + + +ngx_uint_t +ngx_hash_key(u_char *data, size_t len) +{ + ngx_uint_t i, key; + + key = 0; + + for (i = 0; i < len; i++) { + key = ngx_hash(key, data[i]); + } + + return key; +} + + +ngx_uint_t +ngx_hash_key_lc(u_char *data, size_t len) +{ + ngx_uint_t i, key; + + key = 0; + + for (i = 0; i < len; i++) { + key = ngx_hash(key, ngx_tolower(data[i])); + } + + return key; +} + + ngx_int_t -ngx_hash_init(ngx_hash_t *hash, ngx_pool_t *pool, void *names, ngx_uint_t nelts) +ngx_hash0_init(ngx_hash0_t *hash, ngx_pool_t *pool, void *names, + ngx_uint_t nelts) { u_char *p; ngx_str_t *name, *bucket; diff --git a/src/core/ngx_hash.h b/src/core/ngx_hash.h index e9912579a..7449d0571 100644 --- a/src/core/ngx_hash.h +++ b/src/core/ngx_hash.h @@ -13,25 +13,81 @@ typedef struct { - void **buckets; - ngx_uint_t hash_size; - - ngx_uint_t max_size; - ngx_uint_t bucket_limit; - size_t bucket_size; - char *name; - ngx_uint_t min_buckets; + void *value; + u_char len; + u_char name[1]; +} ngx_hash_elt_t; + + +typedef struct { + ngx_hash_elt_t **buckets; + ngx_uint_t size; } ngx_hash_t; typedef struct { - ngx_uint_t hash; - ngx_str_t key; - ngx_str_t value; + ngx_hash_t hash; + void *value; +} ngx_hash_wildcard_t; + + +typedef struct { + ngx_str_t key; + ngx_uint_t key_hash; + void *value; +} ngx_hash_key_t; + + +typedef ngx_uint_t (*ngx_hash_key_pt) (u_char *data, size_t len); + + +typedef struct { + ngx_hash_t *hash; + ngx_hash_key_pt key; + + ngx_uint_t max_size; + ngx_uint_t bucket_size; + + char *name; + ngx_pool_t *pool; + ngx_pool_t *temp_pool; +} ngx_hash_init_t; + + +typedef struct { + void **buckets; + ngx_uint_t hash_size; + + ngx_uint_t max_size; + ngx_uint_t bucket_limit; + size_t bucket_size; + char *name; + ngx_uint_t min_buckets; +} ngx_hash0_t; + + +typedef struct { + ngx_uint_t hash; + ngx_str_t key; + ngx_str_t value; } ngx_table_elt_t; -ngx_int_t ngx_hash_init(ngx_hash_t *hash, ngx_pool_t *pool, void *names, +void *ngx_hash_find(ngx_hash_t *hash, ngx_uint_t key, u_char *name, size_t len); +void *ngx_hash_find_wildcard(ngx_hash_wildcard_t *hwc, u_char *name, + size_t len); + +ngx_int_t ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, + ngx_uint_t nelts); +ngx_int_t ngx_hash_wildcard_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, + ngx_uint_t nelts); + +#define ngx_hash(key, c) key * 31 + c +ngx_uint_t ngx_hash_key(u_char *data, size_t len); +ngx_uint_t ngx_hash_key_lc(u_char *data, size_t len); + + +ngx_int_t ngx_hash0_init(ngx_hash0_t *hash, ngx_pool_t *pool, void *names, ngx_uint_t nelts); diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index 6cbedde82..9e23592ea 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -324,7 +324,7 @@ ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) cf->cycle->new_log->file->name = value[1]; if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name) - == NGX_ERROR) + == NGX_ERROR) { return NGX_CONF_ERROR; } diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c index 3bb0b3598..a0229b2ea 100644 --- a/src/core/ngx_palloc.c +++ b/src/core/ngx_palloc.c @@ -90,10 +90,16 @@ ngx_palloc(ngx_pool_t *pool, size_t size) if (size <= (size_t) NGX_MAX_ALLOC_FROM_POOL && size <= (size_t) (pool->end - (u_char *) pool) - - (size_t) ngx_align(sizeof(ngx_pool_t))) + - (size_t) ngx_align_ptr(sizeof(ngx_pool_t), NGX_ALIGNMENT)) { for (p = pool->current; /* void */ ; p = p->next) { - m = ngx_align(p->last); + + if (size < sizeof(int) || (size & 1)) { + m = p->last; + + } else { + m = ngx_align_ptr(p->last, NGX_ALIGNMENT); + } if ((size_t) (p->end - m) >= size) { p->last = m + size; @@ -122,7 +128,7 @@ ngx_palloc(ngx_pool_t *pool, size_t size) } p->next = n; - m = ngx_align(n->last); + m = ngx_align_ptr(n->last, NGX_ALIGNMENT); n->last = m + size; return m; diff --git a/src/core/ngx_palloc.h b/src/core/ngx_palloc.h index 30590ee9e..239728102 100644 --- a/src/core/ngx_palloc.h +++ b/src/core/ngx_palloc.h @@ -13,7 +13,7 @@ /* - * NGX_MAX_ALLOC_FROM_POOL should be (ngx_page_size - 1), i.e. 4095 on x86. + * NGX_MAX_ALLOC_FROM_POOL should be (ngx_pagesize - 1), i.e. 4095 on x86. * On FreeBSD 5.x it allows to use the zero copy sending. * On Windows NT it decreases a number of locked pages in a kernel. */ diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c index f042d7c33..2bb335a07 100644 --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -980,20 +980,21 @@ ngx_unescape_uri(u_char **dst, u_char **src, size_t size) break; } - /* skip the invalid quoted character */ + /* the invalid quoted character */ - s++; - size--; + state = sw_usual; + + *d++ = ch; break; case sw_quoted_second: + state = sw_usual; + if (ch >= '0' && ch <= '9') { ch = (u_char) ((decoded << 4) + ch - '0'); - state = sw_usual; - if (ch > '%' && ch < 0x7f) { *d++ = ch; break; @@ -1013,8 +1014,6 @@ ngx_unescape_uri(u_char **dst, u_char **src, size_t size) goto done; } - state = sw_usual; - if (ch > '%' && ch < 0x7f) { *d++ = ch; break; @@ -1025,7 +1024,7 @@ ngx_unescape_uri(u_char **dst, u_char **src, size_t size) break; } - /* skip the invalid quoted character */ + /* the invalid quoted character */ break; } diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c index 441472e42..b343718e4 100644 --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c @@ -540,6 +540,7 @@ ngx_ssl_handle_recv(ngx_connection_t *c, int n) c->ssl->no_wait_shutdown = 1; c->ssl->no_send_shutdown = 1; + c->read->eof = 1; if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, @@ -814,9 +815,7 @@ ngx_ssl_shutdown(ngx_connection_t *c) SSL_set_shutdown(c->ssl->connection, mode); again = 0; -#if (NGX_SUPPRESS_WARN) sslerr = 0; -#endif for ( ;; ) { n = SSL_shutdown(c->ssl->connection); @@ -845,27 +844,25 @@ ngx_ssl_shutdown(ngx_connection_t *c) "SSL_get_error: %d", sslerr); } - if (again || sslerr == SSL_ERROR_WANT_READ) { - - ngx_add_timer(c->read, 30000); - + if (again + || sslerr == SSL_ERROR_WANT_READ + || sslerr == SSL_ERROR_WANT_WRITE) + { c->read->handler = ngx_ssl_shutdown_handler; + c->write->handler = ngx_ssl_shutdown_handler; if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { return NGX_ERROR; } - return NGX_AGAIN; - } - - if (sslerr == SSL_ERROR_WANT_WRITE) { - - c->write->handler = ngx_ssl_shutdown_handler; - if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { return NGX_ERROR; } + if (again || sslerr == SSL_ERROR_WANT_READ) { + ngx_add_timer(c->read, 30000); + } + return NGX_AGAIN; } @@ -914,6 +911,9 @@ ngx_ssl_connection_error(ngx_connection_t *c, int sslerr, ngx_err_t err, if (err == NGX_ECONNRESET || err == NGX_EPIPE || err == NGX_ENOTCONN +#if !(NGX_CRIT_ETIMEDOUT) + || err == NGX_ETIMEDOUT +#endif || err == NGX_ECONNREFUSED || err == NGX_EHOSTUNREACH) { @@ -977,13 +977,13 @@ ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, char *fmt, ...) void ngx_ssl_cleanup_ctx(void *data) { - ngx_ssl_t *ssl = data; + ngx_ssl_t *ssl = data; - if (ssl->rsa512_key) { - RSA_free(ssl->rsa512_key); - } + if (ssl->rsa512_key) { + RSA_free(ssl->rsa512_key); + } - SSL_CTX_free(ssl->ctx); + SSL_CTX_free(ssl->ctx); } diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c index bf7b9251b..a6e8db301 100644 --- a/src/http/modules/ngx_http_geo_module.c +++ b/src/http/modules/ngx_http_geo_module.c @@ -13,7 +13,7 @@ typedef struct { ngx_radix_tree_t *tree; ngx_pool_t *pool; ngx_array_t values; -} ngx_http_geo_conf_t; +} ngx_http_geo_conf_ctx_t; static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -95,12 +95,12 @@ ngx_http_geo_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, static char * ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - char *rv; - ngx_str_t *value, name; - ngx_conf_t save; - ngx_pool_t *pool; - ngx_radix_tree_t *tree; - ngx_http_geo_conf_t geo; + char *rv; + ngx_str_t *value, name; + ngx_conf_t save; + ngx_pool_t *pool; + ngx_radix_tree_t *tree; + ngx_http_geo_conf_ctx_t ctx; ngx_http_variable_t *var; value = cf->args->elts; @@ -135,20 +135,20 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } - if (ngx_array_init(&geo.values, pool, 512, + if (ngx_array_init(&ctx.values, pool, 512, sizeof(ngx_http_variable_value_t *)) - == NGX_ERROR) + != NGX_OK) { ngx_destroy_pool(pool); return NGX_CONF_ERROR; } - geo.tree = tree; - geo.pool = cf->pool; + ctx.tree = tree; + ctx.pool = cf->pool; save = *cf; cf->pool = pool; - cf->ctx = &geo; + cf->ctx = &ctx; cf->handler = ngx_http_geo; cf->handler_conf = conf; @@ -182,10 +182,10 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) ngx_str_t *value, file; ngx_uint_t i; ngx_inet_cidr_t cidrin; - ngx_http_geo_conf_t *geo; + ngx_http_geo_conf_ctx_t *ctx; ngx_http_variable_value_t *var, *old, **v; - geo = cf->ctx; + ctx = cf->ctx; if (cf->args->nelts != 2) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, @@ -223,28 +223,27 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) } var = NULL; - v = geo->values.elts; + v = ctx->values.elts; - for (i = 0; i < geo->values.nelts; i++) { + for (i = 0; i < ctx->values.nelts; i++) { if ((size_t) v[i]->len != value[1].len) { continue; } - if (ngx_strncmp(value[1].data, v[i]->data, value[1].len) == 0) - { + if (ngx_strncmp(value[1].data, v[i]->data, value[1].len) == 0) { var = v[i]; break; } } if (var == NULL) { - var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t)); + var = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t)); if (var == NULL) { return NGX_CONF_ERROR; } var->len = value[1].len; - var->data = ngx_pstrdup(geo->pool, &value[1]); + var->data = ngx_pstrdup(ctx->pool, &value[1]); if (var->data == NULL) { return NGX_CONF_ERROR; } @@ -253,7 +252,7 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) var->no_cachable = 0; var->not_found = 0; - v = ngx_array_push(&geo->values); + v = ngx_array_push(&ctx->values); if (v == NULL) { return NGX_CONF_ERROR; } @@ -262,7 +261,7 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) } for (i = 2; i; i--) { - rc = ngx_radix32tree_insert(geo->tree, cidrin.addr, cidrin.mask, + rc = ngx_radix32tree_insert(ctx->tree, cidrin.addr, cidrin.mask, (uintptr_t) var); if (rc == NGX_OK) { return NGX_CONF_OK; @@ -275,14 +274,14 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) /* rc == NGX_BUSY */ old = (ngx_http_variable_value_t *) - ngx_radix32tree_find(geo->tree, cidrin.addr & cidrin.mask); + ngx_radix32tree_find(ctx->tree, cidrin.addr & cidrin.mask); ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "duplicate parameter \"%V\", value: \"%V\", " "old value: \"%V\"", &value[0], var, old); - rc = ngx_radix32tree_delete(geo->tree, cidrin.addr, cidrin.mask); + rc = ngx_radix32tree_delete(ctx->tree, cidrin.addr, cidrin.mask); if (rc == NGX_ERROR) { return NGX_CONF_ERROR; diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c index e8197598f..940e082a5 100644 --- a/src/http/modules/ngx_http_gzip_filter_module.c +++ b/src/http/modules/ngx_http_gzip_filter_module.c @@ -22,7 +22,7 @@ typedef struct { ngx_uint_t http_version; ngx_uint_t proxied; - int level; + ngx_int_t level; size_t wbits; size_t memlevel; ssize_t min_length; @@ -509,7 +509,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ctx->zstream.zfree = ngx_http_gzip_filter_free; ctx->zstream.opaque = ctx; - rc = deflateInit2(&ctx->zstream, conf->level, Z_DEFLATED, + rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, -wbits, memlevel, Z_DEFAULT_STRATEGY); if (rc != Z_OK) { diff --git a/src/http/modules/ngx_http_map_module.c b/src/http/modules/ngx_http_map_module.c new file mode 100644 index 000000000..2769028d6 --- /dev/null +++ b/src/http/modules/ngx_http_map_module.c @@ -0,0 +1,637 @@ + +/* + * Copyright (C) Igor Sysoev + */ + + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_http.h> + + +#define NGX_HTTP_MAP_HASH 10007 + +typedef struct { + ngx_uint_t hash_max_size; + ngx_uint_t hash_bucket_size; +} ngx_http_map_conf_t; + + +typedef struct { + ngx_pool_t *pool; + + ngx_array_t keys; + ngx_array_t *keys_hash; + + ngx_array_t dns_wildcards; + ngx_array_t *dns_hash; + + ngx_array_t *values_hash; + + ngx_http_variable_value_t *default_value; + ngx_uint_t hostnames; /* unsigned hostnames:1 */ +} ngx_http_map_conf_ctx_t; + + +typedef struct { + ngx_hash_t hash; + ngx_hash_wildcard_t *dns_wildcards; + ngx_int_t index; + ngx_http_variable_value_t *default_value; + ngx_uint_t hostnames; /* unsigned hostnames:1 */ +} ngx_http_map_ctx_t; + + +static int ngx_libc_cdecl ngx_http_map_cmp_dns_wildcards(const void *one, + const void *two); +static void *ngx_http_map_create_conf(ngx_conf_t *cf); +static char *ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static char *ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); + + +static ngx_command_t ngx_http_map_commands[] = { + + { ngx_string("map"), + NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2, + ngx_http_map_block, + NGX_HTTP_MAIN_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("map_hash_max_size"), + NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_HTTP_MAIN_CONF_OFFSET, + offsetof(ngx_http_map_conf_t, hash_max_size), + NULL }, + + { ngx_string("map_hash_bucket_size"), + NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_HTTP_MAIN_CONF_OFFSET, + offsetof(ngx_http_map_conf_t, hash_bucket_size), + NULL }, + + ngx_null_command +}; + + +static ngx_http_module_t ngx_http_map_module_ctx = { + NULL, /* preconfiguration */ + NULL, /* postconfiguration */ + + ngx_http_map_create_conf, /* create main configuration */ + NULL, /* init main configuration */ + + NULL, /* create server configuration */ + NULL, /* merge server configuration */ + + NULL, /* create location configuration */ + NULL /* merge location configuration */ +}; + + +ngx_module_t ngx_http_map_module = { + NGX_MODULE_V1, + &ngx_http_map_module_ctx, /* module context */ + ngx_http_map_commands, /* module directives */ + NGX_HTTP_MODULE, /* module type */ + NULL, /* init master */ + NULL, /* init module */ + NULL, /* init process */ + NULL, /* init thread */ + NULL, /* exit thread */ + NULL, /* exit process */ + NULL, /* exit master */ + NGX_MODULE_V1_PADDING +}; + + +static ngx_int_t +ngx_http_map_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, + uintptr_t data) +{ + ngx_http_map_ctx_t *map = (ngx_http_map_ctx_t *) data; + + size_t len; + u_char *name; + ngx_uint_t key, i; + ngx_http_variable_value_t *vv, *value; + + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http map started"); + + vv = ngx_http_get_flushed_variable(r, map->index); + + len = vv->len; + + if (len && map->hostnames && vv->data[len - 1] == '.') { + len--; + } + + if (len == 0) { + *v = *map->default_value; + return NGX_OK; + } + + name = ngx_palloc(r->pool, len); + if (name == NULL) { + return NGX_ERROR; + } + + key = 0; + for (i = 0; i < len; i++) { + name[i] = ngx_tolower(vv->data[i]); + key = ngx_hash(key, name[i]); + } + + value = NULL; + + if (map->hash.buckets) { + value = ngx_hash_find(&map->hash, key, name, len); + } + + if (value) { + *v = *value; + + } else { + if (map->dns_wildcards && map->dns_wildcards->hash.buckets) { + value = ngx_hash_find_wildcard(map->dns_wildcards, name, len); + if (value) { + *v = *value; + + } else { + *v = *map->default_value; + } + + } else { + *v = *map->default_value; + } + } + + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http map: \"%V\" \"%V\"", vv, v); + + return NGX_OK; +} + + +static void * +ngx_http_map_create_conf(ngx_conf_t *cf) +{ + ngx_http_map_conf_t *mcf; + + mcf = ngx_palloc(cf->pool, sizeof(ngx_http_map_conf_t)); + if (mcf == NULL) { + return NGX_CONF_ERROR; + } + + mcf->hash_max_size = NGX_CONF_UNSET_UINT; + mcf->hash_bucket_size = NGX_CONF_UNSET_UINT; + + return mcf; +} + + +static char * +ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_http_map_conf_t *mcf = conf; + + char *rv; + ngx_str_t *value, name; + ngx_conf_t save; + ngx_pool_t *pool; + ngx_hash_init_t hash; + ngx_http_map_ctx_t *map; + ngx_http_variable_t *var; + ngx_http_map_conf_ctx_t ctx; + + if (mcf->hash_max_size == NGX_CONF_UNSET_UINT) { + mcf->hash_max_size = 2048; + } + + if (mcf->hash_bucket_size == NGX_CONF_UNSET_UINT) { + mcf->hash_bucket_size = ngx_cacheline_size; + + } else { + mcf->hash_bucket_size = ngx_align(mcf->hash_bucket_size, + ngx_cacheline_size); + } + + map = ngx_pcalloc(cf->pool, sizeof(ngx_http_map_ctx_t)); + if (map == NULL) { + return NGX_CONF_ERROR; + } + + value = cf->args->elts; + + name = value[1]; + name.len--; + name.data++; + + map->index = ngx_http_get_variable_index(cf, &name); + + if (map->index == NGX_ERROR) { + return NGX_CONF_ERROR; + } + + name = value[2]; + name.len--; + name.data++; + + var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGABLE); + if (var == NULL) { + return NGX_CONF_ERROR; + } + + var->handler = ngx_http_map_variable; + var->data = (uintptr_t) map; + + pool = ngx_create_pool(16384, cf->log); + if (pool == NULL) { + return NGX_CONF_ERROR; + } + + if (ngx_array_init(&ctx.keys, pool, 16384, sizeof(ngx_hash_key_t)) + != NGX_OK) + { + ngx_destroy_pool(pool); + return NGX_CONF_ERROR; + } + + if (ngx_array_init(&ctx.dns_wildcards, pool, 16384, sizeof(ngx_hash_key_t)) + != NGX_OK) + { + ngx_destroy_pool(pool); + return NGX_CONF_ERROR; + } + + ctx.keys_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * NGX_HTTP_MAP_HASH); + if (ctx.keys_hash == NULL) { + ngx_destroy_pool(pool); + return NGX_CONF_ERROR; + } + + ctx.dns_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * NGX_HTTP_MAP_HASH); + if (ctx.dns_hash == NULL) { + ngx_destroy_pool(pool); + return NGX_CONF_ERROR; + } + + ctx.values_hash = ngx_pcalloc(pool, + sizeof(ngx_array_t) * NGX_HTTP_MAP_HASH); + if (ctx.values_hash == NULL) { + ngx_destroy_pool(pool); + return NGX_CONF_ERROR; + } + + ctx.pool = cf->pool; + ctx.default_value = NULL; + ctx.hostnames = 0; + + save = *cf; + cf->pool = pool; + cf->ctx = &ctx; + cf->handler = ngx_http_map; + cf->handler_conf = conf; + + rv = ngx_conf_parse(cf, NULL); + + *cf = save; + + if (rv != NGX_CONF_OK) { + ngx_destroy_pool(pool); + + return rv; + } + + hash.key = ngx_hash_key_lc; + hash.max_size = mcf->hash_max_size; + hash.bucket_size = mcf->hash_bucket_size; + hash.name = "map_hash"; + hash.pool = cf->pool; + + if (ctx.keys.nelts) { + hash.hash = &map->hash; + hash.temp_pool = NULL; + + if (ngx_hash_init(&hash, ctx.keys.elts, ctx.keys.nelts) != NGX_OK) { + return NGX_CONF_ERROR; + } + } + + map->default_value = ctx.default_value ? ctx.default_value: + &ngx_http_variable_null_value; + + if (ctx.dns_wildcards.nelts) { + + ngx_qsort(ctx.dns_wildcards.elts, (size_t) ctx.dns_wildcards.nelts, + sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards); + + hash.hash = NULL; + hash.temp_pool = pool; + + if (ngx_hash_wildcard_init(&hash, ctx.dns_wildcards.elts, + ctx.dns_wildcards.nelts) + != NGX_OK) + { + return NGX_CONF_ERROR; + } + + map->dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; + } + + ngx_destroy_pool(pool); + + return rv; +} + + +static int ngx_libc_cdecl +ngx_http_map_cmp_dns_wildcards(const void *one, const void *two) +{ + ngx_hash_key_t *first, *second; + + first = (ngx_hash_key_t *) one; + second = (ngx_hash_key_t *) two; + + return ngx_strcmp(first->key.data, second->key.data); +} + + +static char * +ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) +{ + size_t len; + ngx_str_t *value, file, *name; + ngx_uint_t i, n, key; + ngx_hash_key_t *m; + ngx_http_map_conf_ctx_t *ctx; + ngx_http_variable_value_t *var, *old, **vp; + u_char buf[2048]; + + ctx = cf->ctx; + + value = cf->args->elts; + + if (cf->args->nelts == 1 + && ngx_strcmp(value[0].data, "hostnames") == 0) + { + ctx->hostnames = 1; + return NGX_CONF_OK; + + } else if (cf->args->nelts != 2) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid number of the map parameters"); + return NGX_CONF_ERROR; + + } else if (value[0].len == 0) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid first parameter"); + return NGX_CONF_ERROR; + } + + if (ngx_strcmp(value[0].data, "include") == 0) { + file = value[1]; + + if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR){ + return NGX_CONF_ERROR; + } + + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data); + + return ngx_conf_parse(cf, &file); + } + + key = 0; + + for (i = 0; i < value[1].len; i++) { + key = ngx_hash(key, value[1].data[i]); + } + + key %= NGX_HTTP_MAP_HASH; + + vp = ctx->values_hash[key].elts; + + if (vp) { + for (i = 0; i < ctx->values_hash[key].nelts; i++) { + if (value[1].len != (size_t) vp[i]->len) { + continue; + } + + if (ngx_strncmp(value[1].data, vp[i]->data, value[1].len) == 0) { + var = vp[i]; + goto found; + } + } + + } else { + if (ngx_array_init(&ctx->values_hash[key], cf->pool, 4, + sizeof(ngx_http_variable_value_t *)) + != NGX_OK) + { + return NGX_CONF_ERROR; + } + } + + var = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t)); + if (var == NULL) { + return NGX_CONF_ERROR; + } + + var->len = value[1].len; + var->data = ngx_pstrdup(ctx->pool, &value[1]); + if (var->data == NULL) { + return NGX_CONF_ERROR; + } + + var->valid = 1; + var->no_cachable = 0; + var->not_found = 0; + + vp = ngx_array_push(&ctx->values_hash[key]); + if (vp == NULL) { + return NGX_CONF_ERROR; + } + + *vp = var; + +found: + + if (value[0].data[0] != '*' || ctx->hostnames == 0) { + + if (ngx_strcmp(value[0].data, "default") != 0) { + + if (value[0].len && value[0].data[0] == '!') { + value[0].len--; + value[0].data++; + } + + key = 0; + + for (i = 0; i < value[0].len; i++) { + value[0].data[i] = ngx_tolower(value[0].data[i]); + key = ngx_hash(key, value[0].data[i]); + } + + key %= NGX_HTTP_MAP_HASH; + + name = ctx->keys_hash[key].elts; + + if (name) { + for (i = 0; i < ctx->keys_hash[key].nelts; i++) { + if (value[0].len != name[i].len) { + continue; + } + + if (ngx_strncmp(value[0].data, name[i].data, value[0].len) + == 0) + { + m = ctx->keys.elts; + for (i = 0; i < ctx->keys.nelts; i++) { + if (ngx_strcmp(value[0].data, m[i].key.data) == 0) { + old = m[i].value; + m[i].value = var; + + goto duplicate; + } + } + } + } + + } else { + if (ngx_array_init(&ctx->keys_hash[key], cf->pool, 4, + sizeof(ngx_str_t)) + != NGX_OK) + { + return NGX_CONF_ERROR; + } + } + + name = ngx_array_push(&ctx->keys_hash[key]); + if (name == NULL) { + return NGX_CONF_ERROR; + } + + *name = value[0]; + + m = ngx_array_push(&ctx->keys); + if (m == NULL) { + return NGX_CONF_ERROR; + } + + m->key = value[0]; + m->key_hash = ngx_hash_key(value[0].data, value[0].len); + m->value = var; + + } else { + if (ctx->default_value) { + old = ctx->default_value; + ctx->default_value = var; + + goto duplicate; + } + + ctx->default_value = var; + } + + } else { + + if (value[0].len < 3 || value[0].data[1] != '.') { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid DNS wildcard \"%V\"", &value[0]); + return NGX_CONF_ERROR; + } + + key = 0; + + for (i = 2; i < value[0].len; i++) { + value[0].data[i] = ngx_tolower(value[0].data[i]); + key = ngx_hash(key, value[0].data[i]); + } + + key %= NGX_HTTP_MAP_HASH; + + /* convert "*.example.com" into "com.example.\0" */ + + len = 0; + n = 0; + + for (i = value[0].len - 1; i; i--) { + if (value[0].data[i] == '.') { + ngx_memcpy(&buf[n], &value[0].data[i + 1], len); + n += len; + buf[n++] = '.'; + len = 0; + continue; + } + + len++; + } + + buf[n] = '\0'; + + name = ctx->dns_hash[key].elts; + + if (name) { + for (i = 0; i < ctx->dns_hash[key].nelts; i++) { + if (value[0].len != name[i].len) { + continue; + } + + if (ngx_strncmp(value[0].data, name[i].data, value[0].len) + == 0) + { + m = ctx->dns_wildcards.elts; + for (i = 0; i < ctx->dns_wildcards.nelts; i++) { + if (ngx_strcmp(buf, m[i].key.data) == 0) { + old = m[i].value; + m[i].value = var; + + goto duplicate; + } + } + } + } + + } else { + if (ngx_array_init(&ctx->dns_hash[key], cf->pool, 4, + sizeof(ngx_str_t)) + != NGX_OK) + { + return NGX_CONF_ERROR; + } + } + + name = ngx_array_push(&ctx->dns_hash[key]); + if (name == NULL) { + return NGX_CONF_ERROR; + } + + *name = value[0]; + + ngx_memcpy(value[0].data, buf, value[0].len); + value[0].len--; + + m = ngx_array_push(&ctx->dns_wildcards); + if (m == NULL) { + return NGX_CONF_ERROR; + } + + m->key = value[0]; + m->key_hash = 0; + m->value = var; + } + + return NGX_CONF_OK; + +duplicate: + + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, + "duplicate parameter \"%V\", value: \"%V\", " + "old value: \"%V\"", + &value[0], var, old); + + return NGX_CONF_OK; +} diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index afadc18ce..c39f32065 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -42,7 +42,7 @@ typedef struct { ngx_array_t *body_set; ngx_array_t *headers_set_len; ngx_array_t *headers_set; - ngx_hash_t *headers_set_hash; + ngx_hash0_t *headers_set_hash; ngx_array_t *headers_source; ngx_array_t *headers_names; @@ -1892,7 +1892,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) *code = (uintptr_t) NULL; - conf->headers_set_hash = ngx_pcalloc(cf->pool, sizeof(ngx_hash_t)); + conf->headers_set_hash = ngx_pcalloc(cf->pool, sizeof(ngx_hash0_t)); if (conf->headers_set_hash == NULL) { return NGX_CONF_ERROR; } @@ -1902,8 +1902,9 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) conf->headers_set_hash->bucket_size = sizeof(ngx_str_t); conf->headers_set_hash->name = "proxy_headers"; - if (ngx_hash_init(conf->headers_set_hash, cf->pool, - conf->headers_names->elts, conf->headers_names->nelts) != NGX_OK) + if (ngx_hash0_init(conf->headers_set_hash, cf->pool, + conf->headers_names->elts, conf->headers_names->nelts) + != NGX_OK) { return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c index dd0e92fcd..c984f7e9e 100644 --- a/src/http/modules/ngx_http_ssi_filter_module.c +++ b/src/http/modules/ngx_http_ssi_filter_module.c @@ -186,6 +186,13 @@ static ngx_command_t ngx_http_ssi_filter_commands[] = { offsetof(ngx_http_ssi_conf_t, min_file_chunk), NULL }, + { ngx_string("ssi_value_length"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_size_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_ssi_conf_t, value_len), + NULL }, + { ngx_string("ssi_types"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, ngx_http_ssi_types, @@ -1728,7 +1735,13 @@ ngx_http_ssi_config(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, value = params[NGX_HTTP_SSI_CONFIG_TIMEFMT]; if (value) { - ctx->timefmt = *value; + ctx->timefmt.len = value->len; + ctx->timefmt.data = ngx_palloc(r->pool, value->len + 1); + if (ctx->timefmt.data == NULL) { + return NGX_HTTP_SSI_ERROR; + } + + ngx_cpystrn(ctx->timefmt.data, value->data, value->len + 1); } value = params[NGX_HTTP_SSI_CONFIG_ERRMSG]; diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 023899870..449a4e9bd 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -371,7 +371,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) cmcf->headers_in_hash.bucket_size = sizeof(ngx_http_header_t); cmcf->headers_in_hash.name = "http headers_in"; - if (ngx_hash_init(&cmcf->headers_in_hash, cf->pool, ngx_http_headers_in, 0) + if (ngx_hash0_init(&cmcf->headers_in_hash, cf->pool, ngx_http_headers_in, 0) != NGX_OK) { return NGX_CONF_ERROR; @@ -770,10 +770,10 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } } -#if (NGX_DEBUG0) +#if 0 { u_char address[20]; - ngx_uint_t p, a, nn; + ngx_uint_t p, a; in_port = in_ports.elts; for (p = 0; p < in_ports.nelts; p++) { diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index c100bee75..e42023b1f 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -164,6 +164,20 @@ static ngx_command_t ngx_http_core_commands[] = { 0, NULL }, + { ngx_string("types_hash_max_size"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_core_loc_conf_t, types_hash_max_size), + NULL }, + + { ngx_string("types_hash_bucket_size"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size), + NULL }, + { ngx_string("types"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF |NGX_CONF_BLOCK|NGX_CONF_NOARGS, @@ -849,9 +863,8 @@ ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) { u_char c, *p, *exten; - uint32_t key; + ngx_str_t *type; ngx_uint_t i; - ngx_http_type_t *type; ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); @@ -876,11 +889,7 @@ ngx_http_set_content_type(ngx_http_request_t *r) for (i = 0; i < r->exten.len; i++) { c = r->exten.data[i]; - if (c >= 'A' && c <= 'Z') { - *p++ = (u_char) (c | 0x20); - } else { - *p++ = c; - } + *p++ = ngx_tolower(c); } r->exten.data = exten; @@ -889,26 +898,17 @@ ngx_http_set_content_type(ngx_http_request_t *r) r->low_case_exten = 1; } - ngx_http_types_hash_key(key, r->exten); - - type = clcf->types[key].elts; - for (i = 0; i < clcf->types[key].nelts; i++) { - if (r->exten.len != type[i].exten.len) { - continue; - } + type = ngx_hash_find(&clcf->types_hash, + ngx_hash_key(r->exten.data, r->exten.len), + r->exten.data, r->exten.len); - if (ngx_memcmp(r->exten.data, type[i].exten.data, r->exten.len) - == 0) - { - r->headers_out.content_type = type[i].type; - break; - } + if (type) { + r->headers_out.content_type = *type; + return NGX_OK; } } - if (r->headers_out.content_type.len == 0) { - r->headers_out.content_type= clcf->default_type; - } + r->headers_out.content_type = clcf->default_type; return NGX_OK; } @@ -1636,39 +1636,55 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; - uint32_t key; - ngx_uint_t i; - ngx_str_t *value; - ngx_http_type_t *type; + ngx_str_t *value, *content_type, *old; + ngx_uint_t i, n; + ngx_hash_key_t *type; if (lcf->types == NULL) { - lcf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME - * sizeof(ngx_array_t)); + lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t)); if (lcf->types == NULL) { return NGX_CONF_ERROR; } + } - for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { - if (ngx_array_init(&lcf->types[i], cf->pool, 4, - sizeof(ngx_http_type_t)) == NGX_ERROR) - { - return NGX_CONF_ERROR; - } - } + content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t)); + if (content_type == NULL) { + return NGX_CONF_ERROR; } value = cf->args->elts; + *content_type = value[0]; for (i = 1; i < cf->args->nelts; i++) { - ngx_http_types_hash_key(key, value[i]); - type = ngx_array_push(&lcf->types[key]); + for (n = 0; n < value[i].len; n++) { + value[i].data[n] = ngx_tolower(value[i].data[n]); + } + + type = lcf->types->elts; + for (n = 0; n < lcf->types->nelts; n++) { + if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { + old = type[n].value; + type[n].value = content_type; + + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, + "duplicate extention \"%V\", " + "content type: \"%V\", " + "old content type: \"%V\"", + &value[i], content_type, old); + continue; + } + } + + + type = ngx_array_push(lcf->types); if (type == NULL) { return NGX_CONF_ERROR; } - type->exten = value[i]; - type->type = value[0]; + type->key = value[i]; + type->key_hash = ngx_hash_key(value[i].data, value[i].len); + type->value = content_type; } return NGX_CONF_OK; @@ -1905,29 +1921,34 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf) lcf->port_in_redirect = NGX_CONF_UNSET; lcf->msie_padding = NGX_CONF_UNSET; lcf->log_not_found = NGX_CONF_UNSET; + lcf->types_hash_max_size = NGX_CONF_UNSET_UINT; + lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; return lcf; } -static ngx_http_type_t ngx_http_core_default_types[] = { - { ngx_string("html"), ngx_string("text/html") }, - { ngx_string("gif"), ngx_string("image/gif") }, - { ngx_string("jpg"), ngx_string("image/jpeg") }, - { ngx_null_string, ngx_null_string } +static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html"); +static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif"); +static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg"); + +static ngx_hash_key_t ngx_http_core_default_types[] = { + { ngx_string("html"), 0, &ngx_http_core_text_html_type }, + { ngx_string("gif"), 0, &ngx_http_core_image_gif_type }, + { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type }, + { ngx_null_string, 0, NULL } }; static char * -ngx_http_core_merge_loc_conf(ngx_conf_t *cf, - void *parent, void *child) +ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_core_loc_conf_t *prev = parent; ngx_http_core_loc_conf_t *conf = child; - uint32_t key; ngx_uint_t i; - ngx_http_type_t *type; + ngx_hash_key_t *type; + ngx_hash_init_t types_hash; ngx_conf_merge_str_value(conf->root, prev->root, "html"); @@ -1939,36 +1960,77 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, conf->post_action = prev->post_action; } + ngx_conf_merge_unsigned_value(conf->types_hash_max_size, + prev->types_hash_max_size, 512); + + ngx_conf_merge_unsigned_value(conf->types_hash_bucket_size, + prev->types_hash_bucket_size, + ngx_cacheline_size); + + conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size, + ngx_cacheline_size); + + /* + * the special handling the "types" directive in the "http" section + * to inherit the http's conf->types_hash to all servers + */ + + if (prev->types && prev->types_hash.buckets == NULL) { + + types_hash.hash = &prev->types_hash; + types_hash.key = ngx_hash_key_lc; + types_hash.max_size = conf->types_hash_max_size; + types_hash.bucket_size = conf->types_hash_bucket_size; + types_hash.name = "mime_types"; + types_hash.pool = cf->pool; + types_hash.temp_pool = NULL; + + if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts) + != NGX_OK) + { + return NGX_CONF_ERROR; + } + } + if (conf->types == NULL) { - if (prev->types) { - conf->types = prev->types; + conf->types = prev->types; + conf->types_hash = prev->types_hash; + } - } else { - conf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME - * sizeof(ngx_array_t)); - if (conf->types == NULL) { + if (conf->types == NULL) { + conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t)); + if (conf->types == NULL) { + return NGX_CONF_ERROR; + } + + for (i = 0; ngx_http_core_default_types[i].key.len; i++) { + type = ngx_array_push(conf->types); + if (type == NULL) { return NGX_CONF_ERROR; } - for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { - if (ngx_array_init(&conf->types[i], cf->pool, 4, - sizeof(ngx_http_type_t)) == NGX_ERROR) - { - return NGX_CONF_ERROR; - } - } + type->key = ngx_http_core_default_types[i].key; + type->key_hash = + ngx_hash_key_lc(ngx_http_core_default_types[i].key.data, + ngx_http_core_default_types[i].key.len); + type->value = ngx_http_core_default_types[i].value; + } + } - for (i = 0; ngx_http_core_default_types[i].exten.len; i++) { - ngx_http_types_hash_key(key, - ngx_http_core_default_types[i].exten); + if (conf->types_hash.buckets == NULL) { - type = ngx_array_push(&conf->types[key]); - if (type == NULL) { - return NGX_CONF_ERROR; - } + types_hash.hash = &conf->types_hash; + types_hash.key = ngx_hash_key_lc; + types_hash.max_size = conf->types_hash_max_size; + types_hash.bucket_size = conf->types_hash_bucket_size; + types_hash.name = "mime_types"; + types_hash.pool = cf->pool; + types_hash.temp_pool = NULL; - *type = ngx_http_core_default_types[i]; - } + if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts) + != NGX_OK) + { + return NGX_CONF_ERROR; } } @@ -2115,6 +2177,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (ngx_strcmp(value[2].data, "default") == 0) { ls->conf.default_server = 1; n = 3; + } else { n = 2; } diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index e9c994dd1..0d8ae74c3 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -70,8 +70,8 @@ typedef struct { ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1]; - ngx_hash_t headers_in_hash; - ngx_hash_t variables_hash; + ngx_hash0_t headers_in_hash; + ngx_hash0_t variables_hash; ngx_uint_t server_names_hash; ngx_uint_t server_names_hash_threshold; @@ -154,23 +154,6 @@ typedef struct { } -#define NGX_HTTP_TYPES_HASH_PRIME 13 - -#define ngx_http_types_hash_key(key, ext) \ - { \ - ngx_uint_t n; \ - for (key = 0, n = 0; n < ext.len; n++) { \ - key += ext.data[n]; \ - } \ - key %= NGX_HTTP_TYPES_HASH_PRIME; \ - } - -typedef struct { - ngx_str_t exten; - ngx_str_t type; -} ngx_http_type_t; - - typedef struct { ngx_int_t status; ngx_int_t overwrite; @@ -203,12 +186,13 @@ struct ngx_http_core_loc_conf_s { ngx_http_handler_pt handler; - ngx_array_t *types; - ngx_str_t default_type; - ngx_str_t root; /* root, alias */ ngx_str_t post_action; + ngx_array_t *types; + ngx_hash_t types_hash; + ngx_str_t default_type; + size_t client_max_body_size; /* client_max_body_size */ size_t client_body_buffer_size; /* client_body_buffer_size */ size_t send_lowat; /* send_lowat */ @@ -241,6 +225,9 @@ struct ngx_http_core_loc_conf_s { ngx_log_t *err_log; + ngx_uint_t types_hash_max_size; + ngx_uint_t types_hash_bucket_size; + #if 0 ngx_http_core_loc_conf_t *prev_location; #endif diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index c6d6d6fc2..ba93c0df3 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -1561,6 +1561,10 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) ngx_del_timer(r->connection->write); } + if (r->connection->destroyed) { + return; + } + #if 0 if (r->connection->read->pending_eof) { #if (NGX_HAVE_KQUEUE) diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index cfaca6e13..fc57fe47b 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -2541,7 +2541,7 @@ ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) umcf->headers_in_hash.bucket_size = sizeof(ngx_http_upstream_header_t); umcf->headers_in_hash.name = "upstream_headers_in"; - if (ngx_hash_init(&umcf->headers_in_hash, cf->pool, + if (ngx_hash0_init(&umcf->headers_in_hash, cf->pool, ngx_http_upstream_headers_in, 0) != NGX_OK) { return NGX_CONF_ERROR; diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h index 203265970..1b4795a31 100644 --- a/src/http/ngx_http_upstream.h +++ b/src/http/ngx_http_upstream.h @@ -40,7 +40,7 @@ typedef struct { typedef struct { - ngx_hash_t headers_in_hash; + ngx_hash0_t headers_in_hash; } ngx_http_upstream_main_conf_t; diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c index 6e831b5b0..93080abd4 100644 --- a/src/http/ngx_http_variables.c +++ b/src/http/ngx_http_variables.c @@ -116,6 +116,10 @@ static ngx_http_variable_t ngx_http_core_variables[] = { offsetof(ngx_http_request_t, args), NGX_HTTP_VAR_NOCACHABLE, 0 }, + { ngx_string("args"), ngx_http_variable_request, + offsetof(ngx_http_request_t, args), + NGX_HTTP_VAR_NOCACHABLE, 0 }, + { ngx_string("request_filename"), ngx_http_variable_request_filename, 0, NGX_HTTP_VAR_NOCACHABLE, 0 }, @@ -857,7 +861,7 @@ ngx_http_variables_init_vars(ngx_conf_t *cf) cmcf->variables_hash.bucket_size = sizeof(ngx_http_variable_t); cmcf->variables_hash.name = "http variables"; - if (ngx_hash_init(&cmcf->variables_hash, cf->pool, + if (ngx_hash0_init(&cmcf->variables_hash, cf->pool, cmcf->all_variables.elts, cmcf->all_variables.nelts) != NGX_OK) { diff --git a/src/imap/ngx_imap_proxy_module.c b/src/imap/ngx_imap_proxy_module.c index 7eb1b947b..97df3825b 100644 --- a/src/imap/ngx_imap_proxy_module.c +++ b/src/imap/ngx_imap_proxy_module.c @@ -566,15 +566,15 @@ ngx_imap_proxy_handler(ngx_event_t *ev) } else { if (ev->write) { - recv_action = "proxying and reading from upstream"; - send_action = "proxying and sending to client"; + recv_action = "proxying and reading from client"; + send_action = "proxying and sending to upstream"; src = s->connection; dst = c; b = s->buffer; } else { - recv_action = "proxying and reading from client"; - send_action = "proxying and sending to upstream"; + recv_action = "proxying and reading from upstream"; + send_action = "proxying and sending to client"; src = c; dst = s->connection; b = s->proxy->buffer; diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c index 72cf4e42e..25606e2f6 100644 --- a/src/os/unix/ngx_alloc.c +++ b/src/os/unix/ngx_alloc.c @@ -8,7 +8,8 @@ #include <ngx_core.h> -int ngx_pagesize; +int ngx_pagesize; +ngx_uint_t ngx_cacheline_size; void * diff --git a/src/os/unix/ngx_alloc.h b/src/os/unix/ngx_alloc.h index 66562a191..a88818e2e 100644 --- a/src/os/unix/ngx_alloc.h +++ b/src/os/unix/ngx_alloc.h @@ -36,7 +36,8 @@ void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log); #endif -extern int ngx_pagesize; +extern int ngx_pagesize; +extern ngx_uint_t ngx_cacheline_size; #endif /* _NGX_ALLOC_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_gcc_atomic_x86.h b/src/os/unix/ngx_gcc_atomic_x86.h index b458032b5..8e3480d71 100644 --- a/src/os/unix/ngx_gcc_atomic_x86.h +++ b/src/os/unix/ngx_gcc_atomic_x86.h @@ -61,7 +61,16 @@ ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, */ -#if !(__GNUC__ == 2 && __GNUC_MINOR__ <= 7) +#if !(( __GNUC__ == 2 && __GNUC_MINOR__ <= 7 ) || ( __INTEL_COMPILER >= 800 )) + +/* + * icc 8.1 and 9.0 compile broken code with -march=pentium4 option: + * ngx_atomic_fetch_add() always return the input "add" value, + * so we use the gcc 2.7 version. + * + * icc 8.1 and 9.0 with -march=pentiumpro option or icc 7.1 compile + * correct code. + */ static ngx_inline ngx_atomic_int_t ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) @@ -77,7 +86,7 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) } -#else /* (__GNUC__ == 2 && __GNUC_MINOR__ <= 7) */ +#else /* * gcc 2.7 does not support "+q", so we have to use the fixed %eax ("=a" and diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c index f3830a8b3..225f9e1ec 100644 --- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -26,21 +26,21 @@ ngx_chain_t * ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) { - int rc, tcp_nodelay; - u_char *prev; - off_t size, send, prev_send, aligned, sent, fprev; - size_t file_size; - ngx_uint_t eintr, complete; - ngx_err_t err; - ngx_buf_t *file; - ngx_array_t header; - ngx_event_t *wev; - ngx_chain_t *cl; - struct iovec *iov, headers[NGX_HEADERS]; + int rc, tcp_nodelay; + off_t size, send, prev_send, aligned, sent, fprev; + u_char *prev; + size_t file_size; + ngx_err_t err; + ngx_buf_t *file; + ngx_uint_t eintr, complete; + ngx_array_t header; + ngx_event_t *wev; + ngx_chain_t *cl; + struct iovec *iov, headers[NGX_HEADERS]; #if (NGX_HAVE_SENDFILE64) - off_t offset; + off_t offset; #else - int32_t offset; + int32_t offset; #endif wev = c->write; @@ -233,6 +233,12 @@ ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) } if (file) { +#if 1 + if (file_size == 0) { + ngx_debug_point(); + return NGX_CHAIN_ERROR; + } +#endif #if (NGX_HAVE_SENDFILE64) offset = file->file_pos; #else diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index 4968de5b9..83d5f3024 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -39,6 +39,7 @@ ngx_os_init(ngx_log_t *log) ngx_init_setproctitle(log); ngx_pagesize = getpagesize(); + ngx_cacheline_size = NGX_CPU_CACHE_LINE; if (ngx_ncpu == 0) { ngx_ncpu = 1; diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 14bbe80b2..a262ba5eb 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -787,6 +787,17 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority) } } + if (ccf->rlimit_core != NGX_CONF_UNSET) { + rlmt.rlim_cur = (rlim_t) ccf->rlimit_core; + rlmt.rlim_max = (rlim_t) ccf->rlimit_core; + + if (setrlimit(RLIMIT_CORE, &rlmt) == -1) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "setrlimit(RLIMIT_CORE, %i) failed", + ccf->rlimit_core); + } + } + #ifdef RLIMIT_SIGPENDING if (ccf->rlimit_sigpending != NGX_CONF_UNSET) { rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending; diff --git a/src/os/win32/ngx_alloc.c b/src/os/win32/ngx_alloc.c index a3bca02a9..82ede7211 100644 --- a/src/os/win32/ngx_alloc.c +++ b/src/os/win32/ngx_alloc.c @@ -8,7 +8,8 @@ #include <ngx_core.h> -int ngx_pagesize; +int ngx_pagesize; +ngx_uint_t ngx_cacheline_size; void *ngx_alloc(size_t size, ngx_log_t *log) diff --git a/src/os/win32/ngx_alloc.h b/src/os/win32/ngx_alloc.h index 6cf6691b9..9d8d83750 100644 --- a/src/os/win32/ngx_alloc.h +++ b/src/os/win32/ngx_alloc.h @@ -18,7 +18,8 @@ void *ngx_calloc(size_t size, ngx_log_t *log); #define ngx_free free #define ngx_memalign(alignment, size, log) ngx_alloc(size, log) -extern int ngx_pagesize; +extern int ngx_pagesize; +extern ngx_uint_t ngx_cacheline_size; #endif /* _NGX_ALLOC_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c index 9c3df96f7..b4ac2b8b5 100644 --- a/src/os/win32/ngx_win32_init.c +++ b/src/os/win32/ngx_win32_init.c @@ -99,6 +99,7 @@ ngx_int_t ngx_os_init(ngx_log_t *log) GetSystemInfo(&si); ngx_pagesize = si.dwPageSize; ngx_ncpu = si.dwNumberOfProcessors; + ngx_cacheline_size = NGX_CPU_CACHE_LINE; /* init Winsock */ |