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 #ifndef WEPOLL_EXPORT 36 #define WEPOLL_EXPORT 37 #endif 38 39 #include <stdint.h> 40 41 enum EPOLL_EVENTS { 42 EPOLLIN = (int) (1U << 0), 43 EPOLLPRI = (int) (1U << 1), 44 EPOLLOUT = (int) (1U << 2), 45 EPOLLERR = (int) (1U << 3), 46 EPOLLHUP = (int) (1U << 4), 47 EPOLLRDNORM = (int) (1U << 6), 48 EPOLLRDBAND = (int) (1U << 7), 49 EPOLLWRNORM = (int) (1U << 8), 50 EPOLLWRBAND = (int) (1U << 9), 51 EPOLLMSG = (int) (1U << 10), /* Never reported. */ 52 EPOLLRDHUP = (int) (1U << 13), 53 EPOLLONESHOT = (int) (1U << 31) 54 }; 55 56 #define EPOLLIN (1U << 0) 57 #define EPOLLPRI (1U << 1) 58 #define EPOLLOUT (1U << 2) 59 #define EPOLLERR (1U << 3) 60 #define EPOLLHUP (1U << 4) 61 #define EPOLLRDNORM (1U << 6) 62 #define EPOLLRDBAND (1U << 7) 63 #define EPOLLWRNORM (1U << 8) 64 #define EPOLLWRBAND (1U << 9) 65 #define EPOLLMSG (1U << 10) 66 #define EPOLLRDHUP (1U << 13) 67 #define EPOLLONESHOT (1U << 31) 68 69 #define EPOLL_CTL_ADD 1 70 #define EPOLL_CTL_MOD 2 71 #define EPOLL_CTL_DEL 3 72 73 typedef void* HANDLE; 74 typedef uintptr_t SOCKET; 75 76 typedef union epoll_data { 77 void* ptr; 78 int fd; 79 uint32_t u32; 80 uint64_t u64; 81 SOCKET sock; /* Windows specific */ 82 HANDLE hnd; /* Windows specific */ 83 } epoll_data_t; 84 85 struct epoll_event { 86 uint32_t events; /* Epoll events and flags */ 87 epoll_data_t data; /* User data variable */ 88 }; 89 90 #ifdef __cplusplus 91 extern "C" { 92 #endif 93 94 WEPOLL_EXPORT HANDLE epoll_create(int size); 95 WEPOLL_EXPORT HANDLE epoll_create1(int flags); 96 97 WEPOLL_EXPORT int epoll_close(HANDLE ephnd); 98 99 WEPOLL_EXPORT int epoll_ctl(HANDLE ephnd, 100 int op, 101 SOCKET sock, 102 struct epoll_event* event); 103 104 WEPOLL_EXPORT int epoll_wait(HANDLE ephnd, 105 struct epoll_event* events, 106 int maxevents, 107 int timeout); 108 109 #ifdef __cplusplus 110 } /* extern "C" */ 111 #endif 112 113 #endif /* WEPOLL_H_ */ 114