# HG changeset patch # User Igor Sysoev # Date 1094226630 0 # Node ID 388a842cbbe157edc77cffb8836a996bd83012ee # Parent de9d4726e28ad3e39b2b5e390c817e9b4ced4a1c nginx-0.0.10-2004-09-03-19:50:30 import diff -r de9d4726e28a -r 388a842cbbe1 auto/sources --- a/auto/sources Tue Aug 31 19:05:39 2004 +0000 +++ b/auto/sources Fri Sep 03 15:50:30 2004 +0000 @@ -9,6 +9,7 @@ src/core/ngx_log.h \ src/core/ngx_palloc.h \ src/core/ngx_array.h \ + src/core/ngx_list.h \ src/core/ngx_table.h \ src/core/ngx_buf.h \ src/core/ngx_string.h \ @@ -28,6 +29,7 @@ src/core/ngx_log.c \ src/core/ngx_palloc.c \ src/core/ngx_array.c \ + src/core/ngx_list.c \ src/core/ngx_buf.c \ src/core/ngx_output_chain.c \ src/core/ngx_string.c \ diff -r de9d4726e28a -r 388a842cbbe1 src/core/ngx_conf_file.c --- a/src/core/ngx_conf_file.c Tue Aug 31 19:05:39 2004 +0000 +++ b/src/core/ngx_conf_file.c Fri Sep 03 15:50:30 2004 +0000 @@ -572,11 +572,28 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) { ngx_uint_t i; + ngx_list_part_t *part; ngx_open_file_t *file; if (name) { + part = &cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + file = part->elts; + i = 0; + } + +#if 0 file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { +#endif if (name->len != file[i].name.len) { continue; } @@ -587,7 +604,7 @@ } } - if (!(file = ngx_push_array(&cycle->open_files))) { + if (!(file = ngx_push_list(&cycle->open_files))) { return NULL; } diff -r de9d4726e28a -r 388a842cbbe1 src/core/ngx_core.h --- a/src/core/ngx_core.h Tue Aug 31 19:05:39 2004 +0000 +++ b/src/core/ngx_core.h Fri Sep 03 15:50:30 2004 +0000 @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include diff -r de9d4726e28a -r 388a842cbbe1 src/core/ngx_cycle.c --- a/src/core/ngx_cycle.c Tue Aug 31 19:05:39 2004 +0000 +++ b/src/core/ngx_cycle.c Fri Sep 03 15:50:30 2004 +0000 @@ -34,6 +34,7 @@ ngx_pool_t *pool; ngx_cycle_t *cycle, **old; ngx_socket_t fd; + ngx_list_part_t *part; ngx_open_file_t *file; ngx_listening_t *ls, *nls; ngx_core_module_t *module; @@ -68,6 +69,30 @@ cycle->pathes.pool = pool; + if (old_cycle->open_files.part.nelts) { + n = old_cycle->open_files.part.nelts; + for (part = old_cycle->open_files.part.next; part; part = part->next) { + n += part->nelts; + } + + } else { + n = 20; + } + + cycle->open_files.part.elts = ngx_palloc(pool, n * sizeof(ngx_open_file_t)); + if (cycle->open_files.part.elts == NULL) { + ngx_destroy_pool(pool); + return NULL; + } + cycle->open_files.part.nelts = 0; + cycle->open_files.part.next = NULL; + cycle->open_files.last = &cycle->open_files.part; + cycle->open_files.size = sizeof(ngx_open_file_t); + cycle->open_files.nalloc = n; + cycle->open_files.pool = pool; + + +#if 0 n = old_cycle->open_files.nelts ? 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) { @@ -78,6 +103,7 @@ cycle->open_files.size = sizeof(ngx_open_file_t); cycle->open_files.nalloc = n; cycle->open_files.pool = pool; +#endif if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) { @@ -180,8 +206,26 @@ if (!failed) { + + part = &cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + file = part->elts; + i = 0; + } + +#if 0 file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { +#endif + if (file[i].name.data == NULL) { continue; } @@ -190,6 +234,11 @@ NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); + log->log_level = NGX_LOG_DEBUG_ALL; + ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, + "log: %0X %d \"%s\"", + &file[i], file[i].fd, file[i].name.data); + if (file[i].fd == NGX_INVALID_FILE) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, ngx_open_file_n " \"%s\" failed", @@ -287,6 +336,12 @@ #if !(WIN32) if (!failed && !ngx_test_config) { + + ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, + "dup2: %0X %d \"%s\"", + cycle->log->file, + cycle->log->file->fd, cycle->log->file->name.data); + if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed"); @@ -300,8 +355,25 @@ /* rollback the new cycle configuration */ + part = &cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + file = part->elts; + i = 0; + } + +#if 0 file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { +#endif + if (file[i].fd == NGX_INVALID_FILE) { continue; } @@ -320,7 +392,7 @@ ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { - if (ls[i].new && ls[i].fd == -1) { + if (ls[i].fd == -1 || !ls[i].new) { continue; } @@ -370,8 +442,25 @@ /* close the unneeded open files */ + part = &old_cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + file = part->elts; + i = 0; + } + +#if 0 file = old_cycle->open_files.elts; for (i = 0; i < old_cycle->open_files.nelts; i++) { +#endif + if (file[i].fd == NGX_INVALID_FILE) { continue; } @@ -534,10 +623,27 @@ { ngx_fd_t fd; ngx_uint_t i; + ngx_list_part_t *part; ngx_open_file_t *file; + part = &cycle->open_files.part; + file = part->elts; + + for (i = 0; /* void */ ; i++) { + + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + part = part->next; + i = 0; + } + +#if 0 file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { +#endif + if (file[i].name.data == NULL) { continue; } diff -r de9d4726e28a -r 388a842cbbe1 src/core/ngx_cycle.h --- a/src/core/ngx_cycle.h Tue Aug 31 19:05:39 2004 +0000 +++ b/src/core/ngx_cycle.h Fri Sep 03 15:50:30 2004 +0000 @@ -14,8 +14,8 @@ ngx_log_t *new_log; ngx_array_t listening; - ngx_array_t open_files; ngx_array_t pathes; + ngx_list_t open_files; ngx_uint_t connection_n; ngx_connection_t *connections; diff -r de9d4726e28a -r 388a842cbbe1 src/core/ngx_list.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/ngx_list.c Fri Sep 03 15:50:30 2004 +0000 @@ -0,0 +1,36 @@ + +#include +#include + + +void *ngx_push_list(ngx_list_t *l) +{ + void *elt; + ngx_list_part_t *last; + + last = l->last; + + if (last->nelts == l->nalloc) { + + /* the last part is full, allocate a new list part */ + + if (!(last = ngx_palloc(l->pool, sizeof(ngx_list_part_t)))) { + return NULL; + } + + if (!(last->elts = ngx_palloc(l->pool, l->nalloc * l->size))) { + return NULL; + } + + last->nelts = 0; + last->next = NULL; + + l->last->next = last; + l->last = last; + } + + elt = (char *) last->elts + l->size * last->nelts; + last->nelts++; + + return elt; +} diff -r de9d4726e28a -r 388a842cbbe1 src/core/ngx_list.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/ngx_list.h Fri Sep 03 15:50:30 2004 +0000 @@ -0,0 +1,48 @@ +#ifndef _NGX_LIST_H_INCLUDED_ +#define _NGX_LIST_H_INCLUDED_ + + +#include +#include + + +typedef struct ngx_list_part_s ngx_list_part_t; + +struct ngx_list_part_s { + void *elts; + ngx_uint_t nelts; + ngx_list_part_t *next; +}; + + +typedef struct { + ngx_list_part_t *last; + ngx_list_part_t part; + size_t size; + ngx_uint_t nalloc; + ngx_pool_t *pool; +} ngx_list_t; + + +#define ngx_init_list(l, p, n, s, rc) \ + if (!(l.part.elts = ngx_palloc(p, n * s))) { \ + return rc; \ + } \ + l.part.nelts = 0; l.part.next = NULL; \ + l.last = &l.part; l.size = s; l.nalloc = n; l.pool = p; + + +#define ngx_iterate_list(p, i) \ + for ( ;; i++) { \ + if (i >= p->nelts) { \ + if (p->next == NULL) { \ + break; \ + } \ + p = p->next; i = 0; \ + } + + +void *ngx_push_list(ngx_list_t *list); + + +#endif /* _NGX_LIST_H_INCLUDED_ */