# HG changeset patch # User Igor Sysoev # Date 1085759363 0 # Node ID 6bdf858bff8c0a0fb18a42fc8195c241b2e6ffe7 # Parent 0ee0642af5f1a9a92216649f57b0508e325dd230 nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t diff --git a/auto/cc b/auto/cc --- a/auto/cc +++ b/auto/cc @@ -296,7 +296,7 @@ case $CC in CFLAGS="$CFLAGS -zq" # Open Watcom C 1.2 - have=HAVE_C99_VARIADIC_MACROS . auto/have + #have=HAVE_C99_VARIADIC_MACROS . auto/have # precompiled headers CORE_DEPS="$CORE_DEPS $OBJS\\ngx_config.pch" diff --git a/auto/sources b/auto/sources --- a/auto/sources +++ b/auto/sources @@ -11,7 +11,7 @@ CORE_DEPS="src/core/nginx.h \ src/core/ngx_alloc.h \ src/core/ngx_array.h \ src/core/ngx_table.h \ - src/core/ngx_hunk.h \ + src/core/ngx_buf.h \ src/core/ngx_string.h \ src/core/ngx_parse.h \ src/core/ngx_inet.h \ @@ -29,7 +29,7 @@ CORE_SRCS="src/core/nginx.c \ src/core/ngx_log.c \ src/core/ngx_alloc.c \ src/core/ngx_array.c \ - src/core/ngx_hunk.c \ + src/core/ngx_buf.c \ src/core/ngx_output_chain.c \ src/core/ngx_string.c \ src/core/ngx_parse.c \ diff --git a/src/core/ngx_hunk.c b/src/core/ngx_buf.c rename from src/core/ngx_hunk.c rename to src/core/ngx_buf.c --- a/src/core/ngx_hunk.c +++ b/src/core/ngx_buf.c @@ -3,63 +3,77 @@ #include -ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, size_t size) +ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size) { - ngx_hunk_t *h; + ngx_buf_t *b; - ngx_test_null(h, ngx_alloc_hunk(pool), NULL); + if (!(b = ngx_calloc_buf(pool))) { + return NULL; + } - ngx_test_null(h->start, ngx_palloc(pool, size), NULL); - - h->pos = h->start; - h->last = h->start; + if (!(b->start = ngx_palloc(pool, size))) { + return NULL; + } - h->file_pos = 0; - h->file_last = 0; - - h->end = h->last + size; + b->pos = b->start; + b->last = b->start; + b->end = b->last + size; + b->temporary = 1; - h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; - h->file = NULL; - h->shadow = NULL; + /* + b->file_pos = 0; + b->file_last = 0; - h->tag = 0; + b->file = NULL; + b->shadow = NULL; - return h; + b->tag = 0; + */ + + return b; } -ngx_chain_t *ngx_create_chain_of_hunks(ngx_pool_t *pool, ngx_bufs_t *bufs) +ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs) { + u_char *p; ngx_int_t i; - u_char *p; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *chain, *cl, **ll; - ngx_test_null(p, ngx_palloc(pool, bufs->num * bufs->size), NULL); + if (!(p = ngx_palloc(pool, bufs->num * bufs->size))) { + return NULL; + } ll = &chain; for (i = 0; i < bufs->num; i++) { - ngx_test_null(h, ngx_alloc_hunk(pool), NULL); + if (!(b = ngx_calloc_buf(pool))) { + return NULL; + } - h->pos = p; - h->last = p; - h->file_pos = 0; - h->file_last = 0; + b->pos = p; + b->last = p; + b->temporary = 1; - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; + b->start = p; + p += bufs->size; + b->end = p; - h->start = p; - p += bufs->size; - h->end = p; + /* + b->file_pos = 0; + b->file_last = 0; - h->file = NULL; - h->shadow = NULL; - h->tag = 0; + b->file = NULL; + b->shadow = NULL; + b->tag = 0; + */ - ngx_test_null(cl, ngx_alloc_chain_link(pool), NULL); - cl->hunk = h; + if (!(cl = ngx_alloc_chain_link(pool))) { + return NULL; + } + + cl->buf = b; *ll = cl; ll = &cl->next; } @@ -83,7 +97,7 @@ int ngx_chain_add_copy(ngx_pool_t *pool, while (in) { ngx_test_null(cl, ngx_alloc_chain_link(pool), NGX_ERROR); - cl->hunk = in->hunk; + cl->buf = in->buf; *ll = cl; ll = &cl->next; in = in->next; @@ -96,7 +110,7 @@ int ngx_chain_add_copy(ngx_pool_t *pool, void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy, - ngx_chain_t **out, ngx_hunk_tag_t tag) + ngx_chain_t **out, ngx_buf_tag_t tag) { ngx_chain_t *tl; @@ -115,22 +129,22 @@ void ngx_chain_update_chains(ngx_chain_t *out = NULL; while (*busy) { - if (ngx_hunk_size((*busy)->hunk) != 0) { + if (ngx_buf_size((*busy)->buf) != 0) { break; } #if (HAVE_WRITE_ZEROCOPY) - if ((*busy)->hunk->type & NGX_HUNK_ZEROCOPY_BUSY) { + if ((*busy)->buf->zerocopy_busy) { break; } #endif - if ((*busy)->hunk->tag != tag) { + if ((*busy)->buf->tag != tag) { *busy = (*busy)->next; continue; } - (*busy)->hunk->pos = (*busy)->hunk->last = (*busy)->hunk->start; + (*busy)->buf->pos = (*busy)->buf->last = (*busy)->buf->start; tl = *busy; *busy = (*busy)->next; diff --git a/src/core/ngx_hunk.h b/src/core/ngx_buf.h rename from src/core/ngx_hunk.h rename to src/core/ngx_buf.h --- a/src/core/ngx_hunk.h +++ b/src/core/ngx_buf.h @@ -1,61 +1,87 @@ -#ifndef _NGX_HUNK_H_INCLUDED_ -#define _NGX_HUNK_H_INCLUDED_ +#ifndef _NGX_BUF_H_INCLUDED_ +#define _NGX_BUF_H_INCLUDED_ #include #include -/* hunk type */ +#if 0 +/* the buf type */ -/* the hunk is in memory */ +/* the buf's content is in memory */ #define NGX_HUNK_IN_MEMORY 0x0001 -/* the hunk's content can be changed */ +/* the buf's content can be changed */ #define NGX_HUNK_TEMP 0x0002 -/* the hunk's content is in cache and can not be changed */ +/* the buf's content is in cache and can not be changed */ #define NGX_HUNK_MEMORY 0x0004 -/* the hunk's content is mmap()ed and can not be changed */ #define NGX_HUNK_MMAP 0x0008 +/* the buf's content is recycled */ #define NGX_HUNK_RECYCLED 0x0010 -/* the hunk is in file */ +/* the buf's content is in a file */ #define NGX_HUNK_FILE 0x0020 #define NGX_HUNK_STORAGE (NGX_HUNK_IN_MEMORY \ |NGX_HUNK_TEMP|NGX_HUNK_MEMORY|NGX_HUNK_MMAP \ |NGX_HUNK_RECYCLED|NGX_HUNK_FILE) -/* hunk flags */ +/* the buf flags */ -/* in thread state flush means to write the hunk completely before return */ -/* in event state flush means to start to write the hunk */ +/* in thread state flush means to write the buf completely before return */ +/* in event state flush means to start to write the buf */ #define NGX_HUNK_FLUSH 0x0100 -/* last hunk */ + +/* the last buf */ #define NGX_HUNK_LAST 0x0200 #define NGX_HUNK_PREREAD 0x2000 #define NGX_HUNK_LAST_SHADOW 0x4000 #define NGX_HUNK_TEMP_FILE 0x8000 +#endif -typedef void * ngx_hunk_tag_t; +typedef void * ngx_buf_tag_t; -typedef struct ngx_hunk_s ngx_hunk_t; +typedef struct ngx_buf_s ngx_buf_t; -struct ngx_hunk_s { +struct ngx_buf_s { u_char *pos; u_char *last; off_t file_pos; off_t file_last; int type; - u_char *start; /* start of hunk */ - u_char *end; /* end of hunk */ - ngx_hunk_tag_t tag; + u_char *start; /* start of buffer */ + u_char *end; /* end of buffer */ + ngx_buf_tag_t tag; ngx_file_t *file; - ngx_hunk_t *shadow; + ngx_buf_t *shadow; + + + /* the buf's content can be changed */ + unsigned temporary:1; + + /* + * the buf's content is in a memory cache or in a read only memory + * and can not be changed + */ + unsigned memory:1; + + /* the buf's content is mmap()ed and can not be changed */ + unsigned mmap:1; + unsigned recycled:1; + unsigned in_file:1; + unsigned flush:1; + unsigned last_buf:1; + + unsigned last_shadow:1; + unsigned temp_file:1; + + unsigned zerocopy_busy:1; + /* STUB */ int num; }; @@ -63,8 +89,8 @@ struct ngx_hunk_s { typedef struct ngx_chain_s ngx_chain_t; struct ngx_chain_s { - ngx_hunk_t *hunk; - ngx_chain_t *next; + ngx_buf_t *buf; + ngx_chain_t *next; }; @@ -77,7 +103,7 @@ typedef struct { typedef int (*ngx_output_chain_filter_pt)(void *ctx, ngx_chain_t *out); typedef struct { - ngx_hunk_t *hunk; + ngx_buf_t *buf; ngx_chain_t *in; ngx_chain_t *free; ngx_chain_t *busy; @@ -87,9 +113,9 @@ typedef struct { unsigned need_in_temp; ngx_pool_t *pool; - ngx_int_t hunks; + ngx_int_t allocated; ngx_bufs_t bufs; - ngx_hunk_tag_t tag; + ngx_buf_tag_t tag; ngx_output_chain_filter_pt output_filter; void *filter_ctx; @@ -107,6 +133,17 @@ typedef struct { #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR +#define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap) +#define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !b->in_file) +#define ngx_buf_special(b) \ + ((b->flush || b->last) && !ngx_buf_in_memory(b) && !b->in_file) + +#define ngx_buf_size(b) \ + (ngx_buf_in_memory(b) ? (size_t) (b->last - b->pos): \ + (size_t) (b->file_last - b->file_pos)) + +#if 0 + #define ngx_hunk_in_memory_only(h) \ ((h->type & (NGX_HUNK_IN_MEMORY|NGX_HUNK_FILE)) == NGX_HUNK_IN_MEMORY) /* @@ -115,28 +152,34 @@ typedef struct { */ -#define ngx_hunk_special(h) \ - (h->type == (h->type & (NGX_HUNK_FLUSH|NGX_HUNK_LAST))) + + +#define ngx_hunk_special(b) \ + (b->type == (b->type & (NGX_HUNK_FLUSH|NGX_HUNK_LAST))) -#define ngx_hunk_size(h) \ - ((h->type & NGX_HUNK_IN_MEMORY) ? (size_t) (h->last - h->pos): \ - (size_t) (h->file_last - h->file_pos)) +#define ngx_hunk_size(b) \ + ((b->type & NGX_HUNK_IN_MEMORY) ? (size_t) (b->last - b->pos): \ + (size_t) (b->file_last - b->file_pos)) + +#endif -ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, size_t size); +ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size); +ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs); -#define ngx_alloc_hunk(pool) ngx_palloc(pool, sizeof(ngx_hunk_t)) -#define ngx_calloc_hunk(pool) ngx_pcalloc(pool, sizeof(ngx_hunk_t)) + +#define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t)) +#define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t)) #define ngx_alloc_chain_link(pool) ngx_palloc(pool, sizeof(ngx_chain_t)) -#define ngx_alloc_link_and_set_hunk(chain, h, pool, error) \ +#define ngx_alloc_link_and_set_buf(chain, b, pool, error) \ do { \ ngx_test_null(chain, ngx_alloc_chain_link(pool), error); \ - chain->hunk = h; \ + chain->buf = b; \ chain->next = NULL; \ } while (0); @@ -155,7 +198,7 @@ int ngx_chain_writer(void *data, ngx_cha int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in); void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy, - ngx_chain_t **out, ngx_hunk_tag_t tag); + ngx_chain_t **out, ngx_buf_tag_t tag); -#endif /* _NGX_HUNK_H_INCLUDED_ */ +#endif /* _NGX_BUF_H_INCLUDED_ */ diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -51,8 +51,8 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx int m, rc, found, valid; char *rv; void *conf, **confp; + ngx_fd_t fd; ngx_str_t *name; - ngx_fd_t fd; ngx_conf_file_t *prev; ngx_command_t *cmd; @@ -73,18 +73,18 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx } prev = cf->conf_file; - ngx_test_null(cf->conf_file, - ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)), - NGX_CONF_ERROR); + if (!(cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)))) { + return NGX_CONF_ERROR; + } if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, ngx_fd_info_n " %s failed", filename->data); } - ngx_test_null(cf->conf_file->hunk, - ngx_create_temp_hunk(cf->pool, 1024), - NGX_CONF_ERROR); + if (!(cf->conf_file->buffer = ngx_create_temp_buf(cf->pool, 1024))) { + return NGX_CONF_ERROR; + } cf->conf_file->file.fd = fd; cf->conf_file->file.name.len = filename->len; @@ -97,8 +97,10 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx for ( ;; ) { rc = ngx_conf_read_token(cf); - /* ngx_conf_read_token() returns NGX_OK, NGX_ERROR, - NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE */ + /* + * ngx_conf_read_token() returns NGX_OK, NGX_ERROR, + * NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE + */ #if 0 ngx_log_debug(cf->log, "token %d" _ rc); @@ -315,7 +317,7 @@ static int ngx_conf_read_token(ngx_conf_ int quoted, s_quoted, d_quoted; ssize_t n; ngx_str_t *word; - ngx_hunk_t *h; + ngx_buf_t *b; found = 0; need_space = 0; @@ -324,8 +326,8 @@ static int ngx_conf_read_token(ngx_conf_ quoted = s_quoted = d_quoted = 0; cf->args->nelts = 0; - h = cf->conf_file->hunk; - start = h->pos; + b = cf->conf_file->buffer; + start = b->pos; #if 0 ngx_log_debug(cf->log, "TOKEN START"); @@ -333,31 +335,31 @@ ngx_log_debug(cf->log, "TOKEN START"); for ( ;; ) { - if (h->pos >= h->last) { + if (b->pos >= b->last) { if (cf->conf_file->file.offset - >= ngx_file_size(&cf->conf_file->file.info)) { + >= ngx_file_size(&cf->conf_file->file.info)) { return NGX_CONF_FILE_DONE; } - if (h->pos - start) { - ngx_memcpy(h->start, start, (size_t) (h->pos - start)); + if (b->pos - start) { + ngx_memcpy(b->start, start, b->pos - start); } n = ngx_read_file(&cf->conf_file->file, - h->start + (h->pos - start), - (size_t) (h->end - (h->start + (h->pos - start))), + b->start + (b->pos - start), + b->end - (b->start + (b->pos - start)), cf->conf_file->file.offset); if (n == NGX_ERROR) { return NGX_ERROR; } - h->pos = h->start + (h->pos - start); - start = h->start; - h->last = h->pos + n; + b->pos = b->start + (b->pos - start); + start = b->start; + b->last = b->pos + n; } - ch = *h->pos++; + ch = *b->pos++; #if 0 ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ @@ -406,7 +408,7 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d ' continue; } - start = h->pos - 1; + start = b->pos - 1; switch (ch) { @@ -485,14 +487,16 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d ' } if (found) { - ngx_test_null(word, ngx_push_array(cf->args), NGX_ERROR); - ngx_test_null(word->data, - ngx_palloc(cf->pool, - (size_t) (h->pos - start + 1)), - NGX_ERROR); + if (!(word = ngx_push_array(cf->args))) { + return NGX_ERROR; + } + + if (!(word->data = ngx_palloc(cf->pool, b->pos - start + 1))) { + return NGX_ERROR; + } for (dst = word->data, src = start, len = 0; - src < h->pos - 1; + src < b->pos - 1; len++) { if (*src == '\\') { @@ -583,8 +587,12 @@ ngx_open_file_t *ngx_conf_open_file(ngx_ } } - ngx_test_null(file, ngx_push_array(&cycle->open_files), NULL); + if (!(file = ngx_push_array(&cycle->open_files))) { + return NULL; + } + file->fd = NGX_INVALID_FILE; + if (name) { file->name = *name; } @@ -917,8 +925,8 @@ char *ngx_conf_unsupported(ngx_conf_t *c char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data) { - ngx_conf_num_bounds_t *bounds = post; - ngx_int_t *np = data; + ngx_conf_num_bounds_t *bounds = post; + ngx_int_t *np = data; if (bounds->high == -1) { if (*np >= bounds->low) { diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -112,7 +112,7 @@ typedef struct { typedef struct { ngx_file_t file; - ngx_hunk_t *hunk; + ngx_buf_t *buffer; int line; } ngx_conf_file_t; diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -88,7 +88,7 @@ struct ngx_connection_s { socklen_t local_socklen; #endif - ngx_hunk_t *buffer; + ngx_buf_t *buffer; ngx_int_t number; diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -26,7 +26,7 @@ typedef struct ngx_connection_s ngx_con #include #include #include -#include +#include #include #include #include diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -8,20 +8,20 @@ ngx_inline static int ngx_output_chain_need_to_copy(ngx_output_chain_ctx_t *ctx, - ngx_hunk_t *hunk); -static int ngx_output_chain_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src, - u_int sendfile); + ngx_buf_t *buf); +static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src, + ngx_uint_t sendfile); int ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) { int rc, last; - size_t size, hsize; + size_t size, bsize; ngx_chain_t *cl, *out, **last_out; /* * the short path for the case when the ctx->in chain is empty - * and the incoming chain is empty too or it has the single hunk + * and the incoming chain is empty too or it has the single buf * that does not require the copy */ @@ -32,7 +32,7 @@ int ngx_output_chain(ngx_output_chain_ct } if (in->next == NULL - && (!ngx_output_chain_need_to_copy(ctx, in->hunk))) + && (!ngx_output_chain_need_to_copy(ctx, in->buf))) { return ctx->output_filter(ctx->filter_ctx, in); } @@ -55,11 +55,11 @@ int ngx_output_chain(ngx_output_chain_ct while (ctx->in) { /* - * cycle while there are the ctx->in hunks - * or there are the free output hunks to copy in + * cycle while there are the ctx->in bufs + * or there are the free output bufs to copy in */ - if (!ngx_output_chain_need_to_copy(ctx, ctx->in->hunk)) { + if (!ngx_output_chain_need_to_copy(ctx, ctx->in->buf)) { /* move the chain link to the output chain */ @@ -73,15 +73,15 @@ int ngx_output_chain(ngx_output_chain_ct continue; } - if (ctx->hunk == NULL) { + if (ctx->buf == NULL) { - /* get the free hunk */ + /* get the free buf */ if (ctx->free) { - ctx->hunk = ctx->free->hunk; + ctx->buf = ctx->free->buf; ctx->free = ctx->free->next; - } else if (out || ctx->hunks == ctx->bufs.num) { + } else if (out || ctx->allocated == ctx->bufs.num) { break; @@ -89,44 +89,45 @@ int ngx_output_chain(ngx_output_chain_ct size = ctx->bufs.size; - if (ctx->in->hunk->type & NGX_HUNK_LAST) { + if (ctx->in->buf->last_buf) { - hsize = ngx_hunk_size(ctx->in->hunk); + bsize = ngx_buf_size(ctx->in->buf); - if (hsize < ctx->bufs.size) { + if (bsize < ctx->bufs.size) { /* - * allocate small temp hunk for the small last hunk + * allocate small temp buf for the small last buf * or its small last part */ - size = hsize; + size = bsize; } else if (ctx->bufs.num == 1 - && (hsize < ctx->bufs.size + && (bsize < ctx->bufs.size + (ctx->bufs.size >> 2))) { /* - * allocate a temp hunk that equals - * to the last hunk if the last hunk size is lesser - * than 1.25 of bufs.size and a temp hunk is single + * allocate a temp buf that equals + * to the last buf if the last buf size is lesser + * than 1.25 of bufs.size and a temp buf is single */ - size = hsize; + size = bsize; } } - ngx_test_null(ctx->hunk, - ngx_create_temp_hunk(ctx->pool, size), - NGX_ERROR); - ctx->hunk->tag = ctx->tag; - ctx->hunk->type |= NGX_HUNK_RECYCLED; - ctx->hunks++; + if (!(ctx->buf = ngx_create_temp_buf(ctx->pool, size))) { + return NGX_ERROR; + } + + ctx->buf->tag = ctx->tag; + ctx->buf->recycled = 1; + ctx->allocated++; } } - rc = ngx_output_chain_copy_hunk(ctx->hunk, ctx->in->hunk, - ctx->sendfile); + rc = ngx_output_chain_copy_buf(ctx->buf, ctx->in->buf, + ctx->sendfile); if (rc == NGX_ERROR) { return rc; @@ -139,16 +140,16 @@ int ngx_output_chain(ngx_output_chain_ct return rc; } - /* delete the completed hunk from the ctx->in chain */ + /* delete the completed buf from the ctx->in chain */ - if (ngx_hunk_size(ctx->in->hunk) == 0) { + if (ngx_buf_size(ctx->in->buf) == 0) { ctx->in = ctx->in->next; } - ngx_alloc_link_and_set_hunk(cl, ctx->hunk, ctx->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(cl, ctx->buf, ctx->pool, NGX_ERROR); *last_out = cl; last_out = &cl->next; - ctx->hunk = NULL; + ctx->buf = NULL; } if (out == NULL && last != NGX_NONE) { @@ -168,26 +169,25 @@ int ngx_output_chain(ngx_output_chain_ct ngx_inline static int ngx_output_chain_need_to_copy(ngx_output_chain_ctx_t *ctx, - ngx_hunk_t *hunk) + ngx_buf_t *buf) { - if (ngx_hunk_special(hunk)) { + if (ngx_buf_special(buf)) { return 0; } if (!ctx->sendfile) { - if (!(hunk->type & NGX_HUNK_IN_MEMORY)) { + if (!ngx_buf_in_memory(buf)) { return 1; } - hunk->type &= ~NGX_HUNK_FILE; + buf->in_file = 0; } - if (ctx->need_in_memory && (!(hunk->type & NGX_HUNK_IN_MEMORY))) { + if (ctx->need_in_memory && !ngx_buf_in_memory(buf)) { return 1; } - - if (ctx->need_in_temp && (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))) { + if (ctx->need_in_temp && (buf->memory || buf->mmap)) { return 1; } @@ -195,29 +195,29 @@ ngx_inline static int ngx_output_chain_n } -static int ngx_output_chain_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src, - u_int sendfile) +static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src, + ngx_uint_t sendfile) { size_t size; ssize_t n; - size = ngx_hunk_size(src); + size = ngx_buf_size(src); if (size > (size_t) (dst->end - dst->pos)) { size = dst->end - dst->pos; } - if (src->type & NGX_HUNK_IN_MEMORY) { + if (ngx_buf_in_memory(src)) { ngx_memcpy(dst->pos, src->pos, size); src->pos += size; dst->last += size; - if (src->type & NGX_HUNK_FILE) { + if (src->in_file) { src->file_pos += size; } - if ((src->type & NGX_HUNK_LAST) && src->pos == src->last) { - dst->type |= NGX_HUNK_LAST; + if (src->last_buf && src->pos == src->last) { + dst->last_buf = 1; } } else { @@ -246,11 +246,11 @@ static int ngx_output_chain_copy_hunk(ng dst->last += n; if (!sendfile) { - dst->type &= ~NGX_HUNK_FILE; + dst->in_file = 0; } - if ((src->type & NGX_HUNK_LAST) && src->file_pos == src->file_last) { - dst->type |= NGX_HUNK_LAST; + if (src->last_buf && src->file_pos == src->file_last) { + dst->last_buf = 1; } } @@ -258,7 +258,7 @@ static int ngx_output_chain_copy_hunk(ng } -int ngx_chain_writer(void *data, ngx_chain_t *in) +ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in) { ngx_chain_writer_ctx_t *ctx = data; @@ -266,7 +266,7 @@ int ngx_chain_writer(void *data, ngx_cha for (/* void */; in; in = in->next) { - ngx_alloc_link_and_set_hunk(cl, in->hunk, ctx->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(cl, in->buf, ctx->pool, NGX_ERROR); *ctx->last = cl; ctx->last = &cl->next; } diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c --- a/src/event/ngx_event_acceptex.c +++ b/src/event/ngx_event_acceptex.c @@ -129,9 +129,9 @@ int ngx_event_post_acceptex(ngx_listenin NGX_ERROR); ngx_test_null(c->buffer, - ngx_create_temp_hunk(c->pool, - ls->post_accept_buffer_size - + 2 * (c->listening->socklen + 16)), + ngx_create_temp_buf(c->pool, + ls->post_accept_buffer_size + + 2 * (c->listening->socklen + 16)), NGX_ERROR); ngx_test_null(c->local_sockaddr, ngx_palloc(c->pool, ls->socklen), diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -5,19 +5,19 @@ #include -static int ngx_event_pipe_read_upstream(ngx_event_pipe_t *p); -static int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p); +static ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p); +static ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p); -static int ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p); -ngx_inline static void ngx_event_pipe_remove_shadow_links(ngx_hunk_t *hunk); -ngx_inline static void ngx_event_pipe_free_shadow_raw_hunk(ngx_chain_t **free, - ngx_hunk_t *h); -ngx_inline static void ngx_event_pipe_add_free_hunk(ngx_chain_t **chain, - ngx_chain_t *cl); -static int ngx_event_pipe_drain_chains(ngx_event_pipe_t *p); +static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p); +ngx_inline static void ngx_event_pipe_remove_shadow_links(ngx_buf_t *buf); +ngx_inline static void ngx_event_pipe_free_shadow_raw_buf(ngx_chain_t **free, + ngx_buf_t *buf); +ngx_inline static void ngx_event_pipe_add_free_buf(ngx_chain_t **chain, + ngx_chain_t *cl); +static ngx_int_t ngx_event_pipe_drain_chains(ngx_event_pipe_t *p); -int ngx_event_pipe(ngx_event_pipe_t *p, int do_write) +ngx_int_t ngx_event_pipe(ngx_event_pipe_t *p, int do_write) { u_int flags; ngx_event_t *rev, *wev; @@ -73,10 +73,10 @@ int ngx_event_pipe(ngx_event_pipe_t *p, } -int ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) +ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) { int n, rc, size; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *chain, *cl, *tl; if (p->upstream_eof || p->upstream_error || p->upstream_done) { @@ -92,16 +92,16 @@ int ngx_event_pipe_read_upstream(ngx_eve break; } - if (p->preread_hunks == NULL && !p->upstream->read->ready) { + if (p->preread_bufs == NULL && !p->upstream->read->ready) { break; } - if (p->preread_hunks) { + if (p->preread_bufs) { - /* use the pre-read hunks if they exist */ + /* use the pre-read bufs if they exist */ - chain = p->preread_hunks; - p->preread_hunks = NULL; + chain = p->preread_bufs; + p->preread_bufs = NULL; n = p->preread_size; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, @@ -115,7 +115,7 @@ int ngx_event_pipe_read_upstream(ngx_eve /* * kqueue notifies about the end of file or a pending error. - * This test allows not to allocate a hunk on these conditions + * This test allows not to allocate a buf on these conditions * and not to call ngx_recv_chain(). */ @@ -142,34 +142,36 @@ int ngx_event_pipe_read_upstream(ngx_eve break; } - if (p->free_raw_hunks) { + if (p->free_raw_bufs) { - /* use the free hunks if they exist */ + /* use the free bufs if they exist */ - chain = p->free_raw_hunks; + chain = p->free_raw_bufs; if (p->single_buf) { - p->free_raw_hunks = p->free_raw_hunks->next; + p->free_raw_bufs = p->free_raw_bufs->next; chain->next = NULL; } else { - p->free_raw_hunks = NULL; + p->free_raw_bufs = NULL; } - } else if (p->hunks < p->bufs.num) { + } else if (p->allocated < p->bufs.num) { - /* allocate a new hunk if it's still allowed */ + /* allocate a new buf if it's still allowed */ - ngx_test_null(h, ngx_create_temp_hunk(p->pool, p->bufs.size), - NGX_ABORT); - p->hunks++; + if (!(b = ngx_create_temp_buf(p->pool, p->bufs.size))) { + return NGX_ABORT; + } - ngx_alloc_link_and_set_hunk(tl, h, p->pool, NGX_ABORT); + p->allocated++; + + ngx_alloc_link_and_set_buf(tl, b, p->pool, NGX_ABORT); chain = tl; } else if (!p->cachable && p->downstream->write->ready) { /* - * if the hunks are not needed to be saved in a cache and - * a downstream is ready then write the hunks to a downstream + * if the bufs are not needed to be saved in a cache and + * a downstream is ready then write the bufs to a downstream */ p->upstream_blocked = 1; @@ -184,7 +186,7 @@ int ngx_event_pipe_read_upstream(ngx_eve { /* - * if it's allowed then save some hunks from r->in + * if it's allowed then save some bufs from r->in * to a temporary file, and add them to a r->out chain */ @@ -210,17 +212,17 @@ int ngx_event_pipe_read_upstream(ngx_eve return rc; } - chain = p->free_raw_hunks; + chain = p->free_raw_bufs; if (p->single_buf) { - p->free_raw_hunks = p->free_raw_hunks->next; + p->free_raw_bufs = p->free_raw_bufs->next; chain->next = NULL; } else { - p->free_raw_hunks = NULL; + p->free_raw_bufs = NULL; } } else { - /* if there're no hunks to read in then disable a level event */ + /* if there're no bufs to read in then disable a level event */ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, "no pipe hunks to read in"); @@ -233,10 +235,10 @@ int ngx_event_pipe_read_upstream(ngx_eve ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe recv chain: %d", n); - if (p->free_raw_hunks) { - chain->next = p->free_raw_hunks; + if (p->free_raw_bufs) { + chain->next = p->free_raw_bufs; } - p->free_raw_hunks = chain; + p->free_raw_bufs = chain; if (n == NGX_ERROR) { p->upstream_error = 1; @@ -245,7 +247,7 @@ int ngx_event_pipe_read_upstream(ngx_eve if (n == NGX_AGAIN) { if (p->single_buf) { - ngx_event_pipe_remove_shadow_links(chain->hunk); + ngx_event_pipe_remove_shadow_links(chain->buf); } break; @@ -264,16 +266,16 @@ int ngx_event_pipe_read_upstream(ngx_eve while (cl && n > 0) { - ngx_event_pipe_remove_shadow_links(cl->hunk); + ngx_event_pipe_remove_shadow_links(cl->buf); - size = cl->hunk->end - cl->hunk->last; + size = cl->buf->end - cl->buf->last; if (n >= size) { - cl->hunk->last = cl->hunk->end; + cl->buf->last = cl->buf->end; - /* STUB */ cl->hunk->num = p->num++; + /* STUB */ cl->buf->num = p->num++; - if (p->input_filter(p, cl->hunk) == NGX_ERROR) { + if (p->input_filter(p, cl->buf) == NGX_ERROR) { return NGX_ABORT; } @@ -281,56 +283,56 @@ int ngx_event_pipe_read_upstream(ngx_eve cl = cl->next; } else { - cl->hunk->last += n; + cl->buf->last += n; n = 0; } } - p->free_raw_hunks = cl; + p->free_raw_bufs = cl; } -#if (NGX_DEBUG0) +#if (NGX_DEBUG) - if (p->in || p->busy || p->free_raw_hunks) { + if (p->in || p->busy || p->free_raw_bufs) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe buf"); } for (cl = p->in; cl; cl = cl->next) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe buf in " PTR_FMT ", pos " PTR_FMT ", size: %d", - cl->hunk->start, cl->hunk->pos, - cl->hunk->last - cl->hunk->pos); + cl->buf->start, cl->buf->pos, + cl->buf->last - cl->buf->pos); } for (cl = p->busy; cl; cl = cl->next) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe buf busy " PTR_FMT ", pos " PTR_FMT ", size: %d", - cl->hunk->start, cl->hunk->pos, - cl->hunk->last - cl->hunk->pos); + cl->buf->start, cl->buf->pos, + cl->buf->last - cl->buf->pos); } - for (cl = p->free_raw_hunks; cl; cl = cl->next) { + for (cl = p->free_raw_bufs; cl; cl = cl->next) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe buf free " PTR_FMT ", last " PTR_FMT ", size: %d", - cl->hunk->start, cl->hunk->last, - cl->hunk->end - cl->hunk->last); + cl->buf->start, cl->buf->last, + cl->buf->end - cl->buf->last); } #endif - if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) { + if ((p->upstream_eof || p->upstream_error) && p->free_raw_bufs) { - /* STUB */ p->free_raw_hunks->hunk->num = p->num++; + /* STUB */ p->free_raw_bufs->buf->num = p->num++; - if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) { + if (p->input_filter(p, p->free_raw_bufs->buf) == NGX_ERROR) { return NGX_ABORT; } - p->free_raw_hunks = p->free_raw_hunks->next; + p->free_raw_bufs = p->free_raw_bufs->next; if (p->free_bufs) { - for (cl = p->free_raw_hunks; cl; cl = cl->next) { - ngx_pfree(p->pool, cl->hunk->start); + for (cl = p->free_raw_bufs; cl; cl = cl->next) { + ngx_pfree(p->pool, cl->buf->start); } } } @@ -345,11 +347,11 @@ int ngx_event_pipe_read_upstream(ngx_eve } -int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) +ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) { size_t bsize; ngx_uint_t flush; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *out, **ll, *cl, *tl; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, @@ -391,7 +393,7 @@ int ngx_event_pipe_write_to_downstream(n ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe write downstream done"); - /* TODO: free unused hunks */ + /* TODO: free unused bufs */ p->downstream_done = 1; break; @@ -401,12 +403,12 @@ int ngx_event_pipe_write_to_downstream(n break; } - /* bsize is the size of the busy hunks */ + /* bsize is the size of the busy bufs */ bsize = 0; for (cl = p->busy; cl; cl = cl->next) { - bsize += cl->hunk->end - cl->hunk->start; + bsize += cl->buf->end - cl->buf->start; } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, @@ -420,19 +422,19 @@ int ngx_event_pipe_write_to_downstream(n if (p->out) { cl = p->out; - if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { + if (bsize + ngx_buf_size(cl->buf) > p->busy_size) { flush = 1; break; } p->out = p->out->next; - ngx_event_pipe_free_shadow_raw_hunk(&p->free_raw_hunks, - cl->hunk); + ngx_event_pipe_free_shadow_raw_buf(&p->free_raw_bufs, + cl->buf); } else if (!p->cachable && p->in) { cl = p->in; - if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { + if (bsize + ngx_buf_size(cl->buf) > p->busy_size) { flush = 1; break; } @@ -443,7 +445,7 @@ int ngx_event_pipe_write_to_downstream(n break; } - bsize += ngx_hunk_size(cl->hunk); + bsize += ngx_buf_size(cl->buf); cl->next = NULL; ngx_chain_add_link(out, ll, cl); } @@ -464,43 +466,33 @@ int ngx_event_pipe_write_to_downstream(n for (cl = p->free; cl; cl = cl->next) { - if (cl->hunk->type & NGX_HUNK_TEMP_FILE) { + if (cl->buf->temp_file) { if (p->cachable || !p->cyclic_temp_file) { continue; } - /* reset p->temp_offset if all hunks had been sent */ + /* reset p->temp_offset if all bufs had been sent */ - if (cl->hunk->file_last == p->temp_file->offset) { + if (cl->buf->file_last == p->temp_file->offset) { p->temp_file->offset = 0; } } - /* TODO: free hunk if p->free_bufs && upstream done */ + /* TODO: free buf if p->free_bufs && upstream done */ - /* add the free shadow raw hunk to p->free_raw_hunks */ + /* add the free shadow raw buf to p->free_raw_bufs */ - if (cl->hunk->type & NGX_HUNK_LAST_SHADOW) { - h = cl->hunk->shadow; - h->pos = h->last = h->start; - h->shadow = NULL; - ngx_alloc_link_and_set_hunk(tl, h, p->pool, NGX_ABORT); - ngx_event_pipe_add_free_hunk(&p->free_raw_hunks, tl); + if (cl->buf->last_shadow) { + b = cl->buf->shadow; + b->pos = b->last = b->start; + b->shadow = NULL; + ngx_alloc_link_and_set_buf(tl, b, p->pool, NGX_ABORT); + ngx_event_pipe_add_free_buf(&p->free_raw_bufs, tl); - cl->hunk->type &= ~NGX_HUNK_LAST_SHADOW; + cl->buf->last_shadow = 0; } - cl->hunk->shadow = NULL; -#if 0 - if (p->cyclic_temp_file && (cl->hunk->type & NGX_HUNK_TEMP_FILE)) { - - /* reset p->temp_offset if all hunks had been sent */ - - if (cl->hunk->file_last == p->temp_file->offset) { - p->temp_file->offset = 0; - } - } -#endif + cl->buf->shadow = NULL; } } @@ -508,14 +500,14 @@ int ngx_event_pipe_write_to_downstream(n } -static int ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p) +static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p) { - int size, hsize; - ngx_hunk_t *h; + size_t size, bsize; + ngx_buf_t *b; ngx_chain_t *cl, *tl, *next, *out, **ll, **last_free, fl; - if (p->hunk_to_file) { - fl.hunk = p->hunk_to_file; + if (p->buf_to_file) { + fl.buf = p->buf_to_file; fl.next = p->in; out = &fl; @@ -533,19 +525,19 @@ static int ngx_event_pipe_write_chain_to "pipe offset: %d", p->temp_file->offset); do { - hsize = cl->hunk->last - cl->hunk->pos; + bsize = cl->buf->last - cl->buf->pos; ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe buf " PTR_FMT ", pos " PTR_FMT ", size: %d", - cl->hunk->start, cl->hunk->pos, hsize); + cl->buf->start, cl->buf->pos, bsize); - if ((size + hsize > p->temp_file_write_size) - || (p->temp_file->offset + size + hsize > p->max_temp_file_size)) + if ((size + bsize > p->temp_file_write_size) + || (p->temp_file->offset + size + bsize > p->max_temp_file_size)) { break; } - size += hsize; + size += bsize; ll = &cl->next; cl = cl->next; @@ -571,16 +563,16 @@ static int ngx_event_pipe_write_chain_to return NGX_ABORT; } - for (last_free = &p->free_raw_hunks; + for (last_free = &p->free_raw_bufs; *last_free != NULL; last_free = &(*last_free)->next) { /* void */ } - if (p->hunk_to_file) { - p->temp_file->offset = p->hunk_to_file->last - p->hunk_to_file->pos; - p->hunk_to_file = NULL; + if (p->buf_to_file) { + p->temp_file->offset = p->buf_to_file->last - p->buf_to_file->pos; + p->buf_to_file = NULL; out = out->next; } @@ -588,27 +580,20 @@ static int ngx_event_pipe_write_chain_to next = cl->next; cl->next = NULL; - h = cl->hunk; - h->file = &p->temp_file->file; - h->file_pos = p->temp_file->offset; - p->temp_file->offset += h->last - h->pos; - h->file_last = p->temp_file->offset; - - h->type |= NGX_HUNK_FILE|NGX_HUNK_TEMP_FILE; + b = cl->buf; + b->file = &p->temp_file->file; + b->file_pos = p->temp_file->offset; + p->temp_file->offset += b->last - b->pos; + b->file_last = p->temp_file->offset; -#if 0 - if (p->cachable) { - h->type |= NGX_HUNK_FILE; - } else { - h->type |= NGX_HUNK_FILE|NGX_HUNK_TEMP_FILE; - } -#endif + b->in_file = 1; + b->temp_file = 1; ngx_chain_add_link(p->out, p->last_out, cl); - if (h->type & NGX_HUNK_LAST_SHADOW) { - h->shadow->last = h->shadow->pos = h->shadow->start; - ngx_alloc_link_and_set_hunk(tl, h->shadow, p->pool, NGX_ABORT); + if (b->last_shadow) { + b->shadow->last = b->shadow->pos = b->shadow->start; + ngx_alloc_link_and_set_buf(tl, b->shadow, p->pool, NGX_ABORT); *last_free = tl; last_free = &tl->next; } @@ -620,32 +605,35 @@ static int ngx_event_pipe_write_chain_to /* the copy input filter */ -int ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_hunk_t *hunk) +ngx_int_t ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) { - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *cl; - if (hunk->pos == hunk->last) { + if (buf->pos == buf->last) { return NGX_OK; } if (p->free) { - h = p->free->hunk; + b = p->free->buf; p->free = p->free->next; } else { - ngx_test_null(h, ngx_alloc_hunk(p->pool), NGX_ERROR); + if (!(b = ngx_alloc_buf(p->pool))) { + return NGX_ERROR; + } } - ngx_memcpy(h, hunk, sizeof(ngx_hunk_t)); - h->shadow = hunk; - h->tag = p->tag; - h->type |= NGX_HUNK_LAST_SHADOW|NGX_HUNK_RECYCLED; - hunk->shadow = h; + ngx_memcpy(b, buf, sizeof(ngx_buf_t)); + b->shadow = buf; + b->tag = p->tag; + b->last_shadow = 1; + b->recycled = 1; + buf->shadow = b; - ngx_alloc_link_and_set_hunk(cl, h, p->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(cl, b, p->pool, NGX_ERROR); - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "hunk #%d", h->num); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "buf #%d", b->num); ngx_chain_add_link(p->in, p->last_in, cl); @@ -653,56 +641,65 @@ int ngx_event_pipe_copy_input_filter(ngx } -ngx_inline static void ngx_event_pipe_remove_shadow_links(ngx_hunk_t *hunk) +ngx_inline static void ngx_event_pipe_remove_shadow_links(ngx_buf_t *buf) { - ngx_hunk_t *h, *next; + ngx_buf_t *b, *next; - if (hunk->shadow == NULL) { + if (buf->shadow == NULL) { return; } - h = hunk->shadow; + b = buf->shadow; - while (!(h->type & NGX_HUNK_LAST_SHADOW)) { - next = h->shadow; - h->type &= ~(NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY|NGX_HUNK_RECYCLED); - h->shadow = NULL; - h = next; + while (!b->last_shadow) { + next = b->shadow; +#if 0 + b->type &= ~(NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY|NGX_HUNK_RECYCLED); +#endif + b->temporary = 0; + b->recycled = 0; + b->shadow = NULL; + b = next; } - h->type &= ~(NGX_HUNK_TEMP +#if 0 + b->type &= ~(NGX_HUNK_TEMP |NGX_HUNK_IN_MEMORY |NGX_HUNK_RECYCLED |NGX_HUNK_LAST_SHADOW); - h->shadow = NULL; +#endif - hunk->shadow = NULL; + b->temporary = 0; + b->recycled = 0; + b->last_shadow = 0; + + b->shadow = NULL; + + buf->shadow = NULL; } -ngx_inline static void ngx_event_pipe_free_shadow_raw_hunk(ngx_chain_t **free, - ngx_hunk_t *h) +ngx_inline static void ngx_event_pipe_free_shadow_raw_buf(ngx_chain_t **free, + ngx_buf_t *buf) { - ngx_hunk_t *s; + ngx_buf_t *s; ngx_chain_t *cl, **ll; - if (h->shadow == NULL) { + if (buf->shadow == NULL) { return; } - for (s = h->shadow; !(s->type & NGX_HUNK_LAST_SHADOW); s = s->shadow) { - /* void */ - } + for (s = buf->shadow; !s->last_shadow; s = s->shadow) { /* void */ } ll = free; for (cl = *free ; cl; cl = cl->next) { - if (cl->hunk == s) { + if (cl->buf == s) { *ll = cl->next; break; } - if (cl->hunk->shadow) { + if (cl->buf->shadow) { break; } @@ -711,15 +708,15 @@ ngx_inline static void ngx_event_pipe_fr } -ngx_inline static void ngx_event_pipe_add_free_hunk(ngx_chain_t **chain, - ngx_chain_t *cl) +ngx_inline static void ngx_event_pipe_add_free_buf(ngx_chain_t **chain, + ngx_chain_t *cl) { if (*chain == NULL) { *chain = cl; return; } - if ((*chain)->hunk->pos != (*chain)->hunk->last) { + if ((*chain)->buf->pos != (*chain)->buf->last) { cl->next = (*chain)->next; (*chain)->next = cl; @@ -730,9 +727,9 @@ ngx_inline static void ngx_event_pipe_ad } -static int ngx_event_pipe_drain_chains(ngx_event_pipe_t *p) +static ngx_int_t ngx_event_pipe_drain_chains(ngx_event_pipe_t *p) { - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *cl, *tl; for ( ;; ) { @@ -753,17 +750,17 @@ static int ngx_event_pipe_drain_chains(n } while (cl) { - if (cl->hunk->type & NGX_HUNK_LAST_SHADOW) { - h = cl->hunk->shadow; - h->pos = h->last = h->start; - h->shadow = NULL; - ngx_alloc_link_and_set_hunk(tl, h, p->pool, NGX_ABORT); - ngx_event_pipe_add_free_hunk(&p->free_raw_hunks, tl); + if (cl->buf->last_shadow) { + b = cl->buf->shadow; + b->pos = b->last = b->start; + b->shadow = NULL; + ngx_alloc_link_and_set_buf(tl, b, p->pool, NGX_ABORT); + ngx_event_pipe_add_free_buf(&p->free_raw_bufs, tl); - cl->hunk->type &= ~NGX_HUNK_LAST_SHADOW; + cl->buf->last_shadow = 0; } - cl->hunk->shadow = NULL; + cl->buf->shadow = NULL; tl = cl->next; cl->next = p->free; p->free = cl; diff --git a/src/event/ngx_event_pipe.h b/src/event/ngx_event_pipe.h --- a/src/event/ngx_event_pipe.h +++ b/src/event/ngx_event_pipe.h @@ -9,16 +9,17 @@ typedef struct ngx_event_pipe_s ngx_event_pipe_t; -typedef int (*ngx_event_pipe_input_filter_pt)(ngx_event_pipe_t *p, - ngx_hunk_t *hunk); -typedef int (*ngx_event_pipe_output_filter_pt)(void *data, ngx_chain_t *chain); +typedef ngx_int_t (*ngx_event_pipe_input_filter_pt)(ngx_event_pipe_t *p, + ngx_buf_t *buf); +typedef ngx_int_t (*ngx_event_pipe_output_filter_pt)(void *data, + ngx_chain_t *chain); struct ngx_event_pipe_s { ngx_connection_t *upstream; ngx_connection_t *downstream; - ngx_chain_t *free_raw_hunks; + ngx_chain_t *free_raw_bufs; ngx_chain_t *in; ngx_chain_t **last_in; @@ -30,14 +31,14 @@ struct ngx_event_pipe_s { /* * the input filter i.e. that moves HTTP/1.1 chunks - * from the raw hunks to an incoming chain + * from the raw bufs to an incoming chain */ ngx_event_pipe_input_filter_pt input_filter; - void *input_ctx; + void *input_ctx; ngx_event_pipe_output_filter_pt output_filter; - void *output_ctx; + void *output_ctx; unsigned read:1; unsigned cachable:1; @@ -51,16 +52,16 @@ struct ngx_event_pipe_s { unsigned downstream_error:1; unsigned cyclic_temp_file:1; - int hunks; + ngx_int_t allocated; ngx_bufs_t bufs; - ngx_hunk_tag_t tag; + ngx_buf_tag_t tag; size_t busy_size; off_t read_length; off_t max_temp_file_size; - int temp_file_write_size; + size_t temp_file_write_size; ngx_msec_t read_timeout; ngx_msec_t send_timeout; @@ -69,9 +70,9 @@ struct ngx_event_pipe_s { ngx_pool_t *pool; ngx_log_t *log; - ngx_chain_t *preread_hunks; - int preread_size; - ngx_hunk_t *hunk_to_file; + ngx_chain_t *preread_bufs; + size_t preread_size; + ngx_buf_t *buf_to_file; ngx_temp_file_t *temp_file; @@ -79,8 +80,8 @@ struct ngx_event_pipe_s { }; -int ngx_event_pipe(ngx_event_pipe_t *p, int do_write); -int ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_hunk_t *hunk); +ngx_int_t ngx_event_pipe(ngx_event_pipe_t *p, int do_write); +ngx_int_t ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf); #endif /* _NGX_EVENT_PIPE_H_INCLUDED_ */ diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -40,7 +40,7 @@ typedef struct { } ngx_http_charset_ctx_t; -static void ngx_charset_recode(ngx_hunk_t *h, char *table); +static void ngx_charset_recode(ngx_buf_t *b, char *table); static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -50,7 +50,7 @@ static char *ngx_http_set_charset_slot(n void *conf); static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name); -static int ngx_http_charset_filter_init(ngx_cycle_t *cycle); +static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle); static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf); static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf); @@ -212,18 +212,18 @@ static int ngx_http_charset_body_filter( table = charsets[lcf->source_charset].tables[lcf->default_charset]; for (cl = in; cl; cl = cl->next) { - ngx_charset_recode(cl->hunk, table); + ngx_charset_recode(cl->buf, table); } return ngx_http_next_body_filter(r, in); } -static void ngx_charset_recode(ngx_hunk_t *h, char *table) +static void ngx_charset_recode(ngx_buf_t *b, char *table) { u_char *p, c; - for (p = h->pos; p < h->last; p++) { + for (p = b->pos; p < b->last; p++) { c = *p; *p = table[c]; } @@ -412,7 +412,7 @@ static ngx_int_t ngx_http_add_charset(ng } -static int ngx_http_charset_filter_init(ngx_cycle_t *cycle) +static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle) { ngx_http_next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_charset_header_filter; diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -58,14 +58,14 @@ static int ngx_http_chunked_body_filter( { u_char *chunk; size_t size, len; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t out, tail, *cl, *tl, **ll; if (in == NULL || !r->chunked) { return ngx_http_next_body_filter(r, in); } - out.hunk = NULL; + out.buf = NULL; ll = &out.next; size = 0; @@ -73,12 +73,12 @@ static int ngx_http_chunked_body_filter( for ( ;; ) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http chunk: %d", ngx_hunk_size(cl->hunk)); + "http chunk: %d", ngx_buf_size(cl->buf)); - size += ngx_hunk_size(cl->hunk); + size += ngx_buf_size(cl->buf); ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR); - tl->hunk = cl->hunk; + tl->buf = cl->buf; *ll = tl; ll = &tl->next; @@ -93,25 +93,26 @@ static int ngx_http_chunked_body_filter( ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size); - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; - h->pos = chunk; - h->last = chunk + len; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->temporary = 1; + b->pos = chunk; + b->last = chunk + len; - out.hunk = h; + out.buf = b; } - if (cl->hunk->type & NGX_HUNK_LAST) { - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY|NGX_HUNK_LAST; - h->pos = (u_char *) CRLF "0" CRLF CRLF; - h->last = h->pos + 7; + if (cl->buf->last_buf) { + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->memory = 1; + b->last_buf = 1; + b->pos = (u_char *) CRLF "0" CRLF CRLF; + b->last = b->pos + 7; - cl->hunk->type &= ~NGX_HUNK_LAST; + cl->buf->last_buf = 0; if (size == 0) { - h->pos += 2; - out.hunk = h; + b->pos += 2; + out.buf = b; out.next = NULL; return ngx_http_next_body_filter(r, &out); @@ -123,13 +124,13 @@ static int ngx_http_chunked_body_filter( return ngx_http_next_body_filter(r, out.next); } - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; - h->pos = (u_char *) CRLF; - h->last = h->pos + 2; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->memory = 1; + b->pos = (u_char *) CRLF; + b->last = b->pos + 2; } - tail.hunk = h; + tail.buf = b; tail.next = NULL; *ll = &tail; diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -39,9 +39,9 @@ typedef struct { ngx_chain_t *busy; ngx_chain_t *out; ngx_chain_t **last_out; - ngx_hunk_t *in_hunk; - ngx_hunk_t *out_hunk; - ngx_int_t hunks; + ngx_buf_t *in_buf; + ngx_buf_t *out_buf; + ngx_int_t bufs; off_t length; @@ -407,7 +407,7 @@ static int ngx_http_gzip_body_filter(ngx { int rc, wbits, memlevel, last; struct gztrailer *trailer; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *cl; ngx_http_gzip_ctx_t *ctx; ngx_http_gzip_conf_t *conf; @@ -465,13 +465,13 @@ static int ngx_http_gzip_body_filter(ngx return ngx_http_gzip_error(ctx); } - ngx_test_null(h, ngx_calloc_hunk(r->pool), ngx_http_gzip_error(ctx)); + ngx_test_null(b, ngx_calloc_buf(r->pool), ngx_http_gzip_error(ctx)); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; - h->pos = gzheader; - h->last = h->pos + 10; + b->memory = 1; + b->pos = gzheader; + b->last = b->pos + 10; - ngx_alloc_link_and_set_hunk(cl, h, r->pool, ngx_http_gzip_error(ctx)); + ngx_alloc_link_and_set_buf(cl, b, r->pool, ngx_http_gzip_error(ctx)); ctx->out = cl; ctx->last_out = &cl->next; @@ -504,29 +504,29 @@ static int ngx_http_gzip_body_filter(ngx break; } - ctx->in_hunk = ctx->in->hunk; + ctx->in_buf = ctx->in->buf; ctx->in = ctx->in->next; - ctx->zstream.next_in = ctx->in_hunk->pos; - ctx->zstream.avail_in = ctx->in_hunk->last - ctx->in_hunk->pos; + ctx->zstream.next_in = ctx->in_buf->pos; + ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos; ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in_hunk:" PTR_FMT " ni:" PTR_FMT " ai:%d", - ctx->in_hunk, + "gzip in_buf:" PTR_FMT " ni:" PTR_FMT " ai:%d", + ctx->in_buf, ctx->zstream.next_in, ctx->zstream.avail_in); /* STUB */ - if (ctx->in_hunk->last < ctx->in_hunk->pos) { + if (ctx->in_buf->last < ctx->in_buf->pos) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, "zstream.avail_in is huge"); ctx->done = 1; return NGX_ERROR; } - if (ctx->in_hunk->type & NGX_HUNK_LAST) { + if (ctx->in_buf->last_buf) { ctx->flush = Z_FINISH; - } else if (ctx->in_hunk->type & NGX_HUNK_FLUSH) { + } else if (ctx->in_buf->flush) { ctx->flush = Z_SYNC_FLUSH; } @@ -545,17 +545,17 @@ static int ngx_http_gzip_body_filter(ngx if (ctx->zstream.avail_out == 0) { if (ctx->free) { - ctx->out_hunk = ctx->free->hunk; + ctx->out_buf = ctx->free->buf; ctx->free = ctx->free->next; - } else if (ctx->hunks < conf->bufs.num) { - ngx_test_null(ctx->out_hunk, - ngx_create_temp_hunk(r->pool, conf->bufs.size), - ngx_http_gzip_error(ctx)); - ctx->out_hunk->tag = (ngx_hunk_tag_t) + } else if (ctx->bufs < conf->bufs.num) { + ngx_test_null(ctx->out_buf, + ngx_create_temp_buf(r->pool, conf->bufs.size), + ngx_http_gzip_error(ctx)); + ctx->out_buf->tag = (ngx_buf_tag_t) &ngx_http_gzip_filter_module; - ctx->out_hunk->type |= NGX_HUNK_RECYCLED; - ctx->hunks++; + ctx->out_buf->recycled = 1; + ctx->bufs++; } else { ctx->blocked = 1; @@ -563,7 +563,7 @@ static int ngx_http_gzip_body_filter(ngx } ctx->blocked = 0; - ctx->zstream.next_out = ctx->out_hunk->pos; + ctx->zstream.next_out = ctx->out_buf->pos; ctx->zstream.avail_out = conf->bufs.size; } @@ -587,23 +587,23 @@ static int ngx_http_gzip_body_filter(ngx rc); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in_hunk:" PTR_FMT " pos:" PTR_FMT, - ctx->in_hunk, ctx->in_hunk->pos); + "gzip in_buf:" PTR_FMT " pos:" PTR_FMT, + ctx->in_buf, ctx->in_buf->pos); if (ctx->zstream.next_in) { - ctx->in_hunk->pos = ctx->zstream.next_in; + ctx->in_buf->pos = ctx->zstream.next_in; if (ctx->zstream.avail_in == 0) { ctx->zstream.next_in = NULL; } } - ctx->out_hunk->last = ctx->zstream.next_out; + ctx->out_buf->last = ctx->zstream.next_out; if (ctx->zstream.avail_out == 0) { - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); + ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, + ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; ctx->redo = 1; @@ -614,11 +614,11 @@ static int ngx_http_gzip_body_filter(ngx ctx->redo = 0; if (ctx->flush == Z_SYNC_FLUSH) { - ctx->out_hunk->type |= NGX_HUNK_FLUSH; + ctx->out_buf->flush = 0; ctx->flush = Z_NO_FLUSH; - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); + ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, + ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; ctx->pass = 1; @@ -640,28 +640,28 @@ static int ngx_http_gzip_body_filter(ngx ngx_pfree(r->pool, ctx->preallocated); - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); + ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, + ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; if (ctx->zstream.avail_out >= 8) { - trailer = (struct gztrailer *) ctx->out_hunk->last; - ctx->out_hunk->type |= NGX_HUNK_LAST; - ctx->out_hunk->last += 8; + trailer = (struct gztrailer *) ctx->out_buf->last; + ctx->out_buf->last += 8; + ctx->out_buf->last_buf = 1; } else { - ngx_test_null(h, ngx_create_temp_hunk(r->pool, 8), + ngx_test_null(b, ngx_create_temp_buf(r->pool, 8), ngx_http_gzip_error(ctx)); - h->type |= NGX_HUNK_LAST; + b->last_buf = 1; - ngx_alloc_link_and_set_hunk(cl, h, r->pool, - ngx_http_gzip_error(ctx)); + ngx_alloc_link_and_set_buf(cl, b, r->pool, + ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; - trailer = (struct gztrailer *) h->pos; - h->last += 8; + trailer = (struct gztrailer *) b->pos; + b->last += 8; } #if (HAVE_LITTLE_ENDIAN) @@ -681,8 +681,8 @@ static int ngx_http_gzip_body_filter(ngx } if (conf->no_buffer && ctx->in == NULL) { - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); + ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, + ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; ctx->pass = 1; @@ -719,7 +719,7 @@ static int ngx_http_gzip_body_filter(ngx } ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out, - (ngx_hunk_tag_t) &ngx_http_gzip_filter_module); + (ngx_buf_tag_t) &ngx_http_gzip_filter_module); ctx->last_out = &ctx->out; if (ctx->done) { diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -406,7 +406,7 @@ static ngx_int_t ngx_http_range_body_fil ngx_chain_t *in) { ngx_uint_t i; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -417,18 +417,15 @@ static ngx_int_t ngx_http_range_body_fil /* * the optimized version for the static files only - * that are passed in the single file hunk + * that are passed in the single file buf */ - if (in - && in->hunk->type & NGX_HUNK_FILE - && in->hunk->type & NGX_HUNK_LAST) - { + if (in && in->buf->in_file && in->buf->last_buf) { range = r->headers_out.ranges.elts; if (r->headers_out.ranges.nelts == 1) { - in->hunk->file_pos = range->start; - in->hunk->file_last = range->end; + in->buf->file_pos = range->start; + in->buf->file_last = range->end; return ngx_http_next_body_filter(r, in); } @@ -446,33 +443,33 @@ static ngx_int_t ngx_http_range_body_fil * "Content-Range: bytes " */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; - h->pos = ctx->boundary_header.data; - h->last = ctx->boundary_header.data + ctx->boundary_header.len; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->memory = 1; + b->pos = ctx->boundary_header.data; + b->last = ctx->boundary_header.data + ctx->boundary_header.len; ngx_test_null(hcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); - hcl->hunk = h; + hcl->buf = b; /* "SSSS-EEEE/TTTT" CRLF CRLF */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; - h->pos = range[i].content_range.data; - h->last = range[i].content_range.data + range[i].content_range.len; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->temporary = 1; + b->pos = range[i].content_range.data; + b->last = range[i].content_range.data + range[i].content_range.len; ngx_test_null(rcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); - rcl->hunk = h; + rcl->buf = b; /* the range data */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_FILE; - h->file_pos = range[i].start; - h->file_last = range[i].end; - h->file = in->hunk->file; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->in_file = 1; + b->file_pos = range[i].start; + b->file_last = range[i].end; + b->file = in->buf->file; - ngx_alloc_link_and_set_hunk(dcl, h, r->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(dcl, b, r->pool, NGX_ERROR); *ll = hcl; hcl->next = rcl; @@ -482,14 +479,15 @@ static ngx_int_t ngx_http_range_body_fil /* the last boundary CRLF "--0123456789--" CRLF */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP|NGX_HUNK_LAST; - ngx_test_null(h->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR); - h->last = ngx_cpymem(h->pos, ctx->boundary_header.data, 4 + 10); - *h->last++ = '-'; *h->last++ = '-'; - *h->last++ = CR; *h->last++ = LF; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->temporary = 1; + b->last_buf = 1; + ngx_test_null(b->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR); + b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10); + *b->last++ = '-'; *b->last++ = '-'; + *b->last++ = CR; *b->last++ = LF; - ngx_alloc_link_and_set_hunk(hcl, h, r->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(hcl, b, r->pool, NGX_ERROR); *ll = hcl; return ngx_http_next_body_filter(r, out); diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -67,7 +67,7 @@ static ngx_int_t ngx_http_static_handler ngx_str_t name, location; ngx_err_t err; ngx_log_t *log; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t out; ngx_file_info_t fi; ngx_http_cleanup_t *file_cleanup, *redirect_cleanup; @@ -472,11 +472,11 @@ static ngx_int_t ngx_http_static_handler /* we need to allocate all before the header would be sent */ - if (!(h = ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)))) { + if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } - if (!(h->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)))) { + if (!(b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -487,15 +487,19 @@ static ngx_int_t ngx_http_static_handler return rc; } - h->type = r->main ? NGX_HUNK_FILE : NGX_HUNK_FILE|NGX_HUNK_LAST; + b->in_file = 1; - h->file_pos = 0; - h->file_last = ngx_file_size(&fi); + if (!r->main) { + b->last_buf = 1; + } - h->file->fd = fd; - h->file->log = log; + b->file_pos = 0; + b->file_last = ngx_file_size(&fi); - out.hunk = h; + b->file->fd = fd; + b->file->log = log; + + out.buf = b; out.next = NULL; return ngx_http_output_filter(r, &out); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -159,7 +159,7 @@ struct ngx_http_proxy_ctx_s { ngx_http_proxy_upstream_t *upstream; ngx_http_proxy_cache_t *cache; - ngx_hunk_t *header_in; + ngx_buf_t *header_in; ngx_http_busy_lock_ctx_t busy_lock; diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -108,7 +108,7 @@ static ngx_chain_t *ngx_http_proxy_creat { size_t len; ngx_uint_t i; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *chain; ngx_table_elt_t *header; ngx_http_request_t *r; @@ -177,71 +177,73 @@ static ngx_chain_t *ngx_http_proxy_creat len += header[i].key.len + 2 + header[i].value.len + 2; } - /* STUB */ len++; +#if (NGX_DEBUG) + len++; +#endif - ngx_test_null(h, ngx_create_temp_hunk(r->pool, len), NULL); - ngx_alloc_link_and_set_hunk(chain, h, r->pool, NULL); + ngx_test_null(b, ngx_create_temp_buf(r->pool, len), NULL); + ngx_alloc_link_and_set_buf(chain, b, r->pool, NULL); /* the request line */ if (p->upstream->method) { - h->last = ngx_cpymem(h->last, + b->last = ngx_cpymem(b->last, http_methods[p->upstream->method - 1].data, http_methods[p->upstream->method - 1].len); } else { - h->last = ngx_cpymem(h->last, r->method_name.data, r->method_name.len); + b->last = ngx_cpymem(b->last, r->method_name.data, r->method_name.len); } - h->last = ngx_cpymem(h->last, uc->uri.data, uc->uri.len); + b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len); - h->last = ngx_cpymem(h->last, + b->last = ngx_cpymem(b->last, r->uri.data + uc->location->len, r->uri.len - uc->location->len); if (r->args.len > 0) { - *(h->last++) = '?'; - h->last = ngx_cpymem(h->last, r->args.data, r->args.len); + *(b->last++) = '?'; + b->last = ngx_cpymem(b->last, r->args.data, r->args.len); } - h->last = ngx_cpymem(h->last, http_version, sizeof(http_version) - 1); + b->last = ngx_cpymem(b->last, http_version, sizeof(http_version) - 1); /* the "Connection: close" header */ - h->last = ngx_cpymem(h->last, connection_close_header, + b->last = ngx_cpymem(b->last, connection_close_header, sizeof(connection_close_header) - 1); /* the "Host" header */ - h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1); + b->last = ngx_cpymem(b->last, host_header, sizeof(host_header) - 1); if (p->lcf->preserve_host && r->headers_in.host) { - h->last = ngx_cpymem(h->last, r->headers_in.host->value.data, + b->last = ngx_cpymem(b->last, r->headers_in.host->value.data, r->headers_in.host_name_len); if (!uc->default_port) { - *(h->last++) = ':'; - h->last = ngx_cpymem(h->last, uc->port_text.data, + *(b->last++) = ':'; + b->last = ngx_cpymem(b->last, uc->port_text.data, uc->port_text.len); } } else { - h->last = ngx_cpymem(h->last, uc->host_header.data, + b->last = ngx_cpymem(b->last, uc->host_header.data, uc->host_header.len); } - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; /* the "X-Real-IP" header */ if (p->lcf->set_x_real_ip) { - h->last = ngx_cpymem(h->last, x_real_ip_header, + b->last = ngx_cpymem(b->last, x_real_ip_header, sizeof(x_real_ip_header) - 1); - h->last = ngx_cpymem(h->last, r->connection->addr_text.data, + b->last = ngx_cpymem(b->last, r->connection->addr_text.data, r->connection->addr_text.len); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } @@ -249,23 +251,23 @@ static ngx_chain_t *ngx_http_proxy_creat if (p->lcf->add_x_forwarded_for) { if (r->headers_in.x_forwarded_for) { - h->last = ngx_cpymem(h->last, x_forwarded_for_header, + b->last = ngx_cpymem(b->last, x_forwarded_for_header, sizeof(x_forwarded_for_header) - 1); - h->last = ngx_cpymem(h->last, + b->last = ngx_cpymem(b->last, r->headers_in.x_forwarded_for->value.data, r->headers_in.x_forwarded_for->value.len); - *(h->last++) = ','; *(h->last++) = ' '; + *(b->last++) = ','; *(b->last++) = ' '; } else { - h->last = ngx_cpymem(h->last, x_forwarded_for_header, + b->last = ngx_cpymem(b->last, x_forwarded_for_header, sizeof(x_forwarded_for_header) - 1); } - h->last = ngx_cpymem(h->last, r->connection->addr_text.data, + b->last = ngx_cpymem(b->last, r->connection->addr_text.data, r->connection->addr_text.len); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } @@ -289,14 +291,14 @@ static ngx_chain_t *ngx_http_proxy_creat continue; } - h->last = ngx_cpymem(h->last, header[i].key.data, header[i].key.len); + b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len); - *(h->last++) = ':'; *(h->last++) = ' '; + *(b->last++) = ':'; *(b->last++) = ' '; - h->last = ngx_cpymem(h->last, header[i].value.data, + b->last = ngx_cpymem(b->last, header[i].value.data, header[i].value.len); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http proxy header: \"%s: %s\"", @@ -304,12 +306,12 @@ static ngx_chain_t *ngx_http_proxy_creat } /* add "\r\n" at the header end */ - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; #if (NGX_DEBUG) - *(h->last) = '\0'; + *(b->last) = '\0'; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http proxy header:\n\"%s\"", h->pos); + "http proxy header:\n\"%s\"", b->pos); #endif return chain; @@ -389,7 +391,7 @@ static void ngx_http_proxy_init_upstream output->sendfile = r->sendfile; output->pool = r->pool; output->bufs.num = 1; - output->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; + output->tag = (ngx_buf_tag_t) &ngx_http_proxy_module; output->output_filter = (ngx_output_chain_filter_pt) ngx_chain_writer; if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) { @@ -420,15 +422,15 @@ static void ngx_http_proxy_reinit_upstre /* reinit the request chain */ for (cl = p->request->request_body->bufs; cl; cl = cl->next) { - cl->hunk->pos = cl->hunk->start; - cl->hunk->file_pos = 0; + cl->buf->pos = cl->buf->start; + cl->buf->file_pos = 0; } /* reinit the ngx_output_chain() context */ output = p->upstream->output_chain_ctx; - output->hunk = NULL; + output->buf = NULL; output->in = NULL; output->free = NULL; output->busy = NULL; @@ -614,9 +616,9 @@ static void ngx_http_proxy_connect(ngx_h return; } - output->free->hunk = r->request_body->buf; - output->free->next = NULL; - output->hunks = 1; + output->free->buf = r->request_body->buf; + output->free->buf = NULL; + output->allocated = 1; r->request_body->buf->pos = r->request_body->buf->start; } @@ -793,13 +795,13 @@ static void ngx_http_proxy_process_upstr } if (p->header_in == NULL) { - p->header_in = ngx_create_temp_hunk(p->request->pool, - p->lcf->header_buffer_size); + p->header_in = ngx_create_temp_buf(p->request->pool, + p->lcf->header_buffer_size); if (p->header_in == NULL) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); return; } - p->header_in->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; + p->header_in->tag = (ngx_buf_tag_t) &ngx_http_proxy_module; if (p->cache) { p->header_in->pos += p->cache->ctx.header_size; @@ -1176,7 +1178,7 @@ static void ngx_http_proxy_send_response ep->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter; ep->output_ctx = r; - ep->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; + ep->tag = (ngx_buf_tag_t) &ngx_http_proxy_module; ep->bufs = p->lcf->bufs; ep->busy_size = p->lcf->busy_buffers_size; ep->upstream = p->upstream->peer.connection; @@ -1206,25 +1208,24 @@ static void ngx_http_proxy_send_response ep->max_temp_file_size = p->lcf->max_temp_file_size; ep->temp_file_write_size = p->lcf->temp_file_write_size; - ep->preread_hunks = ngx_alloc_chain_link(r->pool); - if (ep->preread_hunks == NULL) { + if (!(ep->preread_bufs = ngx_alloc_chain_link(r->pool))) { ngx_http_proxy_finalize_request(p, 0); return; } - ep->preread_hunks->hunk = p->header_in; - ep->preread_hunks->next = NULL; + ep->preread_bufs->buf = p->header_in; + ep->preread_bufs->next = NULL; ep->preread_size = p->header_in->last - p->header_in->pos; if (p->cachable) { - ep->hunk_to_file = ngx_calloc_hunk(r->pool); - if (ep->hunk_to_file == NULL) { + ep->buf_to_file = ngx_calloc_buf(r->pool); + if (ep->buf_to_file == NULL) { ngx_http_proxy_finalize_request(p, 0); return; } - ep->hunk_to_file->pos = p->header_in->start; - ep->hunk_to_file->last = p->header_in->pos; - ep->hunk_to_file->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; + ep->buf_to_file->pos = p->header_in->start; + ep->buf_to_file->last = p->header_in->pos; + ep->buf_to_file->temporary = 1; } if (ngx_event_flags & NGX_USE_AIO_EVENT) { @@ -1232,7 +1233,7 @@ static void ngx_http_proxy_send_response ep->single_buf = 1; } - /* TODO: ep->free_bufs = 0 if use ngx_create_chain_of_hunks() */ + /* TODO: ep->free_bufs = 0 if use ngx_create_chain_of_bufs() */ ep->free_bufs = 1; /* diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -62,7 +62,7 @@ void ngx_http_init_connection(ngx_connec int ngx_http_parse_request_line(ngx_http_request_t *r); int ngx_http_parse_complex_uri(ngx_http_request_t *r); -int ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h); +int ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b); int ngx_http_find_server_conf(ngx_http_request_t *r); void ngx_http_handler(ngx_http_request_t *r); diff --git a/src/http/ngx_http_cache.h b/src/http/ngx_http_cache.h --- a/src/http/ngx_http_cache.h +++ b/src/http/ngx_http_cache.h @@ -76,7 +76,7 @@ typedef struct { uint32_t crc; u_char md5[16]; ngx_path_t *path; - ngx_hunk_t *buf; + ngx_buf_t *buf; time_t expires; time_t last_modified; time_t date; diff --git a/src/http/ngx_http_copy_filter.c b/src/http/ngx_http_copy_filter.c --- a/src/http/ngx_http_copy_filter.c +++ b/src/http/ngx_http_copy_filter.c @@ -80,7 +80,7 @@ ngx_int_t ngx_http_copy_filter(ngx_http_ ctx->pool = r->pool; ctx->bufs = conf->bufs; - ctx->tag = (ngx_hunk_tag_t) &ngx_http_copy_filter_module; + ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module; ctx->output_filter = (ngx_output_chain_filter_pt) ngx_http_next_filter; ctx->filter_ctx = r; diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -95,7 +95,7 @@ static int ngx_http_header_filter(ngx_ht u_char *p; size_t len; ngx_uint_t status, i; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *ln; ngx_table_elt_t *header; @@ -215,39 +215,39 @@ static int ngx_http_header_filter(ngx_ht len += header[i].key.len + 2 + header[i].value.len + 2; } - if (!(h = ngx_create_temp_hunk(r->pool, len))) { + if (!(b = ngx_create_temp_buf(r->pool, len))) { return NGX_ERROR; } /* "HTTP/1.x " */ - h->last = ngx_cpymem(h->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1); + b->last = ngx_cpymem(b->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1); /* status line */ if (r->headers_out.status_line.len) { - h->last = ngx_cpymem(h->last, r->headers_out.status_line.data, + b->last = ngx_cpymem(b->last, r->headers_out.status_line.data, r->headers_out.status_line.len); } else { - h->last = ngx_cpymem(h->last, http_codes[status].data, + b->last = ngx_cpymem(b->last, http_codes[status].data, http_codes[status].len); } - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; if (!(r->headers_out.server && r->headers_out.server->key.len)) { - h->last = ngx_cpymem(h->last, server_string, sizeof(server_string) - 1); + b->last = ngx_cpymem(b->last, server_string, sizeof(server_string) - 1); } if (!(r->headers_out.date && r->headers_out.date->key.len)) { - h->last = ngx_cpymem(h->last, "Date: ", sizeof("Date: ") - 1); - h->last = ngx_cpymem(h->last, ngx_cached_http_time.data, + b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1); + b->last = ngx_cpymem(b->last, ngx_cached_http_time.data, ngx_cached_http_time.len); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } if (r->headers_out.content_length == NULL) { if (r->headers_out.content_length_n >= 0) { - h->last += ngx_snprintf((char *) h->last, + b->last += ngx_snprintf((char *) b->last, sizeof("Content-Length: ") + NGX_OFF_T_LEN + 2, "Content-Length: " OFF_T_FMT CRLF, r->headers_out.content_length_n); @@ -255,69 +255,69 @@ static int ngx_http_header_filter(ngx_ht } if (r->headers_out.content_type && r->headers_out.content_type->value.len) { - h->last = ngx_cpymem(h->last, "Content-Type: ", + b->last = ngx_cpymem(b->last, "Content-Type: ", sizeof("Content-Type: ") - 1); - p = h->last; - h->last = ngx_cpymem(h->last, r->headers_out.content_type->value.data, + p = b->last; + b->last = ngx_cpymem(b->last, r->headers_out.content_type->value.data, r->headers_out.content_type->value.len); if (r->headers_out.charset.len) { - h->last = ngx_cpymem(h->last, "; charset=", + b->last = ngx_cpymem(b->last, "; charset=", sizeof("; charset=") - 1); - h->last = ngx_cpymem(h->last, r->headers_out.charset.data, + b->last = ngx_cpymem(b->last, r->headers_out.charset.data, r->headers_out.charset.len); - r->headers_out.content_type->value.len = h->last - p; + r->headers_out.content_type->value.len = b->last - p; r->headers_out.content_type->value.data = p; } - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } if (r->headers_out.location && r->headers_out.location->value.len && r->headers_out.location->value.data[0] == '/') { - p = h->last + sizeof("Location: ") - 1; - h->last = ngx_cpymem(h->last, "Location: http://", + p = b->last + sizeof("Location: ") - 1; + b->last = ngx_cpymem(b->last, "Location: http://", sizeof("Location: http://") - 1); - h->last = ngx_cpymem(h->last, r->server_name->data, + b->last = ngx_cpymem(b->last, r->server_name->data, r->server_name->len); if (r->port != 80) { - h->last = ngx_cpymem(h->last, r->port_name->data, + b->last = ngx_cpymem(b->last, r->port_name->data, r->port_name->len); } - h->last = ngx_cpymem(h->last, r->headers_out.location->value.data, + b->last = ngx_cpymem(b->last, r->headers_out.location->value.data, r->headers_out.location->value.len); - r->headers_out.location->value.len = h->last - p; + r->headers_out.location->value.len = b->last - p; r->headers_out.location->value.data = p; - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } if (!(r->headers_out.last_modified && r->headers_out.last_modified->key.len) && r->headers_out.last_modified_time != -1) { - h->last = ngx_cpymem(h->last, "Last-Modified: ", + b->last = ngx_cpymem(b->last, "Last-Modified: ", sizeof("Last-Modified: ") - 1); - h->last += ngx_http_time(h->last, r->headers_out.last_modified_time); + b->last += ngx_http_time(b->last, r->headers_out.last_modified_time); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } if (r->chunked) { - h->last = ngx_cpymem(h->last, "Transfer-Encoding: chunked" CRLF, + b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF, sizeof("Transfer-Encoding: chunked" CRLF) - 1); } if (r->keepalive) { - h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF, + b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF, sizeof("Connection: keep-alive" CRLF) - 1); } else { - h->last = ngx_cpymem(h->last, "Connection: close" CRLF, + b->last = ngx_cpymem(b->last, "Connection: close" CRLF, sizeof("Connection: close" CRLF) - 1); } @@ -326,33 +326,33 @@ static int ngx_http_header_filter(ngx_ht continue; } - h->last = ngx_cpymem(h->last, header[i].key.data, header[i].key.len); - *(h->last++) = ':' ; *(h->last++) = ' ' ; + b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len); + *(b->last++) = ':' ; *(b->last++) = ' ' ; - h->last = ngx_cpymem(h->last, header[i].value.data, + b->last = ngx_cpymem(b->last, header[i].value.data, header[i].value.len); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } #if (NGX_DEBUG) - *(h->last) = '\0'; - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%s\n", h->pos); + *(b->last) = '\0'; + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%s\n", b->pos); #endif /* the end of HTTP header */ - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; - r->header_size = h->last - h->pos; + r->header_size = b->last - b->pos; if (r->header_only) { - h->type |= NGX_HUNK_LAST; + b->last_buf = 1; } if (!(ln = ngx_alloc_chain_link(r->pool))) { return NGX_ERROR; } - ln->hunk = h; + ln->buf = b; ln->next = NULL; return ngx_http_write_filter(r, ln); diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -438,7 +438,7 @@ ngx_int_t ngx_http_parse_request_line(ng } -ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h) +ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b) { u_char c, ch, *p; enum { @@ -455,9 +455,9 @@ ngx_int_t ngx_http_parse_header_line(ngx } state; state = r->state; - p = h->pos; + p = b->pos; - while (p < h->last && state < sw_done) { + while (p < b->last && state < sw_done) { ch = *p++; switch (state) { @@ -623,7 +623,7 @@ ngx_int_t ngx_http_parse_header_line(ngx } } - h->pos = p; + b->pos = p; if (state == sw_done) { r->state = sw_start; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -236,8 +236,8 @@ static void ngx_http_init_request(ngx_ev } if (c->buffer == NULL) { - c->buffer = ngx_create_temp_hunk(c->pool, - cscf->client_header_buffer_size); + c->buffer = ngx_create_temp_buf(c->pool, + cscf->client_header_buffer_size); if (c->buffer == NULL) { ngx_http_close_connection(c); return; @@ -1233,7 +1233,7 @@ static int ngx_http_read_discarded_body( static void ngx_http_set_keepalive(ngx_http_request_t *r) { int len; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_event_t *rev, *wev; ngx_connection_t *c; ngx_http_log_ctx_t *ctx; @@ -1257,12 +1257,12 @@ static void ngx_http_set_keepalive(ngx_h return; } - h = c->buffer; + b = c->buffer; wev = c->write; wev->event_handler = ngx_http_empty_handler; - if (h->pos < h->last) { + if (b->pos < b->last) { /* * The pipelined request. @@ -1277,10 +1277,10 @@ static void ngx_http_set_keepalive(ngx_h cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); if (!cscf->large_client_header) { - len = h->last - h->pos; - ngx_memcpy(h->start, h->pos, len); - h->pos = h->start; - h->last = h->start + len; + len = b->last - b->pos; + ngx_memcpy(b->start, b->pos, len); + b->pos = b->start; + b->last = b->start + len; } ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request"); @@ -1293,7 +1293,7 @@ static void ngx_http_set_keepalive(ngx_h c->pipeline = 0; - h->pos = h->last = h->start; + b->pos = b->last = b->start; rev->event_handler = ngx_http_keepalive_handler; if (wev->active) { @@ -1523,12 +1523,15 @@ void ngx_http_empty_handler(ngx_event_t int ngx_http_send_last(ngx_http_request_t *r) { - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t out; - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_LAST; - out.hunk = h; + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + + b->last_buf = 1; + out.buf = b; out.next = NULL; return ngx_http_output_filter(r, &out); diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -176,7 +176,7 @@ typedef struct { typedef struct { ngx_temp_file_t *temp_file; ngx_chain_t *bufs; - ngx_hunk_t *buf; + ngx_buf_t *buf; size_t rest; void (*handler) (void *data); void *data; @@ -216,7 +216,7 @@ struct ngx_http_request_s { ngx_file_t file; ngx_pool_t *pool; - ngx_hunk_t *header_in; + ngx_buf_t *header_in; ngx_http_headers_in_t headers_in; ngx_http_headers_out_t headers_out; diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c --- a/src/http/ngx_http_request_body.c +++ b/src/http/ngx_http_request_body.c @@ -12,7 +12,7 @@ static ngx_int_t ngx_http_do_read_client ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r) { ssize_t size; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *cl; ngx_http_core_loc_conf_t *clcf; @@ -22,14 +22,14 @@ ngx_int_t ngx_http_read_client_request_b /* there is the pre-read part of the request body */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_HTTP_INTERNAL_SERVER_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; - h->start = h->pos = r->header_in->pos; - h->end = h->last = r->header_in->last; + b->temporary = 1; + b->start = b->pos = r->header_in->pos; + b->end = b->last = r->header_in->last; - ngx_alloc_link_and_set_hunk(r->request_body->bufs, h, r->pool, + ngx_alloc_link_and_set_buf(r->request_body->bufs, b, r->pool, NGX_HTTP_INTERNAL_SERVER_ERROR); if (size >= r->headers_in.content_length_n) { @@ -61,11 +61,11 @@ ngx_int_t ngx_http_read_client_request_b size = clcf->client_body_buffer_size; } - ngx_test_null(r->request_body->buf, ngx_create_temp_hunk(r->pool, size), + ngx_test_null(r->request_body->buf, ngx_create_temp_buf(r->pool, size), NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_alloc_link_and_set_hunk(cl, r->request_body->buf, r->pool, - NGX_HTTP_INTERNAL_SERVER_ERROR); + ngx_alloc_link_and_set_buf(cl, r->request_body->buf, r->pool, + NGX_HTTP_INTERNAL_SERVER_ERROR); if (r->request_body->bufs) { r->request_body->bufs->next = cl; @@ -107,7 +107,7 @@ static ngx_int_t ngx_http_do_read_client { size_t size; ssize_t n; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_connection_t *c; ngx_http_core_loc_conf_t *clcf; @@ -199,21 +199,20 @@ static ngx_int_t ngx_http_do_read_client return NGX_HTTP_INTERNAL_SERVER_ERROR; } - h = ngx_calloc_hunk(r->pool); - if (h == NULL) { + if (!(b = ngx_calloc_buf(r->pool))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } - h->type = NGX_HUNK_FILE; - h->file_pos = 0; - h->file_last = r->request_body->temp_file->file.offset; - h->file = &r->request_body->temp_file->file; + b->in_file = 1; + b->file_pos = 0; + b->file_last = r->request_body->temp_file->file.offset; + b->file = &r->request_body->temp_file->file; if (r->request_body->bufs->next) { - r->request_body->bufs->next->hunk = h; + r->request_body->bufs->next->buf = b; } else { - r->request_body->bufs->hunk = h; + r->request_body->bufs->buf = b; } } diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -181,7 +181,7 @@ int ngx_http_special_response_handler(ng { ngx_int_t rc; ngx_uint_t err, i; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *out, **ll, *cl; ngx_http_err_page_t *err_page; ngx_http_core_loc_conf_t *clcf; @@ -293,25 +293,25 @@ int ngx_http_special_response_handler(ng out = NULL; ll = NULL; - if (!(h = ngx_calloc_hunk(r->pool))) { + if (!(b = ngx_calloc_buf(r->pool))) { return NGX_ERROR; } - h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; - h->pos = error_pages[err].data; - h->last = error_pages[err].data + error_pages[err].len; + b->memory = 1; + b->pos = error_pages[err].data; + b->last = error_pages[err].data + error_pages[err].len; - ngx_alloc_link_and_set_hunk(cl, h, r->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR); ngx_chain_add_link(out, ll, cl); - if (!(h = ngx_calloc_hunk(r->pool))) { + if (!(b = ngx_calloc_buf(r->pool))) { return NGX_ERROR; } - h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; - h->pos = error_tail; - h->last = error_tail + sizeof(error_tail) - 1; + b->memory = 1; + b->pos = error_tail; + b->last = error_tail + sizeof(error_tail) - 1; - ngx_alloc_link_and_set_hunk(cl, h, r->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR); ngx_chain_add_link(out, ll, cl); if (clcf->msie_padding @@ -319,18 +319,18 @@ int ngx_http_special_response_handler(ng && error >= NGX_HTTP_BAD_REQUEST && error != NGX_HTTP_REQUEST_URI_TOO_LARGE) { - if (!(h = ngx_calloc_hunk(r->pool))) { + if (!(b = ngx_calloc_buf(r->pool))) { return NGX_ERROR; } - h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; - h->pos = msie_stub; - h->last = msie_stub + sizeof(msie_stub) - 1; + b->memory = 1; + b->pos = msie_stub; + b->last = msie_stub + sizeof(msie_stub) - 1; - ngx_alloc_link_and_set_hunk(cl, h, r->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR); ngx_chain_add_link(out, ll, cl); } - h->type |= NGX_HUNK_LAST; + b->last_buf = 1; return ngx_http_output_filter(r, out); } diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -92,13 +92,13 @@ int ngx_http_write_filter(ngx_http_reque for (cl = ctx->out; cl; cl = cl->next) { ll = &cl->next; - size += ngx_hunk_size(cl->hunk); + size += ngx_buf_size(cl->buf); - if (cl->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { + if (cl->buf->flush || cl->buf->recycled) { flush = size; } - if (cl->hunk->type & NGX_HUNK_LAST) { + if (cl->buf->last_buf) { last = 1; } } @@ -106,17 +106,17 @@ int ngx_http_write_filter(ngx_http_reque /* add the new chain to the existent one */ for (ln = in; ln; ln = ln->next) { - ngx_alloc_link_and_set_hunk(cl, ln->hunk, r->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(cl, ln->buf, r->pool, NGX_ERROR); *ll = cl; ll = &cl->next; - size += ngx_hunk_size(cl->hunk); + size += ngx_buf_size(cl->buf); - if (cl->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { + if (cl->buf->flush || cl->buf->recycled) { flush = size; } - if (cl->hunk->type & NGX_HUNK_LAST) { + if (cl->buf->last_buf) { last = 1; } } diff --git a/src/os/unix/ngx_aio_read_chain.c b/src/os/unix/ngx_aio_read_chain.c --- a/src/os/unix/ngx_aio_read_chain.c +++ b/src/os/unix/ngx_aio_read_chain.c @@ -28,15 +28,15 @@ ssize_t ngx_aio_read_chain(ngx_connectio return total ? total : NGX_AGAIN; } - buf = cl->hunk->last; - prev = cl->hunk->last; + buf = cl->buf->last; + prev = cl->buf->last; size = 0; - /* coalesce the neighbouring hunks */ + /* coalesce the neighbouring bufs */ - while (cl && prev == cl->hunk->last) { - size += cl->hunk->end - cl->hunk->last; - prev = cl->hunk->end; + while (cl && prev == cl->buf->last) { + size += cl->buf->end - cl->buf->last; + prev = cl->buf->end; cl = cl->next; } diff --git a/src/os/unix/ngx_aio_write_chain.c b/src/os/unix/ngx_aio_write_chain.c --- a/src/os/unix/ngx_aio_write_chain.c +++ b/src/os/unix/ngx_aio_write_chain.c @@ -19,7 +19,7 @@ ngx_chain_t *ngx_aio_write_chain(ngx_con while (cl) { - if (cl->hunk->last - cl->hunk->pos == 0) { + if (cl->buf->last - cl->buf->pos == 0) { cl = cl->next; continue; } @@ -30,15 +30,15 @@ ngx_chain_t *ngx_aio_write_chain(ngx_con return cl; } - buf = cl->hunk->pos; + buf = cl->buf->pos; prev = buf; size = 0; - /* coalesce the neighbouring hunks */ + /* coalesce the neighbouring bufs */ - while (cl && prev == cl->hunk->pos) { - size += cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + while (cl && prev == cl->buf->pos) { + size += cl->buf->last - cl->buf->pos; + prev = cl->buf->last; cl = cl->next; } @@ -60,14 +60,14 @@ ngx_chain_t *ngx_aio_write_chain(ngx_con for (cl = in; cl; cl = cl->next) { - if (sent >= cl->hunk->last - cl->hunk->pos) { - sent -= cl->hunk->last - cl->hunk->pos; - cl->hunk->pos = cl->hunk->last; + if (sent >= cl->buf->last - cl->buf->pos) { + sent -= cl->buf->last - cl->buf->pos; + cl->buf->pos = cl->buf->last; continue; } - cl->hunk->pos += sent; + cl->buf->pos += sent; break; } diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c --- a/src/os/unix/ngx_files.c +++ b/src/os/unix/ngx_files.c @@ -128,8 +128,8 @@ ssize_t ngx_write_chain_to_file(ngx_file /* use pwrite() if there's the only hunk in a chain */ if (cl->next == NULL) { - return ngx_write_file(file, cl->hunk->pos, - (size_t) (cl->hunk->last - cl->hunk->pos), + return ngx_write_file(file, cl->buf->pos, + (size_t) (cl->buf->last - cl->buf->pos), offset); } @@ -139,20 +139,20 @@ ssize_t ngx_write_chain_to_file(ngx_file ngx_init_array(io, pool, 10, sizeof(struct iovec), NGX_ERROR); - /* create the iovec and coalesce the neighbouring hunks */ + /* create the iovec and coalesce the neighbouring bufs */ while (cl) { - if (prev == cl->hunk->pos) { - iov->iov_len += cl->hunk->last - cl->hunk->pos; + if (prev == cl->buf->pos) { + iov->iov_len += cl->buf->last - cl->buf->pos; } else { ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); - iov->iov_base = (void *) cl->hunk->pos; - iov->iov_len = cl->hunk->last - cl->hunk->pos; + iov->iov_base = (void *) cl->buf->pos; + iov->iov_len = cl->buf->last - cl->buf->pos; } - size += cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + size += cl->buf->last - cl->buf->pos; + prev = cl->buf->last; cl = cl->next; } diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c --- a/src/os/unix/ngx_freebsd_sendfile_chain.c +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c @@ -39,7 +39,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( struct iovec *iov; struct sf_hdtr hdtr; ngx_err_t err; - ngx_hunk_t *file; + ngx_buf_t *file; ngx_array_t header, trailer; ngx_event_t *wev; ngx_chain_t *cl, *tail; @@ -74,87 +74,87 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( ngx_init_array(trailer, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR); - /* create the header iovec and coalesce the neighbouring hunks */ + /* create the header iovec and coalesce the neighbouring bufs */ prev = NULL; iov = NULL; for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) { - if (ngx_hunk_special(cl->hunk)) { + if (ngx_buf_special(cl->buf)) { continue; } - if (!ngx_hunk_in_memory_only(cl->hunk)) { + if (!ngx_buf_in_memory_only(cl->buf)) { break; } - if (prev == cl->hunk->pos) { - iov->iov_len += cl->hunk->last - cl->hunk->pos; + if (prev == cl->buf->pos) { + iov->iov_len += cl->buf->last - cl->buf->pos; } else { ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR); - iov->iov_base = (void *) cl->hunk->pos; - iov->iov_len = cl->hunk->last - cl->hunk->pos; + iov->iov_base = (void *) cl->buf->pos; + iov->iov_len = cl->buf->last - cl->buf->pos; } - prev = cl->hunk->last; - hsize += cl->hunk->last - cl->hunk->pos; + prev = cl->buf->last; + hsize += cl->buf->last - cl->buf->pos; } - /* get the file hunk */ + /* get the file buf */ - if (cl && (cl->hunk->type & NGX_HUNK_FILE)) { - file = cl->hunk; + if (cl && cl->buf->in_file) { + file = cl->buf; fsize = (size_t) (file->file_last - file->file_pos); fprev = file->file_last; cl = cl->next; - /* coalesce the neighbouring file hunks */ + /* coalesce the neighbouring file bufs */ - while (cl && (cl->hunk->type & NGX_HUNK_FILE)) { - if (file->file->fd != cl->hunk->file->fd - || fprev != cl->hunk->file_pos) + while (cl && cl->buf->in_file) { + if (file->file->fd != cl->buf->file->fd + || fprev != cl->buf->file_pos) { break; } - fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos); - fprev = cl->hunk->file_last; + fsize += (size_t) (cl->buf->file_last - cl->buf->file_pos); + fprev = cl->buf->file_last; cl = cl->next; } } if (file) { - /* create the tailer iovec and coalesce the neighbouring hunks */ + /* create the tailer iovec and coalesce the neighbouring bufs */ prev = NULL; iov = NULL; for ( /* void */; cl && trailer.nelts < IOV_MAX; cl = cl->next) { - if (ngx_hunk_special(cl->hunk)) { + if (ngx_buf_special(cl->buf)) { continue; } - if (!ngx_hunk_in_memory_only(cl->hunk)) { + if (!ngx_buf_in_memory_only(cl->buf)) { break; } - if (prev == cl->hunk->pos) { - iov->iov_len += cl->hunk->last - cl->hunk->pos; + if (prev == cl->buf->pos) { + iov->iov_len += cl->buf->last - cl->buf->pos; } else { ngx_test_null(iov, ngx_push_array(&trailer), NGX_CHAIN_ERROR); - iov->iov_base = (void *) cl->hunk->pos; - iov->iov_len = cl->hunk->last - cl->hunk->pos; + iov->iov_base = (void *) cl->buf->pos; + iov->iov_len = cl->buf->last - cl->buf->pos; } - prev = cl->hunk->last; + prev = cl->buf->last; } } /* - * the tail is the rest of the chain that exceeded + * the tail is the rest of the chain that exceedes * a single sendfile() capability */ @@ -262,7 +262,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( for (cl = in; cl; cl = cl->next) { - if (ngx_hunk_special(cl->hunk)) { + if (ngx_buf_special(cl->buf)) { continue; } @@ -270,28 +270,28 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( break; } - size = ngx_hunk_size(cl->hunk); + size = ngx_buf_size(cl->buf); if (sent >= size) { sent -= size; - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos = cl->hunk->last; + if (ngx_buf_in_memory(cl->buf)) { + cl->buf->pos = cl->buf->last; } - if (cl->hunk->type & NGX_HUNK_FILE) { - cl->hunk->file_pos = cl->hunk->file_last; + if (cl->buf->in_file) { + cl->buf->file_pos = cl->buf->file_last; } continue; } - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos += sent; + if (ngx_buf_in_memory(cl->buf)) { + cl->buf->pos += sent; } - if (cl->hunk->type & NGX_HUNK_FILE) { - cl->hunk->file_pos += sent; + if (cl->buf->in_file) { + cl->buf->file_pos += sent; } break; diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c --- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -28,7 +28,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng ngx_int_t eintr; struct iovec *iov; ngx_err_t err; - ngx_hunk_t *file; + ngx_buf_t *file; ngx_array_t header; ngx_event_t *wev; ngx_chain_t *cl, *tail; @@ -55,7 +55,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng prev = NULL; iov = NULL; - /* create the iovec and coalesce the neighbouring hunks */ + /* create the iovec and coalesce the neighbouring bufs */ for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) { if (ngx_hunk_special(cl->hunk)) { @@ -131,7 +131,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng } /* - * the tail is the rest of the chain that exceeded + * the tail is the rest of the chain that exceedes * a single sendfile() capability */ diff --git a/src/os/unix/ngx_readv_chain.c b/src/os/unix/ngx_readv_chain.c --- a/src/os/unix/ngx_readv_chain.c +++ b/src/os/unix/ngx_readv_chain.c @@ -10,10 +10,10 @@ ssize_t ngx_readv_chain(ngx_connection_t { u_char *prev; ssize_t n, size; - struct iovec *iov; ngx_err_t err; ngx_array_t io; ngx_event_t *rev; + struct iovec *iov; rev = c->read; @@ -50,20 +50,20 @@ ssize_t ngx_readv_chain(ngx_connection_t ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR); - /* coalesce the neighbouring hunks */ + /* coalesce the neighbouring bufs */ while (chain) { - if (prev == chain->hunk->last) { - iov->iov_len += chain->hunk->end - chain->hunk->last; + if (prev == chain->buf->last) { + iov->iov_len += chain->buf->end - chain->buf->last; } else { ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); - iov->iov_base = (void *) chain->hunk->last; - iov->iov_len = chain->hunk->end - chain->hunk->last; + iov->iov_base = (void *) chain->buf->last; + iov->iov_len = chain->buf->end - chain->buf->last; } - size += chain->hunk->end - chain->hunk->last; - prev = chain->hunk->end; + size += chain->buf->end - chain->buf->last; + prev = chain->buf->end; chain = chain->next; } @@ -137,10 +137,10 @@ ssize_t ngx_readv_chain(ngx_connection_t { u_char *prev; ssize_t n, size; - struct iovec *iov; ngx_err_t err; ngx_array_t io; ngx_event_t *rev; + struct iovec *iov; prev = NULL; iov = NULL; @@ -148,20 +148,20 @@ ssize_t ngx_readv_chain(ngx_connection_t ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR); - /* coalesce the neighbouring hunks */ + /* coalesce the neighbouring bufs */ while (chain) { - if (prev == chain->hunk->last) { - iov->iov_len += chain->hunk->end - chain->hunk->last; + if (prev == chain->buf->last) { + iov->iov_len += chain->buf->end - chain->buf->last; } else { ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); - iov->iov_base = chain->hunk->last; - iov->iov_len = chain->hunk->end - chain->hunk->last; + iov->iov_base = chain->buf->last; + iov->iov_len = chain->buf->end - chain->buf->last; } - size += chain->hunk->end - chain->hunk->last; - prev = chain->hunk->end; + size += chain->buf->end - chain->buf->last; + prev = chain->buf->end; chain = chain->next; } diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c --- a/src/os/unix/ngx_solaris_sendfilev_chain.c +++ b/src/os/unix/ngx_solaris_sendfilev_chain.c @@ -40,7 +40,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain ngx_init_array(vec, c->pool, 10, sizeof(sendfilevec_t), NGX_CHAIN_ERROR); - /* create the sendfilevec and coalesce the neighbouring hunks */ + /* create the sendfilevec and coalesce the neighbouring bufs */ for (cl = in; cl && vec.nelts < IOV_MAX; cl = cl->next) { if (ngx_hunk_special(cl->hunk)) { @@ -83,8 +83,8 @@ ngx_chain_t *ngx_solaris_sendfilev_chain } /* - * the tail is the rest of the chain that exceeded a single - * sendfilev() capability, IOV_MAX in Solaris is only 16 + * the tail is the rest of the chain that exceedes a single + * sendfilev() capability, IOV_MAX in Solaris is limited by 16 */ tail = cl; diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c --- a/src/os/unix/ngx_writev_chain.c +++ b/src/os/unix/ngx_writev_chain.c @@ -41,19 +41,19 @@ ngx_chain_t *ngx_writev_chain(ngx_connec iov = NULL; eintr = 0; - /* create the iovec and coalesce the neighbouring hunks */ + /* create the iovec and coalesce the neighbouring bufs */ for (cl = in; cl; cl = cl->next) { - if (prev == cl->hunk->pos) { - iov->iov_len += cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + if (prev == cl->buf->pos) { + iov->iov_len += cl->buf->last - cl->buf->pos; + prev = cl->buf->last; } else { ngx_test_null(iov, ngx_push_array(&io), NGX_CHAIN_ERROR); - iov->iov_base = (void *) cl->hunk->pos; - iov->iov_len = cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + iov->iov_base = (void *) cl->buf->pos; + iov->iov_len = cl->buf->last - cl->buf->pos; + prev = cl->buf->last; } } @@ -86,20 +86,20 @@ ngx_chain_t *ngx_writev_chain(ngx_connec for (cl = in; cl && sent > 0; cl = cl->next) { - size = cl->hunk->last - cl->hunk->pos; + size = cl->buf->last - cl->buf->pos; if (sent >= size) { sent -= size; - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos = cl->hunk->last; + if (ngx_buf_in_memory(cl->buf)) { + cl->buf->pos = cl->buf->last; } continue; } - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos += sent; + if (ngx_buf_in_memory(cl->buf)) { + cl->buf->pos += sent; } break; diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c --- a/src/os/win32/ngx_files.c +++ b/src/os/win32/ngx_files.c @@ -139,15 +139,15 @@ ssize_t ngx_write_chain_to_file(ngx_file total = 0; while (cl) { - buf = cl->hunk->pos; + buf = cl->buf->pos; prev = buf; size = 0; /* coalesce the neighbouring hunks */ - while (cl && prev == cl->hunk->pos) { - size += cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + while (cl && prev == cl->buf->pos) { + size += cl->buf->last - cl->buf->pos; + prev = cl->buf->last; cl = cl->next; } diff --git a/src/os/win32/ngx_wsarecv_chain.c b/src/os/win32/ngx_wsarecv_chain.c --- a/src/os/win32/ngx_wsarecv_chain.c +++ b/src/os/win32/ngx_wsarecv_chain.c @@ -23,20 +23,20 @@ ssize_t ngx_wsarecv_chain(ngx_connection ngx_init_array(io, c->pool, 10, sizeof(WSABUF), NGX_ERROR); - /* coalesce the neighbouring hunks */ + /* coalesce the neighbouring bufs */ while (chain) { - if (prev == chain->hunk->last) { - wsabuf->len += chain->hunk->end - chain->hunk->last; + if (prev == chain->buf->last) { + wsabuf->len += chain->buf->end - chain->buf->last; } else { ngx_test_null(wsabuf, ngx_push_array(&io), NGX_ERROR); - wsabuf->buf = (char *) chain->hunk->last; - wsabuf->len = chain->hunk->end - chain->hunk->last; + wsabuf->buf = (char *) chain->buf->last; + wsabuf->len = chain->buf->end - chain->buf->last; } - size += chain->hunk->end - chain->hunk->last; - prev = chain->hunk->end; + size += chain->buf->end - chain->buf->last; + prev = chain->buf->end; chain = chain->next; } diff --git a/src/os/win32/ngx_wsasend_chain.c b/src/os/win32/ngx_wsasend_chain.c --- a/src/os/win32/ngx_wsasend_chain.c +++ b/src/os/win32/ngx_wsasend_chain.c @@ -36,15 +36,15 @@ ngx_chain_t *ngx_wsasend_chain(ngx_conne for (cl = in; cl; cl = cl->next) { - if (prev == cl->hunk->pos) { - wsabuf->len += cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + if (prev == cl->buf->pos) { + wsabuf->len += cl->buf->last - cl->buf->pos; + prev = cl->buf->last; } else { ngx_test_null(wsabuf, ngx_push_array(&wsabufs), NGX_CHAIN_ERROR); - wsabuf->buf = (char *) cl->hunk->pos; - wsabuf->len = cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + wsabuf->buf = (char *) cl->buf->pos; + wsabuf->len = cl->buf->last - cl->buf->pos; + prev = cl->buf->last; } } @@ -72,20 +72,20 @@ ngx_chain_t *ngx_wsasend_chain(ngx_conne for (cl = in; cl && sent > 0; cl = cl->next) { - size = cl->hunk->last - cl->hunk->pos; + size = cl->buf->last - cl->buf->pos; if (sent >= size) { sent -= size; - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos = cl->hunk->last; + if (ngx_buf_in_memory(cl->buf)) { + cl->buf->pos = cl->buf->last; } continue; } - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos += sent; + if (ngx_buf_in_memory(cl->buf)) { + cl->buf->pos += sent; } break; @@ -136,16 +136,16 @@ ngx_chain_t *ngx_overlapped_wsasend_chai for (cl = in; cl; cl = cl->next) { - if (prev == cl->hunk->pos) { - wsabuf->len += cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + if (prev == cl->buf->pos) { + wsabuf->len += cl->buf->last - cl->buf->pos; + prev = cl->buf->last; } else { ngx_test_null(wsabuf, ngx_push_array(&wsabufs), NGX_CHAIN_ERROR); - wsabuf->buf = (char *) cl->hunk->pos; - wsabuf->len = cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + wsabuf->buf = (char *) cl->buf->pos; + wsabuf->len = cl->buf->last - cl->buf->pos; + prev = cl->buf->last; } } @@ -213,20 +213,20 @@ ngx_chain_t *ngx_overlapped_wsasend_chai for (cl = in; cl && sent > 0; cl = cl->next) { - size = cl->hunk->last - cl->hunk->pos; + size = cl->buf->last - cl->buf->pos; if (sent >= size) { sent -= size; - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos = cl->hunk->last; + if (ngx_buf_in_memory(cl->buf)) { + cl->buf->pos = cl->buf->last; } continue; } - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos += sent; + if (ngx_buf_in_memory(cl->buf)) { + cl->buf->pos += sent; } break;