2003-10-29 16:30:44 +08:00
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
|
|
|
#include <ngx_event.h>
|
|
|
|
#include <ngx_aio.h>
|
|
|
|
|
|
|
|
|
|
|
|
ssize_t ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
char *buf, *prev;
|
|
|
|
size_t size, total;
|
|
|
|
ngx_err_t err;
|
|
|
|
|
2003-10-30 16:51:06 +08:00
|
|
|
if (c->read->aio_eof) {
|
|
|
|
c->read->ready = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
total = 0;
|
|
|
|
|
|
|
|
while (cl) {
|
|
|
|
|
|
|
|
/* we can post the single aio operation only */
|
|
|
|
|
2003-10-30 16:51:06 +08:00
|
|
|
if (!c->read->ready) {
|
2003-10-29 16:30:44 +08:00
|
|
|
return total ? total : NGX_AGAIN;
|
|
|
|
}
|
|
|
|
|
2003-10-30 16:51:06 +08:00
|
|
|
buf = cl->hunk->last;
|
|
|
|
prev = cl->hunk->last;
|
2003-10-29 16:30:44 +08:00
|
|
|
size = 0;
|
|
|
|
|
|
|
|
/* coalesce the neighbouring hunks */
|
|
|
|
|
2003-10-30 16:51:06 +08:00
|
|
|
while (cl && prev == cl->hunk->last) {
|
|
|
|
size += cl->hunk->end - cl->hunk->last;
|
|
|
|
prev = cl->hunk->end;
|
2003-10-29 16:30:44 +08:00
|
|
|
cl = cl->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = ngx_aio_read(c, buf, size);
|
|
|
|
|
2004-02-12 01:08:49 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_read: %d", n);
|
2003-10-29 16:30:44 +08:00
|
|
|
|
|
|
|
if (n == NGX_AGAIN) {
|
|
|
|
return total ? total : NGX_AGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-10-30 16:51:06 +08:00
|
|
|
if (n == 0) {
|
|
|
|
c->read->aio_eof = 1;
|
|
|
|
if (total) {
|
|
|
|
c->read->eof = 0;
|
|
|
|
c->read->ready = 1;
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
if (n > 0) {
|
|
|
|
total += n;
|
|
|
|
}
|
|
|
|
|
2004-02-12 01:08:49 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
|
|
|
"aio_read total: %d", total);
|
2003-10-29 16:30:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return total ? total : NGX_AGAIN;
|
|
|
|
}
|