Mercurial > hg > nginx
comparison src/os/unix/ngx_linux_aio_read.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 | d620f497c50f |
children | f01ab2dbcfdc |
comparison
equal
deleted
inserted
replaced
5979:b2920b517490 | 5980:ccad84a174e0 |
---|---|
22 { | 22 { |
23 return syscall(SYS_io_submit, ctx, n, paiocb); | 23 return syscall(SYS_io_submit, ctx, n, paiocb); |
24 } | 24 } |
25 | 25 |
26 | 26 |
27 ngx_int_t | |
28 ngx_file_aio_init(ngx_file_t *file, ngx_pool_t *pool) | |
29 { | |
30 ngx_event_aio_t *aio; | |
31 | |
32 aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t)); | |
33 if (aio == NULL) { | |
34 return NGX_ERROR; | |
35 } | |
36 | |
37 aio->file = file; | |
38 aio->fd = file->fd; | |
39 aio->event.data = aio; | |
40 aio->event.ready = 1; | |
41 aio->event.log = file->log; | |
42 | |
43 file->aio = aio; | |
44 | |
45 return NGX_OK; | |
46 } | |
47 | |
48 | |
27 ssize_t | 49 ssize_t |
28 ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, | 50 ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, |
29 ngx_pool_t *pool) | 51 ngx_pool_t *pool) |
30 { | 52 { |
31 ngx_err_t err; | 53 ngx_err_t err; |
35 | 57 |
36 if (!ngx_file_aio) { | 58 if (!ngx_file_aio) { |
37 return ngx_read_file(file, buf, size, offset); | 59 return ngx_read_file(file, buf, size, offset); |
38 } | 60 } |
39 | 61 |
40 aio = file->aio; | 62 if (file->aio == NULL && ngx_file_aio_init(file, pool) != NGX_OK) { |
41 | 63 return NGX_ERROR; |
42 if (aio == NULL) { | |
43 aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t)); | |
44 if (aio == NULL) { | |
45 return NGX_ERROR; | |
46 } | |
47 | |
48 aio->file = file; | |
49 aio->fd = file->fd; | |
50 aio->event.data = aio; | |
51 aio->event.ready = 1; | |
52 aio->event.log = file->log; | |
53 file->aio = aio; | |
54 } | 64 } |
55 | 65 |
66 aio = file->aio; | |
56 ev = &aio->event; | 67 ev = &aio->event; |
57 | 68 |
58 if (!ev->ready) { | 69 if (!ev->ready) { |
59 ngx_log_error(NGX_LOG_ALERT, file->log, 0, | 70 ngx_log_error(NGX_LOG_ALERT, file->log, 0, |
60 "second aio post for \"%V\"", &file->name); | 71 "second aio post for \"%V\"", &file->name); |