Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ngx_aio_read.c
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) Nginx, Inc.
5  */
6 
7 
8 #include <ngx_config.h>
9 #include <ngx_core.h>
10 #include <ngx_event.h>
11 
12 
13 extern int ngx_kqueue;
14 
15 
16 ssize_t
17 ngx_aio_read(ngx_connection_t *c, u_char *buf, size_t size)
18 {
19  int n;
20  ngx_event_t *rev;
21 
22  rev = c->read;
23 
24  if (!rev->ready) {
25  ngx_log_error(NGX_LOG_ALERT, c->log, 0, "second aio post");
26  return NGX_AGAIN;
27  }
28 
30  "rev->complete: %d", rev->complete);
32  "aio size: %d", size);
33 
34  if (!rev->complete) {
35  ngx_memzero(&rev->aiocb, sizeof(struct aiocb));
36 
37  rev->aiocb.aio_fildes = c->fd;
38  rev->aiocb.aio_buf = buf;
39  rev->aiocb.aio_nbytes = size;
40 
41 #if (NGX_HAVE_KQUEUE)
42  rev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
43  rev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
44  rev->aiocb.aio_sigevent.sigev_value.sigval_ptr = rev;
45 #endif
46 
47  if (aio_read(&rev->aiocb) == -1) {
49  "aio_read() failed");
50  rev->error = 1;
51  return NGX_ERROR;
52  }
53 
55  "aio_read: #%d OK", c->fd);
56 
57  rev->active = 1;
58  rev->ready = 0;
59  }
60 
61  rev->complete = 0;
62 
63  n = aio_error(&rev->aiocb);
64  if (n == -1) {
65  ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "aio_error() failed");
66  rev->error = 1;
67  return NGX_ERROR;
68  }
69 
70  if (n != 0) {
71  if (n == NGX_EINPROGRESS) {
72  if (rev->ready) {
74  "aio_read() still in progress");
75  rev->ready = 0;
76  }
77  return NGX_AGAIN;
78  }
79 
80  ngx_log_error(NGX_LOG_CRIT, c->log, n, "aio_read() failed");
81  rev->error = 1;
82  rev->ready = 0;
83  return NGX_ERROR;
84  }
85 
86  n = aio_return(&rev->aiocb);
87  if (n == -1) {
89  "aio_return() failed");
90 
91  rev->error = 1;
92  rev->ready = 0;
93  return NGX_ERROR;
94  }
95 
97  "aio_read: #%d %d", c->fd, n);
98 
99  if (n == 0) {
100  rev->eof = 1;
101  rev->ready = 0;
102  } else {
103  rev->ready = 1;
104  }
105 
106  rev->active = 0;
107 
108  return n;
109 }