diff options
author | Igor Sysoev <igor@sysoev.ru> | 2003-11-18 21:34:08 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2003-11-18 21:34:08 +0000 |
commit | 1b138ed141c0bdb0c9944c1ae70e53682ed2d035 (patch) | |
tree | c5b4cabecced530570f4a2d6a93cc7d5fc8e044e /src/core | |
parent | 222a2adf40eb25ff613c251f15032f1e39d7f609 (diff) | |
download | nginx-1b138ed141c0bdb0c9944c1ae70e53682ed2d035.tar.gz nginx-1b138ed141c0bdb0c9944c1ae70e53682ed2d035.zip |
nginx-0.0.1-2003-11-19-00:34:08 import
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nginx.c | 21 | ||||
-rw-r--r-- | src/core/ngx_conf_file.h | 1 | ||||
-rw-r--r-- | src/core/ngx_file.c | 10 | ||||
-rw-r--r-- | src/core/ngx_file.h | 16 | ||||
-rw-r--r-- | src/core/ngx_garbage_collector.c | 53 | ||||
-rw-r--r-- | src/core/ngx_garbage_collector.h | 24 | ||||
-rw-r--r-- | src/core/ngx_times.c | 6 | ||||
-rw-r--r-- | src/core/ngx_times.h | 3 |
8 files changed, 80 insertions, 54 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 8d0b3ea60..b5e4392c0 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -6,7 +6,8 @@ /* STUB */ -void stub_init(ngx_log_t *log); +void stub_init(ngx_cycle_t *cycle); + static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log); @@ -97,10 +98,6 @@ int main(int argc, char *const *argv) return 1; } -#if 0 - stub_init(log); -#endif - ngx_max_module = 0; for (i = 0; ngx_modules[i]; i++) { ngx_modules[i]->index = ngx_max_module++; @@ -261,6 +258,18 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log) cycle->old_cycle = old_cycle; + n = old_cycle ? old_cycle->pathes.nelts : 10; + cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)); + if (cycle->pathes.elts == NULL) { + ngx_destroy_pool(pool); + return NULL; + } + cycle->pathes.nelts = 0; + cycle->pathes.size = sizeof(ngx_path_t *); + cycle->pathes.nalloc = n; + cycle->pathes.pool = pool; + + 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) { @@ -455,6 +464,8 @@ ngx_log_debug(log, "OPEN: %d:%s" _ file[i].fd _ file[i].name.data); } } + stub_init(cycle); + if (old_cycle == NULL) { return cycle; } diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h index d460fbe45..23f436e91 100644 --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -87,6 +87,7 @@ struct ngx_cycle_s { ngx_log_t *log; ngx_array_t listening; ngx_array_t open_files; + ngx_array_t pathes; int connection_n; ngx_connection_t *connections; diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c index f5a1c6601..ee4c653db 100644 --- a/src/core/ngx_file.c +++ b/src/core/ngx_file.c @@ -202,8 +202,14 @@ char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return "is duplicate"; } - ngx_test_null(path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)), NULL); + /* TODO: check duplicate in cf->cycle->pathes */ + ngx_test_null(path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)), + NGX_CONF_ERROR); + + *pp = path; + + ngx_test_null(pp, ngx_push_array(&cf->cycle->pathes), NGX_CONF_ERROR); *pp = path; value = (ngx_str_t *) cf->args->elts; @@ -225,5 +231,7 @@ char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) path->level[i++] = 0; } + path->gc_handler = cmd->post; + return NGX_CONF_OK; } diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h index 33a5250bb..b1e5fb855 100644 --- a/src/core/ngx_file.h +++ b/src/core/ngx_file.h @@ -5,6 +5,10 @@ #include <ngx_config.h> #include <ngx_core.h> +typedef struct ngx_path_s ngx_path_t; + +#include <ngx_garbage_collector.h> + struct ngx_file_s { ngx_fd_t fd; @@ -12,6 +16,7 @@ struct ngx_file_s { ngx_file_info_t info; off_t offset; + off_t sys_offset; ngx_log_t *log; @@ -20,11 +25,12 @@ struct ngx_file_s { #define NGX_MAX_PATH_LEVEL 3 -typedef struct { - ngx_str_t name; - int len; - int level[3]; -} ngx_path_t; +struct ngx_path_s { + ngx_str_t name; + int len; + int level[3]; + ngx_gc_handler_pt gc_handler; +}; typedef struct { diff --git a/src/core/ngx_garbage_collector.c b/src/core/ngx_garbage_collector.c index 087b0ad0c..e673acd5a 100644 --- a/src/core/ngx_garbage_collector.c +++ b/src/core/ngx_garbage_collector.c @@ -1,24 +1,11 @@ #include <ngx_config.h> #include <ngx_core.h> +#include <ngx_garbage_collector.h> -typedef struct ngx_gc_s ngx_gc_t; - -typedef int (*ngx_gc_handler_pt) (ngx_gc_t *ctx, ngx_str_t *name, - ngx_dir_t *dir); - - -static int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, - ngx_dir_t *dir); - -struct ngx_gc_s { - ngx_path_t *path; - u_int deleted; - off_t freed; - ngx_gc_handler_pt handler; - ngx_log_t *log; -}; +int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, + ngx_dir_t *dir); static int ngx_collect_garbage(ngx_gc_t *ctx, ngx_str_t *dname, int level); @@ -64,27 +51,20 @@ void garbage_collector() #endif -void stub_init(ngx_log_t *log) +void stub_init(ngx_cycle_t *cycle) { - ngx_gc_t *ctx; - ngx_path_t path; + int i; + ngx_gc_t ctx; + ngx_path_t **path; - if (!(ctx = ngx_alloc(sizeof(ngx_gc_t), log))) { - return; - } + path = cycle->pathes.elts; + for (i = 0; i < cycle->pathes.nelts; i++) { + ctx.path = path[i]; + ctx.log = cycle->log; + ctx.handler = path[i]->gc_handler; - path.name.len = 4; - path.name.data = "temp"; - path.len = 5; - path.level[0] = 1; - path.level[1] = 2; - path.level[2] = 0; - - ctx->path = &path; - ctx->log = log; - ctx->handler = ngx_garbage_collector_temp_handler; - - ngx_collect_garbage(ctx, &path.name, 0); + ngx_collect_garbage(&ctx, &path[i]->name, 0); + } } @@ -254,8 +234,8 @@ ngx_log_debug(ctx->log, "file %s" _ fname.data); } -static int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, - ngx_dir_t *dir) +int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, + ngx_dir_t *dir) { /* * we use mtime only and do not use atime because: @@ -279,5 +259,6 @@ static int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, ctx->deleted++; ctx->freed += ngx_de_size(dir); + return NGX_OK; } diff --git a/src/core/ngx_garbage_collector.h b/src/core/ngx_garbage_collector.h new file mode 100644 index 000000000..1164484b1 --- /dev/null +++ b/src/core/ngx_garbage_collector.h @@ -0,0 +1,24 @@ +#ifndef _NGX_GARBAGE_COLLECTOR_H_INCLUDED_ +#define _NGX_GARBAGE_COLLECTOR_H_INCLUDED_ + + +typedef struct ngx_gc_s ngx_gc_t; + +typedef int (*ngx_gc_handler_pt) (ngx_gc_t *ctx, ngx_str_t *name, + ngx_dir_t *dir); + + +struct ngx_gc_s { + ngx_path_t *path; + u_int deleted; + off_t freed; + ngx_gc_handler_pt handler; + ngx_log_t *log; +}; + + +int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, + ngx_dir_t *dir); + + +#endif /* _NGX_GARBAGE_COLLECTOR_H_INCLUDED_ */ diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c index e21524351..e741ebdc2 100644 --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -41,12 +41,6 @@ void ngx_init_time() } -time_t ngx_time() -{ - return ngx_cached_time; -} - - void ngx_time_update() { ngx_tm_t tm; diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h index eb618cd0c..212fc8bf6 100644 --- a/src/core/ngx_times.h +++ b/src/core/ngx_times.h @@ -7,11 +7,12 @@ void ngx_init_time(); -time_t ngx_time(); void ngx_time_update(); size_t ngx_http_time(char *buf, time_t t); void ngx_gmtime(time_t t, ngx_tm_t *tp); +#define ngx_time() ngx_cached_time + extern time_t ngx_cached_time; extern ngx_str_t ngx_cached_err_log_time; |