Mercurial > hg > nginx
comparison src/core/ngx_buf.h @ 343:6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 28 May 2004 15:49:23 +0000 |
parents | src/core/ngx_hunk.h@5cfd65b8b0a7 |
children | e366ba5db8f8 |
comparison
equal
deleted
inserted
replaced
342:0ee0642af5f1 | 343:6bdf858bff8c |
---|---|
1 #ifndef _NGX_BUF_H_INCLUDED_ | |
2 #define _NGX_BUF_H_INCLUDED_ | |
3 | |
4 | |
5 #include <ngx_config.h> | |
6 #include <ngx_core.h> | |
7 | |
8 | |
9 #if 0 | |
10 /* the buf type */ | |
11 | |
12 /* the buf's content is in memory */ | |
13 #define NGX_HUNK_IN_MEMORY 0x0001 | |
14 /* the buf's content can be changed */ | |
15 #define NGX_HUNK_TEMP 0x0002 | |
16 /* the buf's content is in cache and can not be changed */ | |
17 #define NGX_HUNK_MEMORY 0x0004 | |
18 #define NGX_HUNK_MMAP 0x0008 | |
19 | |
20 /* the buf's content is recycled */ | |
21 #define NGX_HUNK_RECYCLED 0x0010 | |
22 | |
23 /* the buf's content is in a file */ | |
24 #define NGX_HUNK_FILE 0x0020 | |
25 | |
26 #define NGX_HUNK_STORAGE (NGX_HUNK_IN_MEMORY \ | |
27 |NGX_HUNK_TEMP|NGX_HUNK_MEMORY|NGX_HUNK_MMAP \ | |
28 |NGX_HUNK_RECYCLED|NGX_HUNK_FILE) | |
29 | |
30 /* the buf flags */ | |
31 | |
32 /* in thread state flush means to write the buf completely before return */ | |
33 /* in event state flush means to start to write the buf */ | |
34 #define NGX_HUNK_FLUSH 0x0100 | |
35 | |
36 /* the last buf */ | |
37 #define NGX_HUNK_LAST 0x0200 | |
38 | |
39 | |
40 #define NGX_HUNK_PREREAD 0x2000 | |
41 #define NGX_HUNK_LAST_SHADOW 0x4000 | |
42 #define NGX_HUNK_TEMP_FILE 0x8000 | |
43 #endif | |
44 | |
45 | |
46 typedef void * ngx_buf_tag_t; | |
47 | |
48 typedef struct ngx_buf_s ngx_buf_t; | |
49 | |
50 struct ngx_buf_s { | |
51 u_char *pos; | |
52 u_char *last; | |
53 off_t file_pos; | |
54 off_t file_last; | |
55 | |
56 int type; | |
57 u_char *start; /* start of buffer */ | |
58 u_char *end; /* end of buffer */ | |
59 ngx_buf_tag_t tag; | |
60 ngx_file_t *file; | |
61 ngx_buf_t *shadow; | |
62 | |
63 | |
64 /* the buf's content can be changed */ | |
65 unsigned temporary:1; | |
66 | |
67 /* | |
68 * the buf's content is in a memory cache or in a read only memory | |
69 * and can not be changed | |
70 */ | |
71 unsigned memory:1; | |
72 | |
73 /* the buf's content is mmap()ed and can not be changed */ | |
74 unsigned mmap:1; | |
75 unsigned recycled:1; | |
76 unsigned in_file:1; | |
77 unsigned flush:1; | |
78 unsigned last_buf:1; | |
79 | |
80 unsigned last_shadow:1; | |
81 unsigned temp_file:1; | |
82 | |
83 unsigned zerocopy_busy:1; | |
84 | |
85 /* STUB */ int num; | |
86 }; | |
87 | |
88 | |
89 typedef struct ngx_chain_s ngx_chain_t; | |
90 | |
91 struct ngx_chain_s { | |
92 ngx_buf_t *buf; | |
93 ngx_chain_t *next; | |
94 }; | |
95 | |
96 | |
97 typedef struct { | |
98 ngx_int_t num; | |
99 size_t size; | |
100 } ngx_bufs_t; | |
101 | |
102 | |
103 typedef int (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *out); | |
104 | |
105 typedef struct { | |
106 ngx_buf_t *buf; | |
107 ngx_chain_t *in; | |
108 ngx_chain_t *free; | |
109 ngx_chain_t *busy; | |
110 | |
111 unsigned sendfile; | |
112 unsigned need_in_memory; | |
113 unsigned need_in_temp; | |
114 | |
115 ngx_pool_t *pool; | |
116 ngx_int_t allocated; | |
117 ngx_bufs_t bufs; | |
118 ngx_buf_tag_t tag; | |
119 | |
120 ngx_output_chain_filter_pt output_filter; | |
121 void *filter_ctx; | |
122 } ngx_output_chain_ctx_t; | |
123 | |
124 | |
125 typedef struct { | |
126 ngx_chain_t *out; | |
127 ngx_chain_t **last; | |
128 ngx_connection_t *connection; | |
129 ngx_pool_t *pool; | |
130 } ngx_chain_writer_ctx_t; | |
131 | |
132 | |
133 #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR | |
134 | |
135 | |
136 #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap) | |
137 #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file) | |
138 #define ngx_buf_special(b) \ | |
139 ((b->flush || b->last) && !ngx_buf_in_memory(b) && !b->in_file) | |
140 | |
141 #define ngx_buf_size(b) \ | |
142 (ngx_buf_in_memory(b) ? (size_t) (b->last - b->pos): \ | |
143 (size_t) (b->file_last - b->file_pos)) | |
144 | |
145 #if 0 | |
146 | |
147 #define ngx_hunk_in_memory_only(h) \ | |
148 ((h->type & (NGX_HUNK_IN_MEMORY|NGX_HUNK_FILE)) == NGX_HUNK_IN_MEMORY) | |
149 /* | |
150 ((h->type & (NGX_HUNK_TEMP|NGX_HUNK_MEMORY|NGX_HUNK_MMAP|NGX_HUNK_FILE)) \ | |
151 == (h->type & (NGX_HUNK_TEMP|NGX_HUNK_MEMORY|NGX_HUNK_MMAP))) | |
152 | |
153 */ | |
154 | |
155 | |
156 | |
157 #define ngx_hunk_special(b) \ | |
158 (b->type == (b->type & (NGX_HUNK_FLUSH|NGX_HUNK_LAST))) | |
159 | |
160 | |
161 #define ngx_hunk_size(b) \ | |
162 ((b->type & NGX_HUNK_IN_MEMORY) ? (size_t) (b->last - b->pos): \ | |
163 (size_t) (b->file_last - b->file_pos)) | |
164 | |
165 #endif | |
166 | |
167 | |
168 ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size); | |
169 ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs); | |
170 | |
171 | |
172 #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t)) | |
173 #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t)) | |
174 | |
175 | |
176 #define ngx_alloc_chain_link(pool) ngx_palloc(pool, sizeof(ngx_chain_t)) | |
177 | |
178 | |
179 #define ngx_alloc_link_and_set_buf(chain, b, pool, error) \ | |
180 do { \ | |
181 ngx_test_null(chain, ngx_alloc_chain_link(pool), error); \ | |
182 chain->buf = b; \ | |
183 chain->next = NULL; \ | |
184 } while (0); | |
185 | |
186 | |
187 #define ngx_chain_add_link(chain, last, cl) \ | |
188 if (chain) { \ | |
189 *last = cl; \ | |
190 } else { \ | |
191 chain = cl; \ | |
192 } \ | |
193 last = &cl->next | |
194 | |
195 | |
196 int ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in); | |
197 int ngx_chain_writer(void *data, ngx_chain_t *in); | |
198 | |
199 int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in); | |
200 void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy, | |
201 ngx_chain_t **out, ngx_buf_tag_t tag); | |
202 | |
203 | |
204 #endif /* _NGX_BUF_H_INCLUDED_ */ |