Mercurial > hg > nginx-vendor-1-0
comparison src/core/ngx_output_chain.c @ 518:86dad910eeb6 NGINX_0_8_11
nginx 0.8.11
*) Change: directive "gzip_disable msie6" enables gzipping for
MSIE 6.0 SV1.
*) Feature: file AIO support on FreeBSD and Linux.
*) Feature: the "directio_alignment" directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 28 Aug 2009 00:00:00 +0400 |
parents | f39b9e29530d |
children | 0161f3197817 |
comparison
equal
deleted
inserted
replaced
517:15b5cddc5190 | 518:86dad910eeb6 |
---|---|
14 #endif | 14 #endif |
15 | 15 |
16 /* | 16 /* |
17 * When DIRECTIO is enabled FreeBSD, Solaris, and MacOSX read directly | 17 * When DIRECTIO is enabled FreeBSD, Solaris, and MacOSX read directly |
18 * to an application memory from a device if parameters are aligned | 18 * to an application memory from a device if parameters are aligned |
19 * to device sector boundary(512 bytes). They fallback to usual read | 19 * to device sector boundary (512 bytes). They fallback to usual read |
20 * operation if the parameters are not aligned. | 20 * operation if the parameters are not aligned. |
21 * Linux allows DIRECTIO only if the parameters are aligned to a filesystem | 21 * Linux allows DIRECTIO only if the parameters are aligned to a filesystem |
22 * sector boundary, otherwise it returns EINVAL. The sector size is | 22 * sector boundary, otherwise it returns EINVAL. The sector size is |
23 * usually 512 bytes, however, on XFS it may be 4096 bytes. | 23 * usually 512 bytes, however, on XFS it may be 4096 bytes. |
24 */ | 24 */ |
25 #define NGX_DIRECTIO_BLOCK 4096 | |
26 | |
27 | 25 |
28 #define NGX_NONE 1 | 26 #define NGX_NONE 1 |
29 | 27 |
30 | 28 |
31 static ngx_inline ngx_int_t | 29 static ngx_inline ngx_int_t |
335 return NGX_DECLINED; | 333 return NGX_DECLINED; |
336 } | 334 } |
337 | 335 |
338 ctx->directio = 1; | 336 ctx->directio = 1; |
339 | 337 |
340 size = (size_t) (in->file_pos - (in->file_pos & ~(NGX_DIRECTIO_BLOCK - 1))); | 338 size = (size_t) (in->file_pos - (in->file_pos & ~(ctx->alignment - 1))); |
341 | 339 |
342 if (size == 0) { | 340 if (size == 0) { |
343 | 341 |
344 if (bsize >= (off_t) ctx->bufs.size) { | 342 if (bsize >= (off_t) ctx->bufs.size) { |
345 return NGX_DECLINED; | 343 return NGX_DECLINED; |
346 } | 344 } |
347 | 345 |
348 size = (size_t) bsize; | 346 size = (size_t) bsize; |
349 | 347 |
350 } else { | 348 } else { |
351 size = NGX_DIRECTIO_BLOCK - size; | 349 size = (size_t) ctx->alignment - size; |
352 | 350 |
353 if ((off_t) size > bsize) { | 351 if ((off_t) size > bsize) { |
354 size = (size_t) bsize; | 352 size = (size_t) bsize; |
355 } | 353 } |
356 } | 354 } |
421 /* | 419 /* |
422 * allocate block aligned to a disk sector size to enable | 420 * allocate block aligned to a disk sector size to enable |
423 * userland buffer direct usage conjunctly with directio | 421 * userland buffer direct usage conjunctly with directio |
424 */ | 422 */ |
425 | 423 |
426 b->start = ngx_pmemalign(ctx->pool, size, NGX_DIRECTIO_BLOCK); | 424 b->start = ngx_pmemalign(ctx->pool, size, (size_t) ctx->alignment); |
427 if (b->start == NULL) { | 425 if (b->start == NULL) { |
428 return NGX_ERROR; | 426 return NGX_ERROR; |
429 } | 427 } |
430 | 428 |
431 } else { | 429 } else { |
517 } | 515 } |
518 } | 516 } |
519 | 517 |
520 #endif | 518 #endif |
521 | 519 |
520 #if (NGX_HAVE_FILE_AIO) | |
521 | |
522 if (ctx->aio) { | |
523 n = ngx_file_aio_read(src->file, dst->pos, (size_t) size, | |
524 src->file_pos, ctx->pool); | |
525 if (n == NGX_AGAIN) { | |
526 ctx->aio(ctx, src->file); | |
527 return NGX_AGAIN; | |
528 } | |
529 | |
530 } else { | |
531 n = ngx_read_file(src->file, dst->pos, (size_t) size, | |
532 src->file_pos); | |
533 } | |
534 #else | |
535 | |
522 n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos); | 536 n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos); |
537 | |
538 #endif | |
523 | 539 |
524 #if (NGX_HAVE_ALIGNED_DIRECTIO) | 540 #if (NGX_HAVE_ALIGNED_DIRECTIO) |
525 | 541 |
526 if (ctx->unaligned) { | 542 if (ctx->unaligned) { |
527 ngx_err_t err; | 543 ngx_err_t err; |
542 #endif | 558 #endif |
543 | 559 |
544 if (n == NGX_ERROR) { | 560 if (n == NGX_ERROR) { |
545 return (ngx_int_t) n; | 561 return (ngx_int_t) n; |
546 } | 562 } |
547 | |
548 #if (NGX_FILE_AIO_READ) | |
549 if (n == NGX_AGAIN) { | |
550 return (ngx_int_t) n; | |
551 } | |
552 #endif | |
553 | 563 |
554 if (n != size) { | 564 if (n != size) { |
555 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, | 565 ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0, |
556 ngx_read_file_n " read only %z of %O from \"%s\"", | 566 ngx_read_file_n " read only %z of %O from \"%s\"", |
557 n, size, src->file->name.data); | 567 n, size, src->file->name.data); |