Mercurial > hg > nginx
annotate src/core/ngx_output_chain.c @ 3513:e60e00b4fe0c
ngx_http_split_clients_module
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 14 May 2010 09:02:10 +0000 |
parents | b1b1775698d5 |
children | 76d252724db5 |
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 |
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
|
4 */ |
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 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #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
|
9 #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
|
10 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
469 | 12 #if 0 |
13 #define NGX_SENDFILE_LIMIT 4096 | |
14 #endif | |
15 | |
2316 | 16 /* |
17 * When DIRECTIO is enabled FreeBSD, Solaris, and MacOSX read directly | |
18 * to an application memory from a device if parameters are aligned | |
3053 | 19 * to device sector boundary (512 bytes). They fallback to usual read |
2316 | 20 * operation if the parameters are not aligned. |
21 * Linux allows DIRECTIO only if the parameters are aligned to a filesystem | |
22 * sector boundary, otherwise it returns EINVAL. The sector size is | |
23 * usually 512 bytes, however, on XFS it may be 4096 bytes. | |
24 */ | |
469 | 25 |
26 #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
|
27 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
467 | 29 static ngx_inline ngx_int_t |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
30 ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf); |
469 | 31 static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool, |
499 | 32 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
|
33 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
|
34 off_t bsize); |
2230 | 35 static ngx_int_t ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx, |
36 off_t bsize); | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
37 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
|
38 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 |
499 | 40 ngx_int_t |
41 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
|
42 { |
473 | 43 off_t bsize; |
597 | 44 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
|
45 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
|
46 |
455 | 47 if (ctx->in == NULL && ctx->busy == NULL) { |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
469 | 49 /* |
50 * the short path for the case when the ctx->in and ctx->busy chains | |
51 * are empty, the incoming chain is empty too or has the single buf | |
52 * that does not require the copy | |
53 */ | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 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
|
56 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
|
57 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
59 if (in->next == NULL |
469 | 60 #if (NGX_SENDFILE_LIMIT) |
61 && !(in->buf->in_file && in->buf->file_last > NGX_SENDFILE_LIMIT) | |
62 #endif | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
63 && 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
|
64 { |
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 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
69 /* 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
|
70 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
71 if (in) { |
469 | 72 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
|
73 return NGX_ERROR; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 } |
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 |
3119
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
77 #if (NGX_HAVE_FILE_AIO) |
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
78 if (ctx->aio) { |
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
79 return NGX_AGAIN; |
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
80 } |
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
81 #endif |
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
82 |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
162
diff
changeset
|
83 out = NULL; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 last_out = &out; |
499 | 85 last = NGX_NONE; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 for ( ;; ) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 while (ctx->in) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 |
320
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
91 /* |
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
|
92 * 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
|
93 * 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
|
94 */ |
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
95 |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
96 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
|
97 |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
98 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
|
99 |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
100 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
483 | 101 "zero size buf in output " |
102 "t:%d r:%d f:%d %p %p-%p %p %O-%O", | |
103 ctx->in->buf->temporary, | |
104 ctx->in->buf->recycled, | |
105 ctx->in->buf->in_file, | |
106 ctx->in->buf->start, | |
107 ctx->in->buf->pos, | |
108 ctx->in->buf->last, | |
109 ctx->in->buf->file, | |
110 ctx->in->buf->file_pos, | |
111 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
|
112 |
473 | 113 ngx_debug_point(); |
114 | |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
115 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
|
116 |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
117 continue; |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
118 } |
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
402
diff
changeset
|
119 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
120 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
|
121 |
320
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
122 /* 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
|
123 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 cl = ctx->in; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 ctx->in = cl->next; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 *last_out = cl; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 last_out = &cl->next; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 cl->next = NULL; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 continue; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 |
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
|
134 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
|
135 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
136 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
|
137 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
138 if (rc == NGX_ERROR) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
139 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
140 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
141 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
142 if (rc != NGX_OK) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
143 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
144 if (ctx->free) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
145 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
146 /* 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
|
147 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
148 cl = ctx->free; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
149 ctx->buf = cl->buf; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
150 ctx->free = cl->next; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
151 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
152 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
|
153 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
154 } else if (out || ctx->allocated == ctx->bufs.num) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
155 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
156 break; |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
320
diff
changeset
|
157 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
158 } 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
|
159 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
160 } |
160
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 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
164 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
|
165 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 if (rc == NGX_ERROR) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 if (rc == NGX_AGAIN) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 if (out) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 break; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 } |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
174 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 |
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
|
178 /* 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
|
179 |
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
|
180 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
|
181 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
|
182 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 |
501 | 184 cl = ngx_alloc_chain_link(ctx->pool); |
185 if (cl == NULL) { | |
461 | 186 return NGX_ERROR; |
187 } | |
501 | 188 |
461 | 189 cl->buf = ctx->buf; |
190 cl->next = NULL; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
191 *last_out = cl; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 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
|
193 ctx->buf = NULL; |
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 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 if (out == NULL && last != NGX_NONE) { |
509 | 197 |
198 if (ctx->in) { | |
199 return NGX_AGAIN; | |
200 } | |
201 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 return last; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
203 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
204 |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
205 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
|
206 |
569 | 207 if (last == NGX_ERROR || last == NGX_DONE) { |
208 return last; | |
209 } | |
210 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 ngx_chain_update_chains(&ctx->free, &ctx->busy, &out, ctx->tag); |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
212 last_out = &out; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
213 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
214 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
215 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
216 |
467 | 217 static ngx_inline ngx_int_t |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
218 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
|
219 { |
469 | 220 ngx_uint_t sendfile; |
221 | |
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 if (ngx_buf_special(buf)) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
223 return 1; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
224 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
225 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
226 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
|
227 return 0; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
229 |
469 | 230 sendfile = ctx->sendfile; |
231 | |
232 #if (NGX_SENDFILE_LIMIT) | |
233 | |
234 if (buf->in_file && buf->file_pos >= NGX_SENDFILE_LIMIT) { | |
235 sendfile = 0; | |
236 } | |
237 | |
238 #endif | |
239 | |
240 if (!sendfile) { | |
455 | 241 |
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
|
242 if (!ngx_buf_in_memory(buf)) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
243 return 0; |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
167
diff
changeset
|
244 } |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
167
diff
changeset
|
245 |
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
|
246 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
|
247 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
248 |
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
|
249 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
|
250 return 0; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
251 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
252 |
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
|
253 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
|
254 return 0; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
256 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
257 return 1; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
258 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
259 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
260 |
499 | 261 static ngx_int_t |
262 ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, | |
263 ngx_chain_t *in) | |
469 | 264 { |
265 ngx_chain_t *cl, **ll; | |
266 #if (NGX_SENDFILE_LIMIT) | |
267 ngx_buf_t *b, *buf; | |
268 #endif | |
269 | |
270 ll = chain; | |
271 | |
272 for (cl = *chain; cl; cl = cl->next) { | |
273 ll = &cl->next; | |
274 } | |
275 | |
276 while (in) { | |
277 | |
501 | 278 cl = ngx_alloc_chain_link(pool); |
279 if (cl == NULL) { | |
469 | 280 return NGX_ERROR; |
281 } | |
282 | |
283 #if (NGX_SENDFILE_LIMIT) | |
284 | |
285 buf = in->buf; | |
286 | |
287 if (buf->in_file | |
288 && buf->file_pos < NGX_SENDFILE_LIMIT | |
289 && buf->file_last > NGX_SENDFILE_LIMIT) | |
290 { | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
291 /* 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
|
292 |
501 | 293 b = ngx_calloc_buf(pool); |
294 if (b == NULL) { | |
469 | 295 return NGX_ERROR; |
296 } | |
297 | |
298 ngx_memcpy(b, buf, sizeof(ngx_buf_t)); | |
299 | |
300 if (ngx_buf_in_memory(buf)) { | |
301 buf->pos += (ssize_t) (NGX_SENDFILE_LIMIT - buf->file_pos); | |
302 b->last = buf->pos; | |
303 } | |
304 | |
305 buf->file_pos = NGX_SENDFILE_LIMIT; | |
306 b->file_last = NGX_SENDFILE_LIMIT; | |
307 | |
308 cl->buf = b; | |
309 | |
310 } else { | |
311 cl->buf = buf; | |
312 in = in->next; | |
313 } | |
314 | |
315 #else | |
316 cl->buf = in->buf; | |
317 in = in->next; | |
318 | |
319 #endif | |
320 | |
2910
dc01b26f8de8
leave chain in consistent state on errors
Igor Sysoev <igor@sysoev.ru>
parents:
2899
diff
changeset
|
321 cl->next = NULL; |
469 | 322 *ll = cl; |
323 ll = &cl->next; | |
324 } | |
325 | |
326 return NGX_OK; | |
327 } | |
328 | |
329 | |
499 | 330 static ngx_int_t |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
331 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
|
332 { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
333 size_t size; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
334 ngx_buf_t *in; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
335 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
336 in = ctx->in->buf; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
337 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
338 if (in->file == NULL || !in->file->directio) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
339 return NGX_DECLINED; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
340 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
341 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
342 ctx->directio = 1; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
343 |
3053 | 344 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
|
345 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
346 if (size == 0) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
347 |
2240
a83218b65245
fix building on 64-bit platforms, introduced in r2232
Igor Sysoev <igor@sysoev.ru>
parents:
2231
diff
changeset
|
348 if (bsize >= (off_t) ctx->bufs.size) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
349 return NGX_DECLINED; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
350 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
351 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
352 size = (size_t) bsize; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
353 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
354 } else { |
3057
5ea5a90000d5
fix build by msvc, introduced in r3054
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
355 size = (size_t) ctx->alignment - size; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
356 |
2240
a83218b65245
fix building on 64-bit platforms, introduced in r2232
Igor Sysoev <igor@sysoev.ru>
parents:
2231
diff
changeset
|
357 if ((off_t) size > bsize) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
358 size = (size_t) bsize; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
359 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
360 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
361 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
362 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
|
363 if (ctx->buf == NULL) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
364 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
365 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
366 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
367 /* |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
368 * 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
|
369 * to reuse the buf via ctx->free list |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
370 */ |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
371 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
372 #if (NGX_HAVE_ALIGNED_DIRECTIO) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
373 ctx->unaligned = 1; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
374 #endif |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
375 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
376 return NGX_OK; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
377 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
378 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
379 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
380 static ngx_int_t |
2230 | 381 ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx, off_t bsize) |
382 { | |
383 size_t size; | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
384 ngx_buf_t *b, *in; |
2230 | 385 ngx_uint_t recycled; |
386 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
387 in = ctx->in->buf; |
2230 | 388 size = ctx->bufs.size; |
389 recycled = 1; | |
390 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
391 if (in->last_in_chain) { |
2230 | 392 |
393 if (bsize < (off_t) size) { | |
394 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
395 /* |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
396 * 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
|
397 * or its small last part |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
398 */ |
2230 | 399 |
400 size = (size_t) bsize; | |
401 recycled = 0; | |
402 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
403 } else if (!ctx->directio |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
404 && ctx->bufs.num == 1 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
405 && (bsize < (off_t) (size + size / 4))) |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
406 { |
2230 | 407 /* |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
408 * 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
|
409 * 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
|
410 * than 1.25 of bufs.size and the temp buf is single |
2230 | 411 */ |
412 | |
413 size = (size_t) bsize; | |
414 recycled = 0; | |
415 } | |
416 } | |
417 | |
418 b = ngx_calloc_buf(ctx->pool); | |
419 if (b == NULL) { | |
420 return NGX_ERROR; | |
421 } | |
422 | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
423 if (ctx->directio) { |
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 * 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
|
427 * userland buffer direct usage conjunctly with directio |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
428 */ |
2230 | 429 |
3057
5ea5a90000d5
fix build by msvc, introduced in r3054
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
430 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
|
431 if (b->start == NULL) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
432 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
433 } |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
434 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
435 } else { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
436 b->start = ngx_palloc(ctx->pool, size); |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
437 if (b->start == NULL) { |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
438 return NGX_ERROR; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
439 } |
2230 | 440 } |
441 | |
442 b->pos = b->start; | |
443 b->last = b->start; | |
444 b->end = b->last + size; | |
445 b->temporary = 1; | |
446 b->tag = ctx->tag; | |
447 b->recycled = recycled; | |
448 | |
449 ctx->buf = b; | |
450 ctx->allocated++; | |
451 | |
452 return NGX_OK; | |
453 } | |
454 | |
455 | |
456 static ngx_int_t | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
457 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
|
458 { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
459 off_t size; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
460 ssize_t n; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
461 ngx_buf_t *src, *dst; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
462 ngx_uint_t sendfile; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
463 |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
464 src = ctx->in->buf; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
465 dst = ctx->buf; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
466 |
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
|
467 size = ngx_buf_size(src); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
468 |
473 | 469 if (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
|
470 size = dst->end - dst->pos; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
471 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
472 |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
473 sendfile = ctx->sendfile & !ctx->directio; |
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
474 |
469 | 475 #if (NGX_SENDFILE_LIMIT) |
476 | |
477 if (src->in_file && src->file_pos >= NGX_SENDFILE_LIMIT) { | |
478 sendfile = 0; | |
479 } | |
480 | |
481 #endif | |
482 | |
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
|
483 if (ngx_buf_in_memory(src)) { |
473 | 484 ngx_memcpy(dst->pos, src->pos, (size_t) size); |
485 src->pos += (size_t) size; | |
486 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
|
487 |
455 | 488 if (src->in_file) { |
489 | |
490 if (sendfile) { | |
491 dst->in_file = 1; | |
492 dst->file = src->file; | |
493 dst->file_pos = src->file_pos; | |
494 dst->file_last = src->file_pos + size; | |
495 | |
496 } else { | |
497 dst->in_file = 0; | |
498 } | |
499 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
500 src->file_pos += size; |
452 | 501 |
502 } else { | |
503 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
|
504 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
505 |
1227
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
506 if (src->pos == src->last) { |
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
507 dst->flush = src->flush; |
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
508 dst->last_buf = src->last_buf; |
2899
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2316
diff
changeset
|
509 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
|
510 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
511 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
512 } else { |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
513 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
514 #if (NGX_HAVE_ALIGNED_DIRECTIO) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
515 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
516 if (ctx->unaligned) { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3147
diff
changeset
|
517 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
|
518 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
|
519 ngx_directio_off_n " \"%s\" failed", |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
520 src->file->name.data); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
521 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
522 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
523 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
524 #endif |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
525 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
526 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
527 |
3119
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3057
diff
changeset
|
528 if (ctx->aio_handler) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
529 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
|
530 src->file_pos, ctx->pool); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
531 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
|
532 ctx->aio_handler(ctx, src->file); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
533 return NGX_AGAIN; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
534 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
535 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
536 } else { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
537 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
|
538 src->file_pos); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
539 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
540 #else |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
541 |
473 | 542 n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
543 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
544 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
2910
diff
changeset
|
545 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
546 #if (NGX_HAVE_ALIGNED_DIRECTIO) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
547 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
548 if (ctx->unaligned) { |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
549 ngx_err_t err; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
550 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
551 err = ngx_errno; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
552 |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3147
diff
changeset
|
553 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
|
554 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
|
555 ngx_directio_on_n " \"%s\" failed", |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
556 src->file->name.data); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
557 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
558 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
559 ngx_set_errno(err); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
560 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
561 ctx->unaligned = 0; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
562 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
563 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
564 #endif |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2245
diff
changeset
|
565 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
566 if (n == NGX_ERROR) { |
517 | 567 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
|
568 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
569 |
473 | 570 if (n != size) { |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2230
diff
changeset
|
571 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
|
572 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
|
573 n, size, src->file->name.data); |
3147
cbb1add4a6fe
fail if file size was changed
Igor Sysoev <igor@sysoev.ru>
parents:
3119
diff
changeset
|
574 return NGX_ERROR; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
575 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
576 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
577 dst->last += n; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
578 |
452 | 579 if (sendfile) { |
580 dst->in_file = 1; | |
581 dst->file = src->file; | |
582 dst->file_pos = src->file_pos; | |
455 | 583 dst->file_last = src->file_pos + n; |
452 | 584 |
585 } 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
|
586 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
|
587 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
588 |
455 | 589 src->file_pos += n; |
590 | |
1238 | 591 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
|
592 dst->flush = src->flush; |
3e40f3e4376c
inherit flush flag, this fixes https proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1226
diff
changeset
|
593 dst->last_buf = src->last_buf; |
2899
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2316
diff
changeset
|
594 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
|
595 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
596 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
597 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
598 return NGX_OK; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
599 } |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
600 |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
601 |
499 | 602 ngx_int_t |
603 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
|
604 { |
166
389d7ee9fa60
nginx-0.0.1-2003-10-30-11:51:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
605 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
|
606 |
1962 | 607 off_t size; |
608 ngx_chain_t *cl; | |
609 ngx_connection_t *c; | |
610 | |
611 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
|
612 |
473 | 613 for (size = 0; in; in = in->next) { |
614 | |
615 #if 1 | |
616 if (ngx_buf_size(in->buf) == 0 && !ngx_buf_special(in->buf)) { | |
617 ngx_debug_point(); | |
618 } | |
619 #endif | |
620 | |
621 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
|
622 |
1962 | 623 ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0, |
1226 | 624 "chain writer buf fl:%d s:%uO", |
625 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
|
626 |
501 | 627 cl = ngx_alloc_chain_link(ctx->pool); |
628 if (cl == NULL) { | |
461 | 629 return NGX_ERROR; |
630 } | |
501 | 631 |
461 | 632 cl->buf = in->buf; |
633 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
|
634 *ctx->last = cl; |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
635 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
|
636 } |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
637 |
1962 | 638 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
461 | 639 "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
|
640 |
473 | 641 for (cl = ctx->out; cl; cl = cl->next) { |
642 | |
643 #if 1 | |
644 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { | |
645 ngx_debug_point(); | |
646 } | |
647 | |
648 #endif | |
649 | |
650 size += ngx_buf_size(cl->buf); | |
651 } | |
652 | |
1962 | 653 if (size == 0 && !c->buffered) { |
473 | 654 return NGX_OK; |
655 } | |
656 | |
1962 | 657 ctx->out = 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
|
658 |
1962 | 659 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
461 | 660 "chain writer out: %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
|
661 |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
662 if (ctx->out == NGX_CHAIN_ERROR) { |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
663 return NGX_ERROR; |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
664 } |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
665 |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
666 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
|
667 ctx->last = &ctx->out; |
1211 | 668 |
1962 | 669 if (!c->buffered) { |
1215
fb3ff245c96b
an request body might not be passed to backend,
Igor Sysoev <igor@sysoev.ru>
parents:
1211
diff
changeset
|
670 return NGX_OK; |
fb3ff245c96b
an request body might not be passed to backend,
Igor Sysoev <igor@sysoev.ru>
parents:
1211
diff
changeset
|
671 } |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
672 } |
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 return NGX_AGAIN; |
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
675 } |