1 /* 2 * Public domain 3 * 4 * poll(2) emulation for Windows 5 * 6 * This emulates just-enough poll functionality on Windows to work in the 7 * context of the openssl(1) program. This is not a replacement for 8 * POSIX.1-2001 poll(2). 9 * 10 * Dongsheng Song <dongsheng.song@gmail.com> 11 * Brent Cook <bcook@openbsd.org> 12 */ 13 module libressl_d.compat.poll; 14 15 16 private static import core.stdc.config; 17 private static import core.sys.windows.sdkddkver; 18 private static import core.sys.windows.winnt; 19 public import core.sys.posix.poll; 20 public import core.sys.windows.winsock2; 21 22 extern (C): 23 nothrow @nogc: 24 25 version (Windows) { 26 /* 27 * Type used for the number of file descriptors. 28 */ 29 alias nfds_t = core.stdc.config.c_ulong; 30 31 static if ((!__traits(compiles, core.sys.windows.sdkddkver._WIN32_WINNT)) || (core.sys.windows.sdkddkver._WIN32_WINNT < 0x0600)) { 32 /** 33 * Data structure describing a polling request. 34 */ 35 struct pollfd 36 { 37 /** 38 * file descriptor 39 */ 40 int fd; 41 42 /** 43 * requested events 44 */ 45 short events; 46 47 /** 48 * returned events 49 */ 50 short revents; 51 } 52 53 /* Event types that can be polled */ 54 55 /** 56 * There is data to read. 57 */ 58 enum POLLIN = 0x0001; 59 60 /** 61 * There is urgent data to read. 62 */ 63 enum POLLPRI = 0x0002; 64 65 /** 66 * Writing now will not block. 67 */ 68 enum POLLOUT = 0x0004; 69 70 /** 71 * Normal data may be read. 72 */ 73 enum POLLRDNORM = 0x0040; 74 75 /** 76 * Priority data may be read. 77 */ 78 enum POLLRDBAND = 0x0080; 79 80 /** 81 * Writing now will not block. 82 */ 83 enum POLLWRNORM = 0x0100; 84 85 /** 86 * Priority data may be written. 87 */ 88 enum POLLWRBAND = 0x0200; 89 90 /* Event types always implicitly polled. */ 91 92 /** 93 * Error condition. 94 */ 95 enum POLLERR = 0x0008; 96 97 /** 98 * Hung up. 99 */ 100 enum POLLHUP = 0x0010; 101 102 /** 103 * Invalid polling request. 104 */ 105 enum POLLNVAL = 0x0020; 106 } else { 107 /** 108 * Data structure describing a polling request. 109 */ 110 struct pollfd 111 { 112 /** 113 * file descriptor 114 */ 115 core.sys.windows.winsock2.SOCKET fd; 116 117 /** 118 * requested events 119 */ 120 core.sys.windows.winnt.SHORT events; 121 122 /** 123 * returned events 124 */ 125 core.sys.windows.winnt.SHORT revents; 126 } 127 128 /* Event types that can be polled */ 129 130 /** 131 * There is data to read. 132 */ 133 enum POLLIN = .POLLRDNORM | .POLLRDBAND; 134 135 /** 136 * There is urgent data to read. 137 */ 138 enum POLLPRI = 0x0400; 139 140 /** 141 * Writing now will not block. 142 */ 143 enum POLLOUT = POLLWRNORM; 144 145 /** 146 * Normal data may be read. 147 */ 148 enum POLLRDNORM = 0x0100; 149 150 /** 151 * Priority data may be read. 152 */ 153 enum POLLRDBAND = 0x0200; 154 155 /** 156 * Writing now will not block. 157 */ 158 enum POLLWRNORM = 0x0010; 159 160 /** 161 * Priority data may be written. 162 */ 163 enum POLLWRBAND = 0x0020; 164 165 /* Event types always implicitly polled. */ 166 167 /** 168 * Error condition. 169 */ 170 enum POLLERR = 0x0001; 171 172 /** 173 * Hung up. 174 */ 175 enum POLLHUP = 0x0002; 176 177 /** 178 * Invalid polling request. 179 */ 180 enum POLLNVAL = 0x0004; 181 } 182 183 extern (C) 184 nothrow @nogc 185 int poll(.pollfd* pfds, .nfds_t nfds, int timeout); 186 }