diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ngx_alloc.h | 2 | ||||
-rw-r--r-- | src/core/ngx_hunk.h | 11 | ||||
-rw-r--r-- | src/core/ngx_output_chain.c | 32 |
3 files changed, 42 insertions, 3 deletions
diff --git a/src/core/ngx_alloc.h b/src/core/ngx_alloc.h index 946361182..26a8cdcdb 100644 --- a/src/core/ngx_alloc.h +++ b/src/core/ngx_alloc.h @@ -17,6 +17,8 @@ #define ngx_test_null(p, alloc, rc) if ((p = alloc) == NULL) { return rc; } +#define ngx_is_null(p, alloc) if ((p = alloc) == NULL) + typedef struct ngx_pool_large_s ngx_pool_large_t; diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h index e9bb71cf0..82c5cc6f4 100644 --- a/src/core/ngx_hunk.h +++ b/src/core/ngx_hunk.h @@ -84,7 +84,6 @@ typedef struct { unsigned sendfile; unsigned need_in_memory; unsigned need_in_temp; - unsigned copy_chain; ngx_pool_t *pool; int hunks; @@ -96,6 +95,14 @@ typedef struct { } ngx_output_chain_ctx_t; +typedef struct { + ngx_chain_t *out; + ngx_chain_t **last; + ngx_connection_t *connection; + ngx_pool_t *pool; +} ngx_chain_write_ctx_t; + + #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR @@ -144,6 +151,8 @@ ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size, int ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in); +int ngx_chain_write(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); diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c index 6ef592dca..a2eec1ae1 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -1,6 +1,7 @@ #include <ngx_config.h> #include <ngx_core.h> +#include <ngx_event.h> #define NGX_NONE 1 @@ -30,8 +31,7 @@ int ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) return ctx->output_filter(ctx->output_ctx, in); } - if (!ctx->copy_chain - && in->next == NULL + if (in->next == NULL && (!ngx_output_chain_need_to_copy(ctx, in->hunk))) { return ctx->output_filter(ctx->output_ctx, in); @@ -250,3 +250,31 @@ ngx_log_debug(src->file->log, "READ: %qd:%qd %X:%X %X:%X" _ return NGX_OK; } + + +int ngx_chain_write(void *data, ngx_chain_t *in) +{ + ngx_chain_write_ctx_t *ctx = data; + + ngx_chain_t *cl; + + + for (/* void */; in; in = in->next) { + ngx_alloc_link_and_set_hunk(cl, in->hunk, ctx->pool, NGX_ERROR); + *ctx->last = cl; + ctx->last = &cl->next; + } + + ctx->out = ngx_write_chain(ctx->connection, ctx->out); + + if (ctx->out == NGX_CHAIN_ERROR) { + return NGX_ERROR; + } + + if (ctx->out == NULL) { + ctx->last = &ctx->out; + return NGX_OK; + } + + return NGX_AGAIN; +} |