3 * Copyright (C) Igor Sysoev
7 #include <ngx_config.h>
13 #include <ngx_kqueue_module.h>
18 * the ready data requires 3 syscalls:
19 * aio_write(), aio_error(), aio_return()
20 * the non-ready data requires 4 (kqueue) or 5 syscalls:
21 * aio_write(), aio_error(), notifiction, aio_error(), aio_return()
22 * timeout, aio_cancel(), aio_error()
25 ssize_t
ngx_aio_read(ngx_connection_t
*c
, u_char
*buf
, size_t size
)
33 ngx_log_error(NGX_LOG_ALERT
, c
->log
, 0, "second aio post");
37 ngx_log_debug1(NGX_LOG_DEBUG_EVENT
, c
->log
, 0,
38 "rev->complete: %d", rev
->complete
);
39 ngx_log_debug1(NGX_LOG_DEBUG_EVENT
, c
->log
, 0,
40 "aio size: %d", size
);
43 ngx_memzero(&rev
->aiocb
, sizeof(struct aiocb
));
45 rev
->aiocb
.aio_fildes
= c
->fd
;
46 rev
->aiocb
.aio_buf
= buf
;
47 rev
->aiocb
.aio_nbytes
= size
;
50 rev
->aiocb
.aio_sigevent
.sigev_notify_kqueue
= ngx_kqueue
;
51 rev
->aiocb
.aio_sigevent
.sigev_notify
= SIGEV_KEVENT
;
52 rev
->aiocb
.aio_sigevent
.sigev_value
.sigval_ptr
= rev
;
55 if (aio_read(&rev
->aiocb
) == -1) {
56 ngx_log_error(NGX_LOG_CRIT
, rev
->log
, ngx_errno
,
62 ngx_log_debug1(NGX_LOG_DEBUG_EVENT
, c
->log
, 0,
63 "aio_read: #%d OK", c
->fd
);
71 n
= aio_error(&rev
->aiocb
);
73 ngx_log_error(NGX_LOG_ALERT
, c
->log
, ngx_errno
, "aio_error() failed");
79 if (n
== NGX_EINPROGRESS
) {
81 ngx_log_error(NGX_LOG_ALERT
, c
->log
, n
,
82 "aio_read() still in progress");
88 ngx_log_error(NGX_LOG_CRIT
, c
->log
, n
, "aio_read() failed");
94 n
= aio_return(&rev
->aiocb
);
96 ngx_log_error(NGX_LOG_ALERT
, c
->log
, ngx_errno
,
97 "aio_return() failed");
104 ngx_log_debug2(NGX_LOG_DEBUG_EVENT
, rev
->log
, 0,
105 "aio_read: #%d %d", c
->fd
, n
);