diff options
Diffstat (limited to 'src/os/unix')
| -rw-r--r-- | src/os/unix/ngx_aio_read.c | 26 | ||||
| -rw-r--r-- | src/os/unix/ngx_aio_read_chain.c | 26 | ||||
| -rw-r--r-- | src/os/unix/ngx_aio_write.c | 31 | ||||
| -rw-r--r-- | src/os/unix/ngx_aio_write_chain.c | 2 |
4 files changed, 61 insertions, 24 deletions
diff --git a/src/os/unix/ngx_aio_read.c b/src/os/unix/ngx_aio_read.c index cb498eb5d..28deac6d2 100644 --- a/src/os/unix/ngx_aio_read.c +++ b/src/os/unix/ngx_aio_read.c @@ -24,12 +24,15 @@ ssize_t ngx_aio_read(ngx_connection_t *c, char *buf, size_t size) rev = c->read; - if (rev->active) { + if (!rev->ready) { ngx_log_error(NGX_LOG_ALERT, rev->log, 0, "SECOND AIO POST"); return NGX_AGAIN; } - if (!rev->aio_complete) { + ngx_log_debug(rev->log, "rev->complete: %d" _ rev->complete); + ngx_log_debug(rev->log, "aio size: %d" _ size); + + if (!rev->complete) { ngx_memzero(&rev->aiocb, sizeof(struct aiocb)); rev->aiocb.aio_fildes = c->fd; @@ -49,12 +52,13 @@ ssize_t ngx_aio_read(ngx_connection_t *c, char *buf, size_t size) return NGX_ERROR; } - ngx_log_debug(rev->log, "aio_read: OK"); + ngx_log_debug(rev->log, "aio_read: #%d OK" _ c->fd); rev->active = 1; + rev->ready = 0; } - rev->aio_complete = 0; + rev->complete = 0; n = aio_error(&rev->aiocb); if (n == -1) { @@ -65,15 +69,17 @@ ssize_t ngx_aio_read(ngx_connection_t *c, char *buf, size_t size) if (n != 0) { if (n == NGX_EINPROGRESS) { - if (!rev->active) { + if (rev->ready) { ngx_log_error(NGX_LOG_ALERT, rev->log, n, "aio_read() still in progress"); + rev->ready = 0; } return NGX_AGAIN; } ngx_log_error(NGX_LOG_CRIT, rev->log, n, "aio_read() failed"); rev->error = 1; + rev->ready = 0; return NGX_ERROR; } @@ -83,16 +89,20 @@ ssize_t ngx_aio_read(ngx_connection_t *c, char *buf, size_t size) "aio_return() failed"); rev->error = 1; + rev->ready = 0; return NGX_ERROR; } - rev->active = 0; - - ngx_log_debug(rev->log, "aio_read: %d" _ n); + ngx_log_debug(rev->log, "aio_read: #%d %d" _ c->fd _ n); if (n == 0) { rev->eof = 1; + rev->ready = 0; + } else { + rev->ready = 1; } + rev->active = 0; + return n; } diff --git a/src/os/unix/ngx_aio_read_chain.c b/src/os/unix/ngx_aio_read_chain.c index 31f7c8573..9af48dd98 100644 --- a/src/os/unix/ngx_aio_read_chain.c +++ b/src/os/unix/ngx_aio_read_chain.c @@ -12,25 +12,30 @@ ssize_t ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl) size_t size, total; ngx_err_t err; + if (c->read->aio_eof) { + c->read->ready = 0; + return 0; + } + total = 0; while (cl) { /* we can post the single aio operation only */ - if (c->read->active) { + if (!c->read->ready) { return total ? total : NGX_AGAIN; } - buf = cl->hunk->pos; - prev = buf; + buf = cl->hunk->last; + prev = cl->hunk->last; size = 0; /* coalesce the neighbouring hunks */ - while (cl && prev == cl->hunk->pos) { - size += cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + while (cl && prev == cl->hunk->last) { + size += cl->hunk->end - cl->hunk->last; + prev = cl->hunk->end; cl = cl->next; } @@ -46,6 +51,15 @@ ssize_t ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl) return NGX_ERROR; } + if (n == 0) { + c->read->aio_eof = 1; + if (total) { + c->read->eof = 0; + c->read->ready = 1; + } + return total; + } + if (n > 0) { total += n; } diff --git a/src/os/unix/ngx_aio_write.c b/src/os/unix/ngx_aio_write.c index dcdecc5b6..dc2c876e5 100644 --- a/src/os/unix/ngx_aio_write.c +++ b/src/os/unix/ngx_aio_write.c @@ -24,13 +24,13 @@ ssize_t ngx_aio_write(ngx_connection_t *c, char *buf, size_t size) wev = c->write; - if (wev->active) { + if (!wev->ready) { return NGX_AGAIN; } -ngx_log_debug(wev->log, "aio: wev->aio_complete: %d" _ wev->aio_complete); +ngx_log_debug(wev->log, "aio: wev->complete: %d" _ wev->complete); - if (!wev->aio_complete) { + if (!wev->complete) { ngx_memzero(&wev->aiocb, sizeof(struct aiocb)); wev->aiocb.aio_fildes = c->fd; @@ -52,9 +52,10 @@ ngx_log_debug(wev->log, "aio: wev->aio_complete: %d" _ wev->aio_complete); ngx_log_debug(wev->log, "aio_write: OK"); wev->active = 1; + wev->ready = 0; } - wev->aio_complete = 0; + wev->complete = 0; n = aio_error(&wev->aiocb); if (n == -1) { @@ -65,15 +66,28 @@ ngx_log_debug(wev->log, "aio: wev->aio_complete: %d" _ wev->aio_complete); if (n != 0) { if (n == NGX_EINPROGRESS) { - if (!wev->active) { + if (wev->ready) { ngx_log_error(NGX_LOG_ALERT, wev->log, n, "aio_write() still in progress"); + wev->ready = 0; } return NGX_AGAIN; } ngx_log_error(NGX_LOG_CRIT, wev->log, n, "aio_write() failed"); wev->error = 1; + wev->ready = 0; + +#if 1 + n = aio_return(&wev->aiocb); + if (n == -1) { + ngx_log_error(NGX_LOG_ALERT, wev->log, ngx_errno, + "aio_return() failed"); + } + + ngx_log_error(NGX_LOG_CRIT, wev->log, n, "aio_return() %d", n); +#endif + return NGX_ERROR; } @@ -83,16 +97,15 @@ ngx_log_debug(wev->log, "aio: wev->aio_complete: %d" _ wev->aio_complete); "aio_return() failed"); wev->error = 1; + wev->ready = 0; return NGX_ERROR; } - wev->active = 0; ngx_log_debug(wev->log, "aio_write: %d" _ n); - if (n == 0) { - wev->eof = 1; - } + wev->active = 0; + wev->ready = 1; return n; } diff --git a/src/os/unix/ngx_aio_write_chain.c b/src/os/unix/ngx_aio_write_chain.c index ba24d808e..73150447f 100644 --- a/src/os/unix/ngx_aio_write_chain.c +++ b/src/os/unix/ngx_aio_write_chain.c @@ -26,7 +26,7 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in) /* we can post the single aio operation only */ - if (c->write->active) { + if (!c->write->ready) { return cl; } |
