3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
8 #ifndef _NGX_BUF_H_INCLUDED_
9 #define _NGX_BUF_H_INCLUDED_
12 #include <ngx_config.h>
16 typedef void * ngx_buf_tag_t
;
18 typedef struct ngx_buf_s ngx_buf_t
;
26 u_char
*start
; /* start of buffer */
27 u_char
*end
; /* end of buffer */
33 /* the buf's content could be changed */
37 * the buf's content is in a memory cache or in a read only memory
38 * and must not be changed
42 /* the buf's content is mmap()ed and must not be changed */
50 unsigned last_in_chain
:1;
52 unsigned last_shadow
:1;
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
,
80 struct ngx_output_chain_ctx_s
{
88 #if (NGX_HAVE_ALIGNED_DIRECTIO)
91 unsigned need_in_memory
:1;
92 unsigned need_in_temp
:1;
93 #if (NGX_HAVE_FILE_AIO)
96 ngx_output_chain_aio_pt aio_handler
;
106 ngx_output_chain_filter_pt output_filter
;
114 ngx_connection_t
*connection
;
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) \
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; \
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
,
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_ */