Mercurial > hg > nginx
comparison src/os/unix/ngx_file_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 | 30eff7580d0c |
children | f01ab2dbcfdc |
comparison
equal
deleted
inserted
replaced
5979:b2920b517490 | 5980:ccad84a174e0 |
---|---|
34 static ssize_t ngx_file_aio_result(ngx_file_t *file, ngx_event_aio_t *aio, | 34 static ssize_t ngx_file_aio_result(ngx_file_t *file, ngx_event_aio_t *aio, |
35 ngx_event_t *ev); | 35 ngx_event_t *ev); |
36 static void ngx_file_aio_event_handler(ngx_event_t *ev); | 36 static void ngx_file_aio_event_handler(ngx_event_t *ev); |
37 | 37 |
38 | 38 |
39 ngx_int_t | |
40 ngx_file_aio_init(ngx_file_t *file, ngx_pool_t *pool) | |
41 { | |
42 ngx_event_aio_t *aio; | |
43 | |
44 aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t)); | |
45 if (aio == NULL) { | |
46 return NGX_ERROR; | |
47 } | |
48 | |
49 aio->file = file; | |
50 aio->fd = file->fd; | |
51 aio->event.data = aio; | |
52 aio->event.ready = 1; | |
53 aio->event.log = file->log; | |
54 | |
55 file->aio = aio; | |
56 | |
57 return NGX_OK; | |
58 } | |
59 | |
60 | |
39 ssize_t | 61 ssize_t |
40 ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, | 62 ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, |
41 ngx_pool_t *pool) | 63 ngx_pool_t *pool) |
42 { | 64 { |
43 int n; | 65 int n; |
46 | 68 |
47 if (!ngx_file_aio) { | 69 if (!ngx_file_aio) { |
48 return ngx_read_file(file, buf, size, offset); | 70 return ngx_read_file(file, buf, size, offset); |
49 } | 71 } |
50 | 72 |
73 if (file->aio == NULL && ngx_file_aio_init(file, pool) != NGX_OK) { | |
74 return NGX_ERROR; | |
75 } | |
76 | |
51 aio = file->aio; | 77 aio = file->aio; |
52 | |
53 if (aio == NULL) { | |
54 aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t)); | |
55 if (aio == NULL) { | |
56 return NGX_ERROR; | |
57 } | |
58 | |
59 aio->file = file; | |
60 aio->fd = file->fd; | |
61 aio->event.data = aio; | |
62 aio->event.ready = 1; | |
63 aio->event.log = file->log; | |
64 #if (NGX_HAVE_AIO_SENDFILE) | |
65 aio->last_offset = -1; | |
66 #endif | |
67 file->aio = aio; | |
68 } | |
69 | |
70 ev = &aio->event; | 78 ev = &aio->event; |
71 | 79 |
72 if (!ev->ready) { | 80 if (!ev->ready) { |
73 ngx_log_error(NGX_LOG_ALERT, file->log, 0, | 81 ngx_log_error(NGX_LOG_ALERT, file->log, 0, |
74 "second aio post for \"%V\"", &file->name); | 82 "second aio post for \"%V\"", &file->name); |