Mercurial > hg > nginx-quic
comparison src/core/ngx_output_chain.c @ 5980:ccad84a174e0
Refactored sendfile() AIO preload.
This reduces layering violation and simplifies the logic of AIO preread, since
it's now triggered by the send chain function itself without falling back to
the copy filter. The context of AIO operation is now stored per file buffer,
which makes it possible to properly handle cases when multiple buffers come
from different locations, each with its own configuration.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 11 Feb 2015 17:52:15 +0300 |
parents | bcdfc39bf44d |
children | 1fdba317ee6d |
comparison
equal
deleted
inserted
replaced
5979:b2920b517490 | 5980:ccad84a174e0 |
---|---|
27 #define NGX_NONE 1 | 27 #define NGX_NONE 1 |
28 | 28 |
29 | 29 |
30 static ngx_inline ngx_int_t | 30 static ngx_inline ngx_int_t |
31 ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf); | 31 ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf); |
32 #if (NGX_HAVE_AIO_SENDFILE) | |
33 static ngx_int_t ngx_output_chain_aio_setup(ngx_output_chain_ctx_t *ctx, | |
34 ngx_file_t *file); | |
35 #endif | |
32 static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool, | 36 static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool, |
33 ngx_chain_t **chain, ngx_chain_t *in); | 37 ngx_chain_t **chain, ngx_chain_t *in); |
34 static ngx_int_t ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx, | 38 static ngx_int_t ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx, |
35 off_t bsize); | 39 off_t bsize); |
36 static ngx_int_t ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx, | 40 static ngx_int_t ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx, |
250 } | 254 } |
251 | 255 |
252 buf->in_file = 0; | 256 buf->in_file = 0; |
253 } | 257 } |
254 | 258 |
259 #if (NGX_HAVE_AIO_SENDFILE) | |
260 if (ctx->aio_preload && buf->in_file) { | |
261 (void) ngx_output_chain_aio_setup(ctx, buf->file); | |
262 } | |
263 #endif | |
264 | |
255 if (ctx->need_in_memory && !ngx_buf_in_memory(buf)) { | 265 if (ctx->need_in_memory && !ngx_buf_in_memory(buf)) { |
256 return 0; | 266 return 0; |
257 } | 267 } |
258 | 268 |
259 if (ctx->need_in_temp && (buf->memory || buf->mmap)) { | 269 if (ctx->need_in_temp && (buf->memory || buf->mmap)) { |
260 return 0; | 270 return 0; |
261 } | 271 } |
262 | 272 |
263 return 1; | 273 return 1; |
264 } | 274 } |
275 | |
276 | |
277 #if (NGX_HAVE_AIO_SENDFILE) | |
278 | |
279 static ngx_int_t | |
280 ngx_output_chain_aio_setup(ngx_output_chain_ctx_t *ctx, ngx_file_t *file) | |
281 { | |
282 ngx_event_aio_t *aio; | |
283 | |
284 if (file->aio == NULL && ngx_file_aio_init(file, ctx->pool) != NGX_OK) { | |
285 return NGX_ERROR; | |
286 } | |
287 | |
288 aio = file->aio; | |
289 | |
290 aio->data = ctx->filter_ctx; | |
291 aio->preload_handler = ctx->aio_preload; | |
292 | |
293 return NGX_OK; | |
294 } | |
295 | |
296 #endif | |
265 | 297 |
266 | 298 |
267 static ngx_int_t | 299 static ngx_int_t |
268 ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, | 300 ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, |
269 ngx_chain_t *in) | 301 ngx_chain_t *in) |