Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-05-21 17:28:21 +0400
committerIgor Sysoev <igor@sysoev.ru>2003-05-21 17:28:21 +0400
commitfa73aac7747c9d0a8575eb2beffcdab50171e006 (patch)
treed1e354f2e321b8f1c4e5518984759bab1ae05ddd /src/os/unix/ngx_aio_read.c
parent1c13c662f0ae8066d1d4849b4158d7459a4c7822 (diff)
nginx-0.0.1-2003-05-21-17:28:21 import
Diffstat (limited to 'src/os/unix/ngx_aio_read.c')
-rw-r--r--src/os/unix/ngx_aio_read.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/os/unix/ngx_aio_read.c b/src/os/unix/ngx_aio_read.c
new file mode 100644
index 000000000..4896af9ce
--- /dev/null
+++ b/src/os/unix/ngx_aio_read.c
@@ -0,0 +1,110 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_aio.h>
+
+#if (HAVE_KQUEUE)
+#include <ngx_kqueue_module.h>
+#endif
+
+
+/*
+ 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()
+*/
+
+
+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);
+
+ canceled = 1;
+
+ ev->ready = 1;
+ }
+
+ first = 0;
+
+ 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;
+
+#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;
+#endif
+
+ if (aio_read(&ev->aiocb) == -1) {
+ ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno,
+ "aio_read() failed");
+ return NGX_ERROR;
+ }
+
+ ngx_log_debug(ev->log, "aio_read: OK");
+
+ ev->active = 1;
+ first = 1;
+ }
+
+ ev->ready = 0;
+
+ rc = aio_error(&ev->aiocb);
+ if (rc == -1) {
+ ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, "aio_error() failed");
+ return NGX_ERROR;
+ }
+
+ if (rc != 0) {
+ if (rc == NGX_EINPROGRESS) {
+ if (!first) {
+ ngx_log_error(NGX_LOG_CRIT, ev->log, rc,
+ "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");
+ return NGX_ERROR;
+ }
+
+ rc = aio_return(&ev->aiocb);
+ if (rc == -1) {
+ ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, "aio_return() failed");
+
+ return NGX_ERROR;
+ }
+
+ ngx_log_debug(ev->log, "aio_read: %d" _ rc);
+
+ return rc;
+}