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_linux_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_linux_aio_read.c')
-rw-r--r-- | src/os/unix/ngx_linux_aio_read.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/os/unix/ngx_linux_aio_read.c b/src/os/unix/ngx_linux_aio_read.c index 8273c13f9..b0a923604 100644 --- a/src/os/unix/ngx_linux_aio_read.c +++ b/src/os/unix/ngx_linux_aio_read.c @@ -24,6 +24,28 @@ io_submit(aio_context_t ctx, long n, struct iocb **paiocb) } +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) @@ -37,22 +59,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; - 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) { |