diff options
author | Valentin Bartenev <vbart@nginx.com> | 2015-02-11 17:52:15 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2015-02-11 17:52:15 +0300 |
commit | 2b8d6ad805a0132844cfbc1cf1c6988dfe8c9973 (patch) | |
tree | 0cfe79e6cd5bd968c04ec176383c1fd0efc86757 /src/os/unix/ngx_file_aio_read.c | |
parent | 2b7e167dbb59a6d1152c644080e21782b8b675e3 (diff) | |
download | nginx-2b8d6ad805a0132844cfbc1cf1c6988dfe8c9973.tar.gz nginx-2b8d6ad805a0132844cfbc1cf1c6988dfe8c9973.zip |
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.
Diffstat (limited to 'src/os/unix/ngx_file_aio_read.c')
-rw-r--r-- | src/os/unix/ngx_file_aio_read.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c index 0bb383de5..b11cf8a3d 100644 --- a/src/os/unix/ngx_file_aio_read.c +++ b/src/os/unix/ngx_file_aio_read.c @@ -36,6 +36,28 @@ static ssize_t ngx_file_aio_result(ngx_file_t *file, ngx_event_aio_t *aio, static void ngx_file_aio_event_handler(ngx_event_t *ev); +ngx_int_t +ngx_file_aio_init(ngx_file_t *file, ngx_pool_t *pool) +{ + ngx_event_aio_t *aio; + + aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t)); + if (aio == NULL) { + return NGX_ERROR; + } + + aio->file = file; + aio->fd = file->fd; + aio->event.data = aio; + aio->event.ready = 1; + aio->event.log = file->log; + + file->aio = aio; + + return NGX_OK; +} + + ssize_t ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, ngx_pool_t *pool) @@ -48,25 +70,11 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, return ngx_read_file(file, buf, size, offset); } - aio = file->aio; - - if (aio == NULL) { - aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t)); - if (aio == NULL) { - return NGX_ERROR; - } - - aio->file = file; - aio->fd = file->fd; - aio->event.data = aio; - aio->event.ready = 1; - aio->event.log = file->log; -#if (NGX_HAVE_AIO_SENDFILE) - aio->last_offset = -1; -#endif - file->aio = aio; + if (file->aio == NULL && ngx_file_aio_init(file, pool) != NGX_OK) { + return NGX_ERROR; } + aio = file->aio; ev = &aio->event; if (!ev->ready) { |