diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2003-07-02 14:41:17 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2003-07-02 14:41:17 +0000 |
| commit | 96c56c9ab6e73f9d92242fdc4f0cc3b64495bd23 (patch) | |
| tree | 643c8cf608d27cb9db0624d7099258891ac63689 /src/core | |
| parent | bc5c28714a2db990e9d1bfca66480efeb7b6052a (diff) | |
| download | nginx-96c56c9ab6e73f9d92242fdc4f0cc3b64495bd23.tar.gz nginx-96c56c9ab6e73f9d92242fdc4f0cc3b64495bd23.tar.bz2 | |
nginx-0.0.1-2003-07-02-18:41:17 import
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/nginx.c | 85 | ||||
| -rw-r--r-- | src/core/ngx_conf_file.h | 37 | ||||
| -rw-r--r-- | src/core/ngx_connection.h | 3 | ||||
| -rw-r--r-- | src/core/ngx_core.h | 3 | ||||
| -rw-r--r-- | src/core/ngx_log.c | 11 | ||||
| -rw-r--r-- | src/core/ngx_log.h | 2 |
6 files changed, 86 insertions, 55 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index b011df390..1c54a8c1f 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -5,8 +5,8 @@ #include <nginx.h> - -static int ngx_open_listening_sockets(ngx_log_t *log); +static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log); +static int ngx_open_listening_sockets(ngx_cycle_t *cycle, ngx_log_t *log); void ****ngx_conf_ctx; @@ -16,21 +16,25 @@ ngx_os_io_t ngx_io; int ngx_max_module; +#if 0 void *ctx_conf; +#endif int ngx_connection_counter; +#if 0 ngx_array_t ngx_listening_sockets; +#endif -#if 0 +#if 1 int main(int argc, char *const *argv) { - ngx_str_t conf_file; + int i; ngx_log_t *log; ngx_conf_t conf; - ngx_cycle_t *cycle; + ngx_cycle_t *cycle, *new_cycle; /* TODO */ ngx_max_sockets = -1; @@ -64,10 +68,10 @@ int main(int argc, char *const *argv) for ( ;; ) { - worker(cycle->log); + ngx_worker(cycle); new_cycle = ngx_init_cycle(cycle, cycle->log); - if (new_cycle) == NULL) { + if (new_cycle == NULL) { continue; } @@ -80,9 +84,10 @@ int main(int argc, char *const *argv) } -static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) +static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) { - int i, n; + int i, n, failed; + ngx_str_t conf_file; ngx_conf_t conf; ngx_pool_t *pool; ngx_cycle_t *cycle; @@ -102,6 +107,12 @@ static int 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) { @@ -153,6 +164,8 @@ static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) return NULL; } + failed = 0; + for (i = 0; ngx_modules[i]; i++) { if (ngx_modules[i]->init_module) { if (ngx_modules[i]->init_module(cycle, log) == NGX_ERROR) @@ -166,7 +179,7 @@ static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) if (!failed) { file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { - if (file->name.data = NULL) { + if (file->name.data == NULL) { continue; } @@ -209,7 +222,7 @@ static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) } } - if (ngx_open_listening_sockets(new_cycle) == NGX_ERROR) { + if (ngx_open_listening_sockets(cycle, log) == NGX_ERROR) { failed = 1; } } @@ -220,7 +233,7 @@ static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) for (i = 0; ngx_modules[i]; i++) { if (ngx_modules[i]->rollback_module) { - ngx_modules[i]->rollback_module(cycle); + ngx_modules[i]->rollback_module(cycle, log); } } @@ -230,20 +243,20 @@ static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) continue; } - if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { + if (ngx_close_file(file->fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, ngx_close_file_n " \"%s\" failed", file->name.data); } } - ls[i] = cycle->listening.elts; + ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { if (ls[i].new && ls[i].fd == -1) { continue; } - if (ngx_close_socket(ls[i].fd) == -1) + if (ngx_close_socket(ls[i].fd) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_close_socket_n " %s failed", ls[i].addr_text.data); @@ -252,15 +265,13 @@ static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) ngx_destroy_pool(pool); return NULL; + } - } else { - - /* commit the new cycle configuration */ + /* commit the new cycle configuration */ - for (i = 0; ngx_modules[i]; i++) { - if (ngx_modules[i]->commit_module) { - ngx_modules[i]->commit_module(cycle); - } + for (i = 0; ngx_modules[i]; i++) { + if (ngx_modules[i]->commit_module) { + ngx_modules[i]->commit_module(cycle, log); } } @@ -270,7 +281,7 @@ static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) continue; } - if (ngx_close_socket(ls[i].fd) == -1) + if (ngx_close_socket(ls[i].fd) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_close_socket_n " %s failed", ls[i].addr_text.data); @@ -278,20 +289,19 @@ static int ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) } file = old_cycle->open_files.elts; - for (i = 0; i < cycle->old_open_files.nelts; i++) { + for (i = 0; i < old_cycle->open_files.nelts; i++) { if (file->fd == NGX_INVALID_FILE) { continue; } - if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { + if (ngx_close_file(file->fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, ngx_close_file_n " \"%s\" failed", file->name.data); } } - new_cycle->log = ???; - pool->log = ???; + pool->log = cycle->log; ngx_destroy_pool(old_cycle->pool); @@ -397,7 +407,7 @@ int main(int argc, char *const *argv) #endif -static int ngx_open_listening_sockets(ngx_log_t *log) +static int ngx_open_listening_sockets(ngx_cycle_t *cycle, ngx_log_t *log) { int times, failed, reuseaddr, i; ngx_err_t err; @@ -406,16 +416,19 @@ static int ngx_open_listening_sockets(ngx_log_t *log) reuseaddr = 1; + /* TODO: times configurable */ + for (times = 10; times; times--) { failed = 0; /* for each listening socket */ - ls = ngx_listening_sockets.elts; - for (i = 0; i < ngx_listening_sockets.nelts; i++) { + ls = cycle->listening.elts; + for (i = 0; i < cycle->listening.nelts; i++) { - if (ls[i].bound) + if (ls[i].fd != -1) { continue; + } if (ls[i].inherited) { @@ -423,12 +436,12 @@ static int ngx_open_listening_sockets(ngx_log_t *log) /* TODO: nonblocking */ /* TODO: deferred accept */ - ls[i].bound = 1; continue; } s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol, ls[i].flags); + if (s == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_socket_n " %s falied", ls[i].addr_text.data); @@ -493,22 +506,20 @@ static int ngx_open_listening_sockets(ngx_log_t *log) /* TODO: deferred accept */ ls[i].fd = s; - ls[i].bound = 1; } if (!failed) break; + /* TODO: delay configurable */ + ngx_log_error(NGX_LOG_NOTICE, log, 0, "try again to bind() after 500ms"); ngx_msleep(500); } if (failed) { - - /* TODO: configurable */ - - ngx_log_error(NGX_LOG_EMERG, log, 0, "can not bind(), exiting"); + ngx_log_error(NGX_LOG_EMERG, log, 0, "still can not bind()"); return NGX_ERROR; } diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h index e84137472..932f5bf93 100644 --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -56,13 +56,32 @@ struct ngx_command_s { #define ngx_null_command {ngx_null_string, 0, NULL, 0, 0, NULL} +struct ngx_open_file_s { + ngx_fd_t fd; + ngx_str_t name; +}; + + +struct ngx_cycle_s { + void ****conf_ctx; + ngx_pool_t *pool; + ngx_log_t *log; + ngx_array_t listening; + ngx_array_t open_files; + + unsigned one_process:1; +}; + + struct ngx_module_s { int ctx_index; int index; void *ctx; ngx_command_t *commands; int type; - int (*init_module)(ngx_pool_t *p); + int (*init_module)(ngx_cycle_t *cycle, ngx_log_t *log); + int (*commit_module)(ngx_cycle_t *cycle, ngx_log_t *log); + int (*rollback_module)(ngx_cycle_t *cycle, ngx_log_t *log); }; @@ -73,22 +92,6 @@ typedef struct { } ngx_conf_file_t; -struct ngx_open_file_s { - ngx_fd_t fd; - ngx_str_t name; -}; - - -typedef struct { - ngx_pool_t *pool; - ngx_log_t *log; - ngx_array_t listening; - ngx_array_t open_files; - - unsigned one_process:1; -} ngx_cycle_t; - - typedef char *(*ngx_conf_handler_pt)(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index 1bd97f2bb..6211c5f5c 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -34,6 +34,9 @@ typedef struct { time_t post_accept_timeout; /* should be here because of the deferred accept */ + unsigned new:1; + unsigned remain:1; + unsigned bound:1; /* already bound */ unsigned inherited:1; /* inherited from previous process */ unsigned nonblocking_accept:1; diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h index a1a7c06f0..52ba59b57 100644 --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -10,7 +10,8 @@ typedef struct ngx_module_s ngx_module_t; typedef struct ngx_conf_s ngx_conf_t; -typedef struct ngx_open_file_s ngx_open_file_t;; +typedef struct ngx_cycle_s ngx_cycle_t; +typedef struct ngx_open_file_s ngx_open_file_t; typedef struct ngx_command_s ngx_command_t; typedef struct ngx_file_s ngx_file_t; diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index d4f3df357..51bae3d1a 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -246,6 +246,17 @@ ngx_log_t *ngx_log_init_errlog() } +ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle) +{ + ngx_log_t *log; + + ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL); + ngx_test_null(log->file, ngx_push_array(&cycle->open_files), NULL); + + return log; +} + + char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log) { int len; diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h index d8aca8afa..0de8c3edd 100644 --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -168,6 +168,8 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...); #define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t)) ngx_log_t *ngx_log_init_errlog(); +ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle); + char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log); |
