Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_darwin_sendfile_chain.c @ 5915:ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 13 Aug 2014 15:11:45 +0400 |
parents | 8e903522c17a |
children | e044893b4587 |
rev | line source |
---|---|
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
265
diff
changeset
|
1 |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
265
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:
265
diff
changeset
|
5 */ |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
265
diff
changeset
|
6 |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
9 #include <ngx_core.h> |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
10 #include <ngx_event.h> |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
12 |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
13 /* |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
14 * It seems that Darwin 9.4 (Mac OS X 1.5) sendfile() has the same |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
15 * old bug as early FreeBSD sendfile() syscall: |
5727
675bda8dcfdb
FreeBSD has migrated to Bugzilla.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5320
diff
changeset
|
16 * http://bugs.freebsd.org/33771 |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
17 * |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
18 * Besides sendfile() has another bug: if one calls sendfile() |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
19 * with both a header and a trailer, then sendfile() ignores a file part |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
20 * at all and sends only the header and the trailer together. |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
21 * For this reason we send a trailer only if there is no a header. |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
22 * |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
23 * Although sendfile() allows to pass a header or a trailer, |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
24 * it may send the header or the trailer and a part of the file |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
25 * in different packets. And FreeBSD workaround (TCP_NOPUSH option) |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
26 * does not help. |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
27 */ |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
501 | 30 ngx_chain_t * |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
31 ngx_darwin_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 { |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
33 int rc; |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
34 off_t send, prev_send, sent; |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
35 off_t file_size; |
5851
150df089fe47
Removed the "complete" variable from various send chain functions.
Valentin Bartenev <vbart@nginx.com>
parents:
5850
diff
changeset
|
36 ngx_uint_t eintr; |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 ngx_err_t err; |
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:
297
diff
changeset
|
38 ngx_buf_t *file; |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
39 ngx_event_t *wev; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
40 ngx_chain_t *cl; |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
41 ngx_iovec_t header, trailer; |
428
5e73d0ea4dab
nginx-0.0.11-2004-09-16-20:10:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
42 struct sf_hdtr hdtr; |
5854
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5851
diff
changeset
|
43 struct iovec headers[NGX_IOVS_PREALLOCATE]; |
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5851
diff
changeset
|
44 struct iovec trailers[NGX_IOVS_PREALLOCATE]; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
45 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
46 wev = c->write; |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
47 |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
48 if (!wev->ready) { |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
49 return in; |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
50 } |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
51 |
469 | 52 #if (NGX_HAVE_KQUEUE) |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
53 |
587 | 54 if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) { |
537 | 55 (void) ngx_connection_error(c, wev->kq_errno, |
56 "kevent() reported about an closed connection"); | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
57 wev->error = 1; |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
58 return NGX_CHAIN_ERROR; |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
59 } |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
60 |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
61 #endif |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
62 |
473 | 63 /* the maximum limit size is the maximum size_t value - the page size */ |
64 | |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1182
diff
changeset
|
65 if (limit == 0 || limit > (off_t) (NGX_MAX_SIZE_T_VALUE - ngx_pagesize)) { |
477 | 66 limit = NGX_MAX_SIZE_T_VALUE - ngx_pagesize; |
473 | 67 } |
68 | |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
69 send = 0; |
361
446782c909b3
nginx-0.0.7-2004-06-20-23:54:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
70 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
71 header.iovs = headers; |
5854
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5851
diff
changeset
|
72 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
|
73 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
74 trailer.iovs = trailers; |
5854
b63e829621ab
Generalized definitions of the number of preallocated iovec's.
Valentin Bartenev <vbart@nginx.com>
parents:
5851
diff
changeset
|
75 trailer.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
|
76 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
77 for ( ;; ) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
78 file = NULL; |
473 | 79 file_size = 0; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
80 eintr = 0; |
473 | 81 prev_send = send; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
82 |
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:
297
diff
changeset
|
83 /* create the header iovec and coalesce the neighbouring bufs */ |
143
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
84 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
85 cl = ngx_output_chain_to_iovec(&header, in, limit - send, c->log); |
361
446782c909b3
nginx-0.0.7-2004-06-20-23:54:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
86 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
87 if (cl == NGX_CHAIN_ERROR) { |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
88 return NGX_CHAIN_ERROR; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
89 } |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
90 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
91 send += header.size; |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
92 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
93 if (cl && cl->buf->in_file && send < limit) { |
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:
297
diff
changeset
|
94 file = cl->buf; |
152
fb48bf4fea1c
nginx-0.0.1-2003-10-21-11:47:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
95 |
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:
297
diff
changeset
|
96 /* coalesce the neighbouring file bufs */ |
152
fb48bf4fea1c
nginx-0.0.1-2003-10-21-11:47:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
97 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
98 file_size = 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:
361
diff
changeset
|
99 |
5915
ac3f78219f85
Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
5913
diff
changeset
|
100 send += file_size; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
101 } |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
103 if (file && header.count == 0) { |
455 | 104 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
105 /* create the trailer iovec and coalesce the neighbouring bufs */ |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
106 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
107 cl = ngx_output_chain_to_iovec(&trailer, cl, limit - send, c->log); |
361
446782c909b3
nginx-0.0.7-2004-06-20-23:54:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
108 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
109 if (cl == NGX_CHAIN_ERROR) { |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
110 return NGX_CHAIN_ERROR; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
111 } |
4596
089cc5154c1e
IOV_MAX handling microoptimization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
112 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
113 send += trailer.size; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
114 } |
67
5a7d1aaa1618
nginx-0.0.1-2003-03-11-23:38:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
63
diff
changeset
|
115 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
116 if (file) { |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
118 /* |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
119 * sendfile() returns EINVAL if sf_hdtr's count is 0, |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
120 * but corresponding pointer is not NULL |
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
121 */ |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
122 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
123 hdtr.headers = header.count ? header.iovs : NULL; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
124 hdtr.hdr_cnt = header.count; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
125 hdtr.trailers = trailer.count ? trailer.iovs : NULL; |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
126 hdtr.trl_cnt = trailer.count; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
127 |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
128 sent = header.size + file_size; |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
152
diff
changeset
|
129 |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
130 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
131 "sendfile: @%O %O h:%uz", |
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
132 file->file_pos, sent, header.size); |
203
c9da5900c79e
nginx-0.0.1-2003-12-02-08:47:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
201
diff
changeset
|
133 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
134 rc = sendfile(file->file->fd, c->fd, file->file_pos, |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
135 &sent, &hdtr, 0); |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
136 |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
137 if (rc == -1) { |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
138 err = ngx_errno; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
139 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
140 switch (err) { |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
141 case NGX_EAGAIN: |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
142 break; |
216
f1d0e5f09c1e
nginx-0.0.1-2003-12-25-23:26:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
214
diff
changeset
|
143 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
144 case NGX_EINTR: |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
145 eintr = 1; |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
146 break; |
152
fb48bf4fea1c
nginx-0.0.1-2003-10-21-11:47:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
147 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
148 default: |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
149 wev->error = 1; |
537 | 150 (void) ngx_connection_error(c, err, "sendfile() failed"); |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
151 return NGX_CHAIN_ERROR; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
152 } |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
153 |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
154 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, err, |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
155 "sendfile() sent only %O bytes", sent); |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
156 } |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
157 |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
158 if (rc == 0 && sent == 0) { |
455 | 159 |
160 /* | |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
161 * if rc and sent equal to zero, then someone |
483 | 162 * has truncated the file, so the offset became beyond |
163 * the end of the file | |
455 | 164 */ |
165 | |
166 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | |
167 "sendfile() reported that \"%s\" was truncated", | |
168 file->file->name.data); | |
169 | |
170 return NGX_CHAIN_ERROR; | |
171 } | |
172 | |
214
e0c502f15852
nginx-0.0.1-2003-12-22-12:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
203
diff
changeset
|
173 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, |
2128
345a014436d4
*) move Darwin support to separate files
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
174 "sendfile: %d, @%O %O:%O", |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
175 rc, file->file_pos, sent, file_size + header.size); |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
176 |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
177 } else { |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
178 rc = writev(c->fd, header.iovs, header.count); |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
179 |
297
ee394e997c77
nginx-0.0.3-2004-03-29-21:43:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
180 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
5913
8e903522c17a
Introduced the ngx_output_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents:
5912
diff
changeset
|
181 "writev: %d of %uz", rc, header.size); |
297
ee394e997c77
nginx-0.0.3-2004-03-29-21:43:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
182 |
143
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
183 if (rc == -1) { |
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
184 err = ngx_errno; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
185 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
186 switch (err) { |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
187 case NGX_EAGAIN: |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
188 break; |
216
f1d0e5f09c1e
nginx-0.0.1-2003-12-25-23:26:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
214
diff
changeset
|
189 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
190 case NGX_EINTR: |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
191 eintr = 1; |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
192 break; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
193 |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
194 default: |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
195 wev->error = 1; |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
196 ngx_connection_error(c, err, "writev() failed"); |
143
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
197 return NGX_CHAIN_ERROR; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
198 } |
3063
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
199 |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
200 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
6f6d7ea70805
refactor EAGAIN/EINTR processing
Igor Sysoev <igor@sysoev.ru>
parents:
2128
diff
changeset
|
201 "writev() not ready"); |
143
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
202 } |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
203 |
143
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
204 sent = rc > 0 ? rc : 0; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
205 } |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
206 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
207 c->sent += sent; |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 |
5912
de68ed551bfb
Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().
Valentin Bartenev <vbart@nginx.com>
parents:
5868
diff
changeset
|
209 in = ngx_chain_update_sent(in, sent); |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
210 |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
211 if (eintr) { |
5868
6bbad2e73245
Fixed counting of sent bytes in the send chain functions on EINTR.
Valentin Bartenev <vbart@nginx.com>
parents:
5854
diff
changeset
|
212 send = prev_send + sent; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
213 continue; |
152
fb48bf4fea1c
nginx-0.0.1-2003-10-21-11:47:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
214 } |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
94
diff
changeset
|
215 |
5851
150df089fe47
Removed the "complete" variable from various send chain functions.
Valentin Bartenev <vbart@nginx.com>
parents:
5850
diff
changeset
|
216 if (send - prev_send != sent) { |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
217 wev->ready = 0; |
5320
ad137a80919f
Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().
Gleb Smirnoff <glebius@nginx.com>
parents:
4596
diff
changeset
|
218 return in; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
219 } |
152
fb48bf4fea1c
nginx-0.0.1-2003-10-21-11:47:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
220 |
5320
ad137a80919f
Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().
Gleb Smirnoff <glebius@nginx.com>
parents:
4596
diff
changeset
|
221 if (send >= limit || in == NULL) { |
ad137a80919f
Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().
Gleb Smirnoff <glebius@nginx.com>
parents:
4596
diff
changeset
|
222 return in; |
362
7650aea1816f
nginx-0.0.7-2004-06-21-19:59:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
361
diff
changeset
|
223 } |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
224 } |
63
36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 } |