Mercurial > hg > nginx
annotate src/os/unix/ngx_readv_chain.c @ 9322:d6f75dd66761 default tip
Mp4: added and updated sanity checks for "end" handling.
When handling incorrect data in ngx_http_mp4_crop_stsc_data(),
trak->end_chunk_samples might end up being arbitrary large, leading
to reading before the buffer in ngx_http_mp4_update_stsz_atom(). Fix
is to check that trak->end_chunk_samples corresponds to a memory within
the stsz atom data. For consistency, trak->start_chunk_samples
is checked similarly.
Similarly, trak->end_chunk might end up being smaller than trak->start_chunk,
leading to reading memory after the buffer in ngx_http_mp4_update_stco_atom()
and ngx_http_mp4_update_co64_atom(). Corresponding checks are updated
to explicitly test (trak->end_chunk - trak->start_chunk) instead of just
checking trak->end_chunk and assuming it is larger than trak->start_chunk.
This is generally in line with existing checks of
(trak->end_sample - trak->start_sample) in ngx_http_mp4_update_stsz_atom(),
where trak->end_sample might also become smaller than trak->start_sample
when handling incorrect data in ngx_http_mp4_crop_stts_data().
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 25 Aug 2024 06:35:40 +0300 |
parents | f3510cb959d1 |
children |
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 { | |
8058
f3510cb959d1
Events: fixed EPOLLRDHUP with FIONREAD (ticket #2367).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8018
diff
changeset
|
49 rev->ready = 0; |
587 | 50 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
|
51 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
52 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
53 } |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 |
5852
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
55 #endif |
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
56 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
57 #if (NGX_HAVE_EPOLLRDHUP) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
58 |
8018
5119c8150478
Fixed runtime handling of systems without EPOLLRDHUP support.
Marcus Ball <marcus.ball@live.com>
parents:
7886
diff
changeset
|
59 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) |
5119c8150478
Fixed runtime handling of systems without EPOLLRDHUP support.
Marcus Ball <marcus.ball@live.com>
parents:
7886
diff
changeset
|
60 && ngx_use_epoll_rdhup) |
5119c8150478
Fixed runtime handling of systems without EPOLLRDHUP support.
Marcus Ball <marcus.ball@live.com>
parents:
7886
diff
changeset
|
61 { |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
62 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
63 "readv: eof:%d, avail:%d", |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
64 rev->pending_eof, rev->available); |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
65 |
7583
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
66 if (rev->available == 0 && !rev->pending_eof) { |
8058
f3510cb959d1
Events: fixed EPOLLRDHUP with FIONREAD (ticket #2367).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8018
diff
changeset
|
67 rev->ready = 0; |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
68 return NGX_AGAIN; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
69 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
70 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
71 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
72 #endif |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
73 |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
74 prev = NULL; |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
75 iov = NULL; |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
76 size = 0; |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
77 |
501 | 78 vec.elts = iovs; |
79 vec.nelts = 0; | |
80 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
|
81 vec.nalloc = NGX_IOVS_PREALLOCATE; |
501 | 82 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
|
83 |
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
|
84 /* 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
|
85 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
151
diff
changeset
|
86 while (chain) { |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
87 n = chain->buf->end - chain->buf->last; |
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 if (limit) { |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
90 if (size >= limit) { |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
91 break; |
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 if (size + n > limit) { |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
95 n = (ssize_t) (limit - size); |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
96 } |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
97 } |
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
98 |
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
|
99 if (prev == chain->buf->last) { |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
100 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
|
101 |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
102 } else { |
7886
7f5e3595caff
Use only preallocated memory in ngx_readv_chain() (ticket #1408).
Ruslan Ermilov <ru@nginx.com>
parents:
7583
diff
changeset
|
103 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
|
104 break; |
4be36d5e78ae
Fixed ngx_readv_chain() to honor IOV_MAX (ticket #14).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
105 } |
4be36d5e78ae
Fixed ngx_readv_chain() to honor IOV_MAX (ticket #14).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
106 |
501 | 107 iov = ngx_array_push(&vec); |
108 if (iov == NULL) { | |
109 return NGX_ERROR; | |
110 } | |
111 | |
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
|
112 iov->iov_base = (void *) chain->buf->last; |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
113 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
|
114 } |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
115 |
5882
ec81934727a1
Core: added limit to recv_chain().
Roman Arutyunyan <arut@nginx.com>
parents:
5855
diff
changeset
|
116 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
|
117 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
|
118 chain = chain->next; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
121 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
6480 | 122 "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
|
123 |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
124 do { |
501 | 125 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
|
126 |
6506
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
127 if (n == 0) { |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
128 rev->ready = 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
129 rev->eof = 1; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
130 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
131 #if (NGX_HAVE_KQUEUE) |
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 * 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
|
135 * 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
|
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 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
|
139 rev->available = 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
140 } |
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 #endif |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
143 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
144 return 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
145 } |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
146 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
147 if (n > 0) { |
5852
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
148 |
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
149 #if (NGX_HAVE_KQUEUE) |
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
150 |
455 | 151 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
|
152 rev->available -= n; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
153 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
154 /* |
587 | 155 * 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
|
156 * 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
|
157 */ |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
158 |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
159 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
|
160 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
|
161 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
162 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
163 |
6508
151fd02a4317
Simplified ngx_unix_recv() and ngx_readv_chain().
Ruslan Ermilov <ru@nginx.com>
parents:
6506
diff
changeset
|
164 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
|
165 } |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
167 return n; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
168 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
169 |
6506
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
170 #endif |
5852
43512a33e8f2
Merged implementations of ngx_readv_chain().
Valentin Bartenev <vbart@nginx.com>
parents:
5776
diff
changeset
|
171 |
7583
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
172 #if (NGX_HAVE_FIONREAD) |
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 if (rev->available >= 0) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
175 rev->available -= n; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
176 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
177 /* |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
178 * negative rev->available means some additional bytes |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
179 * were received between kernel notification and readv(), |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
180 * 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
|
181 * edge-triggered event methods |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
182 */ |
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 if (rev->available < 0) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
185 rev->available = 0; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
186 rev->ready = 0; |
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 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
189 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
|
190 "readv: avail:%d", rev->available); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
191 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
192 } else if (n == size) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
193 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
194 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
|
195 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
|
196 ngx_socket_nread_n " failed"); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
197 break; |
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 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
|
201 "readv: avail:%d", rev->available); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
202 } |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
203 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
204 #endif |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
205 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
206 #if (NGX_HAVE_EPOLLRDHUP) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
207 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
208 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
209 && ngx_use_epoll_rdhup) |
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 if (n < size) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
212 if (!rev->pending_eof) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
213 rev->ready = 0; |
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 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
216 rev->available = 0; |
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 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
219 return n; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
220 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
221 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
222 #endif |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
223 |
5267
13c006f0c40e
Events: honor NGX_USE_GREEDY_EVENT when kqueue support is enabled.
Valentin Bartenev <vbart@nginx.com>
parents:
4597
diff
changeset
|
224 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
|
225 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
226 } |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
227 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
228 return n; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
229 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
231 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
|
232 |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
233 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
|
234 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
|
235 "readv() not ready"); |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
236 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
|
237 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
238 } else { |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
239 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
|
240 break; |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
241 } |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
242 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
243 } 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
|
244 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
245 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
246 |
3642 | 247 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
|
248 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
|
249 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
250 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
251 return n; |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
252 } |