0
|
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 u_char *start; /* start of buffer */
|
|
26 u_char *end; /* end of buffer */
|
|
27 ngx_buf_tag_t tag;
|
|
28 ngx_file_t *file;
|
|
29 ngx_buf_t *shadow;
|
|
30
|
|
31
|
|
32 /* the buf's content could be changed */
|
|
33 unsigned temporary:1;
|
|
34
|
|
35 /*
|
|
36 * the buf's content is in a memory cache or in a read only memory
|
|
37 * and must not be changed
|
|
38 */
|
|
39 unsigned memory:1;
|
|
40
|
|
41 /* the buf's content is mmap()ed and must not be changed */
|
|
42 unsigned mmap:1;
|
|
43
|
|
44 unsigned recycled:1;
|
|
45 unsigned in_file:1;
|
|
46 unsigned flush:1;
|
|
47 unsigned last_buf:1;
|
|
48
|
|
49 unsigned last_shadow:1;
|
|
50 unsigned temp_file:1;
|
|
51
|
|
52 unsigned zerocopy_busy:1;
|
|
53
|
|
54 /* STUB */ int num;
|
|
55 };
|
|
56
|
|
57
|
|
58 typedef struct ngx_chain_s ngx_chain_t;
|
|
59
|
|
60 struct ngx_chain_s {
|
|
61 ngx_buf_t *buf;
|
|
62 ngx_chain_t *next;
|
|
63 };
|
|
64
|
|
65
|
|
66 typedef struct {
|
|
67 ngx_int_t num;
|
|
68 size_t size;
|
|
69 } ngx_bufs_t;
|
|
70
|
|
71
|
|
72 typedef int (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *out);
|
|
73
|
|
74 typedef struct {
|
|
75 ngx_buf_t *buf;
|
|
76 ngx_chain_t *in;
|
|
77 ngx_chain_t *free;
|
|
78 ngx_chain_t *busy;
|
|
79
|
|
80 unsigned sendfile;
|
|
81 unsigned need_in_memory;
|
|
82 unsigned need_in_temp;
|
|
83
|
|
84 ngx_pool_t *pool;
|
|
85 ngx_int_t allocated;
|
|
86 ngx_bufs_t bufs;
|
|
87 ngx_buf_tag_t tag;
|
|
88
|
|
89 ngx_output_chain_filter_pt output_filter;
|
|
90 void *filter_ctx;
|
|
91 } ngx_output_chain_ctx_t;
|
|
92
|
|
93
|
|
94 typedef struct {
|
|
95 ngx_chain_t *out;
|
|
96 ngx_chain_t **last;
|
|
97 ngx_connection_t *connection;
|
|
98 ngx_pool_t *pool;
|
|
99 off_t limit;
|
|
100 } ngx_chain_writer_ctx_t;
|
|
101
|
|
102
|
|
103 #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR
|
|
104
|
|
105
|
|
106 #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap)
|
|
107 #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file)
|
|
108 #define ngx_buf_special(b) \
|
|
109 ((b->flush || b->last_buf) && !ngx_buf_in_memory(b) && !b->in_file)
|
|
110
|
|
111 #define ngx_buf_size(b) \
|
22
|
112 (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \
|
|
113 (b->file_last - b->file_pos))
|
0
|
114
|
|
115 ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);
|
|
116 ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);
|
|
117
|
|
118
|
|
119 #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t))
|
|
120 #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t))
|
|
121
|
|
122
|
|
123 #define ngx_alloc_chain_link(pool) ngx_palloc(pool, sizeof(ngx_chain_t))
|
|
124
|
|
125
|
|
126 #define ngx_alloc_link_and_set_buf(chain, b, pool, error) \
|
|
127 do { \
|
|
128 ngx_test_null(chain, ngx_alloc_chain_link(pool), error); \
|
|
129 chain->buf = b; \
|
|
130 chain->next = NULL; \
|
|
131 } while (0);
|
|
132
|
|
133
|
|
134 #define ngx_chain_add_link(chain, last, cl) \
|
|
135 if (chain) { \
|
|
136 *last = cl; \
|
|
137 } else { \
|
|
138 chain = cl; \
|
|
139 } \
|
|
140 last = &cl->next
|
|
141
|
|
142
|
|
143 ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
|
|
144 ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in);
|
|
145
|
|
146 ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
|
|
147 ngx_chain_t *in);
|
|
148 void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
|
|
149 ngx_chain_t **out, ngx_buf_tag_t tag);
|
|
150
|
|
151
|
|
152 #endif /* _NGX_BUF_H_INCLUDED_ */
|