comparison src/core/ngx_output_chain.c @ 22:8b6db3bda591 NGINX_0_1_11

nginx 0.1.11 *) Feature: the worker_priority directive. *) Change: both tcp_nopush and tcp_nodelay directives affect the transferred response. *) Bugfix: nginx did not call initgroups(). Thanks to Andrew Sitnikov and Andrei Nigmatulin. *) Change: now the ngx_http_autoindex_module shows the file size in the bytes. *) Bugfix: the ngx_http_autoindex_module returned the 500 error if the broken symlink was in a directory. *) Bugfix: the files bigger than 4G could not be transferred using sendfile. *) Bugfix: if the backend was resolved to several backends and there was an error while the response waiting then process may got caught in an endless loop. *) Bugfix: the worker process may exit with the "unknown cycle" message when the /dev/poll method was used. *) Bugfix: "close() channel failed" errors. *) Bugfix: the autodetection of the "nobody" and "nogroup" groups. *) Bugfix: the send_lowat directive did not work on Linux. *) Bugfix: the segmentation fault occurred if there was no events section in configuration. *) Bugfix: nginx could not be built on OpenBSD. *) Bugfix: the double slashes in "://" in the URI were converted to ":/".
author Igor Sysoev <http://sysoev.ru>
date Thu, 02 Dec 2004 00:00:00 +0300
parents 6f8b0dc0f8dd
children 7ca9bdc82b3f
comparison
equal deleted inserted replaced
21:4eeb9cfef970 22:8b6db3bda591
26 26
27 27
28 ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) 28 ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)
29 { 29 {
30 int rc, last; 30 int rc, last;
31 size_t size, bsize; 31 off_t bsize;
32 size_t size;
32 ngx_chain_t *cl, *out, **last_out; 33 ngx_chain_t *cl, *out, **last_out;
33 34
34 if (ctx->in == NULL && ctx->busy == NULL) { 35 if (ctx->in == NULL && ctx->busy == NULL) {
35 36
36 /* 37 /*
79 if (bsize == 0 && !ngx_buf_special(ctx->in->buf)) { 80 if (bsize == 0 && !ngx_buf_special(ctx->in->buf)) {
80 81
81 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, 82 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0,
82 "zero size buf"); 83 "zero size buf");
83 84
85 ngx_debug_point();
86
84 ctx->in = ctx->in->next; 87 ctx->in = ctx->in->next;
85 88
86 continue; 89 continue;
87 } 90 }
88 91
116 119
117 size = ctx->bufs.size; 120 size = ctx->bufs.size;
118 121
119 if (ctx->in->buf->last_buf) { 122 if (ctx->in->buf->last_buf) {
120 123
121 if (bsize < ctx->bufs.size) { 124 if (bsize < (off_t) ctx->bufs.size) {
122 125
123 /* 126 /*
124 * allocate small temp buf for the small last buf 127 * allocate small temp buf for the small last buf
125 * or its small last part 128 * or its small last part
126 */ 129 */
127 130
128 size = bsize; 131 size = (size_t) bsize;
129 132
130 } else if (ctx->bufs.num == 1 133 } else if (ctx->bufs.num == 1
131 && (bsize < ctx->bufs.size 134 && (bsize < (off_t) (ctx->bufs.size
132 + (ctx->bufs.size >> 2))) 135 + (ctx->bufs.size >> 2))))
133 { 136 {
134 /* 137 /*
135 * allocate a temp buf that equals 138 * allocate a temp buf that equals
136 * to the last buf if the last buf size is lesser 139 * to the last buf if the last buf size is lesser
137 * than 1.25 of bufs.size and a temp buf is single 140 * than 1.25 of bufs.size and a temp buf is single
138 */ 141 */
139 142
140 size = bsize; 143 size = (size_t) bsize;
141 } 144 }
142 } 145 }
143 146
144 if (!(ctx->buf = ngx_create_temp_buf(ctx->pool, size))) { 147 if (!(ctx->buf = ngx_create_temp_buf(ctx->pool, size))) {
145 return NGX_ERROR; 148 return NGX_ERROR;
304 307
305 308
306 static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src, 309 static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src,
307 ngx_uint_t sendfile) 310 ngx_uint_t sendfile)
308 { 311 {
309 size_t size; 312 off_t size;
310 ssize_t n; 313 ssize_t n;
311 314
312 size = ngx_buf_size(src); 315 size = ngx_buf_size(src);
313 316
314 if (size > (size_t) (dst->end - dst->pos)) { 317 if (size > dst->end - dst->pos) {
315 size = dst->end - dst->pos; 318 size = dst->end - dst->pos;
316 } 319 }
317 320
318 #if (NGX_SENDFILE_LIMIT) 321 #if (NGX_SENDFILE_LIMIT)
319 322
322 } 325 }
323 326
324 #endif 327 #endif
325 328
326 if (ngx_buf_in_memory(src)) { 329 if (ngx_buf_in_memory(src)) {
327 ngx_memcpy(dst->pos, src->pos, size); 330 ngx_memcpy(dst->pos, src->pos, (size_t) size);
328 src->pos += size; 331 src->pos += (size_t) size;
329 dst->last += size; 332 dst->last += (size_t) size;
330 333
331 if (src->in_file) { 334 if (src->in_file) {
332 335
333 if (sendfile) { 336 if (sendfile) {
334 dst->in_file = 1; 337 dst->in_file = 1;
349 if (src->last_buf && src->pos == src->last) { 352 if (src->last_buf && src->pos == src->last) {
350 dst->last_buf = 1; 353 dst->last_buf = 1;
351 } 354 }
352 355
353 } else { 356 } else {
354 n = ngx_read_file(src->file, dst->pos, size, src->file_pos); 357 n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos);
355 358
356 if (n == NGX_ERROR) { 359 if (n == NGX_ERROR) {
357 return n; 360 return n;
358 } 361 }
359 362
361 if (n == NGX_AGAIN) { 364 if (n == NGX_AGAIN) {
362 return n; 365 return n;
363 } 366 }
364 #endif 367 #endif
365 368
366 if ((size_t) n != size) { 369 if (n != size) {
367 ngx_log_error(NGX_LOG_ALERT, src->file->log, 0, 370 ngx_log_error(NGX_LOG_ALERT, src->file->log, 0,
368 ngx_read_file_n " reads only %z of %uz from file", 371 ngx_read_file_n " reads only %z of %O from file",
369 n, size); 372 n, size);
370 if (n == 0) { 373 if (n == 0) {
371 return NGX_ERROR; 374 return NGX_ERROR;
372 } 375 }
373 } 376 }
397 400
398 ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in) 401 ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in)
399 { 402 {
400 ngx_chain_writer_ctx_t *ctx = data; 403 ngx_chain_writer_ctx_t *ctx = data;
401 404
405 off_t size;
402 ngx_chain_t *cl; 406 ngx_chain_t *cl;
403 407
404 408
405 for (/* void */; in; in = in->next) { 409 for (size = 0; in; in = in->next) {
410
411 #if 1
412 if (ngx_buf_size(in->buf) == 0 && !ngx_buf_special(in->buf)) {
413 ngx_debug_point();
414 }
415 #endif
416
417 size += ngx_buf_size(in->buf);
406 418
407 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, 419 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
408 "chain writer buf size: %uz", ngx_buf_size(in->buf)); 420 "chain writer buf size: %uz", ngx_buf_size(in->buf));
409 421
410 if (!(cl = ngx_alloc_chain_link(ctx->pool))) { 422 if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
417 } 429 }
418 430
419 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, 431 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
420 "chain writer in: %p", ctx->out); 432 "chain writer in: %p", ctx->out);
421 433
434 for (cl = ctx->out; cl; cl = cl->next) {
435
436 #if 1
437
438 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
439 ngx_debug_point();
440 }
441
442 #endif
443
444 size += ngx_buf_size(cl->buf);
445 }
446
447 if (size == 0) {
448 return NGX_OK;
449 }
450
422 ctx->out = ngx_send_chain(ctx->connection, ctx->out, ctx->limit); 451 ctx->out = ngx_send_chain(ctx->connection, ctx->out, ctx->limit);
423 452
424 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, 453 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
425 "chain writer out: %p", ctx->out); 454 "chain writer out: %p", ctx->out);
426 455