]> granicus.if.org Git - libevent/blob - wepoll.h
cmake: Fix Android build.
[libevent] / wepoll.h
1 /*
2  * wepoll - epoll for Windows
3  * https://github.com/piscisaureus/wepoll
4  *
5  * Copyright 2012-2020, Bert Belder <bertbelder@gmail.com>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *
15  *   * Redistributions in binary form must reproduce the above copyright
16  *     notice, this list of conditions and the following disclaimer in the
17  *     documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef WEPOLL_H_
33 #define WEPOLL_H_
34
35 #define WEPOLL_EXPORT
36
37 #include <stdint.h>
38
39 enum EPOLL_EVENTS {
40   EPOLLIN      = (int) (1U <<  0),
41   EPOLLPRI     = (int) (1U <<  1),
42   EPOLLOUT     = (int) (1U <<  2),
43   EPOLLERR     = (int) (1U <<  3),
44   EPOLLHUP     = (int) (1U <<  4),
45   EPOLLRDNORM  = (int) (1U <<  6),
46   EPOLLRDBAND  = (int) (1U <<  7),
47   EPOLLWRNORM  = (int) (1U <<  8),
48   EPOLLWRBAND  = (int) (1U <<  9),
49   EPOLLMSG     = (int) (1U << 10), /* Never reported. */
50   EPOLLRDHUP   = (int) (1U << 13),
51   EPOLLONESHOT = (int) (1U << 31)
52 };
53
54 #define EPOLLIN      (1U <<  0)
55 #define EPOLLPRI     (1U <<  1)
56 #define EPOLLOUT     (1U <<  2)
57 #define EPOLLERR     (1U <<  3)
58 #define EPOLLHUP     (1U <<  4)
59 #define EPOLLRDNORM  (1U <<  6)
60 #define EPOLLRDBAND  (1U <<  7)
61 #define EPOLLWRNORM  (1U <<  8)
62 #define EPOLLWRBAND  (1U <<  9)
63 #define EPOLLMSG     (1U << 10)
64 #define EPOLLRDHUP   (1U << 13)
65 #define EPOLLONESHOT (1U << 31)
66
67 #define EPOLL_CTL_ADD 1
68 #define EPOLL_CTL_MOD 2
69 #define EPOLL_CTL_DEL 3
70
71 typedef void* HANDLE;
72 typedef uintptr_t SOCKET;
73
74 typedef union epoll_data {
75   void* ptr;
76   int fd;
77   uint32_t u32;
78   uint64_t u64;
79   SOCKET sock; /* Windows specific */
80   HANDLE hnd;  /* Windows specific */
81 } epoll_data_t;
82
83 struct epoll_event {
84   uint32_t events;   /* Epoll events and flags */
85   epoll_data_t data; /* User data variable */
86 };
87
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91
92 WEPOLL_EXPORT HANDLE epoll_create(int size);
93 WEPOLL_EXPORT HANDLE epoll_create1(int flags);
94
95 WEPOLL_EXPORT int epoll_close(HANDLE ephnd);
96
97 WEPOLL_EXPORT int epoll_ctl(HANDLE ephnd,
98                             int op,
99                             SOCKET sock,
100                             struct epoll_event* event);
101
102 WEPOLL_EXPORT int epoll_wait(HANDLE ephnd,
103                              struct epoll_event* events,
104                              int maxevents,
105                              int timeout);
106
107 #ifdef __cplusplus
108 } /* extern "C" */
109 #endif
110
111 #endif /* WEPOLL_H_ */