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;
|
2004-03-30 14:27:36 +08:00
|
|
|
u_char *buf, *prev;
|
2004-04-16 23:27:31 +08:00
|
|
|
size_t size;
|
|
|
|
ssize_t total;
|
2003-10-29 16:30:44 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-05-28 23:49:23 +08:00
|
|
|
buf = cl->buf->last;
|
|
|
|
prev = cl->buf->last;
|
2003-10-29 16:30:44 +08:00
|
|
|
size = 0;
|
|
|
|
|
2004-05-28 23:49:23 +08:00
|
|
|
/* coalesce the neighbouring bufs */
|
2003-10-29 16:30:44 +08:00
|
|
|
|
2004-05-28 23:49:23 +08:00
|
|
|
while (cl && prev == cl->buf->last) {
|
|
|
|
size += cl->buf->end - cl->buf->last;
|
|
|
|
prev = cl->buf->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;
|
|
|
|
}
|