diff options
author | Igor Sysoev <igor@sysoev.ru> | 2003-10-29 11:30:44 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2003-10-29 11:30:44 +0300 |
commit | b5faed2dc853ee7e6bda6004b16ceedc6c194641 (patch) | |
tree | 7812abde1b258c5e751ac6a85072c792549d55f5 /src/os/unix/ngx_aio_read.c | |
parent | ab0c4f5038cec58e23a023d8a1e01be038504e3e (diff) |
nginx-0.0.1-2003-10-29-11:30:44 import
Diffstat (limited to 'src/os/unix/ngx_aio_read.c')
-rw-r--r-- | src/os/unix/ngx_aio_read.c | 111 |
1 files changed, 49 insertions, 62 deletions
diff --git a/src/os/unix/ngx_aio_read.c b/src/os/unix/ngx_aio_read.c index bc5055860..cb498eb5d 100644 --- a/src/os/unix/ngx_aio_read.c +++ b/src/os/unix/ngx_aio_read.c @@ -10,102 +10,89 @@ /* - The data is ready - 3 syscalls: - aio_read(), aio_error(), aio_return() - The data is not ready - 4 (kqueue) or 5 syscalls: - aio_read(), aio_error(), notifiction, - aio_error(), aio_return() - aio_cancel(), aio_error() -*/ - + * the ready data requires 3 syscalls: + * aio_write(), aio_error(), aio_return() + * the non-ready data requires 4 (kqueue) or 5 syscalls: + * aio_write(), aio_error(), notifiction, aio_error(), aio_return() + * timeout, aio_cancel(), aio_error() + */ ssize_t ngx_aio_read(ngx_connection_t *c, char *buf, size_t size) { - int rc, first, canceled; - ngx_event_t *ev; - - ev = c->read; - - canceled = 0; - - if (ev->timedout) { - ngx_set_socket_errno(NGX_ETIMEDOUT); - ngx_log_error(NGX_LOG_ERR, ev->log, 0, "aio_read() timed out"); - - rc = aio_cancel(c->fd, &ev->aiocb); - if (rc == -1) { - ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, - "aio_cancel() failed"); - return NGX_ERROR; - } - - ngx_log_debug(ev->log, "aio_cancel: %d" _ rc); + int n; + ngx_event_t *rev; - canceled = 1; + rev = c->read; - ev->ready = 1; + if (rev->active) { + ngx_log_error(NGX_LOG_ALERT, rev->log, 0, "SECOND AIO POST"); + return NGX_AGAIN; } - first = 0; + if (!rev->aio_complete) { + ngx_memzero(&rev->aiocb, sizeof(struct aiocb)); - if (!ev->ready) { - ngx_memzero(&ev->aiocb, sizeof(struct aiocb)); - - ev->aiocb.aio_fildes = c->fd; - ev->aiocb.aio_buf = buf; - ev->aiocb.aio_nbytes = size; + rev->aiocb.aio_fildes = c->fd; + rev->aiocb.aio_buf = buf; + rev->aiocb.aio_nbytes = size; #if (HAVE_KQUEUE) - ev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue; - ev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT; - ev->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev; + rev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue; + rev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT; + rev->aiocb.aio_sigevent.sigev_value.sigval_ptr = rev; #endif - if (aio_read(&ev->aiocb) == -1) { - ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, + if (aio_read(&rev->aiocb) == -1) { + ngx_log_error(NGX_LOG_CRIT, rev->log, ngx_errno, "aio_read() failed"); + rev->error = 1; return NGX_ERROR; } - ngx_log_debug(ev->log, "aio_read: OK"); + ngx_log_debug(rev->log, "aio_read: OK"); - ev->active = 1; - first = 1; + rev->active = 1; } - ev->ready = 0; + rev->aio_complete = 0; - rc = aio_error(&ev->aiocb); - if (rc == -1) { - ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, "aio_error() failed"); + n = aio_error(&rev->aiocb); + if (n == -1) { + ngx_log_error(NGX_LOG_ALERT, rev->log, ngx_errno, "aio_error() failed"); + rev->error = 1; return NGX_ERROR; } - if (rc != 0) { - if (rc == NGX_EINPROGRESS) { - if (!first) { - ngx_log_error(NGX_LOG_CRIT, ev->log, rc, + if (n != 0) { + if (n == NGX_EINPROGRESS) { + if (!rev->active) { + ngx_log_error(NGX_LOG_ALERT, rev->log, n, "aio_read() still in progress"); } return NGX_AGAIN; } - if (rc == NGX_ECANCELED && canceled) { - return NGX_ERROR; - } - - ngx_log_error(NGX_LOG_CRIT, ev->log, rc, "aio_read() failed"); + ngx_log_error(NGX_LOG_CRIT, rev->log, n, "aio_read() failed"); + rev->error = 1; return NGX_ERROR; } - rc = aio_return(&ev->aiocb); - if (rc == -1) { - ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, "aio_return() failed"); + n = aio_return(&rev->aiocb); + if (n == -1) { + ngx_log_error(NGX_LOG_ALERT, rev->log, ngx_errno, + "aio_return() failed"); + rev->error = 1; return NGX_ERROR; } - ngx_log_debug(ev->log, "aio_read: %d" _ rc); + rev->active = 0; + + ngx_log_debug(rev->log, "aio_read: %d" _ n); + + if (n == 0) { + rev->eof = 1; + } - return rc; + return n; } |