]> git.kaiwu.me - nginx.git/commitdiff
nginx-0.0.1-2003-07-02-22:51:41 import
authorIgor Sysoev <igor@sysoev.ru>
Wed, 2 Jul 2003 18:51:41 +0000 (18:51 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Wed, 2 Jul 2003 18:51:41 +0000 (18:51 +0000)
12 files changed:
src/core/nginx.c
src/core/ngx_string.h
src/event/modules/ngx_devpoll_module.c
src/http/modules/ngx_http_charset_filter.c
src/http/modules/ngx_http_chunked_filter.c
src/http/modules/ngx_http_index_handler.c
src/http/modules/ngx_http_range_filter.c
src/http/ngx_http.c
src/http/ngx_http_core_module.c
src/http/ngx_http_core_module.h
src/http/ngx_http_header_filter.c
src/http/ngx_http_write_filter.c

index 1c54a8c1f0988ef822380360c4c9a0c1f959f607..30ebf3fe93ae16fdb77aa9c310b3fcc33a698e96 100644 (file)
@@ -15,17 +15,12 @@ void  ****ngx_conf_ctx;
 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 main(int argc, char *const *argv)
 {
     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 @@ int main(int argc, char *const *argv)
 
     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 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
     }
     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 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
     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 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
 
     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 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
     }
 
     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 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
         }
     }
 
+    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 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
         }
     }
 
-    pool->log = cycle->log;
-
     ngx_destroy_pool(old_cycle->pool);
 
     return cycle;
index 73ed43a958679984788c11c5940ad4806fdc8dad..9171ea07311726e3a24d5fac188ee98b76f1ebcf 100644 (file)
@@ -46,7 +46,7 @@ typedef struct {
  * 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)
index 766d4032850a6b1d6d5decbbc1e02a528ca4cc1f..47313e94936c11a5a68ffbf0ec0713c76032e2d5 100644 (file)
@@ -193,6 +193,8 @@ static int ngx_devpoll_del_event(ngx_event_t *ev, int event, u_int flags)
     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 @@ static int ngx_devpoll_del_event(ngx_event_t *ev, int event, u_int flags)
         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;
index baf6d9aba60ae50ed3dbb2e3b27b42061fb11b1c..bcddc9222cdfeb9ecd01de5c026716bd35ced590 100644 (file)
@@ -12,7 +12,7 @@ typedef struct {
 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_module_t  ngx_http_charset_filter_module = {
     &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 @@ static int ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 #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;
index bdd0a7c7a8d0b045ea98380447fa1c285e78205c..09b480bc04567ff53bcd1be87a4b75f1819f5308 100644 (file)
@@ -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_module_t  ngx_http_chunked_filter_module = {
     &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_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 }
 
 
-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;
index ffb9779bf8e88a82e73ab4fa287d9b3c3b68f645..9af01211369bdf165453013f638b71ce646c59eb 100644 (file)
@@ -14,7 +14,7 @@ typedef struct {
 
 
 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_module_t  ngx_http_index_module = {
     &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 @@ ngx_log_debug(r->connection->log, "IS_DIR: %s" _ r->path.data);
 }
 
 
-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;
 
index d0273ec1c93cb339454ddc75d8f3acf9bcd928da..125551ebdd53a04974104758f578418d46da81a7 100644 (file)
@@ -9,7 +9,7 @@ typedef struct {
 } 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_module_t  ngx_http_range_filter_module = {
     &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_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 }
 
 
-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;
index 10f0023119bad1afd943021fdecd7e0309c59791..a1ea12aa1a8b11f79f231d5d1ec88c849a82de23 100644 (file)
@@ -11,10 +11,6 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 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 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     /* 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 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         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 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
                                                      INET_ADDRSTRLEN),
                                      6, ":%d", in_port[p].port);
 
+            ls->fd = -1;
             ls->family = AF_INET;
             ls->type = SOCK_STREAM;
             ls->protocol = IPPROTO_IP;
index 4cc4388f2c4314ec997e782b2e6b1eb76922dde5..8e9a96673308dba872f0119bff3ec590664171b6 100644 (file)
@@ -422,11 +422,14 @@ ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
 
 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;
+
+    cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
 
-    h = (ngx_http_handler_pt *) ngx_http_index_handlers.elts;
-    for (i = ngx_http_index_handlers.nelts; i > 0; /* void */) {
+    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 @@ int ngx_http_internal_redirect(ngx_http_request_t *r,
 
 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;
+
+    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(&ngx_http_translate_handlers), NGX_ERROR);
+    ngx_test_null(h, ngx_push_array(&cmcf->translate_handlers), NGX_ERROR);
 
     *h = ngx_http_core_translate_handler;
 
index 8acf4feb1af8132dba7e24dbe9897ffcbaa9ea9d..c6b2bccd55b23671bfe73eae05b028bce18f10af 100644 (file)
@@ -20,6 +20,7 @@ typedef struct {
 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;
 
 
index 0f7c95330119d42993a1563b2a1b519c7735f9e4..aa200c10898703e23280051e8f019cf049a93ce0 100644 (file)
@@ -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_module_t  ngx_http_header_filter_module = {
     &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(ngx_http_request_t *r)
 }
 
 
-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;
index 6b76f73907d73d215c0dcf892debea33e725d079..fc96b077212ce458b1f56e033ac410ad84e37091 100644 (file)
@@ -18,7 +18,7 @@ typedef struct {
 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_module_t  ngx_http_write_filter_module = {
     &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 char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool,
 }
 
 
-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;