summaryrefslogtreecommitdiffhomepage
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/http')
-rw-r--r--src/http/ngx_http_copy_filter_module.c62
-rw-r--r--src/http/ngx_http_core_module.c20
-rw-r--r--src/http/ngx_http_core_module.h5
-rw-r--r--src/http/ngx_http_request.h3
4 files changed, 87 insertions, 3 deletions
diff --git a/src/http/ngx_http_copy_filter_module.c b/src/http/ngx_http_copy_filter_module.c
index 61c3cb231..f3d0f1161 100644
--- a/src/http/ngx_http_copy_filter_module.c
+++ b/src/http/ngx_http_copy_filter_module.c
@@ -18,6 +18,9 @@ typedef struct {
static void ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx,
ngx_file_t *file);
static void ngx_http_copy_aio_event_handler(ngx_event_t *ev);
+#if (NGX_HAVE_AIO_SENDFILE)
+static void ngx_http_copy_aio_sendfile_event_handler(ngx_event_t *ev);
+#endif
#endif
static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf);
@@ -121,6 +124,9 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
#if (NGX_HAVE_FILE_AIO)
if (clcf->aio) {
ctx->aio = ngx_http_copy_aio_handler;
+#if (NGX_HAVE_AIO_SENDFILE)
+ c->aio_sendfile = (clcf->aio == NGX_HTTP_AIO_SENDFILE);
+#endif
}
#endif
@@ -139,6 +145,42 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
+#if (NGX_HAVE_AIO_SENDFILE)
+
+ if (c->busy_sendfile) {
+ off_t offset;
+ ngx_file_t *file;
+ ngx_http_ephemeral_t *e;
+
+ 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 (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;
+
+ (void) 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;
+
+ r->main->blocked++;
+ r->aio = 1;
+ }
+ }
+
+#endif
+
return rc;
}
@@ -175,6 +217,26 @@ ngx_http_copy_aio_event_handler(ngx_event_t *ev)
r->connection->write->handler(r->connection->write);
}
+
+#if (NGX_HAVE_AIO_SENDFILE)
+
+static void
+ngx_http_copy_aio_sendfile_event_handler(ngx_event_t *ev)
+{
+ ngx_event_aio_t *aio;
+ ngx_http_request_t *r;
+
+ aio = ev->data;
+ r = aio->data;
+
+ r->main->blocked--;
+ r->aio = 0;
+ ev->complete = 0;
+
+ r->connection->write->handler(r->connection->write);
+}
+
+#endif
#endif
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index cd2d774e3..e8484ee45 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -104,6 +104,20 @@ static ngx_conf_enum_t ngx_http_core_request_body_in_file[] = {
};
+#if (NGX_HAVE_FILE_AIO)
+
+static ngx_conf_enum_t ngx_http_core_aio[] = {
+ { ngx_string("off"), NGX_HTTP_AIO_OFF },
+ { ngx_string("on"), NGX_HTTP_AIO_ON },
+#if (NGX_HAVE_AIO_SENDFILE)
+ { ngx_string("sendfile"), NGX_HTTP_AIO_SENDFILE },
+#endif
+ { ngx_null_string, 0 }
+};
+
+#endif
+
+
static ngx_conf_enum_t ngx_http_core_satisfy[] = {
{ ngx_string("all"), NGX_HTTP_SATISFY_ALL },
{ ngx_string("any"), NGX_HTTP_SATISFY_ANY },
@@ -386,11 +400,11 @@ static ngx_command_t ngx_http_core_commands[] = {
#if (NGX_HAVE_FILE_AIO)
{ ngx_string("aio"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_enum_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, aio),
- NULL },
+ &ngx_http_core_aio },
#endif
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 826b403d6..9946c4f33 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -24,6 +24,11 @@
#define NGX_HTTP_GZIP_PROXIED_ANY 0x0200
+#define NGX_HTTP_AIO_OFF 0
+#define NGX_HTTP_AIO_ON 1
+#define NGX_HTTP_AIO_SENDFILE 2
+
+
#define NGX_HTTP_SATISFY_ALL 0
#define NGX_HTTP_SATISFY_ANY 1
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 425737af0..2ca215377 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -546,6 +546,9 @@ struct ngx_http_request_s {
typedef struct {
ngx_http_posted_request_t terminal_posted_request;
+#if (NGX_HAVE_AIO_SENDFILE)
+ u_char preload[4];
+#endif
} ngx_http_ephemeral_t;