Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_readv_chain.c @ 8717:e06283038ec8 quic
QUIC: clear SSL_OP_ENABLE_MIDDLEBOX_COMPAT on SSL context switch.
The SSL_OP_ENABLE_MIDDLEBOX_COMPAT option is provided by QuicTLS and enabled
by default in the newly created SSL contexts. SSL_set_quic_method() is used
to clear it, which is required for SSL handshake to work on QUIC connections.
Switching context in the ngx_http_ssl_servername() SNI callback overrides SSL
options from the new SSL context. This results in the option set again.
Fix is to explicitly clear it when switching to another SSL context.
Initially reported here (in Russian):
http://mailman.nginx.org/pipermail/nginx-ru/2021-November/063989.html
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 07 Dec 2021 15:49:51 +0300 |
parents | 7f5e3595caff |
children | 5119c8150478 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
6 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
10 #include <ngx_event.h> |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
501 | 13 ssize_t |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
14 ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit) |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
16 u_char *prev; |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
17 ssize_t n, size; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
18 ngx_err_t err; |
501 | 19 ngx_array_t vec; |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
20 ngx_event_t *rev; |
5854
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5852
diff
changeset
|
21 struct iovec *iov, iovs[NGX_IOVS_PREALLOCATE]; |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
22 |
577 | 23 rev = c->read; |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
24 |
5852
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
25 #if (NGX_HAVE_KQUEUE) |
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
26 |
455 | 27 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
28 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
29 "readv: eof:%d, avail:%d, err:%d", |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
30 rev->pending_eof, rev->available, rev->kq_errno); |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
31 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
32 if (rev->available == 0) { |
587 | 33 if (rev->pending_eof) { |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
34 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
35 rev->eof = 1; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
36 |
587 | 37 ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, |
38 "kevent() reported about an closed connection"); | |
39 | |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
40 if (rev->kq_errno) { |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
41 rev->error = 1; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
42 ngx_set_socket_errno(rev->kq_errno); |
587 | 43 return NGX_ERROR; |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
44 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
45 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
46 return 0; |
587 | 47 |
48 } else { | |
49 return NGX_AGAIN; | |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
50 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
51 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
52 } |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
5852
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
54 #endif |
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
55 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
56 #if (NGX_HAVE_EPOLLRDHUP) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
57 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
58 if (ngx_event_flags & NGX_USE_EPOLL_EVENT) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
59 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
60 "readv: eof:%d, avail:%d", |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
61 rev->pending_eof, rev->available); |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
62 |
7583
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
63 if (rev->available == 0 && !rev->pending_eof) { |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
64 return NGX_AGAIN; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
65 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
66 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
67 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
68 #endif |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
69 |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
70 prev = NULL; |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
71 iov = NULL; |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
72 size = 0; |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
73 |
501 | 74 vec.elts = iovs; |
75 vec.nelts = 0; | |
76 vec.size = sizeof(struct iovec); | |
5854
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5852
diff
changeset
|
77 vec.nalloc = NGX_IOVS_PREALLOCATE; |
501 | 78 vec.pool = c->pool; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
328
diff
changeset
|
80 /* coalesce the neighbouring bufs */ |
150
ad5f382c9e7d
nginx-0.0.1-2003-10-19-23:57:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
81 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
151
diff
changeset
|
82 while (chain) { |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
83 n = chain->buf->end - chain->buf->last; |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
84 |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
85 if (limit) { |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
86 if (size >= limit) { |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
87 break; |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
88 } |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
89 |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
90 if (size + n > limit) { |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
91 n = (ssize_t) (limit - size); |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
92 } |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
93 } |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
94 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
328
diff
changeset
|
95 if (prev == chain->buf->last) { |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
96 iov->iov_len += n; |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
97 |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
98 } else { |
8534
7f5e3595caff
Use only preallocated memory in ngx_readv_chain() (ticket #1408).
Ruslan Ermilov <ru@nginx.com>
parents:
7583
diff
changeset
|
99 if (vec.nelts == vec.nalloc) { |
4597
4be36d5e78ae
Fixed ngx_readv_chain() to honor IOV_MAX (ticket #14).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
100 break; |
4be36d5e78ae
Fixed ngx_readv_chain() to honor IOV_MAX (ticket #14).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
101 } |
4be36d5e78ae
Fixed ngx_readv_chain() to honor IOV_MAX (ticket #14).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
102 |
501 | 103 iov = ngx_array_push(&vec); |
104 if (iov == NULL) { | |
105 return NGX_ERROR; | |
106 } | |
107 | |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
328
diff
changeset
|
108 iov->iov_base = (void *) chain->buf->last; |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
109 iov->iov_len = n; |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
110 } |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
111 |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
112 size += n; |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
328
diff
changeset
|
113 prev = chain->buf->end; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
151
diff
changeset
|
114 chain = chain->next; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
117 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
6480 | 118 "readv: %ui, last:%uz", vec.nelts, iov->iov_len); |
75
869b10be682f
nginx-0.0.1-2003-04-14-21:04:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
74
diff
changeset
|
119 |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
120 do { |
501 | 121 n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 |
6506
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
123 if (n == 0) { |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
124 rev->ready = 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
125 rev->eof = 1; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
126 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
127 #if (NGX_HAVE_KQUEUE) |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
128 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
129 /* |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
130 * on FreeBSD readv() may return 0 on closed socket |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
131 * even if kqueue reported about available data |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
132 */ |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
133 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
134 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
135 rev->available = 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
136 } |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
137 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
138 #endif |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
139 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
140 return 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
141 } |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
142 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
143 if (n > 0) { |
5852
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
144 |
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
145 #if (NGX_HAVE_KQUEUE) |
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
146 |
455 | 147 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
148 rev->available -= n; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
149 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
150 /* |
587 | 151 * rev->available may be negative here because some additional |
6506
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
152 * bytes may be received between kevent() and readv() |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
153 */ |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
154 |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
155 if (rev->available <= 0) { |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
156 if (!rev->pending_eof) { |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
157 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
158 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
159 |
6508
151fd02a4317
Simplified ngx_unix_recv() and ngx_readv_chain().
Ruslan Ermilov <ru@nginx.com>
parents:
6506
diff
changeset
|
160 rev->available = 0; |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
161 } |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
163 return n; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
164 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
165 |
6506
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
166 #endif |
5852
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
167 |
7583
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
168 #if (NGX_HAVE_FIONREAD) |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
169 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
170 if (rev->available >= 0) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
171 rev->available -= n; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
172 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
173 /* |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
174 * negative rev->available means some additional bytes |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
175 * were received between kernel notification and readv(), |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
176 * and therefore ev->ready can be safely reset even for |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
177 * edge-triggered event methods |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
178 */ |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
179 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
180 if (rev->available < 0) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
181 rev->available = 0; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
182 rev->ready = 0; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
183 } |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
184 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
185 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
186 "readv: avail:%d", rev->available); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
187 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
188 } else if (n == size) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
189 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
190 if (ngx_socket_nread(c->fd, &rev->available) == -1) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
191 n = ngx_connection_error(c, ngx_socket_errno, |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
192 ngx_socket_nread_n " failed"); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
193 break; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
194 } |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
195 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
196 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
197 "readv: avail:%d", rev->available); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
198 } |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
199 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
200 #endif |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
201 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
202 #if (NGX_HAVE_EPOLLRDHUP) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
203 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
204 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
205 && ngx_use_epoll_rdhup) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
206 { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
207 if (n < size) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
208 if (!rev->pending_eof) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
209 rev->ready = 0; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
210 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
211 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
212 rev->available = 0; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
213 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
214 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
215 return n; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
216 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
217 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
218 #endif |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
219 |
5267
13c006f0c40e
Events: honor NGX_USE_GREEDY_EVENT when kqueue support is enabled.
Valentin Bartenev <vbart@nginx.com>
parents:
4597
diff
changeset
|
220 if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) { |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
221 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
222 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
223 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
224 return n; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
226 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
227 err = ngx_socket_errno; |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
228 |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
229 if (err == NGX_EAGAIN || err == NGX_EINTR) { |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
230 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
231 "readv() not ready"); |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
232 n = NGX_AGAIN; |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
233 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
234 } else { |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
235 n = ngx_connection_error(c, err, "readv() failed"); |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
236 break; |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
237 } |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
238 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
239 } while (err == NGX_EINTR); |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
240 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
241 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
242 |
3642 | 243 if (n == NGX_ERROR) { |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
244 c->read->error = 1; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 return n; |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
248 } |