3 * Copyright (C) Igor Sysoev
7 #ifndef _NGX_BUF_H_INCLUDED_
8 #define _NGX_BUF_H_INCLUDED_
11 #include <ngx_config.h>
15 typedef void * ngx_buf_tag_t;
17 typedef struct ngx_buf_s ngx_buf_t;
25 u_char *start; /* start of buffer */
26 u_char *end; /* end of buffer */
32 /* the buf's content could be changed */
36 * the buf's content is in a memory cache or in a read only memory
37 * and must not be changed
41 /* the buf's content is mmap()ed and must not be changed */
49 unsigned last_in_chain:1;
51 unsigned last_shadow:1;
70 typedef ngx_int_t (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *in);
80 #if (NGX_HAVE_ALIGNED_DIRECTIO)
83 unsigned need_in_memory;
84 unsigned need_in_temp;
91 ngx_output_chain_filter_pt output_filter;
93 } ngx_output_chain_ctx_t;
99 ngx_connection_t *connection;
102 } ngx_chain_writer_ctx_t;
105 #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR
108 #define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap)
109 #define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file)
111 #define ngx_buf_special(b) \
112 ((b->flush || b->last_buf || b->sync) \
113 && !ngx_buf_in_memory(b) && !b->in_file)
115 #define ngx_buf_sync_only(b) \
117 && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf)
119 #define ngx_buf_size(b) \
120 (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \
121 (b->file_last - b->file_pos))
123 ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);
124 ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);
127 #define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t))
128 #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t))
130 ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool);
131 #define ngx_free_chain(pool, cl) \
132 cl->next = pool->chain; \
137 ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
138 ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in);
140 ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
142 ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free);
143 void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
144 ngx_chain_t **out, ngx_buf_tag_t tag);
147 #endif /* _NGX_BUF_H_INCLUDED_ */