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 sync:1;
48 unsigned last_buf:1;
49 unsigned last_in_chain:1;
50
51 unsigned last_shadow:1;
52 unsigned temp_file:1;
53
54 /* STUB */ int num;
55 };
56
57
58 struct ngx_chain_s {
59 ngx_buf_t *buf;
60 ngx_chain_t *next;
61 };
62
63
64 typedef struct {
65 ngx_int_t num;
66 size_t size;
67 } ngx_bufs_t;
68
69
70 typedef struct ngx_output_chain_ctx_s ngx_output_chain_ctx_t;
71
72 typedef ngx_int_t (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *in);
73
74 #if (NGX_HAVE_FILE_AIO)
75 typedef void (*ngx_output_chain_aio_pt)(ngx_output_chain_ctx_t *ctx,
76 ngx_file_t *file);
77 #endif
78
79 struct ngx_output_chain_ctx_s {
80 ngx_buf_t *buf;
81 ngx_chain_t *in;
82 ngx_chain_t *free;
83 ngx_chain_t *busy;
84
85 unsigned sendfile:1;
86 unsigned directio:1;
87 #if (NGX_HAVE_ALIGNED_DIRECTIO)
88 unsigned unaligned:1;
89 #endif
90 unsigned need_in_memory:1;
91 unsigned need_in_temp:1;
92 #if (NGX_HAVE_FILE_AIO)
93 unsigned aio:1;
94
95 ngx_output_chain_aio_pt aio_handler;
96 #endif
97
98 off_t alignment;
99
100 ngx_pool_t *pool;
101 ngx_int_t allocated;
102 ngx_bufs_t bufs;
103 ngx_buf_tag_t tag;
104
105 ngx_output_chain_filter_pt output_filter;
106 void *filter_ctx;
107 };
108
109
110 typedef struct {
111 ngx_chain_t *out;
112 ngx_chain_t **last;
113 ngx_connection_t *connection;
114 ngx_pool_t *pool;
115 off_t limit;
116 } ngx_chain_writer_ctx_t;
117
118
119 #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR
120
121
122 #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap)
123 #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file)
124
125 #define ngx_buf_special(b) \
126 ((b->flush || b->last_buf || b->sync) \
127 && !ngx_buf_in_memory(b) && !b->in_file)
128
129 #define ngx_buf_sync_only(b) \
130 (b->sync \
131 && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf)
132
133 #define ngx_buf_size(b) \
134 (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \
135 (b->file_last - b->file_pos))
136
137 ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);
138 ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);
139
140
141 #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t))
142 #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t))
143
144 ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool);
145 #define ngx_free_chain(pool, cl) \
146 cl->next = pool->chain; \
147 pool->chain = cl
148
149
150
151 ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
152 ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in);
153
154 ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
155 ngx_chain_t *in);
156 ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free);
157 void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
158 ngx_chain_t **out, ngx_buf_tag_t tag);
159
160
161 #endif /* _NGX_BUF_H_INCLUDED_ */
162
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.