Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-08-31 18:00:16 +0400
committerIgor Sysoev <igor@sysoev.ru>2009-08-31 18:00:16 +0400
commit9f9054df82b73c652cb414da9a10c9bc08185ac1 (patch)
tree94fb5f8007ca0df9ad1bb5f29fbc2814b0bc869d
parent06bb9d294a77f5448fb7a4a6da0d9349c636ef9f (diff)
retry aio sendfile if data are ready
-rw-r--r--src/http/ngx_http_copy_filter_module.c73
1 files changed, 41 insertions, 32 deletions
diff --git a/src/http/ngx_http_copy_filter_module.c b/src/http/ngx_http_copy_filter_module.c
index 4aefd8d7f..954717d8b 100644
--- a/src/http/ngx_http_copy_filter_module.c
+++ b/src/http/ngx_http_copy_filter_module.c
@@ -133,55 +133,64 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
r->request_output = 1;
}
- rc = ngx_output_chain(ctx, in);
+ for ( ;; ) {
+ rc = ngx_output_chain(ctx, in);
- if (ctx->in == NULL) {
- r->buffered &= ~NGX_HTTP_COPY_BUFFERED;
+ if (ctx->in == NULL) {
+ r->buffered &= ~NGX_HTTP_COPY_BUFFERED;
- } else {
- r->buffered |= NGX_HTTP_COPY_BUFFERED;
- }
+ } else {
+ r->buffered |= NGX_HTTP_COPY_BUFFERED;
+ }
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
+ "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
#if (NGX_HAVE_FILE_AIO && NGX_HAVE_AIO_SENDFILE)
- if (c->busy_sendfile) {
- off_t offset;
- ngx_file_t *file;
- ngx_http_ephemeral_t *e;
+ if (c->busy_sendfile) {
+ ssize_t n;
+ off_t offset;
+ ngx_file_t *file;
+ ngx_http_ephemeral_t *e;
- file = c->busy_sendfile->file;
- offset = c->busy_sendfile->file_pos;
+ file = c->busy_sendfile->file;
+ offset = c->busy_sendfile->file_pos;
- if (file->aio) {
- c->aio_sendfile = (offset != file->aio->last_offset);
- file->aio->last_offset = offset;
+ if (file->aio) {
+ c->aio_sendfile = (offset != file->aio->last_offset);
+ file->aio->last_offset = offset;
- if (c->aio_sendfile == 0) {
- ngx_log_error(NGX_LOG_ALERT, c->log, 0,
- "sendfile(%V) returned busy again", &file->name);
+ if (c->aio_sendfile == 0) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "sendfile(%V) returned busy again",
+ &file->name);
+ }
}
- }
- c->busy_sendfile = NULL;
- e = (ngx_http_ephemeral_t *) &r->uri_start;
+ c->busy_sendfile = NULL;
+ e = (ngx_http_ephemeral_t *) &r->uri_start;
- (void) ngx_file_aio_read(file, e->preload, 4, offset, r->pool);
+ n = ngx_file_aio_read(file, e->preload, 4, offset, r->pool);
- if (file->aio) {
- file->aio->data = r;
- file->aio->handler = ngx_http_copy_aio_sendfile_event_handler;
+ if (n > 0) {
+ continue;
+ }
- r->main->blocked++;
- r->aio = 1;
- }
- }
+ rc = n;
+
+ if (file->aio) {
+ file->aio->data = r;
+ file->aio->handler = ngx_http_copy_aio_sendfile_event_handler;
+ r->main->blocked++;
+ r->aio = 1;
+ }
+ }
#endif
- return rc;
+ return rc;
+ }
}