0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_event.h>
|
|
10
|
|
11
|
18
|
12 #if 0
|
|
13 #define NGX_SENDFILE_LIMIT 4096
|
|
14 #endif
|
|
15
|
420
|
16 /*
|
|
17 * When DIRECTIO is enabled FreeBSD, Solaris, and MacOSX read directly
|
|
18 * to an application memory from a device if parameters are aligned
|
518
|
19 * to device sector boundary (512 bytes). They fallback to usual read
|
420
|
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 */
|
18
|
25
|
|
26 #define NGX_NONE 1
|
0
|
27
|
|
28
|
16
|
29 static ngx_inline ngx_int_t
|
406
|
30 ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf);
|
18
|
31 static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool,
|
48
|
32 ngx_chain_t **chain, ngx_chain_t *in);
|
406
|
33 static ngx_int_t ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx,
|
|
34 off_t bsize);
|
|
35 static ngx_int_t ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx,
|
|
36 off_t bsize);
|
|
37 static ngx_int_t ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx);
|
0
|
38
|
|
39
|
48
|
40 ngx_int_t
|
|
41 ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)
|
0
|
42 {
|
22
|
43 off_t bsize;
|
146
|
44 ngx_int_t rc, last;
|
0
|
45 ngx_chain_t *cl, *out, **last_out;
|
|
46
|
4
|
47 if (ctx->in == NULL && ctx->busy == NULL) {
|
0
|
48
|
18
|
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 */
|
0
|
54
|
|
55 if (in == NULL) {
|
|
56 return ctx->output_filter(ctx->filter_ctx, in);
|
|
57 }
|
|
58
|
|
59 if (in->next == NULL
|
18
|
60 #if (NGX_SENDFILE_LIMIT)
|
|
61 && !(in->buf->in_file && in->buf->file_last > NGX_SENDFILE_LIMIT)
|
|
62 #endif
|
406
|
63 && ngx_output_chain_as_is(ctx, in->buf))
|
0
|
64 {
|
|
65 return ctx->output_filter(ctx->filter_ctx, in);
|
|
66 }
|
|
67 }
|
|
68
|
|
69 /* add the incoming buf to the chain ctx->in */
|
|
70
|
|
71 if (in) {
|
18
|
72 if (ngx_output_chain_add_copy(ctx->pool, &ctx->in, in) == NGX_ERROR) {
|
0
|
73 return NGX_ERROR;
|
|
74 }
|
|
75 }
|
|
76
|
|
77 out = NULL;
|
|
78 last_out = &out;
|
48
|
79 last = NGX_NONE;
|
0
|
80
|
|
81 for ( ;; ) {
|
|
82
|
602
|
83 #if (NGX_HAVE_FILE_AIO)
|
|
84 if (ctx->aio) {
|
|
85 return NGX_AGAIN;
|
|
86 }
|
|
87 #endif
|
|
88
|
0
|
89 while (ctx->in) {
|
|
90
|
|
91 /*
|
|
92 * cycle while there are the ctx->in bufs
|
406
|
93 * and there are the free output bufs to copy in
|
0
|
94 */
|
|
95
|
|
96 bsize = ngx_buf_size(ctx->in->buf);
|
|
97
|
|
98 if (bsize == 0 && !ngx_buf_special(ctx->in->buf)) {
|
|
99
|
|
100 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0,
|
32
|
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);
|
0
|
112
|
22
|
113 ngx_debug_point();
|
|
114
|
0
|
115 ctx->in = ctx->in->next;
|
|
116
|
|
117 continue;
|
|
118 }
|
|
119
|
406
|
120 if (ngx_output_chain_as_is(ctx, ctx->in->buf)) {
|
0
|
121
|
|
122 /* move the chain link to the output chain */
|
|
123
|
|
124 cl = ctx->in;
|
|
125 ctx->in = cl->next;
|
|
126
|
|
127 *last_out = cl;
|
|
128 last_out = &cl->next;
|
|
129 cl->next = NULL;
|
|
130
|
|
131 continue;
|
|
132 }
|
|
133
|
|
134 if (ctx->buf == NULL) {
|
|
135
|
406
|
136 rc = ngx_output_chain_align_file_buf(ctx, bsize);
|
0
|
137
|
406
|
138 if (rc == NGX_ERROR) {
|
|
139 return NGX_ERROR;
|
|
140 }
|
0
|
141
|
406
|
142 if (rc != NGX_OK) {
|
0
|
143
|
406
|
144 if (ctx->free) {
|
0
|
145
|
406
|
146 /* get the free buf */
|
0
|
147
|
406
|
148 cl = ctx->free;
|
|
149 ctx->buf = cl->buf;
|
|
150 ctx->free = cl->next;
|
0
|
151
|
406
|
152 ngx_free_chain(ctx->pool, cl);
|
0
|
153
|
406
|
154 } else if (out || ctx->allocated == ctx->bufs.num) {
|
0
|
155
|
406
|
156 break;
|
0
|
157
|
406
|
158 } else if (ngx_output_chain_get_buf(ctx, bsize) != NGX_OK) {
|
0
|
159 return NGX_ERROR;
|
|
160 }
|
|
161 }
|
|
162 }
|
|
163
|
406
|
164 rc = ngx_output_chain_copy_buf(ctx);
|
0
|
165
|
|
166 if (rc == NGX_ERROR) {
|
|
167 return rc;
|
|
168 }
|
|
169
|
|
170 if (rc == NGX_AGAIN) {
|
|
171 if (out) {
|
|
172 break;
|
|
173 }
|
|
174
|
|
175 return rc;
|
|
176 }
|
|
177
|
|
178 /* delete the completed buf from the ctx->in chain */
|
|
179
|
|
180 if (ngx_buf_size(ctx->in->buf) == 0) {
|
|
181 ctx->in = ctx->in->next;
|
|
182 }
|
|
183
|
50
|
184 cl = ngx_alloc_chain_link(ctx->pool);
|
|
185 if (cl == NULL) {
|
10
|
186 return NGX_ERROR;
|
|
187 }
|
50
|
188
|
10
|
189 cl->buf = ctx->buf;
|
|
190 cl->next = NULL;
|
0
|
191 *last_out = cl;
|
|
192 last_out = &cl->next;
|
|
193 ctx->buf = NULL;
|
|
194 }
|
|
195
|
|
196 if (out == NULL && last != NGX_NONE) {
|
58
|
197
|
|
198 if (ctx->in) {
|
|
199 return NGX_AGAIN;
|
|
200 }
|
|
201
|
0
|
202 return last;
|
|
203 }
|
|
204
|
|
205 last = ctx->output_filter(ctx->filter_ctx, out);
|
|
206
|
118
|
207 if (last == NGX_ERROR || last == NGX_DONE) {
|
|
208 return last;
|
|
209 }
|
|
210
|
640
|
211 ngx_chain_update_chains(ctx->pool, &ctx->free, &ctx->busy, &out,
|
|
212 ctx->tag);
|
0
|
213 last_out = &out;
|
|
214 }
|
|
215 }
|
|
216
|
|
217
|
16
|
218 static ngx_inline ngx_int_t
|
406
|
219 ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf)
|
0
|
220 {
|
18
|
221 ngx_uint_t sendfile;
|
|
222
|
0
|
223 if (ngx_buf_special(buf)) {
|
406
|
224 return 1;
|
|
225 }
|
|
226
|
|
227 if (buf->in_file && buf->file->directio) {
|
0
|
228 return 0;
|
|
229 }
|
|
230
|
18
|
231 sendfile = ctx->sendfile;
|
|
232
|
|
233 #if (NGX_SENDFILE_LIMIT)
|
|
234
|
|
235 if (buf->in_file && buf->file_pos >= NGX_SENDFILE_LIMIT) {
|
|
236 sendfile = 0;
|
|
237 }
|
|
238
|
|
239 #endif
|
|
240
|
|
241 if (!sendfile) {
|
4
|
242
|
0
|
243 if (!ngx_buf_in_memory(buf)) {
|
406
|
244 return 0;
|
0
|
245 }
|
|
246
|
|
247 buf->in_file = 0;
|
|
248 }
|
|
249
|
|
250 if (ctx->need_in_memory && !ngx_buf_in_memory(buf)) {
|
406
|
251 return 0;
|
0
|
252 }
|
|
253
|
|
254 if (ctx->need_in_temp && (buf->memory || buf->mmap)) {
|
406
|
255 return 0;
|
0
|
256 }
|
|
257
|
406
|
258 return 1;
|
0
|
259 }
|
|
260
|
|
261
|
48
|
262 static ngx_int_t
|
|
263 ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
|
|
264 ngx_chain_t *in)
|
18
|
265 {
|
|
266 ngx_chain_t *cl, **ll;
|
|
267 #if (NGX_SENDFILE_LIMIT)
|
|
268 ngx_buf_t *b, *buf;
|
|
269 #endif
|
|
270
|
|
271 ll = chain;
|
|
272
|
|
273 for (cl = *chain; cl; cl = cl->next) {
|
|
274 ll = &cl->next;
|
|
275 }
|
|
276
|
|
277 while (in) {
|
|
278
|
50
|
279 cl = ngx_alloc_chain_link(pool);
|
|
280 if (cl == NULL) {
|
18
|
281 return NGX_ERROR;
|
|
282 }
|
|
283
|
|
284 #if (NGX_SENDFILE_LIMIT)
|
|
285
|
|
286 buf = in->buf;
|
|
287
|
|
288 if (buf->in_file
|
|
289 && buf->file_pos < NGX_SENDFILE_LIMIT
|
|
290 && buf->file_last > NGX_SENDFILE_LIMIT)
|
|
291 {
|
406
|
292 /* split a file buf on two bufs by the sendfile limit */
|
|
293
|
50
|
294 b = ngx_calloc_buf(pool);
|
|
295 if (b == NULL) {
|
18
|
296 return NGX_ERROR;
|
|
297 }
|
|
298
|
|
299 ngx_memcpy(b, buf, sizeof(ngx_buf_t));
|
|
300
|
|
301 if (ngx_buf_in_memory(buf)) {
|
|
302 buf->pos += (ssize_t) (NGX_SENDFILE_LIMIT - buf->file_pos);
|
|
303 b->last = buf->pos;
|
|
304 }
|
|
305
|
|
306 buf->file_pos = NGX_SENDFILE_LIMIT;
|
|
307 b->file_last = NGX_SENDFILE_LIMIT;
|
|
308
|
|
309 cl->buf = b;
|
|
310
|
|
311 } else {
|
|
312 cl->buf = buf;
|
|
313 in = in->next;
|
|
314 }
|
|
315
|
|
316 #else
|
|
317 cl->buf = in->buf;
|
|
318 in = in->next;
|
|
319
|
|
320 #endif
|
|
321
|
496
|
322 cl->next = NULL;
|
18
|
323 *ll = cl;
|
|
324 ll = &cl->next;
|
|
325 }
|
|
326
|
|
327 return NGX_OK;
|
|
328 }
|
|
329
|
|
330
|
48
|
331 static ngx_int_t
|
406
|
332 ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx, off_t bsize)
|
|
333 {
|
|
334 size_t size;
|
|
335 ngx_buf_t *in;
|
|
336
|
|
337 in = ctx->in->buf;
|
|
338
|
|
339 if (in->file == NULL || !in->file->directio) {
|
|
340 return NGX_DECLINED;
|
|
341 }
|
|
342
|
|
343 ctx->directio = 1;
|
|
344
|
518
|
345 size = (size_t) (in->file_pos - (in->file_pos & ~(ctx->alignment - 1)));
|
406
|
346
|
|
347 if (size == 0) {
|
|
348
|
408
|
349 if (bsize >= (off_t) ctx->bufs.size) {
|
406
|
350 return NGX_DECLINED;
|
|
351 }
|
|
352
|
|
353 size = (size_t) bsize;
|
|
354
|
|
355 } else {
|
518
|
356 size = (size_t) ctx->alignment - size;
|
406
|
357
|
408
|
358 if ((off_t) size > bsize) {
|
406
|
359 size = (size_t) bsize;
|
|
360 }
|
|
361 }
|
|
362
|
|
363 ctx->buf = ngx_create_temp_buf(ctx->pool, size);
|
|
364 if (ctx->buf == NULL) {
|
|
365 return NGX_ERROR;
|
|
366 }
|
|
367
|
|
368 /*
|
|
369 * we do not set ctx->buf->tag, because we do not want
|
|
370 * to reuse the buf via ctx->free list
|
|
371 */
|
|
372
|
410
|
373 #if (NGX_HAVE_ALIGNED_DIRECTIO)
|
|
374 ctx->unaligned = 1;
|
|
375 #endif
|
|
376
|
406
|
377 return NGX_OK;
|
|
378 }
|
|
379
|
|
380
|
|
381 static ngx_int_t
|
|
382 ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx, off_t bsize)
|
0
|
383 {
|
406
|
384 size_t size;
|
|
385 ngx_buf_t *b, *in;
|
|
386 ngx_uint_t recycled;
|
|
387
|
|
388 in = ctx->in->buf;
|
|
389 size = ctx->bufs.size;
|
|
390 recycled = 1;
|
|
391
|
|
392 if (in->last_in_chain) {
|
|
393
|
|
394 if (bsize < (off_t) size) {
|
|
395
|
|
396 /*
|
|
397 * allocate a small temp buf for a small last buf
|
|
398 * or its small last part
|
|
399 */
|
|
400
|
|
401 size = (size_t) bsize;
|
|
402 recycled = 0;
|
|
403
|
|
404 } else if (!ctx->directio
|
|
405 && ctx->bufs.num == 1
|
|
406 && (bsize < (off_t) (size + size / 4)))
|
|
407 {
|
|
408 /*
|
|
409 * allocate a temp buf that equals to a last buf,
|
|
410 * if there is no directio, the last buf size is lesser
|
|
411 * than 1.25 of bufs.size and the temp buf is single
|
|
412 */
|
|
413
|
|
414 size = (size_t) bsize;
|
|
415 recycled = 0;
|
|
416 }
|
|
417 }
|
|
418
|
|
419 b = ngx_calloc_buf(ctx->pool);
|
|
420 if (b == NULL) {
|
|
421 return NGX_ERROR;
|
|
422 }
|
|
423
|
|
424 if (ctx->directio) {
|
|
425
|
|
426 /*
|
|
427 * allocate block aligned to a disk sector size to enable
|
|
428 * userland buffer direct usage conjunctly with directio
|
|
429 */
|
|
430
|
518
|
431 b->start = ngx_pmemalign(ctx->pool, size, (size_t) ctx->alignment);
|
406
|
432 if (b->start == NULL) {
|
|
433 return NGX_ERROR;
|
|
434 }
|
|
435
|
|
436 } else {
|
|
437 b->start = ngx_palloc(ctx->pool, size);
|
|
438 if (b->start == NULL) {
|
|
439 return NGX_ERROR;
|
|
440 }
|
|
441 }
|
|
442
|
|
443 b->pos = b->start;
|
|
444 b->last = b->start;
|
|
445 b->end = b->last + size;
|
|
446 b->temporary = 1;
|
|
447 b->tag = ctx->tag;
|
|
448 b->recycled = recycled;
|
|
449
|
|
450 ctx->buf = b;
|
|
451 ctx->allocated++;
|
|
452
|
|
453 return NGX_OK;
|
|
454 }
|
|
455
|
|
456
|
|
457 static ngx_int_t
|
|
458 ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx)
|
|
459 {
|
|
460 off_t size;
|
|
461 ssize_t n;
|
|
462 ngx_buf_t *src, *dst;
|
|
463 ngx_uint_t sendfile;
|
|
464
|
|
465 src = ctx->in->buf;
|
|
466 dst = ctx->buf;
|
0
|
467
|
|
468 size = ngx_buf_size(src);
|
570
|
469 size = ngx_min(size, dst->end - dst->pos);
|
0
|
470
|
406
|
471 sendfile = ctx->sendfile & !ctx->directio;
|
|
472
|
18
|
473 #if (NGX_SENDFILE_LIMIT)
|
|
474
|
|
475 if (src->in_file && src->file_pos >= NGX_SENDFILE_LIMIT) {
|
|
476 sendfile = 0;
|
|
477 }
|
|
478
|
|
479 #endif
|
|
480
|
0
|
481 if (ngx_buf_in_memory(src)) {
|
22
|
482 ngx_memcpy(dst->pos, src->pos, (size_t) size);
|
|
483 src->pos += (size_t) size;
|
|
484 dst->last += (size_t) size;
|
0
|
485
|
4
|
486 if (src->in_file) {
|
|
487
|
|
488 if (sendfile) {
|
|
489 dst->in_file = 1;
|
|
490 dst->file = src->file;
|
|
491 dst->file_pos = src->file_pos;
|
|
492 dst->file_last = src->file_pos + size;
|
|
493
|
|
494 } else {
|
|
495 dst->in_file = 0;
|
|
496 }
|
|
497
|
0
|
498 src->file_pos += size;
|
2
|
499
|
|
500 } else {
|
|
501 dst->in_file = 0;
|
0
|
502 }
|
|
503
|
306
|
504 if (src->pos == src->last) {
|
|
505 dst->flush = src->flush;
|
|
506 dst->last_buf = src->last_buf;
|
496
|
507 dst->last_in_chain = src->last_in_chain;
|
0
|
508 }
|
|
509
|
|
510 } else {
|
410
|
511
|
|
512 #if (NGX_HAVE_ALIGNED_DIRECTIO)
|
|
513
|
|
514 if (ctx->unaligned) {
|
530
|
515 if (ngx_directio_off(src->file->fd) == NGX_FILE_ERROR) {
|
410
|
516 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno,
|
|
517 ngx_directio_off_n " \"%s\" failed",
|
|
518 src->file->name.data);
|
|
519 }
|
|
520 }
|
|
521
|
|
522 #endif
|
|
523
|
518
|
524 #if (NGX_HAVE_FILE_AIO)
|
|
525
|
526
|
526 if (ctx->aio_handler) {
|
518
|
527 n = ngx_file_aio_read(src->file, dst->pos, (size_t) size,
|
|
528 src->file_pos, ctx->pool);
|
|
529 if (n == NGX_AGAIN) {
|
526
|
530 ctx->aio_handler(ctx, src->file);
|
518
|
531 return NGX_AGAIN;
|
|
532 }
|
|
533
|
|
534 } else {
|
|
535 n = ngx_read_file(src->file, dst->pos, (size_t) size,
|
|
536 src->file_pos);
|
|
537 }
|
|
538 #else
|
|
539
|
22
|
540 n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos);
|
0
|
541
|
518
|
542 #endif
|
|
543
|
410
|
544 #if (NGX_HAVE_ALIGNED_DIRECTIO)
|
|
545
|
|
546 if (ctx->unaligned) {
|
|
547 ngx_err_t err;
|
|
548
|
|
549 err = ngx_errno;
|
|
550
|
530
|
551 if (ngx_directio_on(src->file->fd) == NGX_FILE_ERROR) {
|
410
|
552 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno,
|
|
553 ngx_directio_on_n " \"%s\" failed",
|
|
554 src->file->name.data);
|
|
555 }
|
|
556
|
|
557 ngx_set_errno(err);
|
|
558
|
|
559 ctx->unaligned = 0;
|
|
560 }
|
|
561
|
|
562 #endif
|
|
563
|
0
|
564 if (n == NGX_ERROR) {
|
66
|
565 return (ngx_int_t) n;
|
0
|
566 }
|
|
567
|
22
|
568 if (n != size) {
|
406
|
569 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0,
|
410
|
570 ngx_read_file_n " read only %z of %O from \"%s\"",
|
|
571 n, size, src->file->name.data);
|
528
|
572 return NGX_ERROR;
|
0
|
573 }
|
|
574
|
|
575 dst->last += n;
|
|
576
|
2
|
577 if (sendfile) {
|
|
578 dst->in_file = 1;
|
|
579 dst->file = src->file;
|
|
580 dst->file_pos = src->file_pos;
|
4
|
581 dst->file_last = src->file_pos + n;
|
2
|
582
|
|
583 } else {
|
0
|
584 dst->in_file = 0;
|
|
585 }
|
|
586
|
4
|
587 src->file_pos += n;
|
|
588
|
308
|
589 if (src->file_pos == src->file_last) {
|
306
|
590 dst->flush = src->flush;
|
|
591 dst->last_buf = src->last_buf;
|
496
|
592 dst->last_in_chain = src->last_in_chain;
|
0
|
593 }
|
|
594 }
|
|
595
|
|
596 return NGX_OK;
|
|
597 }
|
|
598
|
|
599
|
48
|
600 ngx_int_t
|
|
601 ngx_chain_writer(void *data, ngx_chain_t *in)
|
0
|
602 {
|
|
603 ngx_chain_writer_ctx_t *ctx = data;
|
|
604
|
372
|
605 off_t size;
|
|
606 ngx_chain_t *cl;
|
|
607 ngx_connection_t *c;
|
|
608
|
|
609 c = ctx->connection;
|
0
|
610
|
22
|
611 for (size = 0; in; in = in->next) {
|
|
612
|
|
613 #if 1
|
|
614 if (ngx_buf_size(in->buf) == 0 && !ngx_buf_special(in->buf)) {
|
|
615 ngx_debug_point();
|
|
616 }
|
|
617 #endif
|
|
618
|
|
619 size += ngx_buf_size(in->buf);
|
0
|
620
|
372
|
621 ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0,
|
306
|
622 "chain writer buf fl:%d s:%uO",
|
|
623 in->buf->flush, ngx_buf_size(in->buf));
|
0
|
624
|
50
|
625 cl = ngx_alloc_chain_link(ctx->pool);
|
|
626 if (cl == NULL) {
|
10
|
627 return NGX_ERROR;
|
|
628 }
|
50
|
629
|
10
|
630 cl->buf = in->buf;
|
|
631 cl->next = NULL;
|
0
|
632 *ctx->last = cl;
|
|
633 ctx->last = &cl->next;
|
|
634 }
|
|
635
|
372
|
636 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
|
10
|
637 "chain writer in: %p", ctx->out);
|
0
|
638
|
22
|
639 for (cl = ctx->out; cl; cl = cl->next) {
|
|
640
|
|
641 #if 1
|
|
642 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
|
|
643 ngx_debug_point();
|
|
644 }
|
|
645
|
|
646 #endif
|
|
647
|
|
648 size += ngx_buf_size(cl->buf);
|
|
649 }
|
|
650
|
372
|
651 if (size == 0 && !c->buffered) {
|
22
|
652 return NGX_OK;
|
|
653 }
|
|
654
|
372
|
655 ctx->out = c->send_chain(c, ctx->out, ctx->limit);
|
0
|
656
|
372
|
657 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
|
10
|
658 "chain writer out: %p", ctx->out);
|
0
|
659
|
|
660 if (ctx->out == NGX_CHAIN_ERROR) {
|
|
661 return NGX_ERROR;
|
|
662 }
|
|
663
|
|
664 if (ctx->out == NULL) {
|
|
665 ctx->last = &ctx->out;
|
302
|
666
|
372
|
667 if (!c->buffered) {
|
304
|
668 return NGX_OK;
|
|
669 }
|
0
|
670 }
|
|
671
|
|
672 return NGX_AGAIN;
|
|
673 }
|