Mercurial > hg > nginx
annotate src/os/unix/ngx_linux_sendfile_chain.c @ 6470:62d950bc0f15
Updated OpenSSL used for win32 builds.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 29 Mar 2016 09:54:11 +0300 |
parents | 248aa2757332 |
children | f01ab2dbcfdc |
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 |
5997
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
13 static ssize_t ngx_linux_sendfile(ngx_connection_t *c, ngx_buf_t *file, |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
14 size_t size); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
15 |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
16 #if (NGX_THREADS) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
17 #include <ngx_thread_pool.h> |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
18 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
19 #if !(NGX_HAVE_SENDFILE64) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
20 #error sendfile64() is required! |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
21 #endif |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
22 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
23 static ngx_int_t ngx_linux_sendfile_thread(ngx_connection_t *c, ngx_buf_t *file, |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
24 size_t size, size_t *sent); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
25 static void ngx_linux_sendfile_thread_handler(void *data, ngx_log_t *log); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
26 #endif |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
27 |
5997
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
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 /* |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
30 * On Linux up to 2.4.21 sendfile() (syscall #187) works with 32-bit |
479 | 31 * offsets only, and the including <sys/sendfile.h> breaks the compiling, |
32 * if off_t is 64 bit wide. So we use own sendfile() definition, where offset | |
33 * parameter is int32_t, and use sendfile() for the file parts below 2G only, | |
34 * 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
|
35 * |
687
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
36 * 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
|
37 * |
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
38 * 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
|
39 * 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
|
40 * 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
|
41 */ |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
42 |
5322
bdb3588681c9
Unbreak building on Linux without sendfile64() support.
Valentin Bartenev <vbart@nginx.com>
parents:
5320
diff
changeset
|
43 #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
|
44 |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
198
diff
changeset
|
45 |
585 | 46 ngx_chain_t * |
47 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
|
48 { |
5918
c50b5ed3cd4b
Fixed type of sendfile() return value on Linux.
Valentin Bartenev <vbart@nginx.com>
parents:
5917
diff
changeset
|
49 int tcp_nodelay; |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
50 off_t send, prev_send; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
51 size_t file_size, sent; |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
52 ssize_t n; |
589 | 53 ngx_err_t err; |
54 ngx_buf_t *file; | |
55 ngx_event_t *wev; | |
56 ngx_chain_t *cl; | |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
57 ngx_iovec_t header; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
58 struct iovec headers[NGX_IOVS_PREALLOCATE]; |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
59 #if (NGX_THREADS) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
60 ngx_int_t rc; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
61 ngx_uint_t thread_handled, thread_complete; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
62 #endif |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
63 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
64 wev = c->write; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
66 if (!wev->ready) { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
67 return in; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
68 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
69 |
473 | 70 |
687
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
71 /* the maximum limit size is 2G-1 - the page size */ |
473 | 72 |
5322
bdb3588681c9
Unbreak building on Linux without sendfile64() support.
Valentin Bartenev <vbart@nginx.com>
parents:
5320
diff
changeset
|
73 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
|
74 limit = NGX_SENDFILE_MAXSIZE - ngx_pagesize; |
473 | 75 } |
76 | |
77 | |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
78 send = 0; |
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
79 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
80 header.iovs = headers; |
5854
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5851
diff
changeset
|
81 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
|
82 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
83 for ( ;; ) { |
473 | 84 prev_send = send; |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
85 #if (NGX_THREADS) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
86 thread_handled = 0; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
87 thread_complete = 0; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
88 #endif |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 |
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
|
90 /* 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
|
91 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
92 cl = ngx_output_chain_to_iovec(&header, in, limit - send, c->log); |
479 | 93 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
94 if (cl == NGX_CHAIN_ERROR) { |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
95 return NGX_CHAIN_ERROR; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
96 } |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
98 send += header.size; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
100 /* 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
|
101 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
102 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
|
103 && 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
|
104 && cl |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
105 && 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
|
106 { |
473 | 107 /* the TCP_CORK and TCP_NODELAY are mutually exclusive */ |
108 | |
483 | 109 if (c->tcp_nodelay == NGX_TCP_NODELAY_SET) { |
473 | 110 |
111 tcp_nodelay = 0; | |
112 | |
113 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, | |
114 (const void *) &tcp_nodelay, sizeof(int)) == -1) | |
115 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5322
diff
changeset
|
116 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
|
117 |
473 | 118 /* |
479 | 119 * there is a tiny chance to be interrupted, however, |
473 | 120 * we continue a processing with the TCP_NODELAY |
121 * and without the TCP_CORK | |
122 */ | |
123 | |
577 | 124 if (err != NGX_EINTR) { |
473 | 125 wev->error = 1; |
483 | 126 ngx_connection_error(c, err, |
473 | 127 "setsockopt(TCP_NODELAY) failed"); |
128 return NGX_CHAIN_ERROR; | |
129 } | |
130 | |
131 } else { | |
483 | 132 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
|
133 |
5222
23a186e8ca45
Style: remove unnecessary references to HTTP from non-HTTP modules.
Piotr Sikora <piotr@cloudflare.com>
parents:
4596
diff
changeset
|
134 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
473 | 135 "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
|
136 } |
473 | 137 } |
138 | |
483 | 139 if (c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
473 | 140 |
141 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
|
142 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
|
143 |
473 | 144 /* |
479 | 145 * there is a tiny chance to be interrupted, however, |
473 | 146 * we continue a processing without the TCP_CORK |
147 */ | |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
148 |
577 | 149 if (err != NGX_EINTR) { |
473 | 150 wev->error = 1; |
151 ngx_connection_error(c, err, | |
152 ngx_tcp_nopush_n " failed"); | |
153 return NGX_CHAIN_ERROR; | |
154 } | |
155 | |
156 } else { | |
157 c->tcp_nopush = NGX_TCP_NOPUSH_SET; | |
577 | 158 |
473 | 159 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
160 "tcp_nopush"); | |
161 } | |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
165 /* 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
|
166 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
167 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
|
168 file = cl->buf; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
170 /* 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
|
171 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
172 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
|
173 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
174 send += file_size; |
589 | 175 #if 1 |
176 if (file_size == 0) { | |
177 ngx_debug_point(); | |
178 return NGX_CHAIN_ERROR; | |
179 } | |
180 #endif | |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
181 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
182 #if (NGX_THREADS) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
183 if (file->file->thread_handler) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
184 rc = ngx_linux_sendfile_thread(c, file, file_size, &sent); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
185 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
186 switch (rc) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
187 case NGX_OK: |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
188 thread_handled = 1; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
189 break; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
190 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
191 case NGX_DONE: |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
192 thread_complete = 1; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
193 break; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
194 |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
195 case NGX_AGAIN: |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
196 break; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
197 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
198 default: /* NGX_ERROR */ |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
199 return NGX_CHAIN_ERROR; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
200 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
201 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
202 } else |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
203 #endif |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
204 { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
205 n = ngx_linux_sendfile(c, file, file_size); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
206 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
207 if (n == NGX_ERROR) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
208 return NGX_CHAIN_ERROR; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
209 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
210 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
211 sent = (n == NGX_AGAIN) ? 0 : n; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
212 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
213 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
214 } else { |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
215 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
|
216 |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
217 if (n == NGX_ERROR) { |
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
218 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
|
219 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
221 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
|
222 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
224 c->sent += sent; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
225 |
5912
de68ed551bfb
Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().
Valentin Bartenev <vbart@nginx.com>
parents:
5868
diff
changeset
|
226 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
|
227 |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
228 if ((size_t) (send - prev_send) != sent) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
229 #if (NGX_THREADS) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
230 if (thread_handled) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
231 return in; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
232 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
233 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
234 if (thread_complete) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
235 send = prev_send + sent; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
236 continue; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
237 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
238 #endif |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
239 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
|
240 return in; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
241 } |
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
242 |
5320
ad137a80919f
Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().
Gleb Smirnoff <glebius@nginx.com>
parents:
5222
diff
changeset
|
243 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
|
244 return in; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
245 } |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 } |
5997
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
248 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
249 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
250 static ssize_t |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
251 ngx_linux_sendfile(ngx_connection_t *c, ngx_buf_t *file, size_t size) |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
252 { |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
253 #if (NGX_HAVE_SENDFILE64) |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
254 off_t offset; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
255 #else |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
256 int32_t offset; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
257 #endif |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
258 ssize_t n; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
259 ngx_err_t err; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
260 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
261 #if (NGX_HAVE_SENDFILE64) |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
262 offset = file->file_pos; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
263 #else |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
264 offset = (int32_t) file->file_pos; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
265 #endif |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
266 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
267 eintr: |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
268 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
269 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
270 "sendfile: @%O %uz", file->file_pos, size); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
271 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
272 n = sendfile(c->fd, file->file->fd, &offset, size); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
273 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
274 if (n == -1) { |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
275 err = ngx_errno; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
276 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
277 switch (err) { |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
278 case NGX_EAGAIN: |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
279 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
280 "sendfile() is not ready"); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
281 return NGX_AGAIN; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
282 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
283 case NGX_EINTR: |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
284 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
285 "sendfile() was interrupted"); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
286 goto eintr; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
287 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
288 default: |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
289 c->write->error = 1; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
290 ngx_connection_error(c, err, "sendfile() failed"); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
291 return NGX_ERROR; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
292 } |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
293 } |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
294 |
6437
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
295 if (n == 0) { |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
296 /* |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
297 * if sendfile returns zero, then someone has truncated the file, |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
298 * so the offset became beyond the end of the file |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
299 */ |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
300 |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
301 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
302 "sendfile() reported that \"%s\" was truncated at %O", |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
303 file->file->name.data, file->file_pos); |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
304 |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
305 return NGX_ERROR; |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
306 } |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
307 |
5997
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
308 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, "sendfile: %z of %uz @%O", |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
309 n, size, file->file_pos); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
310 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
311 return n; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
312 } |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
313 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
314 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
315 #if (NGX_THREADS) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
316 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
317 typedef struct { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
318 ngx_buf_t *file; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
319 ngx_socket_t socket; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
320 size_t size; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
321 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
322 size_t sent; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
323 ngx_err_t err; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
324 } ngx_linux_sendfile_ctx_t; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
325 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
326 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
327 static ngx_int_t |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
328 ngx_linux_sendfile_thread(ngx_connection_t *c, ngx_buf_t *file, size_t size, |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
329 size_t *sent) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
330 { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
331 ngx_event_t *wev; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
332 ngx_thread_task_t *task; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
333 ngx_linux_sendfile_ctx_t *ctx; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
334 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
335 ngx_log_debug3(NGX_LOG_DEBUG_CORE, c->log, 0, |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
336 "linux sendfile thread: %d, %uz, %O", |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
337 file->file->fd, size, file->file_pos); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
338 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
339 task = c->sendfile_task; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
340 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
341 if (task == NULL) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
342 task = ngx_thread_task_alloc(c->pool, sizeof(ngx_linux_sendfile_ctx_t)); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
343 if (task == NULL) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
344 return NGX_ERROR; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
345 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
346 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
347 task->handler = ngx_linux_sendfile_thread_handler; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
348 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
349 c->sendfile_task = task; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
350 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
351 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
352 ctx = task->ctx; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
353 wev = c->write; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
354 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
355 if (task->event.complete) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
356 task->event.complete = 0; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
357 |
6431
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
358 if (ctx->err == NGX_EAGAIN) { |
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
359 *sent = 0; |
6440
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
360 |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
361 if (wev->complete) { |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
362 return NGX_DONE; |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
363 } |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
364 |
6431
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
365 return NGX_AGAIN; |
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
366 } |
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
367 |
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
368 if (ctx->err) { |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
369 wev->error = 1; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
370 ngx_connection_error(c, ctx->err, "sendfile() failed"); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
371 return NGX_ERROR; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
372 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
373 |
6437
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
374 if (ctx->sent == 0) { |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
375 /* |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
376 * if sendfile returns zero, then someone has truncated the file, |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
377 * so the offset became beyond the end of the file |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
378 */ |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
379 |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
380 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
381 "sendfile() reported that \"%s\" was truncated at %O", |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
382 file->file->name.data, file->file_pos); |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
383 |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
384 return NGX_ERROR; |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
385 } |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
386 |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
387 *sent = ctx->sent; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
388 |
6440
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
389 if (ctx->sent == ctx->size || wev->complete) { |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
390 return NGX_DONE; |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
391 } |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
392 |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
393 return NGX_AGAIN; |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
394 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
395 |
6422
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
396 if (task->event.active && ctx->file == file) { |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
397 /* |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
398 * tolerate duplicate calls; they can happen due to subrequests |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
399 * or multiple calls of the next body filter from a filter |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
400 */ |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
401 |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
402 *sent = 0; |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
403 |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
404 return NGX_OK; |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
405 } |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
406 |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
407 ctx->file = file; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
408 ctx->socket = c->fd; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
409 ctx->size = size; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
410 |
6440
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
411 wev->complete = 0; |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
412 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
413 if (file->file->thread_handler(task, file->file) != NGX_OK) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
414 return NGX_ERROR; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
415 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
416 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
417 *sent = 0; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
418 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
419 return NGX_OK; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
420 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
421 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
422 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
423 static void |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
424 ngx_linux_sendfile_thread_handler(void *data, ngx_log_t *log) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
425 { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
426 ngx_linux_sendfile_ctx_t *ctx = data; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
427 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
428 off_t offset; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
429 ssize_t n; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
430 ngx_buf_t *file; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
431 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
432 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "linux sendfile thread handler"); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
433 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
434 file = ctx->file; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
435 offset = file->file_pos; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
436 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
437 again: |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
438 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
439 n = sendfile(ctx->socket, file->file->fd, &offset, ctx->size); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
440 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
441 if (n == -1) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
442 ctx->err = ngx_errno; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
443 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
444 } else { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
445 ctx->sent = n; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
446 ctx->err = 0; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
447 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
448 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
449 #if 0 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
450 ngx_time_update(); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
451 #endif |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
452 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
453 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
454 "sendfile: %z (err: %i) of %uz @%O", |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
455 n, ctx->err, ctx->size, file->file_pos); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
456 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
457 if (ctx->err == NGX_EINTR) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
458 goto again; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
459 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
460 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
461 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
462 #endif /* NGX_THREADS */ |