nginx-0.0.1-2003-07-02-22:51:41 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 1c54a8c..30ebf3f 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -15,17 +15,12 @@
ngx_os_io_t ngx_io;
+ngx_cycle_t *cycle;
+
int ngx_max_module;
-#if 0
-void *ctx_conf;
-#endif
int ngx_connection_counter;
-#if 0
-ngx_array_t ngx_listening_sockets;
-#endif
-
#if 1
@@ -33,8 +28,7 @@
{
int i;
ngx_log_t *log;
- ngx_conf_t conf;
- ngx_cycle_t *cycle, *new_cycle;
+ ngx_cycle_t *new_cycle;
/* TODO */ ngx_max_sockets = -1;
@@ -60,10 +54,16 @@
for ( ;; ) {
+ /* STUB */
+ ngx_io = ngx_os_io;
+
/* forks */
ngx_init_temp_number();
+ /* STUB */
+ ngx_pre_thread(&cycle->listening, cycle->pool, cycle->log);
+
/* threads */
for ( ;; ) {
@@ -107,12 +107,6 @@
}
cycle->pool = pool;
- cycle->log = ngx_log_create_errlog(cycle);
- if (cycle->log == NULL) {
- ngx_destroy_pool(pool);
- return NULL;
- }
-
n = old_cycle ? old_cycle->open_files.nelts : 20;
cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t));
if (cycle->open_files.elts == NULL) {
@@ -124,6 +118,12 @@
cycle->open_files.nalloc = n;
cycle->open_files.pool = pool;
+ cycle->log = ngx_log_create_errlog(cycle);
+ if (cycle->log == NULL) {
+ ngx_destroy_pool(pool);
+ return NULL;
+ }
+
n = old_cycle ? old_cycle->listening.nelts : 10;
cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
if (cycle->listening.elts == NULL) {
@@ -151,7 +151,7 @@
conf.ctx = cycle->conf_ctx;
conf.cycle = cycle;
- /* STUB */ conf.pool = cycle->pool;
+ /* STUB */ conf.pool = cycle->pool; ngx_conf_ctx = cycle->conf_ctx;
conf.log = log;
conf.module_type = NGX_CORE_MODULE;
conf.cmd_type = NGX_MAIN_CONF;
@@ -200,25 +200,27 @@
}
if (!failed) {
- ls = old_cycle->listening.elts;
- for (i = 0; i < old_cycle->listening.nelts; i++) {
- ls[i].remain = 0;
- }
-
- nls = cycle->listening.elts;
- for (n = 0; n < cycle->listening.nelts; n++) {
+ if (old_cycle) {
+ ls = old_cycle->listening.elts;
for (i = 0; i < old_cycle->listening.nelts; i++) {
- if (ngx_memcmp(nls[n].sockaddr,
- ls[i].sockaddr, ls[i].socklen) == 0)
- {
- nls[n].fd = ls[i].fd;
- ls[i].remain = 1;
- break;
- }
+ ls[i].remain = 0;
}
- if (nls[n].fd == -1) {
- nls[n].new = 1;
+ nls = cycle->listening.elts;
+ for (n = 0; n < cycle->listening.nelts; n++) {
+ for (i = 0; i < old_cycle->listening.nelts; i++) {
+ if (ngx_memcmp(nls[n].sockaddr,
+ ls[i].sockaddr, ls[i].socklen) == 0)
+ {
+ nls[n].fd = ls[i].fd;
+ ls[i].remain = 1;
+ break;
+ }
+ }
+
+ if (nls[n].fd == -1) {
+ nls[n].new = 1;
+ }
}
}
@@ -275,6 +277,12 @@
}
}
+ pool->log = cycle->log;
+
+ if (old_cycle == NULL) {
+ return cycle;
+ }
+
ls = old_cycle->listening.elts;
for (i = 0; i < old_cycle->listening.nelts; i++) {
if (ls[i].remain) {
@@ -301,8 +309,6 @@
}
}
- pool->log = cycle->log;
-
ngx_destroy_pool(old_cycle->pool);
return cycle;
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index 73ed43a..9171ea0 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -46,7 +46,7 @@
* msvc and icc compile memset() to inline "rep stos"
* while ZeroMemory and bzero are calls.
*/
-#define ngx_memzero(buf, n) memset(buf, n, 0)
+#define ngx_memzero(buf, n) memset(buf, 0, n)
/* msvc and icc compile memcpy() to inline "rep movs" */
#define ngx_memcpy(dst, src, n) memcpy(dst, src, n)
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index 766d403..47313e9 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -193,6 +193,8 @@
ngx_event_t *e;
ngx_connection_t *c;
+ c = ev->data;
+
#if (NGX_DEBUG_EVENT)
ngx_log_debug(c->log, "del event: %d, %d" _ c->fd _ event);
#endif
@@ -207,9 +209,7 @@
return NGX_OK;
}
- /* we need to restore second event if it exists */
-
- c = ev->data;
+ /* we need to restore the second event if it exists */
if (event == NGX_READ_EVENT) {
e = c->write;
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c
index baf6d9a..bcddc92 100644
--- a/src/http/modules/ngx_http_charset_filter.c
+++ b/src/http/modules/ngx_http_charset_filter.c
@@ -12,7 +12,7 @@
static void *ngx_http_charset_create_loc_conf(ngx_pool_t *pool);
static char *ngx_http_charset_merge_loc_conf(ngx_pool_t *pool,
void *parent, void *child);
-static int ngx_http_charset_filter_init(ngx_pool_t *pool);
+static int ngx_http_charset_filter_init(ngx_cycle_t *cycle, ngx_log_t *log);
static ngx_command_t ngx_http_charset_filter_commands[] = {
@@ -45,7 +45,9 @@
&ngx_http_charset_filter_module_ctx, /* module context */
ngx_http_charset_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
- ngx_http_charset_filter_init /* init module */
+ ngx_http_charset_filter_init, /* init module */
+ NULL, /* commit module */
+ NULL /* rollback module */
};
@@ -85,7 +87,7 @@
#endif
-static int ngx_http_charset_filter_init(ngx_pool_t *pool)
+static int ngx_http_charset_filter_init(ngx_cycle_t *cycle, ngx_log_t *log)
{
next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_charset_header_filter;
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c
index bdd0a7c..09b480b 100644
--- a/src/http/modules/ngx_http_chunked_filter.c
+++ b/src/http/modules/ngx_http_chunked_filter.c
@@ -4,7 +4,7 @@
#include <ngx_http.h>
-static int ngx_http_chunked_filter_init(ngx_pool_t *pool);
+static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle, ngx_log_t *log);
static ngx_http_module_t ngx_http_chunked_filter_module_ctx = {
@@ -24,7 +24,9 @@
&ngx_http_chunked_filter_module_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
- ngx_http_chunked_filter_init /* init module */
+ ngx_http_chunked_filter_init, /* init module */
+ NULL, /* commit module */
+ NULL /* rollback module */
};
@@ -117,7 +119,7 @@
}
-static int ngx_http_chunked_filter_init(ngx_pool_t *pool)
+static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle, ngx_log_t *log)
{
next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_chunked_header_filter;
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index ffb9779..9af0121 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -14,7 +14,7 @@
static int ngx_http_index_test_dir(ngx_http_request_t *r);
-static int ngx_http_index_init(ngx_pool_t *pool);
+static int ngx_http_index_init(ngx_cycle_t *cycle, ngx_log_t *log);
static void *ngx_http_index_create_conf(ngx_pool_t *pool);
static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent,
void *child);
@@ -52,7 +52,9 @@
&ngx_http_index_module_ctx, /* module context */
ngx_http_index_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
- ngx_http_index_init /* init module */
+ ngx_http_index_init, /* init module */
+ NULL, /* commit module */
+ NULL /* rollback module */
};
@@ -202,11 +204,16 @@
}
-static int ngx_http_index_init(ngx_pool_t *pool)
+static int ngx_http_index_init(ngx_cycle_t *cycle, ngx_log_t *log)
{
- ngx_http_handler_pt *h;
+ ngx_http_handler_pt *h;
+ ngx_http_conf_ctx_t *ctx;
+ ngx_http_core_main_conf_t *cmcf;
- ngx_test_null(h, ngx_push_array(&ngx_http_index_handlers), NGX_ERROR);
+ ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
+ cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
+
+ ngx_test_null(h, ngx_push_array(&cmcf->index_handlers), NGX_ERROR);
*h = ngx_http_index_handler;
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c
index d0273ec..125551e 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter.c
@@ -9,7 +9,7 @@
} ngx_http_range_filter_ctx_t;
-static int ngx_http_range_filter_init(ngx_pool_t *pool);
+static int ngx_http_range_filter_init(ngx_cycle_t *cycle, ngx_log_t *log);
static ngx_http_module_t ngx_http_range_filter_module_ctx = {
@@ -29,7 +29,9 @@
&ngx_http_range_filter_module_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
- ngx_http_range_filter_init /* init module */
+ ngx_http_range_filter_init, /* init module */
+ NULL, /* commit module */
+ NULL /* rollback module */
};
@@ -354,7 +356,7 @@
}
-static int ngx_http_range_filter_init(ngx_pool_t *pool)
+static int ngx_http_range_filter_init(ngx_cycle_t *cycle, ngx_log_t *log)
{
next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_range_header_filter;
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 10f0023..a1ea12a 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -11,10 +11,6 @@
int ngx_http_max_module;
-ngx_array_t ngx_http_translate_handlers;
-ngx_array_t ngx_http_index_handlers;
-
-
int (*ngx_http_top_header_filter) (ngx_http_request_t *r);
int (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
@@ -210,11 +206,11 @@
/* init list of the handlers */
- ngx_init_array(ngx_http_translate_handlers,
- cf->pool, 10, sizeof(ngx_http_handler_pt), NGX_CONF_ERROR);
+ ngx_init_array(cmcf->translate_handlers, cf->cycle->pool,
+ 10, sizeof(ngx_http_handler_pt), NGX_CONF_ERROR);
- ngx_init_array(ngx_http_index_handlers,
- cf->pool, 3, sizeof(ngx_http_handler_pt), NGX_CONF_ERROR);
+ ngx_init_array(cmcf->index_handlers, cf->cycle->pool,
+ 3, sizeof(ngx_http_handler_pt), NGX_CONF_ERROR);
/* create the lists of the ports, the addresses and the server names
@@ -429,7 +425,7 @@
in_addr = in_port[p].addrs.elts;
while (a < in_port[p].addrs.nelts) {
- ngx_test_null(ls, ngx_push_array(&ngx_listening_sockets),
+ ngx_test_null(ls, ngx_push_array(&cf->cycle->listening),
NGX_CONF_ERROR);
ngx_memzero(ls, sizeof(ngx_listening_t));
@@ -453,6 +449,7 @@
INET_ADDRSTRLEN),
6, ":%d", in_port[p].port);
+ ls->fd = -1;
ls->family = AF_INET;
ls->type = SOCK_STREAM;
ls->protocol = IPPROTO_IP;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 4cc4388..8e9a966 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -422,11 +422,14 @@
static int ngx_http_core_index_handler(ngx_http_request_t *r)
{
- int i, rc;
- ngx_http_handler_pt *h;
+ int i, rc;
+ ngx_http_handler_pt *h;
+ ngx_http_core_main_conf_t *cmcf;
- h = (ngx_http_handler_pt *) ngx_http_index_handlers.elts;
- for (i = ngx_http_index_handlers.nelts; i > 0; /* void */) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+ h = cmcf->index_handlers.elts;
+ for (i = cmcf->index_handlers.nelts; i > 0; /* void */) {
rc = h[--i](r);
if (rc != NGX_DECLINED) {
@@ -528,9 +531,14 @@
static int ngx_http_core_init(ngx_cycle_t *cycle, ngx_log_t *log)
{
- ngx_http_handler_pt *h;
+ ngx_http_handler_pt *h;
+ ngx_http_conf_ctx_t *ctx;
+ ngx_http_core_main_conf_t *cmcf;
- ngx_test_null(h, ngx_push_array(&ngx_http_translate_handlers), NGX_ERROR);
+ ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
+ cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
+
+ ngx_test_null(h, ngx_push_array(&cmcf->translate_handlers), NGX_ERROR);
*h = ngx_http_core_translate_handler;
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 8acf4fe..c6b2bcc 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -20,6 +20,7 @@
typedef struct {
ngx_array_t servers; /* array of ngx_http_core_srv_conf_t */
ngx_array_t translate_handlers;
+ ngx_array_t index_handlers;
} ngx_http_core_main_conf_t;
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 0f7c953..aa200c1 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -11,7 +11,7 @@
-static int ngx_http_header_filter_init(ngx_pool_t *pool);
+static int ngx_http_header_filter_init(ngx_cycle_t *cycle, ngx_log_t *log);
static int ngx_http_header_filter(ngx_http_request_t *r);
@@ -32,7 +32,9 @@
&ngx_http_header_filter_module_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
- ngx_http_header_filter_init /* init module */
+ ngx_http_header_filter_init, /* init module */
+ NULL, /* commit module */
+ NULL /* rollback module */
};
@@ -387,7 +389,7 @@
}
-static int ngx_http_header_filter_init(ngx_pool_t *pool)
+static int ngx_http_header_filter_init(ngx_cycle_t *cycle, ngx_log_t *log)
{
ngx_http_top_header_filter = ngx_http_header_filter;
return NGX_OK;
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 6b76f73..fc96b07 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -18,7 +18,7 @@
static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool);
static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool,
void *parent, void *child);
-static int ngx_http_write_filter_init(ngx_pool_t *pool);
+static int ngx_http_write_filter_init(ngx_cycle_t *cycle, ngx_log_t *log);
static ngx_command_t ngx_http_write_filter_commands[] = {
@@ -51,7 +51,9 @@
&ngx_http_write_filter_module_ctx, /* module context */
ngx_http_write_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
- ngx_http_write_filter_init /* init module */
+ ngx_http_write_filter_init, /* init module */
+ NULL, /* commit module */
+ NULL /* rollback module */
};
@@ -187,7 +189,7 @@
}
-static int ngx_http_write_filter_init(ngx_pool_t *pool)
+static int ngx_http_write_filter_init(ngx_cycle_t *cycle, ngx_log_t *log)
{
ngx_http_top_body_filter = ngx_http_write_filter;