Mercurial > hg > nginx
annotate src/os/unix/ngx_linux_sendfile_chain.c @ 7292:f9661f56c717
Allowed digits, '+', '-', and '.' in scheme names as per RFC 3986.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 24 May 2018 12:06:35 +0300 |
parents | 400a3412b1e3 |
children | a2613fc1bce5 |
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 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
23 static ssize_t ngx_linux_sendfile_thread(ngx_connection_t *c, ngx_buf_t *file, |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
24 size_t size); |
6023
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]; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
59 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
60 wev = c->write; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
62 if (!wev->ready) { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
63 return in; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
64 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
65 |
473 | 66 |
687
8e446a2daf48
workaround of 2G+ file bug in 64-bit Linux sendfile()
Igor Sysoev <igor@sysoev.ru>
parents:
597
diff
changeset
|
67 /* the maximum limit size is 2G-1 - the page size */ |
473 | 68 |
5322
bdb3588681c9
Unbreak building on Linux without sendfile64() support.
Valentin Bartenev <vbart@nginx.com>
parents:
5320
diff
changeset
|
69 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
|
70 limit = NGX_SENDFILE_MAXSIZE - ngx_pagesize; |
473 | 71 } |
72 | |
73 | |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
74 send = 0; |
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
75 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
76 header.iovs = headers; |
5854
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5851
diff
changeset
|
77 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
|
78 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
79 for ( ;; ) { |
473 | 80 prev_send = send; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
81 |
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
|
82 /* 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
|
83 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
84 cl = ngx_output_chain_to_iovec(&header, in, limit - send, c->log); |
479 | 85 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
86 if (cl == NGX_CHAIN_ERROR) { |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
87 return NGX_CHAIN_ERROR; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
88 } |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
90 send += header.size; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
92 /* 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
|
93 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
94 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
|
95 && 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
|
96 && cl |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
97 && 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
|
98 { |
473 | 99 /* the TCP_CORK and TCP_NODELAY are mutually exclusive */ |
100 | |
483 | 101 if (c->tcp_nodelay == NGX_TCP_NODELAY_SET) { |
473 | 102 |
103 tcp_nodelay = 0; | |
104 | |
105 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, | |
106 (const void *) &tcp_nodelay, sizeof(int)) == -1) | |
107 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5322
diff
changeset
|
108 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
|
109 |
473 | 110 /* |
479 | 111 * there is a tiny chance to be interrupted, however, |
473 | 112 * we continue a processing with the TCP_NODELAY |
113 * and without the TCP_CORK | |
114 */ | |
115 | |
577 | 116 if (err != NGX_EINTR) { |
473 | 117 wev->error = 1; |
483 | 118 ngx_connection_error(c, err, |
473 | 119 "setsockopt(TCP_NODELAY) failed"); |
120 return NGX_CHAIN_ERROR; | |
121 } | |
122 | |
123 } else { | |
483 | 124 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
|
125 |
5222
23a186e8ca45
Style: remove unnecessary references to HTTP from non-HTTP modules.
Piotr Sikora <piotr@cloudflare.com>
parents:
4596
diff
changeset
|
126 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
473 | 127 "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
|
128 } |
473 | 129 } |
130 | |
483 | 131 if (c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
473 | 132 |
7239
400a3412b1e3
Fixed checking ngx_tcp_push() and ngx_tcp_nopush() return values.
Ruslan Ermilov <ru@nginx.com>
parents:
6949
diff
changeset
|
133 if (ngx_tcp_nopush(c->fd) == -1) { |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5322
diff
changeset
|
134 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
|
135 |
473 | 136 /* |
479 | 137 * there is a tiny chance to be interrupted, however, |
473 | 138 * we continue a processing without the TCP_CORK |
139 */ | |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
140 |
577 | 141 if (err != NGX_EINTR) { |
473 | 142 wev->error = 1; |
143 ngx_connection_error(c, err, | |
144 ngx_tcp_nopush_n " failed"); | |
145 return NGX_CHAIN_ERROR; | |
146 } | |
147 | |
148 } else { | |
149 c->tcp_nopush = NGX_TCP_NOPUSH_SET; | |
577 | 150 |
473 | 151 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
152 "tcp_nopush"); | |
153 } | |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
157 /* 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
|
158 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
159 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
|
160 file = cl->buf; |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
162 /* 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
|
163 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
164 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
|
165 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
166 send += file_size; |
589 | 167 #if 1 |
168 if (file_size == 0) { | |
169 ngx_debug_point(); | |
170 return NGX_CHAIN_ERROR; | |
171 } | |
172 #endif | |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
173 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
174 n = ngx_linux_sendfile(c, file, file_size); |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
175 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
176 if (n == NGX_ERROR) { |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
177 return NGX_CHAIN_ERROR; |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
178 } |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
179 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
180 if (n == NGX_DONE) { |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
181 /* thread task posted */ |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
182 return in; |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
183 } |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
184 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
185 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
|
186 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
187 } else { |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
188 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
|
189 |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
190 if (n == NGX_ERROR) { |
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
191 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
|
192 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 |
5917
2c64b69daec5
Moved writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5916
diff
changeset
|
194 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
|
195 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
197 c->sent += sent; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
97
diff
changeset
|
198 |
5912
de68ed551bfb
Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().
Valentin Bartenev <vbart@nginx.com>
parents:
5868
diff
changeset
|
199 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
|
200 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
201 if (n == NGX_AGAIN) { |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
202 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
|
203 return in; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
204 } |
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
205 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
206 if ((size_t) (send - prev_send) != sent) { |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
207 |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
208 /* |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
209 * sendfile() on Linux 4.3+ might be interrupted at any time, |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
210 * and provides no indication if it was interrupted or not, |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
211 * so we have to retry till an explicit EAGAIN |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
212 * |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
213 * sendfile() in threads can also report less bytes written |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
214 * than we are prepared to send now, since it was started in |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
215 * some point in the past, so we again have to retry |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
216 */ |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
217 |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
218 send = prev_send + sent; |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
219 continue; |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
220 } |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
221 |
5320
ad137a80919f
Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().
Gleb Smirnoff <glebius@nginx.com>
parents:
5222
diff
changeset
|
222 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
|
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 } |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
226 } |
5997
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
227 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
228 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
229 static ssize_t |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
230 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
|
231 { |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
232 #if (NGX_HAVE_SENDFILE64) |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
233 off_t offset; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
234 #else |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
235 int32_t offset; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
236 #endif |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
237 ssize_t n; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
238 ngx_err_t err; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
239 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
240 #if (NGX_THREADS) |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
241 |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
242 if (file->file->thread_handler) { |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
243 return ngx_linux_sendfile_thread(c, file, size); |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
244 } |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
245 |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
246 #endif |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
247 |
5997
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
248 #if (NGX_HAVE_SENDFILE64) |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
249 offset = file->file_pos; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
250 #else |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
251 offset = (int32_t) file->file_pos; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
252 #endif |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
253 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
254 eintr: |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
255 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
256 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
|
257 "sendfile: @%O %uz", file->file_pos, size); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
258 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
259 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
|
260 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
261 if (n == -1) { |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
262 err = ngx_errno; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
263 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
264 switch (err) { |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
265 case NGX_EAGAIN: |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
266 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
|
267 "sendfile() is not ready"); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
268 return NGX_AGAIN; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
269 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
270 case NGX_EINTR: |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
271 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
|
272 "sendfile() was interrupted"); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
273 goto eintr; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
274 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
275 default: |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
276 c->write->error = 1; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
277 ngx_connection_error(c, err, "sendfile() failed"); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
278 return NGX_ERROR; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
279 } |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
280 } |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
281 |
6437
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
282 if (n == 0) { |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
283 /* |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
284 * 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
|
285 * 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
|
286 */ |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
287 |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
288 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
|
289 "sendfile() reported that \"%s\" was truncated at %O", |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
290 file->file->name.data, file->file_pos); |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
291 |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
292 return NGX_ERROR; |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
293 } |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
294 |
5997
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
295 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
|
296 n, size, file->file_pos); |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
297 |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
298 return n; |
c901f2764c27
Refactored ngx_linux_sendfile_chain() even more.
Valentin Bartenev <vbart@nginx.com>
parents:
5918
diff
changeset
|
299 } |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
300 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
301 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
302 #if (NGX_THREADS) |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
303 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
304 typedef struct { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
305 ngx_buf_t *file; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
306 ngx_socket_t socket; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
307 size_t size; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
308 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
309 size_t sent; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
310 ngx_err_t err; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
311 } ngx_linux_sendfile_ctx_t; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
312 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
313 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
314 static ssize_t |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
315 ngx_linux_sendfile_thread(ngx_connection_t *c, ngx_buf_t *file, size_t size) |
6023
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 ngx_event_t *wev; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
318 ngx_thread_task_t *task; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
319 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
|
320 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
321 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
|
322 "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
|
323 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
|
324 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
325 task = c->sendfile_task; |
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 if (task == NULL) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
328 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
|
329 if (task == NULL) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
330 return NGX_ERROR; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
331 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
332 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
333 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
|
334 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
335 c->sendfile_task = task; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
336 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
337 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
338 ctx = task->ctx; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
339 wev = c->write; |
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->event.complete) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
342 task->event.complete = 0; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
343 |
6431
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
344 if (ctx->err == NGX_EAGAIN) { |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
345 /* |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
346 * if wev->complete is set, this means that a write event |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
347 * happened while we were waiting for the thread task, so |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
348 * we have to retry sending even on EAGAIN |
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
349 */ |
6440
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
350 |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
351 if (wev->complete) { |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
352 return 0; |
6440
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
353 } |
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
354 |
6431
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
355 return NGX_AGAIN; |
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
356 } |
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
357 |
3b9c6b91d988
Fixed handling of EAGAIN with sendfile in threads.
Valentin Bartenev <vbart@nginx.com>
parents:
6422
diff
changeset
|
358 if (ctx->err) { |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
359 wev->error = 1; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
360 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
|
361 return NGX_ERROR; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
362 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
363 |
6437
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
364 if (ctx->sent == 0) { |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
365 /* |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
366 * 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
|
367 * 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
|
368 */ |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
369 |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
370 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
|
371 "sendfile() reported that \"%s\" was truncated at %O", |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
372 file->file->name.data, file->file_pos); |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
373 |
4df3d9fcdee8
Truncation detection in sendfile() on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6431
diff
changeset
|
374 return NGX_ERROR; |
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 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
377 return ctx->sent; |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
378 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
379 |
6422
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
380 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
|
381 /* |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
382 * 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
|
383 * 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
|
384 */ |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
385 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
386 return NGX_DONE; |
6422
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
387 } |
768e287a6f36
Fixed sendfile in threads (or with aio preload) and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6023
diff
changeset
|
388 |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
389 ctx->file = file; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
390 ctx->socket = c->fd; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
391 ctx->size = size; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
392 |
6440
248aa2757332
Fixed timeouts with threaded sendfile() and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6437
diff
changeset
|
393 wev->complete = 0; |
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 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
|
396 return NGX_ERROR; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
397 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
398 |
6949
ff0c8e11edbc
Simplified and improved sendfile() code on Linux.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
399 return NGX_DONE; |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
400 } |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
401 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
402 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
403 static void |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
404 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
|
405 { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
406 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
|
407 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
408 off_t offset; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
409 ssize_t n; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
410 ngx_buf_t *file; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
411 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
412 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
|
413 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
414 file = ctx->file; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
415 offset = file->file_pos; |
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 again: |
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 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
|
420 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
421 if (n == -1) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
422 ctx->err = ngx_errno; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
423 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
424 } else { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
425 ctx->sent = n; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
426 ctx->err = 0; |
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 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
429 #if 0 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
430 ngx_time_update(); |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
431 #endif |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
432 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
433 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, |
6480 | 434 "sendfile: %z (err: %d) of %uz @%O", |
6023
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
435 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
|
436 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
437 if (ctx->err == NGX_EINTR) { |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
438 goto again; |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
439 } |
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 |
b550563ef96e
Added support for offloading Linux sendfile() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5997
diff
changeset
|
442 #endif /* NGX_THREADS */ |