upstream nginx-0.7.39
[nginx.git] / nginx / src / core / ngx_open_file_cache.h
1
2 /*
3  * Copyright (C) Igor Sysoev
4  */
5
6
7 #include <ngx_config.h>
8 #include <ngx_core.h>
9
10
11 #ifndef _NGX_OPEN_FILE_CACHE_H_INCLUDED_
12 #define _NGX_OPEN_FILE_CACHE_H_INCLUDED_
13
14
15 #define NGX_OPEN_FILE_DIRECTIO_OFF  NGX_MAX_OFF_T_VALUE
16
17
18 typedef struct {
19     ngx_fd_t                 fd;
20     ngx_file_uniq_t          uniq;
21     time_t                   mtime;
22     off_t                    size;
23     off_t                    directio;
24     ngx_err_t                err;
25
26     time_t                   valid;
27
28     ngx_uint_t               min_uses;
29
30     unsigned                 test_dir:1;
31     unsigned                 log:1;
32     unsigned                 errors:1;
33     unsigned                 events:1;
34
35     unsigned                 is_dir:1;
36     unsigned                 is_file:1;
37     unsigned                 is_link:1;
38     unsigned                 is_exec:1;
39     unsigned                 is_directio:1;
40 } ngx_open_file_info_t;
41
42
43 typedef struct ngx_cached_open_file_s  ngx_cached_open_file_t;
44
45 struct ngx_cached_open_file_s {
46     ngx_rbtree_node_t        node;
47     ngx_queue_t              queue;
48
49     u_char                  *name;
50     time_t                   created;
51     time_t                   accessed;
52
53     ngx_fd_t                 fd;
54     ngx_file_uniq_t          uniq;
55     time_t                   mtime;
56     off_t                    size;
57     ngx_err_t                err;
58
59     uint32_t                 uses;
60
61     unsigned                 count:24;
62     unsigned                 close:1;
63     unsigned                 use_event:1;
64
65     unsigned                 is_dir:1;
66     unsigned                 is_file:1;
67     unsigned                 is_link:1;
68     unsigned                 is_exec:1;
69     unsigned                 is_directio:1;
70
71     ngx_event_t             *event;
72 };
73
74
75 typedef struct {
76     ngx_rbtree_t             rbtree;
77     ngx_rbtree_node_t        sentinel;
78     ngx_queue_t              expire_queue;
79
80     ngx_uint_t               current;
81     ngx_uint_t               max;
82     time_t                   inactive;
83 } ngx_open_file_cache_t;
84
85
86 typedef struct {
87     ngx_open_file_cache_t   *cache;
88     ngx_cached_open_file_t  *file;
89     ngx_uint_t               min_uses;
90     ngx_log_t               *log;
91 } ngx_open_file_cache_cleanup_t;
92
93
94 typedef struct {
95
96     /* ngx_connection_t stub to allow use c->fd as event ident */
97     void                    *data;
98     ngx_event_t             *read;
99     ngx_event_t             *write;
100     ngx_fd_t                 fd;
101
102     ngx_cached_open_file_t  *file;
103     ngx_open_file_cache_t   *cache;
104 } ngx_open_file_cache_event_t;
105
106
107 ngx_open_file_cache_t *ngx_open_file_cache_init(ngx_pool_t *pool,
108     ngx_uint_t max, time_t inactive);
109 ngx_int_t ngx_open_cached_file(ngx_open_file_cache_t *cache, ngx_str_t *name,
110     ngx_open_file_info_t *of, ngx_pool_t *pool);
111
112
113 #endif /* _NGX_OPEN_FILE_CACHE_H_INCLUDED_ */