Mercurial > hg > nginx-quic
annotate src/core/ngx_output_chain.c @ 8582:0dcec8e5d50a
HTTP/2: reworked body reading to better match HTTP/1.x code.
In particular, now the code always uses a buffer limited by
client_body_buffer_size. At the cost of an additional copy it
ensures that small DATA frames are not directly mapped to small
write() syscalls, but rather buffered in memory before writing.
Further, requests without Content-Length are no longer forced
to use temporary files.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 29 Aug 2021 22:20:36 +0300 |
parents | a7ff19afbb14 |
children | 862f6130d357 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
430
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
430
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
430
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
430
diff
changeset
|
6 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
10 #include <ngx_event.h> |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
469 | 13 #if 0 |
14 #define NGX_SENDFILE_LIMIT 4096 | |
15 #endif | |
16 | |
2316 | 17 /* |
18 * When DIRECTIO is enabled FreeBSD, Solaris, and MacOSX read directly | |
19 * to an application memory from a device if parameters are aligned | |
3053 | 20 * to device sector boundary (512 bytes). They fallback to usual read |
2316 | 21 * operation if the parameters are not aligned. |
22 * Linux allows DIRECTIO only if the parameters are aligned to a filesystem | |
23 * sector boundary, otherwise it returns EINVAL. The sector size is | |
24 * usually 512 bytes, however, on XFS it may be 4096 bytes. | |
25 */ | |
469 | 26 |
27 #define NGX_NONE 1 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
467 | 30 static ngx_inline ngx_int_t |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
31 ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf); |
5980
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
32 #if (NGX_HAVE_AIO_SENDFILE) |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
33 static ngx_int_t ngx_output_chain_aio_setup(ngx_output_chain_ctx_t *ctx, |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
34 ngx_file_t *file); |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
35 #endif |
469 | 36 static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool, |
499 | 37 ngx_chain_t **chain, ngx_chain_t *in); |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
38 static ngx_int_t ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx, |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
39 off_t bsize); |
2230 | 40 static ngx_int_t ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx, |
41 off_t bsize); | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
42 static ngx_int_t ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 |
499 | 45 ngx_int_t |
46 ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 { |
473 | 48 off_t bsize; |
597 | 49 ngx_int_t rc, last; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 ngx_chain_t *cl, *out, **last_out; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 |
5966
bcdfc39bf44d
Fixed AIO handling in the output chain.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
52 if (ctx->in == NULL && ctx->busy == NULL |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
53 #if (NGX_HAVE_FILE_AIO || NGX_THREADS) |
5966
bcdfc39bf44d
Fixed AIO handling in the output chain.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
54 && !ctx->aio |
bcdfc39bf44d
Fixed AIO handling in the output chain.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
55 #endif |
bcdfc39bf44d
Fixed AIO handling in the output chain.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
56 ) |
bcdfc39bf44d
Fixed AIO handling in the output chain.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
57 { |
469 | 58 /* |
59 * the short path for the case when the ctx->in and ctx->busy chains | |
60 * are empty, the incoming chain is empty too or has the single buf | |
61 * that does not require the copy | |
62 */ | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 if (in == NULL) { |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
65 return ctx->output_filter(ctx->filter_ctx, in); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
68 if (in->next == NULL |
469 | 69 #if (NGX_SENDFILE_LIMIT) |
70 && !(in->buf->in_file && in->buf->file_last > NGX_SENDFILE_LIMIT) | |
71 #endif | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
72 && ngx_output_chain_as_is(ctx, in->buf)) |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 { |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
74 return ctx->output_filter(ctx->filter_ctx, in); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
78 /* add the incoming buf to the chain ctx->in */ |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 if (in) { |
469 | 81 if (ngx_output_chain_add_copy(ctx->pool, &ctx->in, in) == NGX_ERROR) { |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 return NGX_ERROR; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
162
diff
changeset
|
86 out = NULL; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 last_out = &out; |
499 | 88 last = NGX_NONE; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 for ( ;; ) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
92 #if (NGX_HAVE_FILE_AIO || NGX_THREADS) |
3776
7450029ff51e
file AIO read may be posted inside loop
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
93 if (ctx->aio) { |
7450029ff51e
file AIO read may be posted inside loop
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
94 return NGX_AGAIN; |
7450029ff51e
file AIO read may be posted inside loop
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
95 } |
7450029ff51e
file AIO read may be posted inside loop
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
96 #endif |
7450029ff51e
file AIO read may be posted inside loop
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
97 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 while (ctx->in) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 |
320
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
100 /* |
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:
334
diff
changeset
|
101 * cycle while there are the ctx->in bufs |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
102 * and there are the free output bufs to copy in |
320
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
103 */ |
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
104 |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
105 bsize = ngx_buf_size(ctx->in->buf); |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
106 |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
107 if (bsize == 0 && !ngx_buf_special(ctx->in->buf)) { |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
108 |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
109 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
483 | 110 "zero size buf in output " |
111 "t:%d r:%d f:%d %p %p-%p %p %O-%O", | |
112 ctx->in->buf->temporary, | |
113 ctx->in->buf->recycled, | |
114 ctx->in->buf->in_file, | |
115 ctx->in->buf->start, | |
116 ctx->in->buf->pos, | |
117 ctx->in->buf->last, | |
118 ctx->in->buf->file, | |
119 ctx->in->buf->file_pos, | |
120 ctx->in->buf->file_last); | |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
121 |
473 | 122 ngx_debug_point(); |
123 | |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
124 ctx->in = ctx->in->next; |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
125 |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
126 continue; |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
127 } |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
128 |
7401
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
129 if (bsize < 0) { |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
130 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
131 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
132 "negative size buf in output " |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
133 "t:%d r:%d f:%d %p %p-%p %p %O-%O", |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
134 ctx->in->buf->temporary, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
135 ctx->in->buf->recycled, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
136 ctx->in->buf->in_file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
137 ctx->in->buf->start, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
138 ctx->in->buf->pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
139 ctx->in->buf->last, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
140 ctx->in->buf->file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
141 ctx->in->buf->file_pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
142 ctx->in->buf->file_last); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
143 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
144 ngx_debug_point(); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
145 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
146 return NGX_ERROR; |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
147 } |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
148 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
149 if (ngx_output_chain_as_is(ctx, ctx->in->buf)) { |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 |
320
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
151 /* move the chain link to the output chain */ |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 cl = ctx->in; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 ctx->in = cl->next; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 *last_out = cl; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 last_out = &cl->next; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 cl->next = NULL; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 continue; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 |
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:
334
diff
changeset
|
163 if (ctx->buf == NULL) { |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
165 rc = ngx_output_chain_align_file_buf(ctx, bsize); |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
166 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
167 if (rc == NGX_ERROR) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
168 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
169 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
170 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
171 if (rc != NGX_OK) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
172 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
173 if (ctx->free) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
174 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
175 /* get the free buf */ |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
177 cl = ctx->free; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
178 ctx->buf = cl->buf; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
179 ctx->free = cl->next; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
180 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
181 ngx_free_chain(ctx->pool, cl); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
183 } else if (out || ctx->allocated == ctx->bufs.num) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
184 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
185 break; |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
320
diff
changeset
|
186 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
187 } else if (ngx_output_chain_get_buf(ctx, bsize) != NGX_OK) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
188 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
189 } |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
191 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
193 rc = ngx_output_chain_copy_buf(ctx); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 if (rc == NGX_ERROR) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
198 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 if (rc == NGX_AGAIN) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 if (out) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 break; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 } |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
203 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
204 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
205 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
206 |
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:
334
diff
changeset
|
207 /* delete the completed buf from the ctx->in chain */ |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 |
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:
334
diff
changeset
|
209 if (ngx_buf_size(ctx->in->buf) == 0) { |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
210 ctx->in = ctx->in->next; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
212 |
501 | 213 cl = ngx_alloc_chain_link(ctx->pool); |
214 if (cl == NULL) { | |
461 | 215 return NGX_ERROR; |
216 } | |
501 | 217 |
461 | 218 cl->buf = ctx->buf; |
219 cl->next = NULL; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 *last_out = cl; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
221 last_out = &cl->next; |
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:
334
diff
changeset
|
222 ctx->buf = NULL; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
224 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 if (out == NULL && last != NGX_NONE) { |
509 | 226 |
227 if (ctx->in) { | |
228 return NGX_AGAIN; | |
229 } | |
230 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 return last; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
233 |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
234 last = ctx->output_filter(ctx->filter_ctx, out); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
235 |
569 | 236 if (last == NGX_ERROR || last == NGX_DONE) { |
237 return last; | |
238 } | |
239 | |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3776
diff
changeset
|
240 ngx_chain_update_chains(ctx->pool, &ctx->free, &ctx->busy, &out, |
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3776
diff
changeset
|
241 ctx->tag); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 last_out = &out; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
243 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
244 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 |
467 | 247 static ngx_inline ngx_int_t |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
248 ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf) |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
249 { |
469 | 250 ngx_uint_t sendfile; |
251 | |
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:
334
diff
changeset
|
252 if (ngx_buf_special(buf)) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
253 return 1; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
254 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
255 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
256 #if (NGX_THREADS) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
257 if (buf->in_file) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
258 buf->file->thread_handler = ctx->thread_handler; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
259 buf->file->thread_ctx = ctx->filter_ctx; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
260 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
261 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
262 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
263 if (buf->in_file && buf->file->directio) { |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
264 return 0; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
265 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
266 |
469 | 267 sendfile = ctx->sendfile; |
268 | |
269 #if (NGX_SENDFILE_LIMIT) | |
270 | |
271 if (buf->in_file && buf->file_pos >= NGX_SENDFILE_LIMIT) { | |
272 sendfile = 0; | |
273 } | |
274 | |
275 #endif | |
276 | |
277 if (!sendfile) { | |
455 | 278 |
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:
334
diff
changeset
|
279 if (!ngx_buf_in_memory(buf)) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
280 return 0; |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
167
diff
changeset
|
281 } |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
167
diff
changeset
|
282 |
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:
334
diff
changeset
|
283 buf->in_file = 0; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
284 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
285 |
5980
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
286 #if (NGX_HAVE_AIO_SENDFILE) |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
287 if (ctx->aio_preload && buf->in_file) { |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
288 (void) ngx_output_chain_aio_setup(ctx, buf->file); |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
289 } |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
290 #endif |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
291 |
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:
334
diff
changeset
|
292 if (ctx->need_in_memory && !ngx_buf_in_memory(buf)) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
293 return 0; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
294 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
295 |
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:
334
diff
changeset
|
296 if (ctx->need_in_temp && (buf->memory || buf->mmap)) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
297 return 0; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
298 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
299 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
300 return 1; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
302 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
303 |
5980
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
304 #if (NGX_HAVE_AIO_SENDFILE) |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
305 |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
306 static ngx_int_t |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
307 ngx_output_chain_aio_setup(ngx_output_chain_ctx_t *ctx, ngx_file_t *file) |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
308 { |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
309 ngx_event_aio_t *aio; |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
310 |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
311 if (file->aio == NULL && ngx_file_aio_init(file, ctx->pool) != NGX_OK) { |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
312 return NGX_ERROR; |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
313 } |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
314 |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
315 aio = file->aio; |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
316 |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
317 aio->data = ctx->filter_ctx; |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
318 aio->preload_handler = ctx->aio_preload; |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
319 |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
320 return NGX_OK; |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
321 } |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
322 |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
323 #endif |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
324 |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5966
diff
changeset
|
325 |
499 | 326 static ngx_int_t |
327 ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, | |
328 ngx_chain_t *in) | |
469 | 329 { |
330 ngx_chain_t *cl, **ll; | |
331 #if (NGX_SENDFILE_LIMIT) | |
332 ngx_buf_t *b, *buf; | |
333 #endif | |
334 | |
335 ll = chain; | |
336 | |
337 for (cl = *chain; cl; cl = cl->next) { | |
338 ll = &cl->next; | |
339 } | |
340 | |
341 while (in) { | |
342 | |
501 | 343 cl = ngx_alloc_chain_link(pool); |
344 if (cl == NULL) { | |
469 | 345 return NGX_ERROR; |
346 } | |
347 | |
348 #if (NGX_SENDFILE_LIMIT) | |
349 | |
350 buf = in->buf; | |
351 | |
352 if (buf->in_file | |
353 && buf->file_pos < NGX_SENDFILE_LIMIT | |
354 && buf->file_last > NGX_SENDFILE_LIMIT) | |
355 { | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
356 /* split a file buf on two bufs by the sendfile limit */ |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
357 |
501 | 358 b = ngx_calloc_buf(pool); |
359 if (b == NULL) { | |
469 | 360 return NGX_ERROR; |
361 } | |
362 | |
363 ngx_memcpy(b, buf, sizeof(ngx_buf_t)); | |
364 | |
365 if (ngx_buf_in_memory(buf)) { | |
366 buf->pos += (ssize_t) (NGX_SENDFILE_LIMIT - buf->file_pos); | |
367 b->last = buf->pos; | |
368 } | |
369 | |
370 buf->file_pos = NGX_SENDFILE_LIMIT; | |
371 b->file_last = NGX_SENDFILE_LIMIT; | |
372 | |
373 cl->buf = b; | |
374 | |
375 } else { | |
376 cl->buf = buf; | |
377 in = in->next; | |
378 } | |
379 | |
380 #else | |
381 cl->buf = in->buf; | |
382 in = in->next; | |
383 | |
384 #endif | |
385 | |
2910
dc01b26f8de8
leave chain in consistent state on errors
Igor Sysoev <igor@sysoev.ru>
parents:
2899
diff
changeset
|
386 cl->next = NULL; |
469 | 387 *ll = cl; |
388 ll = &cl->next; | |
389 } | |
390 | |
391 return NGX_OK; | |
392 } | |
393 | |
394 | |
499 | 395 static ngx_int_t |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
396 ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx, off_t bsize) |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
397 { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
398 size_t size; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
399 ngx_buf_t *in; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
400 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
401 in = ctx->in->buf; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
402 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
403 if (in->file == NULL || !in->file->directio) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
404 return NGX_DECLINED; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
405 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
406 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
407 ctx->directio = 1; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
408 |
3053 | 409 size = (size_t) (in->file_pos - (in->file_pos & ~(ctx->alignment - 1))); |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
410 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
411 if (size == 0) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
412 |
2240
a83218b65245
fix building on 64-bit platforms, introduced in r2232
Igor Sysoev <igor@sysoev.ru>
parents:
2231
diff
changeset
|
413 if (bsize >= (off_t) ctx->bufs.size) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
414 return NGX_DECLINED; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
415 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
416 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
417 size = (size_t) bsize; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
418 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
419 } else { |
3057
5ea5a90000d5
fix build by msvc, introduced in r3054
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
420 size = (size_t) ctx->alignment - size; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
421 |
2240
a83218b65245
fix building on 64-bit platforms, introduced in r2232
Igor Sysoev <igor@sysoev.ru>
parents:
2231
diff
changeset
|
422 if ((off_t) size > bsize) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
423 size = (size_t) bsize; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
424 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
425 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
426 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
427 ctx->buf = ngx_create_temp_buf(ctx->pool, size); |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
428 if (ctx->buf == NULL) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
429 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
430 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
431 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
432 /* |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
433 * we do not set ctx->buf->tag, because we do not want |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
434 * to reuse the buf via ctx->free list |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
435 */ |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
436 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
437 #if (NGX_HAVE_ALIGNED_DIRECTIO) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
438 ctx->unaligned = 1; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
439 #endif |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
440 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
441 return NGX_OK; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
442 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
443 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
444 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
445 static ngx_int_t |
2230 | 446 ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx, off_t bsize) |
447 { | |
448 size_t size; | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
449 ngx_buf_t *b, *in; |
2230 | 450 ngx_uint_t recycled; |
451 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
452 in = ctx->in->buf; |
2230 | 453 size = ctx->bufs.size; |
454 recycled = 1; | |
455 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
456 if (in->last_in_chain) { |
2230 | 457 |
458 if (bsize < (off_t) size) { | |
459 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
460 /* |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
461 * allocate a small temp buf for a small last buf |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
462 * or its small last part |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
463 */ |
2230 | 464 |
465 size = (size_t) bsize; | |
466 recycled = 0; | |
467 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
468 } else if (!ctx->directio |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
469 && ctx->bufs.num == 1 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
470 && (bsize < (off_t) (size + size / 4))) |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
471 { |
2230 | 472 /* |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
473 * allocate a temp buf that equals to a last buf, |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
474 * if there is no directio, the last buf size is lesser |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
475 * than 1.25 of bufs.size and the temp buf is single |
2230 | 476 */ |
477 | |
478 size = (size_t) bsize; | |
479 recycled = 0; | |
480 } | |
481 } | |
482 | |
483 b = ngx_calloc_buf(ctx->pool); | |
484 if (b == NULL) { | |
485 return NGX_ERROR; | |
486 } | |
487 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
488 if (ctx->directio) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
489 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
490 /* |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
491 * allocate block aligned to a disk sector size to enable |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
492 * userland buffer direct usage conjunctly with directio |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
493 */ |
2230 | 494 |
3057
5ea5a90000d5
fix build by msvc, introduced in r3054
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
495 b->start = ngx_pmemalign(ctx->pool, size, (size_t) ctx->alignment); |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
496 if (b->start == NULL) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
497 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
498 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
499 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
500 } else { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
501 b->start = ngx_palloc(ctx->pool, size); |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
502 if (b->start == NULL) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
503 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
504 } |
2230 | 505 } |
506 | |
507 b->pos = b->start; | |
508 b->last = b->start; | |
509 b->end = b->last + size; | |
510 b->temporary = 1; | |
511 b->tag = ctx->tag; | |
512 b->recycled = recycled; | |
513 | |
514 ctx->buf = b; | |
515 ctx->allocated++; | |
516 | |
517 return NGX_OK; | |
518 } | |
519 | |
520 | |
521 static ngx_int_t | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
522 ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx) |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
523 { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
524 off_t size; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
525 ssize_t n; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
526 ngx_buf_t *src, *dst; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
527 ngx_uint_t sendfile; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
528 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
529 src = ctx->in->buf; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
530 dst = ctx->buf; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
531 |
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:
334
diff
changeset
|
532 size = ngx_buf_size(src); |
3515 | 533 size = ngx_min(size, dst->end - dst->pos); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
534 |
6819
4395758d08e6
Fixed spelling of logical AND operator, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6441
diff
changeset
|
535 sendfile = ctx->sendfile && !ctx->directio; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
536 |
469 | 537 #if (NGX_SENDFILE_LIMIT) |
538 | |
539 if (src->in_file && src->file_pos >= NGX_SENDFILE_LIMIT) { | |
540 sendfile = 0; | |
541 } | |
542 | |
543 #endif | |
544 | |
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:
334
diff
changeset
|
545 if (ngx_buf_in_memory(src)) { |
473 | 546 ngx_memcpy(dst->pos, src->pos, (size_t) size); |
547 src->pos += (size_t) size; | |
548 dst->last += (size_t) size; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
549 |
455 | 550 if (src->in_file) { |
551 | |
552 if (sendfile) { | |
553 dst->in_file = 1; | |
554 dst->file = src->file; | |
555 dst->file_pos = src->file_pos; | |
556 dst->file_last = src->file_pos + size; | |
557 | |
558 } else { | |
559 dst->in_file = 0; | |
560 } | |
561 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
562 src->file_pos += size; |
452 | 563 |
564 } else { | |
565 dst->in_file = 0; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
566 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
567 |
1227
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
568 if (src->pos == src->last) { |
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
569 dst->flush = src->flush; |
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
570 dst->last_buf = src->last_buf; |
2899
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2316
diff
changeset
|
571 dst->last_in_chain = src->last_in_chain; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
572 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
573 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
574 } else { |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
575 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
576 #if (NGX_HAVE_ALIGNED_DIRECTIO) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
577 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
578 if (ctx->unaligned) { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3147
diff
changeset
|
579 if (ngx_directio_off(src->file->fd) == NGX_FILE_ERROR) { |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
580 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno, |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
581 ngx_directio_off_n " \"%s\" failed", |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
582 src->file->name.data); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
583 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
584 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
585 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
586 #endif |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
587 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
588 #if (NGX_HAVE_FILE_AIO) |
3119
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
589 if (ctx->aio_handler) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
590 n = ngx_file_aio_read(src->file, dst->pos, (size_t) size, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
591 src->file_pos, ctx->pool); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
592 if (n == NGX_AGAIN) { |
3119
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
593 ctx->aio_handler(ctx, src->file); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
594 return NGX_AGAIN; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
595 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
596 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
597 } else |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
598 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
599 #if (NGX_THREADS) |
6441
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
600 if (ctx->thread_handler) { |
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
601 src->file->thread_task = ctx->thread_task; |
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
602 src->file->thread_handler = ctx->thread_handler; |
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
603 src->file->thread_ctx = ctx->filter_ctx; |
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
604 |
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
605 n = ngx_thread_read(src->file, dst->pos, (size_t) size, |
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
606 src->file_pos, ctx->pool); |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
607 if (n == NGX_AGAIN) { |
6441
9fd738b85fad
Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
608 ctx->thread_task = src->file->thread_task; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
609 return NGX_AGAIN; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
610 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
611 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
612 } else |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
613 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
5980
diff
changeset
|
614 { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
615 n = ngx_read_file(src->file, dst->pos, (size_t) size, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
616 src->file_pos); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
617 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
618 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
619 #if (NGX_HAVE_ALIGNED_DIRECTIO) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
620 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
621 if (ctx->unaligned) { |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
622 ngx_err_t err; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
623 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
624 err = ngx_errno; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
625 |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3147
diff
changeset
|
626 if (ngx_directio_on(src->file->fd) == NGX_FILE_ERROR) { |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
627 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno, |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
628 ngx_directio_on_n " \"%s\" failed", |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
629 src->file->name.data); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
630 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
631 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
632 ngx_set_errno(err); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
633 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
634 ctx->unaligned = 0; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
635 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
636 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
637 #endif |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
638 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
639 if (n == NGX_ERROR) { |
517 | 640 return (ngx_int_t) n; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
641 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
642 |
473 | 643 if (n != size) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
644 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
2245
8a98616abb73
add filename to the log message
Igor Sysoev <igor@sysoev.ru>
parents:
2240
diff
changeset
|
645 ngx_read_file_n " read only %z of %O from \"%s\"", |
8a98616abb73
add filename to the log message
Igor Sysoev <igor@sysoev.ru>
parents:
2240
diff
changeset
|
646 n, size, src->file->name.data); |
3147
cbb1add4a6fe
fail if file size was changed
Igor Sysoev <igor@sysoev.ru>
parents:
3119
diff
changeset
|
647 return NGX_ERROR; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
648 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
649 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
650 dst->last += n; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
651 |
452 | 652 if (sendfile) { |
653 dst->in_file = 1; | |
654 dst->file = src->file; | |
655 dst->file_pos = src->file_pos; | |
455 | 656 dst->file_last = src->file_pos + n; |
452 | 657 |
658 } else { | |
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:
334
diff
changeset
|
659 dst->in_file = 0; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
660 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
661 |
455 | 662 src->file_pos += n; |
663 | |
1238 | 664 if (src->file_pos == src->file_last) { |
1227
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
665 dst->flush = src->flush; |
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
666 dst->last_buf = src->last_buf; |
2899
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2316
diff
changeset
|
667 dst->last_in_chain = src->last_in_chain; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
668 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
669 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
670 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
671 return NGX_OK; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
672 } |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
673 |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
674 |
499 | 675 ngx_int_t |
676 ngx_chain_writer(void *data, ngx_chain_t *in) | |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
677 { |
166
389d7ee9fa60
nginx-0.0.1-2003-10-30-11:51:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
678 ngx_chain_writer_ctx_t *ctx = data; |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
679 |
1962 | 680 off_t size; |
6046
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
681 ngx_chain_t *cl, *ln, *chain; |
1962 | 682 ngx_connection_t *c; |
683 | |
684 c = ctx->connection; | |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
685 |
473 | 686 for (size = 0; in; in = in->next) { |
687 | |
688 if (ngx_buf_size(in->buf) == 0 && !ngx_buf_special(in->buf)) { | |
6045
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
689 |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
690 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
691 "zero size buf in chain writer " |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
692 "t:%d r:%d f:%d %p %p-%p %p %O-%O", |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
693 in->buf->temporary, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
694 in->buf->recycled, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
695 in->buf->in_file, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
696 in->buf->start, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
697 in->buf->pos, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
698 in->buf->last, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
699 in->buf->file, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
700 in->buf->file_pos, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
701 in->buf->file_last); |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
702 |
473 | 703 ngx_debug_point(); |
6045
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
704 |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
705 continue; |
473 | 706 } |
7401
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
707 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
708 if (ngx_buf_size(in->buf) < 0) { |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
709 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
710 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
711 "negative size buf in chain writer " |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
712 "t:%d r:%d f:%d %p %p-%p %p %O-%O", |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
713 in->buf->temporary, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
714 in->buf->recycled, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
715 in->buf->in_file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
716 in->buf->start, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
717 in->buf->pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
718 in->buf->last, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
719 in->buf->file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
720 in->buf->file_pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
721 in->buf->file_last); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
722 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
723 ngx_debug_point(); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
724 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
725 return NGX_ERROR; |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
726 } |
473 | 727 |
728 size += ngx_buf_size(in->buf); | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
403
diff
changeset
|
729 |
1962 | 730 ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0, |
1226 | 731 "chain writer buf fl:%d s:%uO", |
732 in->buf->flush, ngx_buf_size(in->buf)); | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
403
diff
changeset
|
733 |
501 | 734 cl = ngx_alloc_chain_link(ctx->pool); |
735 if (cl == NULL) { | |
461 | 736 return NGX_ERROR; |
737 } | |
501 | 738 |
461 | 739 cl->buf = in->buf; |
740 cl->next = NULL; | |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
741 *ctx->last = cl; |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
742 ctx->last = &cl->next; |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
743 } |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
744 |
1962 | 745 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
461 | 746 "chain writer in: %p", ctx->out); |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
747 |
473 | 748 for (cl = ctx->out; cl; cl = cl->next) { |
749 | |
750 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { | |
6045
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
751 |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
752 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
753 "zero size buf in chain writer " |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
754 "t:%d r:%d f:%d %p %p-%p %p %O-%O", |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
755 cl->buf->temporary, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
756 cl->buf->recycled, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
757 cl->buf->in_file, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
758 cl->buf->start, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
759 cl->buf->pos, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
760 cl->buf->last, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
761 cl->buf->file, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
762 cl->buf->file_pos, |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
763 cl->buf->file_last); |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
764 |
473 | 765 ngx_debug_point(); |
6045
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
766 |
6ab301ddf469
Output chain: zero size buf alerts in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6022
diff
changeset
|
767 continue; |
473 | 768 } |
7401
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
769 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
770 if (ngx_buf_size(cl->buf) < 0) { |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
771 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
772 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
773 "negative size buf in chain writer " |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
774 "t:%d r:%d f:%d %p %p-%p %p %O-%O", |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
775 cl->buf->temporary, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
776 cl->buf->recycled, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
777 cl->buf->in_file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
778 cl->buf->start, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
779 cl->buf->pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
780 cl->buf->last, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
781 cl->buf->file, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
782 cl->buf->file_pos, |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
783 cl->buf->file_last); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
784 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
785 ngx_debug_point(); |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
786 |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
787 return NGX_ERROR; |
a7ff19afbb14
Negative size buffers detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6819
diff
changeset
|
788 } |
473 | 789 |
790 size += ngx_buf_size(cl->buf); | |
791 } | |
792 | |
1962 | 793 if (size == 0 && !c->buffered) { |
473 | 794 return NGX_OK; |
795 } | |
796 | |
6046
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
797 chain = c->send_chain(c, ctx->out, ctx->limit); |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
798 |
1962 | 799 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
6046
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
800 "chain writer out: %p", chain); |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
801 |
6046
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
802 if (chain == NGX_CHAIN_ERROR) { |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
803 return NGX_ERROR; |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
804 } |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
805 |
6046
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
806 for (cl = ctx->out; cl && cl != chain; /* void */) { |
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
807 ln = cl; |
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
808 cl = cl->next; |
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
809 ngx_free_chain(ctx->pool, ln); |
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
810 } |
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
811 |
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
812 ctx->out = chain; |
66176dfea01e
Output chain: free chain links in ngx_chain_writer().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6045
diff
changeset
|
813 |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
814 if (ctx->out == NULL) { |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
815 ctx->last = &ctx->out; |
1211 | 816 |
1962 | 817 if (!c->buffered) { |
1215
fb3ff245c96b
an request body might not be passed to backend,
Igor Sysoev <igor@sysoev.ru>
parents:
1211
diff
changeset
|
818 return NGX_OK; |
fb3ff245c96b
an request body might not be passed to backend,
Igor Sysoev <igor@sysoev.ru>
parents:
1211
diff
changeset
|
819 } |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
820 } |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
821 |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
822 return NGX_AGAIN; |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
823 } |