Mercurial > hg > nginx
comparison src/core/ngx_garbage_collector.c @ 190:02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 18 Nov 2003 21:34:08 +0000 |
parents | c1f3a3c7c5db |
children | 2357fa41738a |
comparison
equal
deleted
inserted
replaced
189:c966c09be66b | 190:02a715e85df1 |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 | 4 #include <ngx_garbage_collector.h> |
5 | 5 |
6 typedef struct ngx_gc_s ngx_gc_t; | 6 |
7 | 7 int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, |
8 typedef int (*ngx_gc_handler_pt) (ngx_gc_t *ctx, ngx_str_t *name, | 8 ngx_dir_t *dir); |
9 ngx_dir_t *dir); | |
10 | |
11 | |
12 static int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, | |
13 ngx_dir_t *dir); | |
14 | |
15 struct ngx_gc_s { | |
16 ngx_path_t *path; | |
17 u_int deleted; | |
18 off_t freed; | |
19 ngx_gc_handler_pt handler; | |
20 ngx_log_t *log; | |
21 }; | |
22 | 9 |
23 | 10 |
24 static int ngx_collect_garbage(ngx_gc_t *ctx, ngx_str_t *dname, int level); | 11 static int ngx_collect_garbage(ngx_gc_t *ctx, ngx_str_t *dname, int level); |
25 | 12 |
26 | 13 |
62 } | 49 } |
63 | 50 |
64 #endif | 51 #endif |
65 | 52 |
66 | 53 |
67 void stub_init(ngx_log_t *log) | 54 void stub_init(ngx_cycle_t *cycle) |
68 { | 55 { |
69 ngx_gc_t *ctx; | 56 int i; |
70 ngx_path_t path; | 57 ngx_gc_t ctx; |
71 | 58 ngx_path_t **path; |
72 if (!(ctx = ngx_alloc(sizeof(ngx_gc_t), log))) { | 59 |
73 return; | 60 path = cycle->pathes.elts; |
74 } | 61 for (i = 0; i < cycle->pathes.nelts; i++) { |
75 | 62 ctx.path = path[i]; |
76 path.name.len = 4; | 63 ctx.log = cycle->log; |
77 path.name.data = "temp"; | 64 ctx.handler = path[i]->gc_handler; |
78 path.len = 5; | 65 |
79 path.level[0] = 1; | 66 ngx_collect_garbage(&ctx, &path[i]->name, 0); |
80 path.level[1] = 2; | 67 } |
81 path.level[2] = 0; | |
82 | |
83 ctx->path = &path; | |
84 ctx->log = log; | |
85 ctx->handler = ngx_garbage_collector_temp_handler; | |
86 | |
87 ngx_collect_garbage(ctx, &path.name, 0); | |
88 } | 68 } |
89 | 69 |
90 | 70 |
91 static int ngx_collect_garbage(ngx_gc_t *ctx, ngx_str_t *dname, int level) | 71 static int ngx_collect_garbage(ngx_gc_t *ctx, ngx_str_t *dname, int level) |
92 { | 72 { |
252 | 232 |
253 return rc; | 233 return rc; |
254 } | 234 } |
255 | 235 |
256 | 236 |
257 static int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, | 237 int ngx_garbage_collector_temp_handler(ngx_gc_t *ctx, ngx_str_t *name, |
258 ngx_dir_t *dir) | 238 ngx_dir_t *dir) |
259 { | 239 { |
260 /* | 240 /* |
261 * we use mtime only and do not use atime because: | 241 * we use mtime only and do not use atime because: |
262 * on NTFS access time has a resolution of 1 hour, | 242 * on NTFS access time has a resolution of 1 hour, |
263 * on NT FAT access time has a resolution of 1 day, | 243 * on NT FAT access time has a resolution of 1 day, |
277 return NGX_ERROR; | 257 return NGX_ERROR; |
278 } | 258 } |
279 | 259 |
280 ctx->deleted++; | 260 ctx->deleted++; |
281 ctx->freed += ngx_de_size(dir); | 261 ctx->freed += ngx_de_size(dir); |
262 | |
282 return NGX_OK; | 263 return NGX_OK; |
283 } | 264 } |