comparison src/http/ngx_http_file_cache.c @ 3294:04cfc09b8b8d

export aio presence knowledge to prevent using "aio sendfile", if aio does not present
author Igor Sysoev <igor@sysoev.ru>
date Thu, 05 Nov 2009 13:12:30 +0000
parents b495a56f1f24
children 479468a7d982
comparison
equal deleted inserted replaced
3293:8abb88374c6c 3294:04cfc09b8b8d
9 #include <ngx_http.h> 9 #include <ngx_http.h>
10 #include <ngx_md5.h> 10 #include <ngx_md5.h>
11 11
12 12
13 static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r, 13 static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r,
14 ngx_http_cache_t *c);
15 static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r,
14 ngx_http_cache_t *c); 16 ngx_http_cache_t *c);
15 #if (NGX_HAVE_FILE_AIO) 17 #if (NGX_HAVE_FILE_AIO)
16 static void ngx_http_cache_aio_event_handler(ngx_event_t *ev); 18 static void ngx_http_cache_aio_event_handler(ngx_event_t *ev);
17 #endif 19 #endif
18 static ngx_int_t ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, 20 static ngx_int_t ngx_http_file_cache_exists(ngx_http_file_cache_t *cache,
328 ngx_http_file_cache_t *cache; 330 ngx_http_file_cache_t *cache;
329 ngx_http_file_cache_header_t *h; 331 ngx_http_file_cache_header_t *h;
330 332
331 c = r->cache; 333 c = r->cache;
332 334
333 #if (NGX_HAVE_FILE_AIO) 335 n = ngx_http_file_cache_aio_read(r, c);
334 { 336
335 ngx_http_core_loc_conf_t *clcf; 337 if (n < 0) {
336
337 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
338
339 if (clcf->aio) {
340 n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
341
342 if (n == NGX_AGAIN) {
343 c->file.aio->data = r;
344 c->file.aio->handler = ngx_http_cache_aio_event_handler;
345
346 r->main->blocked++;
347 r->aio = 1;
348
349 return NGX_AGAIN;
350 }
351
352 } else {
353 n = ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
354 }
355 }
356 #else
357
358 n = ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
359
360 #endif
361
362 if (n == NGX_ERROR) {
363 return n; 338 return n;
364 } 339 }
365 340
366 if ((size_t) n <= c->header_start) { 341 if ((size_t) n <= c->header_start) {
367 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, 342 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
430 405
431 return NGX_OK; 406 return NGX_OK;
432 } 407 }
433 408
434 409
410 static ssize_t
411 ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c)
412 {
435 #if (NGX_HAVE_FILE_AIO) 413 #if (NGX_HAVE_FILE_AIO)
436 414 ssize_t n;
415 ngx_http_core_loc_conf_t *clcf;
416
417 if (!ngx_file_aio) {
418 goto noaio;
419 }
420
421 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
422
423 if (!clcf->aio) {
424 goto noaio;
425 }
426
427 n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
428
429 if (n != NGX_AGAIN) {
430 return n;
431 }
432
433 c->file.aio->data = r;
434 c->file.aio->handler = ngx_http_cache_aio_event_handler;
435
436 r->main->blocked++;
437 r->aio = 1;
438
439 return NGX_AGAIN;
440
441 noaio:
442
443 #endif
444
445 return ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
446 }
447
448
449 #if (NGX_HAVE_FILE_AIO)
437 450
438 static void 451 static void
439 ngx_http_cache_aio_event_handler(ngx_event_t *ev) 452 ngx_http_cache_aio_event_handler(ngx_event_t *ev)
440 { 453 {
441 ngx_event_aio_t *aio; 454 ngx_event_aio_t *aio;