comparison src/os/unix/ngx_aio_read.c @ 164:84036764e215

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