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