nginx-0.0.10-2004-09-03-19:50:30 import

This commit is contained in:
Igor Sysoev 2004-09-03 15:50:30 +00:00
parent 9e51181229
commit b9e344175f
7 changed files with 213 additions and 3 deletions

View File

@ -9,6 +9,7 @@ CORE_DEPS="src/core/nginx.h \
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 @@ CORE_SRCS="src/core/nginx.c \
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 \

View File

@ -572,11 +572,28 @@ static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
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 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
}
}
if (!(file = ngx_push_array(&cycle->open_files))) {
if (!(file = ngx_push_list(&cycle->open_files))) {
return NULL;
}

View File

@ -43,6 +43,7 @@ typedef void (*ngx_event_handler_pt)(ngx_event_t *ev);
#include <ngx_palloc.h>
#include <ngx_buf.h>
#include <ngx_array.h>
#include <ngx_list.h>
#include <ngx_table.h>
#include <ngx_file.h>
#include <ngx_files.h>

View File

@ -34,6 +34,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
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_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
#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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
/* 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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
/* 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 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
{
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;
}

View File

@ -14,8 +14,8 @@ struct ngx_cycle_s {
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;

36
src/core/ngx_list.c Normal file
View File

@ -0,0 +1,36 @@
#include <ngx_config.h>
#include <ngx_core.h>
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;
}

48
src/core/ngx_list.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef _NGX_LIST_H_INCLUDED_
#define _NGX_LIST_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_core.h>
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_ */