comparison src/os/unix/ngx_aio_read.c @ 93:738fe44c70d5

nginx-0.0.1-2003-05-21-17:28:21 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 21 May 2003 13:28:21 +0000
parents
children 6dfda4cf5200
comparison
equal deleted inserted replaced
92:19cc647ecd91 93:738fe44c70d5
1
2 #include <ngx_config.h>
3 #include <ngx_core.h>
4 #include <ngx_aio.h>
5
6 #if (HAVE_KQUEUE)
7 #include <ngx_kqueue_module.h>
8 #endif
9
10
11 /*
12 The data is ready - 3 syscalls:
13 aio_read(), aio_error(), aio_return()
14 The data is not ready - 4 (kqueue) or 5 syscalls:
15 aio_read(), aio_error(), notifiction,
16 aio_error(), aio_return()
17 aio_cancel(), aio_error()
18 */
19
20
21 ssize_t ngx_aio_read(ngx_connection_t *c, char *buf, size_t size)
22 {
23 int rc, first, canceled;
24 ngx_event_t *ev;
25
26 ev = c->read;
27
28 canceled = 0;
29
30 if (ev->timedout) {
31 ngx_set_socket_errno(NGX_ETIMEDOUT);
32 ngx_log_error(NGX_LOG_ERR, ev->log, 0, "aio_read() timed out");
33
34 rc = aio_cancel(c->fd, &ev->aiocb);
35 if (rc == -1) {
36 ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno,
37 "aio_cancel() failed");
38 return NGX_ERROR;
39 }
40
41 ngx_log_debug(ev->log, "aio_cancel: %d" _ rc);
42
43 canceled = 1;
44
45 ev->ready = 1;
46 }
47
48 first = 0;
49
50 if (!ev->ready) {
51 ngx_memzero(&ev->aiocb, sizeof(struct aiocb));
52
53 ev->aiocb.aio_fildes = c->fd;
54 ev->aiocb.aio_buf = buf;
55 ev->aiocb.aio_nbytes = size;
56
57 #if (HAVE_KQUEUE)
58 ev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
59 ev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
60 ev->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
61 #endif
62
63 if (aio_read(&ev->aiocb) == -1) {
64 ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno,
65 "aio_read() failed");
66 return NGX_ERROR;
67 }
68
69 ngx_log_debug(ev->log, "aio_read: OK");
70
71 ev->active = 1;
72 first = 1;
73 }
74
75 ev->ready = 0;
76
77 rc = aio_error(&ev->aiocb);
78 if (rc == -1) {
79 ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, "aio_error() failed");
80 return NGX_ERROR;
81 }
82
83 if (rc != 0) {
84 if (rc == NGX_EINPROGRESS) {
85 if (!first) {
86 ngx_log_error(NGX_LOG_CRIT, ev->log, rc,
87 "aio_read() still in progress");
88 }
89 return NGX_AGAIN;
90 }
91
92 if (rc == NGX_ECANCELED && canceled) {
93 return NGX_ERROR;
94 }
95
96 ngx_log_error(NGX_LOG_CRIT, ev->log, rc, "aio_read() failed");
97 return NGX_ERROR;
98 }
99
100 rc = aio_return(&ev->aiocb);
101 if (rc == -1) {
102 ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, "aio_return() failed");
103
104 return NGX_ERROR;
105 }
106
107 ngx_log_debug(ev->log, "aio_read: %d" _ rc);
108
109 return rc;
110 }