comparison src/os/unix/ngx_aio_write.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 ef8c87afcfc5
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_write(), 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_write(), 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 19
21 ssize_t ngx_aio_write(ngx_connection_t *c, char *buf, size_t size) 20 ssize_t ngx_aio_write(ngx_connection_t *c, char *buf, size_t size)
22 { 21 {
23 int rc, first, canceled; 22 int n;
24 ngx_event_t *ev; 23 ngx_event_t *wev;
25 24
26 ev = c->write; 25 wev = c->write;
27 26
28 canceled = 0; 27 if (wev->active) {
28 return NGX_AGAIN;
29 }
29 30
30 ngx_log_debug(ev->log, "aio: ev->ready: %d" _ ev->ready); 31 ngx_log_debug(wev->log, "aio: wev->aio_complete: %d" _ wev->aio_complete);
31 ngx_log_debug(ev->log, "aio: aiocb: %08x" _ &ev->aiocb);
32 32
33 #if 0 33 if (!wev->aio_complete) {
34 if (ev->timedout) { 34 ngx_memzero(&wev->aiocb, sizeof(struct aiocb));
35 ngx_set_socket_errno(NGX_ETIMEDOUT);
36 ngx_log_error(NGX_LOG_ERR, ev->log, 0, "aio_write() timed out");
37 35
38 rc = aio_cancel(c->fd, &ev->aiocb); 36 wev->aiocb.aio_fildes = c->fd;
39 if (rc == -1) { 37 wev->aiocb.aio_buf = buf;
40 ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, 38 wev->aiocb.aio_nbytes = size;
41 "aio_cancel() failed");
42 return NGX_ERROR;
43 }
44 39
45 ngx_log_debug(ev->log, "aio_cancel: %d" _ rc); 40 #if (HAVE_KQUEUE)
46 41 wev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
47 canceled = 1; 42 wev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
48 43 wev->aiocb.aio_sigevent.sigev_value.sigval_ptr = wev;
49 ev->ready = 1;
50 }
51 #endif 44 #endif
52 45
53 first = 0; 46 if (aio_write(&wev->aiocb) == -1) {
54 47 ngx_log_error(NGX_LOG_CRIT, wev->log, ngx_errno,
55 if (!ev->ready) {
56 ngx_memzero(&ev->aiocb, sizeof(struct aiocb));
57
58 ev->aiocb.aio_fildes = c->fd;
59 ev->aiocb.aio_buf = buf;
60 ev->aiocb.aio_nbytes = size;
61
62 #if (HAVE_KQUEUE)
63 ev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
64 ev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
65 ev->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
66 #endif
67
68 if (aio_write(&ev->aiocb) == -1) {
69 ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno,
70 "aio_write() failed"); 48 "aio_write() failed");
71 return NGX_ERROR; 49 return NGX_ERROR;
72 } 50 }
73 51
74 ngx_log_debug(ev->log, "aio_write: OK"); 52 ngx_log_debug(wev->log, "aio_write: OK");
75 53
76 ev->active = 1; 54 wev->active = 1;
77 first = 1;
78 } 55 }
79 56
80 ev->ready = 0; 57 wev->aio_complete = 0;
81 58
82 rc = aio_error(&ev->aiocb); 59 n = aio_error(&wev->aiocb);
83 if (rc == -1) { 60 if (n == -1) {
84 ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, "aio_error() failed"); 61 ngx_log_error(NGX_LOG_CRIT, wev->log, ngx_errno, "aio_error() failed");
62 wev->error = 1;
85 return NGX_ERROR; 63 return NGX_ERROR;
86 } 64 }
87 65
88 if (rc != 0) { 66 if (n != 0) {
89 if (rc == NGX_EINPROGRESS) { 67 if (n == NGX_EINPROGRESS) {
90 if (!first) { 68 if (!wev->active) {
91 ngx_log_error(NGX_LOG_CRIT, ev->log, rc, 69 ngx_log_error(NGX_LOG_ALERT, wev->log, n,
92 "aio_write() still in progress"); 70 "aio_write() still in progress");
93 } 71 }
94 return NGX_AGAIN; 72 return NGX_AGAIN;
95 } 73 }
96 74
97 if (rc == NGX_ECANCELED && canceled) { 75 ngx_log_error(NGX_LOG_CRIT, wev->log, n, "aio_write() failed");
98 return NGX_ERROR; 76 wev->error = 1;
99 }
100
101 ngx_log_error(NGX_LOG_CRIT, ev->log, rc, "aio_write() failed");
102 return NGX_ERROR; 77 return NGX_ERROR;
103 } 78 }
104 79
105 rc = aio_return(&ev->aiocb); 80 n = aio_return(&wev->aiocb);
106 if (rc == -1) { 81 if (n == -1) {
107 ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_errno, "aio_return() failed"); 82 ngx_log_error(NGX_LOG_ALERT, wev->log, ngx_errno,
83 "aio_return() failed");
108 84
85 wev->error = 1;
109 return NGX_ERROR; 86 return NGX_ERROR;
110 } 87 }
111 88
112 ev->active = 0; 89 wev->active = 0;
113 ngx_log_debug(ev->log, "aio_write: %d" _ rc);
114 90
115 return rc; 91 ngx_log_debug(wev->log, "aio_write: %d" _ n);
92
93 if (n == 0) {
94 wev->eof = 1;
95 }
96
97 return n;
116 } 98 }