Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_linux_aio_read.c @ 4160:88369902edb1 stable-1.0
Merging r4010, r4065:
SSL related fixes:
*) Fixing proxy_set_body and proxy_pass_request_body with SSL.
Flush flag wasn't set in constructed buffer and this prevented any data
from being actually sent to upstream due to SSL buffering. Make sure
we always set flush in the last buffer we are going to sent.
See here for report:
http://nginx.org/pipermail/nginx-ru/2011-June/041552.html
*) Proper SSL shutdown handling.
If connection has unsent alerts, SSL_shutdown() tries to send them even
if SSL_set_shutdown(SSL_RECEIVED_SHUTDOWN|SSL_SENT_SHUTDOWN) was used.
This can be prevented by SSL_set_quiet_shutdown(). SSL_set_shutdown()
is required nevertheless to preserve session.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 30 Sep 2011 13:42:59 +0000 |
parents | cd04f652478c |
children | 37da005a5808 |
rev | line source |
---|---|
3052 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_event.h> | |
10 | |
11 | |
12 extern int ngx_eventfd; | |
13 extern aio_context_t ngx_aio_ctx; | |
14 | |
15 | |
16 static void ngx_file_aio_event_handler(ngx_event_t *ev); | |
17 | |
18 | |
19 static long | |
20 io_submit(aio_context_t ctx, long n, struct iocb **paiocb) | |
21 { | |
22 return syscall(SYS_io_submit, ctx, n, paiocb); | |
23 } | |
24 | |
25 | |
26 ssize_t | |
27 ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, | |
28 ngx_pool_t *pool) | |
29 { | |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
30 long n; |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
31 struct iocb *piocb[1]; |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
32 ngx_event_t *ev; |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
33 ngx_event_aio_t *aio; |
3052 | 34 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
35 if (!ngx_file_aio) { |
3052 | 36 return ngx_read_file(file, buf, size, offset); |
37 } | |
38 | |
39 aio = file->aio; | |
40 | |
41 if (aio == NULL) { | |
42 aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t)); | |
43 if (aio == NULL) { | |
44 return NGX_ERROR; | |
45 } | |
46 | |
47 aio->file = file; | |
48 aio->fd = file->fd; | |
49 aio->event.data = aio; | |
50 aio->event.ready = 1; | |
51 aio->event.log = file->log; | |
52 file->aio = aio; | |
53 } | |
54 | |
55 ev = &aio->event; | |
56 | |
57 if (!ev->ready) { | |
58 ngx_log_error(NGX_LOG_ALERT, file->log, 0, | |
59 "second aio post for \"%V\"", &file->name); | |
60 return NGX_AGAIN; | |
61 } | |
62 | |
63 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, | |
64 "aio complete:%d @%O:%z %V", | |
65 ev->complete, offset, size, &file->name); | |
66 | |
67 if (ev->complete) { | |
68 ev->active = 0; | |
69 ev->complete = 0; | |
70 | |
71 if (aio->res >= 0) { | |
72 ngx_set_errno(0); | |
73 return aio->res; | |
74 } | |
75 | |
76 ngx_set_errno(-aio->res); | |
77 return NGX_ERROR; | |
78 } | |
79 | |
80 ngx_memzero(&aio->aiocb, sizeof(struct iocb)); | |
81 | |
82 aio->aiocb.aio_data = (uint64_t) (uintptr_t) ev; | |
83 aio->aiocb.aio_lio_opcode = IOCB_CMD_PREAD; | |
84 aio->aiocb.aio_fildes = file->fd; | |
85 aio->aiocb.aio_buf = (uint64_t) (uintptr_t) buf; | |
86 aio->aiocb.aio_nbytes = size; | |
87 aio->aiocb.aio_offset = offset; | |
88 aio->aiocb.aio_flags = IOCB_FLAG_RESFD; | |
89 aio->aiocb.aio_resfd = ngx_eventfd; | |
90 | |
91 ev->handler = ngx_file_aio_event_handler; | |
92 | |
93 piocb[0] = &aio->aiocb; | |
94 | |
95 n = io_submit(ngx_aio_ctx, 1, piocb); | |
96 | |
97 if (n == 1) { | |
3777
cd04f652478c
update event flags after successful io_submit()
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
98 ev->active = 1; |
cd04f652478c
update event flags after successful io_submit()
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
99 ev->ready = 0; |
cd04f652478c
update event flags after successful io_submit()
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
100 ev->complete = 0; |
cd04f652478c
update event flags after successful io_submit()
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
101 |
3052 | 102 return NGX_AGAIN; |
103 } | |
104 | |
105 n = -n; | |
106 | |
107 if (n == NGX_EAGAIN) { | |
108 return ngx_read_file(file, buf, size, offset); | |
109 } | |
110 | |
111 ngx_log_error(NGX_LOG_CRIT, file->log, n, | |
112 "io_submit(\"%V\") failed", &file->name); | |
113 | |
114 if (n == NGX_ENOSYS) { | |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3052
diff
changeset
|
115 ngx_file_aio = 0; |
3052 | 116 return ngx_read_file(file, buf, size, offset); |
117 } | |
118 | |
119 return NGX_ERROR; | |
120 } | |
121 | |
122 | |
123 static void | |
124 ngx_file_aio_event_handler(ngx_event_t *ev) | |
125 { | |
126 ngx_event_aio_t *aio; | |
127 | |
128 aio = ev->data; | |
129 | |
130 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ev->log, 0, | |
131 "aio event handler fd:%d %V", aio->fd, &aio->file->name); | |
132 | |
133 aio->handler(ev); | |
134 } |