comparison src/core/ngx_buf.h @ 0:f0b350454894 NGINX_0_1_0

nginx 0.1.0 *) The first public version.
author Igor Sysoev <http://sysoev.ru>
date Mon, 04 Oct 2004 00:00:00 +0400
parents
children 4b2dafa26fe2
comparison
equal deleted inserted replaced
-1:000000000000 0:f0b350454894
1
2 /*
3 * Copyright (C) Igor Sysoev
4 */
5
6
7 #ifndef _NGX_BUF_H_INCLUDED_
8 #define _NGX_BUF_H_INCLUDED_
9
10
11 #include <ngx_config.h>
12 #include <ngx_core.h>
13
14
15 typedef void * ngx_buf_tag_t;
16
17 typedef struct ngx_buf_s ngx_buf_t;
18
19 struct ngx_buf_s {
20 u_char *pos;
21 u_char *last;
22 off_t file_pos;
23 off_t file_last;
24
25 int type;
26 u_char *start; /* start of buffer */
27 u_char *end; /* end of buffer */
28 ngx_buf_tag_t tag;
29 ngx_file_t *file;
30 ngx_buf_t *shadow;
31
32
33 /* the buf's content could be changed */
34 unsigned temporary:1;
35
36 /*
37 * the buf's content is in a memory cache or in a read only memory
38 * and must not be changed
39 */
40 unsigned memory:1;
41
42 /* the buf's content is mmap()ed and must not be changed */
43 unsigned mmap:1;
44
45 unsigned recycled:1;
46 unsigned in_file:1;
47 unsigned flush:1;
48 unsigned last_buf:1;
49
50 unsigned last_shadow:1;
51 unsigned temp_file:1;
52
53 unsigned zerocopy_busy:1;
54
55 /* STUB */ int num;
56 };
57
58
59 typedef struct ngx_chain_s ngx_chain_t;
60
61 struct ngx_chain_s {
62 ngx_buf_t *buf;
63 ngx_chain_t *next;
64 };
65
66
67 typedef struct {
68 ngx_int_t num;
69 size_t size;
70 } ngx_bufs_t;
71
72
73 typedef int (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *out);
74
75 typedef struct {
76 ngx_buf_t *buf;
77 ngx_chain_t *in;
78 ngx_chain_t *free;
79 ngx_chain_t *busy;
80
81 unsigned sendfile;
82 unsigned need_in_memory;
83 unsigned need_in_temp;
84
85 ngx_pool_t *pool;
86 ngx_int_t allocated;
87 ngx_bufs_t bufs;
88 ngx_buf_tag_t tag;
89
90 ngx_output_chain_filter_pt output_filter;
91 void *filter_ctx;
92 } ngx_output_chain_ctx_t;
93
94
95 typedef struct {
96 ngx_chain_t *out;
97 ngx_chain_t **last;
98 ngx_connection_t *connection;
99 ngx_pool_t *pool;
100 off_t limit;
101 } ngx_chain_writer_ctx_t;
102
103
104 #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR
105
106
107 #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap)
108 #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file)
109 #define ngx_buf_special(b) \
110 ((b->flush || b->last_buf) && !ngx_buf_in_memory(b) && !b->in_file)
111
112 #define ngx_buf_size(b) \
113 (ngx_buf_in_memory(b) ? (size_t) (b->last - b->pos): \
114 (size_t) (b->file_last - b->file_pos))
115
116 ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);
117 ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);
118
119
120 #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t))
121 #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t))
122
123
124 #define ngx_alloc_chain_link(pool) ngx_palloc(pool, sizeof(ngx_chain_t))
125
126
127 #define ngx_alloc_link_and_set_buf(chain, b, pool, error) \
128 do { \
129 ngx_test_null(chain, ngx_alloc_chain_link(pool), error); \
130 chain->buf = b; \
131 chain->next = NULL; \
132 } while (0);
133
134
135 #define ngx_chain_add_link(chain, last, cl) \
136 if (chain) { \
137 *last = cl; \
138 } else { \
139 chain = cl; \
140 } \
141 last = &cl->next
142
143
144 ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
145 ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in);
146
147 ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
148 ngx_chain_t *in);
149 void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
150 ngx_chain_t **out, ngx_buf_tag_t tag);
151
152
153 #endif /* _NGX_BUF_H_INCLUDED_ */