annotate src/os/unix/ngx_file_aio_read.c @ 4500:9dfe02dd0f11

Added msleep() on reload to allow new processes to start. This is expected to ensure smoother operation on reload (and with less chance of listen queue overflows). Prodded by Igor Sysoev.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 28 Feb 2012 11:40:18 +0000
parents 30eff7580d0c
children ccad84a174e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4133
diff changeset
4 * Copyright (C) Nginx, Inc.
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_event.h>
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 /*
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 * FreeBSD file AIO features and quirks:
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 *
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 * if an asked data are already in VM cache, then aio_error() returns 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 * and the data are already copied in buffer;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 *
3065
113cd532b328 aio sendfile
Igor Sysoev <igor@sysoev.ru>
parents: 3052
diff changeset
19 * aio_read() preread in VM cache as minimum 16K (probably BKVASIZE);
113cd532b328 aio sendfile
Igor Sysoev <igor@sysoev.ru>
parents: 3052
diff changeset
20 * the first AIO preload may be up to 128K;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 *
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 * aio_read/aio_error() may return EINPROGRESS for just written data;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 *
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 * kqueue EVFILT_AIO filter is level triggered only: an event repeats
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 * until aio_return() will be called;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 *
4133
59b99f217c6d Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents: 4076
diff changeset
27 * aio_cancel() cannot cancel file AIO: it returns AIO_NOTCANCELED always.
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 */
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 extern int ngx_kqueue;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 static ssize_t ngx_file_aio_result(ngx_file_t *file, ngx_event_aio_t *aio,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 ngx_event_t *ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 static void ngx_file_aio_event_handler(ngx_event_t *ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 ssize_t
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 ngx_pool_t *pool)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 {
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
43 int n;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
44 ngx_event_t *ev;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
45 ngx_event_aio_t *aio;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
47 if (!ngx_file_aio) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 return ngx_read_file(file, buf, size, offset);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 aio = file->aio;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53 if (aio == NULL) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54 aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t));
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 if (aio == NULL) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 aio->file = file;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 aio->fd = file->fd;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 aio->event.data = aio;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 aio->event.ready = 1;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 aio->event.log = file->log;
3065
113cd532b328 aio sendfile
Igor Sysoev <igor@sysoev.ru>
parents: 3052
diff changeset
64 #if (NGX_HAVE_AIO_SENDFILE)
113cd532b328 aio sendfile
Igor Sysoev <igor@sysoev.ru>
parents: 3052
diff changeset
65 aio->last_offset = -1;
113cd532b328 aio sendfile
Igor Sysoev <igor@sysoev.ru>
parents: 3052
diff changeset
66 #endif
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67 file->aio = aio;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 ev = &aio->event;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 if (!ev->ready) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 ngx_log_error(NGX_LOG_ALERT, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 "second aio post for \"%V\"", &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 return NGX_AGAIN;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 "aio complete:%d @%O:%z %V",
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 ev->complete, offset, size, &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 if (ev->complete) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 ev->complete = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 ngx_set_errno(aio->err);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 if (aio->err == 0) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 return aio->nbytes;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89
4076
37da005a5808 Bugfix: open_file_cache lost is_directio flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3294
diff changeset
90 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
37da005a5808 Bugfix: open_file_cache lost is_directio flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3294
diff changeset
91 "aio read \"%s\" failed", file->name.data);
37da005a5808 Bugfix: open_file_cache lost is_directio flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3294
diff changeset
92
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 ngx_memzero(&aio->aiocb, sizeof(struct aiocb));
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 aio->aiocb.aio_fildes = file->fd;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 aio->aiocb.aio_offset = offset;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100 aio->aiocb.aio_buf = buf;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 aio->aiocb.aio_nbytes = size;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 #if (NGX_HAVE_KQUEUE)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105 aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 #endif
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 ev->handler = ngx_file_aio_event_handler;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109 n = aio_read(&aio->aiocb);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 if (n == -1) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 n = ngx_errno;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 if (n == NGX_EAGAIN) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 return ngx_read_file(file, buf, size, offset);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 ngx_log_error(NGX_LOG_CRIT, file->log, n,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 "aio_read(\"%V\") failed", &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 if (n == NGX_ENOSYS) {
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3065
diff changeset
122 ngx_file_aio = 0;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 return ngx_read_file(file, buf, size, offset);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 "aio_read: fd:%d %d", file->fd, n);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 ev->active = 1;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 ev->ready = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 ev->complete = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 return ngx_file_aio_result(aio->file, aio, ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 static ssize_t
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 ngx_file_aio_result(ngx_file_t *file, ngx_event_aio_t *aio, ngx_event_t *ev)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 int n;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 ngx_err_t err;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 n = aio_error(&aio->aiocb);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 "aio_error: fd:%d %d", file->fd, n);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 if (n == -1) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 err = ngx_errno;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 aio->err = err;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 ngx_log_error(NGX_LOG_ALERT, file->log, err,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 "aio_error(\"%V\") failed", &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159
4415
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
160 if (n == NGX_EINPROGRESS) {
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
161 if (ev->ready) {
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
162 ev->ready = 0;
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
163 ngx_log_error(NGX_LOG_ALERT, file->log, n,
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
164 "aio_read(\"%V\") still in progress",
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
165 &file->name);
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
4415
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
168 return NGX_AGAIN;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 n = aio_return(&aio->aiocb);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 if (n == -1) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 err = ngx_errno;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 aio->err = err;
4415
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
176 ev->ready = 1;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177
4415
30eff7580d0c Fixed AIO error handling on FreeBSD.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
178 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 "aio_return(\"%V\") failed", &file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 aio->err = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 aio->nbytes = n;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 ev->ready = 1;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 ev->active = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 "aio_return: fd:%d %d", file->fd, n);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 return n;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195 static void
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 ngx_file_aio_event_handler(ngx_event_t *ev)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 ngx_event_aio_t *aio;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 aio = ev->data;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ev->log, 0,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 "aio event handler fd:%d %V", aio->fd, &aio->file->name);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 if (ngx_file_aio_result(aio->file, aio, ev) != NGX_AGAIN) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 aio->handler(ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 }