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