2003-02-27 04:21:43 +08:00
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
2003-10-13 00:49:16 +08:00
|
|
|
#include <ngx_event.h>
|
2003-05-21 21:28:21 +08:00
|
|
|
#include <ngx_aio.h>
|
2003-02-27 04:21:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|
|
|
{
|
2003-10-29 16:30:44 +08:00
|
|
|
int n;
|
2004-03-30 14:27:36 +08:00
|
|
|
u_char *buf, *prev;
|
2003-10-29 16:30:44 +08:00
|
|
|
off_t sent;
|
|
|
|
size_t size;
|
|
|
|
ngx_err_t err;
|
|
|
|
ngx_chain_t *cl;
|
2003-02-27 04:21:43 +08:00
|
|
|
|
|
|
|
sent = 0;
|
2003-10-29 16:30:44 +08:00
|
|
|
cl = in;
|
2003-02-27 04:21:43 +08:00
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
while (cl) {
|
|
|
|
|
|
|
|
if (cl->hunk->last - cl->hunk->pos == 0) {
|
|
|
|
cl = cl->next;
|
|
|
|
continue;
|
|
|
|
}
|
2003-10-13 00:49:16 +08:00
|
|
|
|
|
|
|
/* we can post the single aio operation only */
|
|
|
|
|
2003-10-30 16:51:06 +08:00
|
|
|
if (!c->write->ready) {
|
2003-10-29 16:30:44 +08:00
|
|
|
return cl;
|
2003-10-13 00:49:16 +08:00
|
|
|
}
|
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
buf = cl->hunk->pos;
|
|
|
|
prev = buf;
|
2003-02-27 04:21:43 +08:00
|
|
|
size = 0;
|
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
/* coalesce the neighbouring hunks */
|
2003-10-13 00:49:16 +08:00
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
while (cl && prev == cl->hunk->pos) {
|
|
|
|
size += cl->hunk->last - cl->hunk->pos;
|
|
|
|
prev = cl->hunk->last;
|
|
|
|
cl = cl->next;
|
2003-02-27 04:21:43 +08:00
|
|
|
}
|
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
n = ngx_aio_write(c, buf, size);
|
2003-02-27 04:21:43 +08:00
|
|
|
|
2004-02-12 01:08:49 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_write: %d", n);
|
2003-02-27 04:21:43 +08:00
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
if (n == NGX_ERROR) {
|
2003-10-13 00:49:16 +08:00
|
|
|
return NGX_CHAIN_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
if (n > 0) {
|
|
|
|
sent += n;
|
|
|
|
c->sent += n;
|
2003-02-27 04:21:43 +08:00
|
|
|
}
|
|
|
|
|
2004-02-12 01:08:49 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
|
|
|
"aio_write sent: " OFF_T_FMT, c->sent);
|
2003-02-27 04:21:43 +08:00
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
for (cl = in; cl; cl = cl->next) {
|
2003-02-27 04:21:43 +08:00
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
if (sent >= cl->hunk->last - cl->hunk->pos) {
|
|
|
|
sent -= cl->hunk->last - cl->hunk->pos;
|
|
|
|
cl->hunk->pos = cl->hunk->last;
|
2003-02-27 04:21:43 +08:00
|
|
|
|
2003-10-13 00:49:16 +08:00
|
|
|
continue;
|
|
|
|
}
|
2003-02-27 04:21:43 +08:00
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
cl->hunk->pos += sent;
|
2003-02-27 04:21:43 +08:00
|
|
|
|
2003-10-13 00:49:16 +08:00
|
|
|
break;
|
|
|
|
}
|
2003-02-27 04:21:43 +08:00
|
|
|
}
|
|
|
|
|
2003-10-29 16:30:44 +08:00
|
|
|
return cl;
|
2003-02-27 04:21:43 +08:00
|
|
|
}
|