Update and clean Tomato RAF files
[tomato.git] / release / src / router / nginx / src / core / ngx_buf.h
blobffc53109433d66480bdcb13a46edb0339ae9786b
2 /*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
8 #ifndef _NGX_BUF_H_INCLUDED_
9 #define _NGX_BUF_H_INCLUDED_
12 #include <ngx_config.h>
13 #include <ngx_core.h>
16 typedef void * ngx_buf_tag_t;
18 typedef struct ngx_buf_s ngx_buf_t;
20 struct ngx_buf_s {
21 u_char *pos;
22 u_char *last;
23 off_t file_pos;
24 off_t file_last;
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;
33 /* the buf's content could be changed */
34 unsigned temporary:1;
37 * the buf's content is in a memory cache or in a read only memory
38 * and must not be changed
40 unsigned memory:1;
42 /* the buf's content is mmap()ed and must not be changed */
43 unsigned mmap:1;
45 unsigned recycled:1;
46 unsigned in_file:1;
47 unsigned flush:1;
48 unsigned sync:1;
49 unsigned last_buf:1;
50 unsigned last_in_chain:1;
52 unsigned last_shadow:1;
53 unsigned temp_file:1;
55 /* STUB */ int num;
59 struct ngx_chain_s {
60 ngx_buf_t *buf;
61 ngx_chain_t *next;
65 typedef struct {
66 ngx_int_t num;
67 size_t size;
68 } ngx_bufs_t;
71 typedef struct ngx_output_chain_ctx_s ngx_output_chain_ctx_t;
73 typedef ngx_int_t (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *in);
75 #if (NGX_HAVE_FILE_AIO)
76 typedef void (*ngx_output_chain_aio_pt)(ngx_output_chain_ctx_t *ctx,
77 ngx_file_t *file);
78 #endif
80 struct ngx_output_chain_ctx_s {
81 ngx_buf_t *buf;
82 ngx_chain_t *in;
83 ngx_chain_t *free;
84 ngx_chain_t *busy;
86 unsigned sendfile:1;
87 unsigned directio:1;
88 #if (NGX_HAVE_ALIGNED_DIRECTIO)
89 unsigned unaligned:1;
90 #endif
91 unsigned need_in_memory:1;
92 unsigned need_in_temp:1;
93 #if (NGX_HAVE_FILE_AIO)
94 unsigned aio:1;
96 ngx_output_chain_aio_pt aio_handler;
97 #endif
99 off_t alignment;
101 ngx_pool_t *pool;
102 ngx_int_t allocated;
103 ngx_bufs_t bufs;
104 ngx_buf_tag_t tag;
106 ngx_output_chain_filter_pt output_filter;
107 void *filter_ctx;
111 typedef struct {
112 ngx_chain_t *out;
113 ngx_chain_t **last;
114 ngx_connection_t *connection;
115 ngx_pool_t *pool;
116 off_t limit;
117 } ngx_chain_writer_ctx_t;
120 #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR
123 #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap)
124 #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file)
126 #define ngx_buf_special(b) \
127 ((b->flush || b->last_buf || b->sync) \
128 && !ngx_buf_in_memory(b) && !b->in_file)
130 #define ngx_buf_sync_only(b) \
131 (b->sync \
132 && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf)
134 #define ngx_buf_size(b) \
135 (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \
136 (b->file_last - b->file_pos))
138 ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);
139 ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);
142 #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t))
143 #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t))
145 ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool);
146 #define ngx_free_chain(pool, cl) \
147 cl->next = pool->chain; \
148 pool->chain = cl
152 ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
153 ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in);
155 ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
156 ngx_chain_t *in);
157 ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free);
158 void ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free,
159 ngx_chain_t **busy, ngx_chain_t **out, ngx_buf_tag_t tag);
162 #endif /* _NGX_BUF_H_INCLUDED_ */