summaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ngx_buf.c154
-rw-r--r--src/core/ngx_buf.h (renamed from src/core/ngx_hunk.h)115
-rw-r--r--src/core/ngx_conf_file.c72
-rw-r--r--src/core/ngx_conf_file.h2
-rw-r--r--src/core/ngx_connection.h2
-rw-r--r--src/core/ngx_core.h2
-rw-r--r--src/core/ngx_hunk.c140
-rw-r--r--src/core/ngx_output_chain.c108
8 files changed, 330 insertions, 265 deletions
diff --git a/src/core/ngx_buf.c b/src/core/ngx_buf.c
new file mode 100644
index 000000000..90973a66d
--- /dev/null
+++ b/src/core/ngx_buf.c
@@ -0,0 +1,154 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size)
+{
+ ngx_buf_t *b;
+
+ if (!(b = ngx_calloc_buf(pool))) {
+ return NULL;
+ }
+
+ if (!(b->start = ngx_palloc(pool, size))) {
+ return NULL;
+ }
+
+ b->pos = b->start;
+ b->last = b->start;
+ b->end = b->last + size;
+ b->temporary = 1;
+
+ /*
+ b->file_pos = 0;
+ b->file_last = 0;
+
+ b->file = NULL;
+ b->shadow = NULL;
+
+ b->tag = 0;
+ */
+
+ return b;
+}
+
+
+ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs)
+{
+ u_char *p;
+ ngx_int_t i;
+ ngx_buf_t *b;
+ ngx_chain_t *chain, *cl, **ll;
+
+ if (!(p = ngx_palloc(pool, bufs->num * bufs->size))) {
+ return NULL;
+ }
+
+ ll = &chain;
+
+ for (i = 0; i < bufs->num; i++) {
+ if (!(b = ngx_calloc_buf(pool))) {
+ return NULL;
+ }
+
+ b->pos = p;
+ b->last = p;
+ b->temporary = 1;
+
+ b->start = p;
+ p += bufs->size;
+ b->end = p;
+
+ /*
+ b->file_pos = 0;
+ b->file_last = 0;
+
+ b->file = NULL;
+ b->shadow = NULL;
+ b->tag = 0;
+ */
+
+ if (!(cl = ngx_alloc_chain_link(pool))) {
+ return NULL;
+ }
+
+ cl->buf = b;
+ *ll = cl;
+ ll = &cl->next;
+ }
+
+ *ll = NULL;
+
+ return chain;
+}
+
+
+int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in)
+{
+ ngx_chain_t *cl, **ll;
+
+ ll = chain;
+
+ for (cl = *chain; cl; cl = cl->next) {
+ ll = &cl->next;
+ }
+
+ while (in) {
+ ngx_test_null(cl, ngx_alloc_chain_link(pool), NGX_ERROR);
+
+ cl->buf = in->buf;
+ *ll = cl;
+ ll = &cl->next;
+ in = in->next;
+ }
+
+ *ll = NULL;
+
+ return NGX_OK;
+}
+
+
+void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
+ ngx_chain_t **out, ngx_buf_tag_t tag)
+{
+ ngx_chain_t *tl;
+
+ if (*busy == NULL) {
+ *busy = *out;
+
+ } else {
+ for (tl = *busy; /* void */ ; tl = tl->next) {
+ if (tl->next == NULL) {
+ tl->next = *out;
+ break;
+ }
+ }
+ }
+
+ *out = NULL;
+
+ while (*busy) {
+ if (ngx_buf_size((*busy)->buf) != 0) {
+ break;
+ }
+
+#if (HAVE_WRITE_ZEROCOPY)
+ if ((*busy)->buf->zerocopy_busy) {
+ break;
+ }
+#endif
+
+ if ((*busy)->buf->tag != tag) {
+ *busy = (*busy)->next;
+ continue;
+ }
+
+ (*busy)->buf->pos = (*busy)->buf->last = (*busy)->buf->start;
+
+ tl = *busy;
+ *busy = (*busy)->next;
+ tl->next = *free;
+ *free = tl;
+ }
+}
diff --git a/src/core/ngx_hunk.h b/src/core/ngx_buf.h
index afeca1e93..f2489f1a6 100644
--- 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 <ngx_config.h>
#include <ngx_core.h>
-/* 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_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_special(b) \
+ (b->type == (b->type & (NGX_HUNK_FLUSH|NGX_HUNK_LAST)))
+
+
+#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_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);
-ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, size_t size);
-#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_chain_t *in);
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
index 1a29eb06c..e415becfb 100644
--- 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_str_t *filename)
int m, rc, found, valid;
char *rv;
void *conf, **confp;
- ngx_str_t *name;
ngx_fd_t fd;
+ ngx_str_t *name;
ngx_conf_file_t *prev;
ngx_command_t *cmd;
@@ -73,18 +73,18 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
}
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_str_t *filename)
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_t *cf)
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_t *cf)
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 '%c'" _
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 '%c'" _
}
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_cycle_t *cycle, ngx_str_t *name)
}
}
- 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 *cf, ngx_command_t *cmd, void *conf)
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
index ff01e8871..4b9fd90d9 100644
--- 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
index 835f5e1cb..af85e7d81 100644
--- 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
index ed105e592..ccb357bfe 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -26,7 +26,7 @@ typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_parse.h>
#include <ngx_log.h>
#include <ngx_alloc.h>
-#include <ngx_hunk.h>
+#include <ngx_buf.h>
#include <ngx_array.h>
#include <ngx_table.h>
#include <ngx_types.h>
diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c
deleted file mode 100644
index b448b3963..000000000
--- a/src/core/ngx_hunk.c
+++ /dev/null
@@ -1,140 +0,0 @@
-
-#include <ngx_config.h>
-#include <ngx_core.h>
-
-
-ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, size_t size)
-{
- ngx_hunk_t *h;
-
- ngx_test_null(h, ngx_alloc_hunk(pool), NULL);
-
- ngx_test_null(h->start, ngx_palloc(pool, size), NULL);
-
- h->pos = h->start;
- h->last = h->start;
-
- h->file_pos = 0;
- h->file_last = 0;
-
- h->end = h->last + size;
-
- h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
- h->file = NULL;
- h->shadow = NULL;
-
- h->tag = 0;
-
- return h;
-}
-
-
-ngx_chain_t *ngx_create_chain_of_hunks(ngx_pool_t *pool, ngx_bufs_t *bufs)
-{
- ngx_int_t i;
- u_char *p;
- ngx_hunk_t *h;
- ngx_chain_t *chain, *cl, **ll;
-
- ngx_test_null(p, ngx_palloc(pool, bufs->num * bufs->size), NULL);
-
- ll = &chain;
-
- for (i = 0; i < bufs->num; i++) {
- ngx_test_null(h, ngx_alloc_hunk(pool), NULL);
-
- h->pos = p;
- h->last = p;
- h->file_pos = 0;
- h->file_last = 0;
-
- h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP;
-
- h->start = p;
- p += bufs->size;
- h->end = p;
-
- h->file = NULL;
- h->shadow = NULL;
- h->tag = 0;
-
- ngx_test_null(cl, ngx_alloc_chain_link(pool), NULL);
- cl->hunk = h;
- *ll = cl;
- ll = &cl->next;
- }
-
- *ll = NULL;
-
- return chain;
-}
-
-
-int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in)
-{
- ngx_chain_t *cl, **ll;
-
- ll = chain;
-
- for (cl = *chain; cl; cl = cl->next) {
- ll = &cl->next;
- }
-
- while (in) {
- ngx_test_null(cl, ngx_alloc_chain_link(pool), NGX_ERROR);
-
- cl->hunk = in->hunk;
- *ll = cl;
- ll = &cl->next;
- in = in->next;
- }
-
- *ll = NULL;
-
- return NGX_OK;
-}
-
-
-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 *tl;
-
- if (*busy == NULL) {
- *busy = *out;
-
- } else {
- for (tl = *busy; /* void */ ; tl = tl->next) {
- if (tl->next == NULL) {
- tl->next = *out;
- break;
- }
- }
- }
-
- *out = NULL;
-
- while (*busy) {
- if (ngx_hunk_size((*busy)->hunk) != 0) {
- break;
- }
-
-#if (HAVE_WRITE_ZEROCOPY)
- if ((*busy)->hunk->type & NGX_HUNK_ZEROCOPY_BUSY) {
- break;
- }
-#endif
-
- if ((*busy)->hunk->tag != tag) {
- *busy = (*busy)->next;
- continue;
- }
-
- (*busy)->hunk->pos = (*busy)->hunk->last = (*busy)->hunk->start;
-
- tl = *busy;
- *busy = (*busy)->next;
- tl->next = *free;
- *free = tl;
- }
-}
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index b54cbafa8..0afa697f7 100644
--- 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_ctx_t *ctx, ngx_chain_t *in)
}
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_ctx_t *ctx, ngx_chain_t *in)
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_ctx_t *ctx, ngx_chain_t *in)
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_ctx_t *ctx, ngx_chain_t *in)
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_ctx_t *ctx, ngx_chain_t *in)
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_ctx_t *ctx, ngx_chain_t *in)
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_need_to_copy(ngx_output_chain_ctx_t *ctx,
}
-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(ngx_hunk_t *dst, ngx_hunk_t *src,
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(ngx_hunk_t *dst, ngx_hunk_t *src,
}
-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_chain_t *in)
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;
}