static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r,
ngx_http_cache_t *c);
+static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r,
+ ngx_http_cache_t *c);
#if (NGX_HAVE_FILE_AIO)
static void ngx_http_cache_aio_event_handler(ngx_event_t *ev);
#endif
c = r->cache;
-#if (NGX_HAVE_FILE_AIO)
- {
- ngx_http_core_loc_conf_t *clcf;
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->aio) {
- n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
-
- if (n == NGX_AGAIN) {
- c->file.aio->data = r;
- c->file.aio->handler = ngx_http_cache_aio_event_handler;
-
- r->main->blocked++;
- r->aio = 1;
-
- return NGX_AGAIN;
- }
-
- } else {
- n = ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
- }
- }
-#else
-
- n = ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
+ n = ngx_http_file_cache_aio_read(r, c);
-#endif
-
- if (n == NGX_ERROR) {
+ if (n < 0) {
return n;
}
}
+static ssize_t
+ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c)
+{
#if (NGX_HAVE_FILE_AIO)
+ ssize_t n;
+ ngx_http_core_loc_conf_t *clcf;
+ if (!ngx_file_aio) {
+ goto noaio;
+ }
+
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+ if (!clcf->aio) {
+ goto noaio;
+ }
+
+ n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
+
+ if (n != NGX_AGAIN) {
+ return n;
+ }
+
+ c->file.aio->data = r;
+ c->file.aio->handler = ngx_http_cache_aio_event_handler;
+
+ r->main->blocked++;
+ r->aio = 1;
+
+ return NGX_AGAIN;
+
+noaio:
+
+#endif
+
+ return ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
+}
+
+
+#if (NGX_HAVE_FILE_AIO)
static void
ngx_http_cache_aio_event_handler(ngx_event_t *ev)
ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
ngx_pool_t *pool)
{
- int n;
- ngx_event_t *ev;
- ngx_event_aio_t *aio;
- static ngx_uint_t enosys = 0;
+ int n;
+ ngx_event_t *ev;
+ ngx_event_aio_t *aio;
- if (enosys) {
+ if (!ngx_file_aio) {
return ngx_read_file(file, buf, size, offset);
}
"aio_read(\"%V\") failed", &file->name);
if (n == NGX_ENOSYS) {
- enosys = 1;
+ ngx_file_aio = 0;
return ngx_read_file(file, buf, size, offset);
}
ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
ngx_pool_t *pool)
{
- long n;
- struct iocb *piocb[1];
- ngx_event_t *ev;
- ngx_event_aio_t *aio;
- static ngx_uint_t enosys = 0;
+ long n;
+ struct iocb *piocb[1];
+ ngx_event_t *ev;
+ ngx_event_aio_t *aio;
- if (enosys) {
+ if (!ngx_file_aio) {
return ngx_read_file(file, buf, size, offset);
}
"io_submit(\"%V\") failed", &file->name);
if (n == NGX_ENOSYS) {
- enosys = 1;
+ ngx_file_aio = 0;
return ngx_read_file(file, buf, size, offset);
}