1 | #pragma once |
2 | |
3 | #include <boost/noncopyable.hpp> |
4 | |
5 | #if defined(__linux__) |
6 | |
7 | /// https://stackoverflow.com/questions/20759750/resolving-redefinition-of-timespec-in-time-h |
8 | #define timespec linux_timespec |
9 | #define timeval linux_timeval |
10 | #define itimerspec linux_itimerspec |
11 | #define sigset_t linux_sigset_t |
12 | |
13 | #include <linux/aio_abi.h> |
14 | |
15 | #undef timespec |
16 | #undef timeval |
17 | #undef itimerspec |
18 | #undef sigset_t |
19 | |
20 | |
21 | /** Small wrappers for asynchronous I/O. |
22 | */ |
23 | |
24 | int io_setup(unsigned nr, aio_context_t * ctxp); |
25 | |
26 | int io_destroy(aio_context_t ctx); |
27 | |
28 | /// last argument is an array of pointers technically speaking |
29 | int io_submit(aio_context_t ctx, long nr, struct iocb * iocbpp[]); |
30 | |
31 | int io_getevents(aio_context_t ctx, long min_nr, long max_nr, io_event * events, struct timespec * timeout); |
32 | |
33 | |
34 | struct AIOContext : private boost::noncopyable |
35 | { |
36 | aio_context_t ctx; |
37 | |
38 | AIOContext(unsigned int nr_events = 128); |
39 | ~AIOContext(); |
40 | }; |
41 | |
42 | #elif defined(__FreeBSD__) |
43 | |
44 | #include <aio.h> |
45 | #include <sys/types.h> |
46 | #include <sys/event.h> |
47 | #include <sys/time.h> |
48 | |
49 | typedef struct kevent io_event; |
50 | typedef int aio_context_t; |
51 | |
52 | struct iocb |
53 | { |
54 | struct aiocb aio; |
55 | long aio_data; |
56 | }; |
57 | |
58 | int io_setup(void); |
59 | |
60 | int io_destroy(void); |
61 | |
62 | /// last argument is an array of pointers technically speaking |
63 | int io_submit(int ctx, long nr, struct iocb * iocbpp[]); |
64 | |
65 | int io_getevents(int ctx, long min_nr, long max_nr, struct kevent * events, struct timespec * timeout); |
66 | |
67 | |
68 | struct AIOContext : private boost::noncopyable |
69 | { |
70 | int ctx; |
71 | |
72 | AIOContext(unsigned int nr_events = 128); |
73 | ~AIOContext(); |
74 | }; |
75 | |
76 | #endif |
77 | |