Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_BUF_H_INCLUDED_
0009 #define _NGX_BUF_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 
0016 typedef void *            ngx_buf_tag_t;
0017 
0018 typedef struct ngx_buf_s  ngx_buf_t;
0019 
0020 struct ngx_buf_s {
0021     u_char          *pos;
0022     u_char          *last;
0023     off_t            file_pos;
0024     off_t            file_last;
0025 
0026     u_char          *start;         /* start of buffer */
0027     u_char          *end;           /* end of buffer */
0028     ngx_buf_tag_t    tag;
0029     ngx_file_t      *file;
0030     ngx_buf_t       *shadow;
0031 
0032 
0033     /* the buf's content could be changed */
0034     unsigned         temporary:1;
0035 
0036     /*
0037      * the buf's content is in a memory cache or in a read only memory
0038      * and must not be changed
0039      */
0040     unsigned         memory:1;
0041 
0042     /* the buf's content is mmap()ed and must not be changed */
0043     unsigned         mmap:1;
0044 
0045     unsigned         recycled:1;
0046     unsigned         in_file:1;
0047     unsigned         flush:1;
0048     unsigned         sync:1;
0049     unsigned         last_buf:1;
0050     unsigned         last_in_chain:1;
0051 
0052     unsigned         last_shadow:1;
0053     unsigned         temp_file:1;
0054 
0055     /* STUB */ int   num;
0056 };
0057 
0058 
0059 struct ngx_chain_s {
0060     ngx_buf_t    *buf;
0061     ngx_chain_t  *next;
0062 };
0063 
0064 
0065 typedef struct {
0066     ngx_int_t    num;
0067     size_t       size;
0068 } ngx_bufs_t;
0069 
0070 
0071 typedef struct ngx_output_chain_ctx_s  ngx_output_chain_ctx_t;
0072 
0073 typedef ngx_int_t (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *in);
0074 
0075 typedef void (*ngx_output_chain_aio_pt)(ngx_output_chain_ctx_t *ctx,
0076     ngx_file_t *file);
0077 
0078 struct ngx_output_chain_ctx_s {
0079     ngx_buf_t                   *buf;
0080     ngx_chain_t                 *in;
0081     ngx_chain_t                 *free;
0082     ngx_chain_t                 *busy;
0083 
0084     unsigned                     sendfile:1;
0085     unsigned                     directio:1;
0086     unsigned                     unaligned:1;
0087     unsigned                     need_in_memory:1;
0088     unsigned                     need_in_temp:1;
0089     unsigned                     aio:1;
0090 
0091 #if (NGX_HAVE_FILE_AIO || NGX_COMPAT)
0092     ngx_output_chain_aio_pt      aio_handler;
0093 #if (NGX_HAVE_AIO_SENDFILE || NGX_COMPAT)
0094     ssize_t                    (*aio_preload)(ngx_buf_t *file);
0095 #endif
0096 #endif
0097 
0098 #if (NGX_THREADS || NGX_COMPAT)
0099     ngx_int_t                  (*thread_handler)(ngx_thread_task_t *task,
0100                                                  ngx_file_t *file);
0101     ngx_thread_task_t           *thread_task;
0102 #endif
0103 
0104     off_t                        alignment;
0105 
0106     ngx_pool_t                  *pool;
0107     ngx_int_t                    allocated;
0108     ngx_bufs_t                   bufs;
0109     ngx_buf_tag_t                tag;
0110 
0111     ngx_output_chain_filter_pt   output_filter;
0112     void                        *filter_ctx;
0113 };
0114 
0115 
0116 typedef struct {
0117     ngx_chain_t                 *out;
0118     ngx_chain_t                **last;
0119     ngx_connection_t            *connection;
0120     ngx_pool_t                  *pool;
0121     off_t                        limit;
0122 } ngx_chain_writer_ctx_t;
0123 
0124 
0125 #define NGX_CHAIN_ERROR     (ngx_chain_t *) NGX_ERROR
0126 
0127 
0128 #define ngx_buf_in_memory(b)        (b->temporary || b->memory || b->mmap)
0129 #define ngx_buf_in_memory_only(b)   (ngx_buf_in_memory(b) && !b->in_file)
0130 
0131 #define ngx_buf_special(b)                                                   \
0132     ((b->flush || b->last_buf || b->sync)                                    \
0133      && !ngx_buf_in_memory(b) && !b->in_file)
0134 
0135 #define ngx_buf_sync_only(b)                                                 \
0136     (b->sync                                                                 \
0137      && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf)
0138 
0139 #define ngx_buf_size(b)                                                      \
0140     (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos):                      \
0141                             (b->file_last - b->file_pos))
0142 
0143 ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);
0144 ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);
0145 
0146 
0147 #define ngx_alloc_buf(pool)  ngx_palloc(pool, sizeof(ngx_buf_t))
0148 #define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t))
0149 
0150 ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool);
0151 #define ngx_free_chain(pool, cl)                                             \
0152     cl->next = pool->chain;                                                  \
0153     pool->chain = cl
0154 
0155 
0156 
0157 ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
0158 ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in);
0159 
0160 ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
0161     ngx_chain_t *in);
0162 ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free);
0163 void ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free,
0164     ngx_chain_t **busy, ngx_chain_t **out, ngx_buf_tag_t tag);
0165 
0166 off_t ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit);
0167 
0168 ngx_chain_t *ngx_chain_update_sent(ngx_chain_t *in, off_t sent);
0169 
0170 #endif /* _NGX_BUF_H_INCLUDED_ */