nginx/src/os/unix/ngx_aio_write_chain.c

75 lines
1.5 KiB
C
Raw Normal View History

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)
{
int rc;
char *buf, *prev;
off_t sent;
size_t size;
ngx_err_t err;
ngx_chain_t *ce;
sent = 0;
ce = in;
while (ce) {
2003-10-13 00:49:16 +08:00
/* we can post the single aio operation only */
if (c->write->active) {
return ce;
}
2003-05-21 21:28:21 +08:00
buf = prev = ce->hunk->pos;
2003-02-27 04:21:43 +08:00
size = 0;
/* coalesce the neighbouring chain entries */
2003-10-13 00:49:16 +08:00
2003-05-21 21:28:21 +08:00
while (ce && prev == ce->hunk->pos) {
size += ce->hunk->last - ce->hunk->pos;
prev = ce->hunk->last;
2003-02-27 04:21:43 +08:00
ce = ce->next;
}
2003-05-21 21:28:21 +08:00
rc = ngx_aio_write(c, buf, size);
2003-02-27 04:21:43 +08:00
2003-05-23 19:53:01 +08:00
#if (NGX_DEBUG_WRITE_CHAIN)
ngx_log_debug(c->log, "aio_write rc: %d" _ rc);
#endif
2003-02-27 04:21:43 +08:00
2003-10-13 00:49:16 +08:00
if (rc == NGX_ERROR) {
return NGX_CHAIN_ERROR;
}
2003-02-27 04:21:43 +08:00
if (rc > 0) {
sent += rc;
c->sent += rc;
}
#if (NGX_DEBUG_WRITE_CHAIN)
2003-10-13 00:49:16 +08:00
ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent);
2003-02-27 04:21:43 +08:00
#endif
2003-10-13 00:49:16 +08:00
for (ce = in; ce; ce = ce->next) {
2003-02-27 04:21:43 +08:00
2003-10-13 00:49:16 +08:00
if (sent >= ce->hunk->last - ce->hunk->pos) {
sent -= ce->hunk->last - ce->hunk->pos;
ce->hunk->pos = ce->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-13 00:49:16 +08:00
ce->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
}
return ce;
}