Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_linux_sendfile_chain.c @ 5970:74edc0ccf27a
Core: fixed a race resulting in extra sem_post()'s.
The mtx->wait counter was not decremented if we were able to obtain the lock
right after incrementing it. This resulted in unneeded sem_post() calls,
eventually leading to EOVERFLOW errors being logged, "sem_post() failed
while wake shmtx (75: Value too large for defined data type)".
To close the race, mtx->wait is now decremented if we obtain the lock right
after incrementing it in ngx_shmtx_lock(). The result can become -1 if a
concurrent ngx_shmtx_unlock() decrements mtx->wait before the added code does.
However, that only leads to one extra iteration in the next call of
ngx_shmtx_lock().
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 04 Feb 2015 16:22:43 +0300 |
parents | c50b5ed3cd4b |
children | c901f2764c27 |
rev | line source |
---|---|
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
262
diff
changeset
|
1 |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
262
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. |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
262
diff
changeset
|
5 */ |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
262
diff
changeset
|
6 |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
10 #include <ngx_event.h> |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
13 /* |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
14 * On Linux up to 2.4.21 sendfile() (syscall #187) works with 32-bit |
479 | 15 * offsets only, and the including <sys/sendfile.h> breaks the compiling, |
16 * if off_t is 64 bit wide. So we use own sendfile() definition, where offset | |
17 * parameter is int32_t, and use sendfile() for the file parts below 2G only, | |
18 * see src/os/unix/ngx_linux_config.h | |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
19 * |
687
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
20 * Linux 2.4.21 has the new sendfile64() syscall #239. |
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
21 * |
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
22 * On Linux up to 2.6.16 sendfile() does not allow to pass the count parameter |
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
23 * more than 2G-1 bytes even on 64-bit platforms: it returns EINVAL, |
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
24 * so we limit it to 2G-1 bytes. |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
25 */ |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
26 |
5322
bdb3588681c9
Unbreak building on Linux without sendfile64() support.
Valentin Bartenev <vbart@nginx.com>
parents:
5320
diff
changeset
|
27 #define NGX_SENDFILE_MAXSIZE 2147483647L |
687
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
28 |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
29 |
585 | 30 ngx_chain_t * |
31 ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) | |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 { |
5918
c50b5ed3cd4b
Fixed type of sendfile() return value on Linux.
Valentin Bartenev <vbart@nginx.com>
parents:
5917
diff
changeset
|
33 int tcp_nodelay; |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
34 off_t send, prev_send, sent; |
589 | 35 size_t file_size; |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
36 ssize_t n; |
589 | 37 ngx_err_t err; |
38 ngx_buf_t *file; | |
5851
150df089fe47
Removed the "complete" variable from various send chain functions.
Valentin Bartenev <vbart@nginx.com>
parents:
5850
diff
changeset
|
39 ngx_uint_t eintr; |
589 | 40 ngx_event_t *wev; |
41 ngx_chain_t *cl; | |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
42 ngx_iovec_t header; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
43 struct iovec headers[NGX_IOVS_PREALLOCATE]; |
455 | 44 #if (NGX_HAVE_SENDFILE64) |
589 | 45 off_t offset; |
198
34995c5ec6c4
nginx-0.0.1-2003-11-27-22:01:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
46 #else |
589 | 47 int32_t offset; |
198
34995c5ec6c4
nginx-0.0.1-2003-11-27-22:01:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
48 #endif |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
49 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
50 wev = c->write; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
52 if (!wev->ready) { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
53 return in; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
54 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
55 |
473 | 56 |
687
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
57 /* the maximum limit size is 2G-1 - the page size */ |
473 | 58 |
5322
bdb3588681c9
Unbreak building on Linux without sendfile64() support.
Valentin Bartenev <vbart@nginx.com>
parents:
5320
diff
changeset
|
59 if (limit == 0 || limit > (off_t) (NGX_SENDFILE_MAXSIZE - ngx_pagesize)) { |
bdb3588681c9
Unbreak building on Linux without sendfile64() support.
Valentin Bartenev <vbart@nginx.com>
parents:
5320
diff
changeset
|
60 limit = NGX_SENDFILE_MAXSIZE - ngx_pagesize; |
473 | 61 } |
62 | |
63 | |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
64 send = 0; |
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
65 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
66 header.iovs = headers; |
5854
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5851
diff
changeset
|
67 header.nalloc = NGX_IOVS_PREALLOCATE; |
428
5e73d0ea4dab
nginx-0.0.11-2004-09-16-20:10:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
68 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
69 for ( ;; ) { |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
70 eintr = 0; |
473 | 71 prev_send = send; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 |
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:
290
diff
changeset
|
73 /* create the iovec and coalesce the neighbouring bufs */ |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
74 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
75 cl = ngx_output_chain_to_iovec(&header, in, limit - send, c->log); |
479 | 76 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
77 if (cl == NGX_CHAIN_ERROR) { |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
78 return NGX_CHAIN_ERROR; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
79 } |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
81 send += header.size; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
83 /* set TCP_CORK if there is a header before a file */ |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
85 if (c->tcp_nopush == NGX_TCP_NOPUSH_UNSET |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
86 && header.count != 0 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
87 && cl |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
88 && cl->buf->in_file) |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
89 { |
473 | 90 /* the TCP_CORK and TCP_NODELAY are mutually exclusive */ |
91 | |
483 | 92 if (c->tcp_nodelay == NGX_TCP_NODELAY_SET) { |
473 | 93 |
94 tcp_nodelay = 0; | |
95 | |
96 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, | |
97 (const void *) &tcp_nodelay, sizeof(int)) == -1) | |
98 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5322
diff
changeset
|
99 err = ngx_socket_errno; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 |
473 | 101 /* |
479 | 102 * there is a tiny chance to be interrupted, however, |
473 | 103 * we continue a processing with the TCP_NODELAY |
104 * and without the TCP_CORK | |
105 */ | |
106 | |
577 | 107 if (err != NGX_EINTR) { |
473 | 108 wev->error = 1; |
483 | 109 ngx_connection_error(c, err, |
473 | 110 "setsockopt(TCP_NODELAY) failed"); |
111 return NGX_CHAIN_ERROR; | |
112 } | |
113 | |
114 } else { | |
483 | 115 c->tcp_nodelay = NGX_TCP_NODELAY_UNSET; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 |
5222
23a186e8ca45
Style: remove unnecessary references to HTTP from non-HTTP modules.
Piotr Sikora <piotr@cloudflare.com>
parents:
4596
diff
changeset
|
117 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
473 | 118 "no tcp_nodelay"); |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
119 } |
473 | 120 } |
121 | |
483 | 122 if (c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
473 | 123 |
124 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5322
diff
changeset
|
125 err = ngx_socket_errno; |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
126 |
473 | 127 /* |
479 | 128 * there is a tiny chance to be interrupted, however, |
473 | 129 * we continue a processing without the TCP_CORK |
130 */ | |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
131 |
577 | 132 if (err != NGX_EINTR) { |
473 | 133 wev->error = 1; |
134 ngx_connection_error(c, err, | |
135 ngx_tcp_nopush_n " failed"); | |
136 return NGX_CHAIN_ERROR; | |
137 } | |
138 | |
139 } else { | |
140 c->tcp_nopush = NGX_TCP_NOPUSH_SET; | |
577 | 141 |
473 | 142 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
143 "tcp_nopush"); | |
144 } | |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
148 /* get the file buf */ |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
150 if (header.count == 0 && cl && cl->buf->in_file && send < limit) { |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
151 file = cl->buf; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
153 /* coalesce the neighbouring file bufs */ |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
155 file_size = (size_t) ngx_chain_coalesce_file(&cl, limit - send); |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
156 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
157 send += file_size; |
589 | 158 #if 1 |
159 if (file_size == 0) { | |
160 ngx_debug_point(); | |
161 return NGX_CHAIN_ERROR; | |
162 } | |
163 #endif | |
455 | 164 #if (NGX_HAVE_SENDFILE64) |
196
11fbd0fc041d
nginx-0.0.1-2003-11-26-18:42:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
165 offset = file->file_pos; |
198
34995c5ec6c4
nginx-0.0.1-2003-11-27-22:01:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
166 #else |
34995c5ec6c4
nginx-0.0.1-2003-11-27-22:01:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
167 offset = (int32_t) file->file_pos; |
34995c5ec6c4
nginx-0.0.1-2003-11-27-22:01:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
168 #endif |
1198 | 169 |
170 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | |
171 "sendfile: @%O %uz", file->file_pos, file_size); | |
172 | |
5918
c50b5ed3cd4b
Fixed type of sendfile() return value on Linux.
Valentin Bartenev <vbart@nginx.com>
parents:
5917
diff
changeset
|
173 n = sendfile(c->fd, file->file->fd, &offset, file_size); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
174 |
5918
c50b5ed3cd4b
Fixed type of sendfile() return value on Linux.
Valentin Bartenev <vbart@nginx.com>
parents:
5917
diff
changeset
|
175 if (n == -1) { |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
176 err = ngx_errno; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
177 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
178 switch (err) { |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
179 case NGX_EAGAIN: |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
180 break; |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
181 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
182 case NGX_EINTR: |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
183 eintr = 1; |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
184 break; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
185 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
186 default: |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
187 wev->error = 1; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
188 ngx_connection_error(c, err, "sendfile() failed"); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
189 return NGX_CHAIN_ERROR; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
190 } |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
191 |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
192 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
193 "sendfile() is not ready"); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
194 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
195 |
5918
c50b5ed3cd4b
Fixed type of sendfile() return value on Linux.
Valentin Bartenev <vbart@nginx.com>
parents:
5917
diff
changeset
|
196 sent = n > 0 ? n : 0; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
198 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, |
5918
c50b5ed3cd4b
Fixed type of sendfile() return value on Linux.
Valentin Bartenev <vbart@nginx.com>
parents:
5917
diff
changeset
|
199 "sendfile: %z, @%O %O:%uz", |
c50b5ed3cd4b
Fixed type of sendfile() return value on Linux.
Valentin Bartenev <vbart@nginx.com>
parents:
5917
diff
changeset
|
200 n, file->file_pos, sent, file_size); |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
201 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
202 } else { |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
203 n = ngx_writev(c, &header); |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
204 |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
205 if (n == NGX_ERROR) { |
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
206 return NGX_CHAIN_ERROR; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
207 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
209 sent = (n == NGX_AGAIN) ? 0 : n; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
210 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
212 c->sent += sent; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
213 |
5912
de68ed551bfb
Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().
Valentin Bartenev <vbart@nginx.com>
parents:
5868
diff
changeset
|
214 in = ngx_chain_update_sent(in, sent); |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
215 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
216 if (eintr) { |
5868
6bbad2e73245
Fixed counting of sent bytes in the send chain functions on EINTR.
Valentin Bartenev <vbart@nginx.com>
parents:
5854
diff
changeset
|
217 send = prev_send; |
577 | 218 continue; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
219 } |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
220 |
5851
150df089fe47
Removed the "complete" variable from various send chain functions.
Valentin Bartenev <vbart@nginx.com>
parents:
5850
diff
changeset
|
221 if (send - prev_send != sent) { |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
222 wev->ready = 0; |
5320
ad137a80919f
Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().
Gleb Smirnoff <glebius@nginx.com>
parents:
5222
diff
changeset
|
223 return in; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
224 } |
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
225 |
5320
ad137a80919f
Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().
Gleb Smirnoff <glebius@nginx.com>
parents:
5222
diff
changeset
|
226 if (send >= limit || in == NULL) { |
ad137a80919f
Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().
Gleb Smirnoff <glebius@nginx.com>
parents:
5222
diff
changeset
|
227 return in; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
228 } |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
229 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 } |