Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(select_select__doc__, |
| 6 | "select($module, rlist, wlist, xlist, timeout=None, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "Wait until one or more file descriptors are ready for some kind of I/O.\n" |
| 10 | "\n" |
| 11 | "The first three arguments are sequences of file descriptors to be waited for:\n" |
| 12 | "rlist -- wait until ready for reading\n" |
| 13 | "wlist -- wait until ready for writing\n" |
| 14 | "xlist -- wait for an \"exceptional condition\"\n" |
| 15 | "If only one kind of condition is required, pass [] for the other lists.\n" |
| 16 | "\n" |
| 17 | "A file descriptor is either a socket or file object, or a small integer\n" |
| 18 | "gotten from a fileno() method call on one of those.\n" |
| 19 | "\n" |
| 20 | "The optional 4th argument specifies a timeout in seconds; it may be\n" |
| 21 | "a floating point number to specify fractions of seconds. If it is absent\n" |
| 22 | "or None, the call will never time out.\n" |
| 23 | "\n" |
| 24 | "The return value is a tuple of three lists corresponding to the first three\n" |
| 25 | "arguments; each contains the subset of the corresponding file descriptors\n" |
| 26 | "that are ready.\n" |
| 27 | "\n" |
| 28 | "*** IMPORTANT NOTICE ***\n" |
| 29 | "On Windows, only sockets are supported; on Unix, all file\n" |
| 30 | "descriptors can be used."); |
| 31 | |
| 32 | #define SELECT_SELECT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 33 | {"select", (PyCFunction)(void(*)(void))select_select, METH_FASTCALL, select_select__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 34 | |
| 35 | static PyObject * |
| 36 | select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist, |
| 37 | PyObject *xlist, PyObject *timeout_obj); |
| 38 | |
| 39 | static PyObject * |
| 40 | select_select(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 41 | { |
| 42 | PyObject *return_value = NULL; |
| 43 | PyObject *rlist; |
| 44 | PyObject *wlist; |
| 45 | PyObject *xlist; |
| 46 | PyObject *timeout_obj = Py_None; |
| 47 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 48 | if (!_PyArg_CheckPositional("select", nargs, 3, 4)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 49 | goto exit; |
| 50 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 51 | rlist = args[0]; |
| 52 | wlist = args[1]; |
| 53 | xlist = args[2]; |
| 54 | if (nargs < 4) { |
| 55 | goto skip_optional; |
| 56 | } |
| 57 | timeout_obj = args[3]; |
| 58 | skip_optional: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 59 | return_value = select_select_impl(module, rlist, wlist, xlist, timeout_obj); |
| 60 | |
| 61 | exit: |
| 62 | return return_value; |
| 63 | } |
| 64 | |
| 65 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) |
| 66 | |
| 67 | PyDoc_STRVAR(select_poll_register__doc__, |
| 68 | "register($self, fd, eventmask=POLLIN | POLLPRI | POLLOUT, /)\n" |
| 69 | "--\n" |
| 70 | "\n" |
| 71 | "Register a file descriptor with the polling object.\n" |
| 72 | "\n" |
| 73 | " fd\n" |
| 74 | " either an integer, or an object with a fileno() method returning an int\n" |
| 75 | " eventmask\n" |
| 76 | " an optional bitmask describing the type of events to check for"); |
| 77 | |
| 78 | #define SELECT_POLL_REGISTER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 79 | {"register", (PyCFunction)(void(*)(void))select_poll_register, METH_FASTCALL, select_poll_register__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 80 | |
| 81 | static PyObject * |
| 82 | select_poll_register_impl(pollObject *self, int fd, unsigned short eventmask); |
| 83 | |
| 84 | static PyObject * |
| 85 | select_poll_register(pollObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 86 | { |
| 87 | PyObject *return_value = NULL; |
| 88 | int fd; |
| 89 | unsigned short eventmask = POLLIN | POLLPRI | POLLOUT; |
| 90 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 91 | if (!_PyArg_CheckPositional("register", nargs, 1, 2)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 92 | goto exit; |
| 93 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 94 | if (!fildes_converter(args[0], &fd)) { |
| 95 | goto exit; |
| 96 | } |
| 97 | if (nargs < 2) { |
| 98 | goto skip_optional; |
| 99 | } |
| 100 | if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) { |
| 101 | goto exit; |
| 102 | } |
| 103 | skip_optional: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 104 | return_value = select_poll_register_impl(self, fd, eventmask); |
| 105 | |
| 106 | exit: |
| 107 | return return_value; |
| 108 | } |
| 109 | |
| 110 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */ |
| 111 | |
| 112 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) |
| 113 | |
| 114 | PyDoc_STRVAR(select_poll_modify__doc__, |
| 115 | "modify($self, fd, eventmask, /)\n" |
| 116 | "--\n" |
| 117 | "\n" |
| 118 | "Modify an already registered file descriptor.\n" |
| 119 | "\n" |
| 120 | " fd\n" |
| 121 | " either an integer, or an object with a fileno() method returning\n" |
| 122 | " an int\n" |
| 123 | " eventmask\n" |
| 124 | " a bitmask describing the type of events to check for"); |
| 125 | |
| 126 | #define SELECT_POLL_MODIFY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 127 | {"modify", (PyCFunction)(void(*)(void))select_poll_modify, METH_FASTCALL, select_poll_modify__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 128 | |
| 129 | static PyObject * |
| 130 | select_poll_modify_impl(pollObject *self, int fd, unsigned short eventmask); |
| 131 | |
| 132 | static PyObject * |
| 133 | select_poll_modify(pollObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 134 | { |
| 135 | PyObject *return_value = NULL; |
| 136 | int fd; |
| 137 | unsigned short eventmask; |
| 138 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 139 | if (!_PyArg_CheckPositional("modify", nargs, 2, 2)) { |
| 140 | goto exit; |
| 141 | } |
| 142 | if (!fildes_converter(args[0], &fd)) { |
| 143 | goto exit; |
| 144 | } |
| 145 | if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 146 | goto exit; |
| 147 | } |
| 148 | return_value = select_poll_modify_impl(self, fd, eventmask); |
| 149 | |
| 150 | exit: |
| 151 | return return_value; |
| 152 | } |
| 153 | |
| 154 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */ |
| 155 | |
| 156 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) |
| 157 | |
| 158 | PyDoc_STRVAR(select_poll_unregister__doc__, |
| 159 | "unregister($self, fd, /)\n" |
| 160 | "--\n" |
| 161 | "\n" |
| 162 | "Remove a file descriptor being tracked by the polling object."); |
| 163 | |
| 164 | #define SELECT_POLL_UNREGISTER_METHODDEF \ |
| 165 | {"unregister", (PyCFunction)select_poll_unregister, METH_O, select_poll_unregister__doc__}, |
| 166 | |
| 167 | static PyObject * |
| 168 | select_poll_unregister_impl(pollObject *self, int fd); |
| 169 | |
| 170 | static PyObject * |
| 171 | select_poll_unregister(pollObject *self, PyObject *arg) |
| 172 | { |
| 173 | PyObject *return_value = NULL; |
| 174 | int fd; |
| 175 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 176 | if (!fildes_converter(arg, &fd)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 177 | goto exit; |
| 178 | } |
| 179 | return_value = select_poll_unregister_impl(self, fd); |
| 180 | |
| 181 | exit: |
| 182 | return return_value; |
| 183 | } |
| 184 | |
| 185 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */ |
| 186 | |
| 187 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) |
| 188 | |
| 189 | PyDoc_STRVAR(select_poll_poll__doc__, |
| 190 | "poll($self, timeout=None, /)\n" |
| 191 | "--\n" |
| 192 | "\n" |
| 193 | "Polls the set of registered file descriptors.\n" |
| 194 | "\n" |
| 195 | "Returns a list containing any descriptors that have events or errors to\n" |
| 196 | "report, as a list of (fd, event) 2-tuples."); |
| 197 | |
| 198 | #define SELECT_POLL_POLL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 199 | {"poll", (PyCFunction)(void(*)(void))select_poll_poll, METH_FASTCALL, select_poll_poll__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 200 | |
| 201 | static PyObject * |
| 202 | select_poll_poll_impl(pollObject *self, PyObject *timeout_obj); |
| 203 | |
| 204 | static PyObject * |
| 205 | select_poll_poll(pollObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 206 | { |
| 207 | PyObject *return_value = NULL; |
| 208 | PyObject *timeout_obj = Py_None; |
| 209 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 210 | if (!_PyArg_CheckPositional("poll", nargs, 0, 1)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 211 | goto exit; |
| 212 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 213 | if (nargs < 1) { |
| 214 | goto skip_optional; |
| 215 | } |
| 216 | timeout_obj = args[0]; |
| 217 | skip_optional: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 218 | return_value = select_poll_poll_impl(self, timeout_obj); |
| 219 | |
| 220 | exit: |
| 221 | return return_value; |
| 222 | } |
| 223 | |
| 224 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */ |
| 225 | |
| 226 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) |
| 227 | |
| 228 | PyDoc_STRVAR(select_devpoll_register__doc__, |
| 229 | "register($self, fd, eventmask=POLLIN | POLLPRI | POLLOUT, /)\n" |
| 230 | "--\n" |
| 231 | "\n" |
| 232 | "Register a file descriptor with the polling object.\n" |
| 233 | "\n" |
| 234 | " fd\n" |
| 235 | " either an integer, or an object with a fileno() method returning\n" |
| 236 | " an int\n" |
| 237 | " eventmask\n" |
| 238 | " an optional bitmask describing the type of events to check for"); |
| 239 | |
| 240 | #define SELECT_DEVPOLL_REGISTER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 241 | {"register", (PyCFunction)(void(*)(void))select_devpoll_register, METH_FASTCALL, select_devpoll_register__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 242 | |
| 243 | static PyObject * |
| 244 | select_devpoll_register_impl(devpollObject *self, int fd, |
| 245 | unsigned short eventmask); |
| 246 | |
| 247 | static PyObject * |
| 248 | select_devpoll_register(devpollObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 249 | { |
| 250 | PyObject *return_value = NULL; |
| 251 | int fd; |
| 252 | unsigned short eventmask = POLLIN | POLLPRI | POLLOUT; |
| 253 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 254 | if (!_PyArg_CheckPositional("register", nargs, 1, 2)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 255 | goto exit; |
| 256 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 257 | if (!fildes_converter(args[0], &fd)) { |
| 258 | goto exit; |
| 259 | } |
| 260 | if (nargs < 2) { |
| 261 | goto skip_optional; |
| 262 | } |
| 263 | if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) { |
| 264 | goto exit; |
| 265 | } |
| 266 | skip_optional: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 267 | return_value = select_devpoll_register_impl(self, fd, eventmask); |
| 268 | |
| 269 | exit: |
| 270 | return return_value; |
| 271 | } |
| 272 | |
| 273 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */ |
| 274 | |
| 275 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) |
| 276 | |
| 277 | PyDoc_STRVAR(select_devpoll_modify__doc__, |
| 278 | "modify($self, fd, eventmask=POLLIN | POLLPRI | POLLOUT, /)\n" |
| 279 | "--\n" |
| 280 | "\n" |
| 281 | "Modify a possible already registered file descriptor.\n" |
| 282 | "\n" |
| 283 | " fd\n" |
| 284 | " either an integer, or an object with a fileno() method returning\n" |
| 285 | " an int\n" |
| 286 | " eventmask\n" |
| 287 | " an optional bitmask describing the type of events to check for"); |
| 288 | |
| 289 | #define SELECT_DEVPOLL_MODIFY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 290 | {"modify", (PyCFunction)(void(*)(void))select_devpoll_modify, METH_FASTCALL, select_devpoll_modify__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 291 | |
| 292 | static PyObject * |
| 293 | select_devpoll_modify_impl(devpollObject *self, int fd, |
| 294 | unsigned short eventmask); |
| 295 | |
| 296 | static PyObject * |
| 297 | select_devpoll_modify(devpollObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 298 | { |
| 299 | PyObject *return_value = NULL; |
| 300 | int fd; |
| 301 | unsigned short eventmask = POLLIN | POLLPRI | POLLOUT; |
| 302 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 303 | if (!_PyArg_CheckPositional("modify", nargs, 1, 2)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 304 | goto exit; |
| 305 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 306 | if (!fildes_converter(args[0], &fd)) { |
| 307 | goto exit; |
| 308 | } |
| 309 | if (nargs < 2) { |
| 310 | goto skip_optional; |
| 311 | } |
| 312 | if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) { |
| 313 | goto exit; |
| 314 | } |
| 315 | skip_optional: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 316 | return_value = select_devpoll_modify_impl(self, fd, eventmask); |
| 317 | |
| 318 | exit: |
| 319 | return return_value; |
| 320 | } |
| 321 | |
| 322 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */ |
| 323 | |
| 324 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) |
| 325 | |
| 326 | PyDoc_STRVAR(select_devpoll_unregister__doc__, |
| 327 | "unregister($self, fd, /)\n" |
| 328 | "--\n" |
| 329 | "\n" |
| 330 | "Remove a file descriptor being tracked by the polling object."); |
| 331 | |
| 332 | #define SELECT_DEVPOLL_UNREGISTER_METHODDEF \ |
| 333 | {"unregister", (PyCFunction)select_devpoll_unregister, METH_O, select_devpoll_unregister__doc__}, |
| 334 | |
| 335 | static PyObject * |
| 336 | select_devpoll_unregister_impl(devpollObject *self, int fd); |
| 337 | |
| 338 | static PyObject * |
| 339 | select_devpoll_unregister(devpollObject *self, PyObject *arg) |
| 340 | { |
| 341 | PyObject *return_value = NULL; |
| 342 | int fd; |
| 343 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 344 | if (!fildes_converter(arg, &fd)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 345 | goto exit; |
| 346 | } |
| 347 | return_value = select_devpoll_unregister_impl(self, fd); |
| 348 | |
| 349 | exit: |
| 350 | return return_value; |
| 351 | } |
| 352 | |
| 353 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */ |
| 354 | |
| 355 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) |
| 356 | |
| 357 | PyDoc_STRVAR(select_devpoll_poll__doc__, |
| 358 | "poll($self, timeout=None, /)\n" |
| 359 | "--\n" |
| 360 | "\n" |
| 361 | "Polls the set of registered file descriptors.\n" |
| 362 | "\n" |
| 363 | "Returns a list containing any descriptors that have events or errors to\n" |
| 364 | "report, as a list of (fd, event) 2-tuples."); |
| 365 | |
| 366 | #define SELECT_DEVPOLL_POLL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 367 | {"poll", (PyCFunction)(void(*)(void))select_devpoll_poll, METH_FASTCALL, select_devpoll_poll__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 368 | |
| 369 | static PyObject * |
| 370 | select_devpoll_poll_impl(devpollObject *self, PyObject *timeout_obj); |
| 371 | |
| 372 | static PyObject * |
| 373 | select_devpoll_poll(devpollObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 374 | { |
| 375 | PyObject *return_value = NULL; |
| 376 | PyObject *timeout_obj = Py_None; |
| 377 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 378 | if (!_PyArg_CheckPositional("poll", nargs, 0, 1)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 379 | goto exit; |
| 380 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 381 | if (nargs < 1) { |
| 382 | goto skip_optional; |
| 383 | } |
| 384 | timeout_obj = args[0]; |
| 385 | skip_optional: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 386 | return_value = select_devpoll_poll_impl(self, timeout_obj); |
| 387 | |
| 388 | exit: |
| 389 | return return_value; |
| 390 | } |
| 391 | |
| 392 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */ |
| 393 | |
| 394 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) |
| 395 | |
| 396 | PyDoc_STRVAR(select_devpoll_close__doc__, |
| 397 | "close($self, /)\n" |
| 398 | "--\n" |
| 399 | "\n" |
| 400 | "Close the devpoll file descriptor.\n" |
| 401 | "\n" |
| 402 | "Further operations on the devpoll object will raise an exception."); |
| 403 | |
| 404 | #define SELECT_DEVPOLL_CLOSE_METHODDEF \ |
| 405 | {"close", (PyCFunction)select_devpoll_close, METH_NOARGS, select_devpoll_close__doc__}, |
| 406 | |
| 407 | static PyObject * |
| 408 | select_devpoll_close_impl(devpollObject *self); |
| 409 | |
| 410 | static PyObject * |
| 411 | select_devpoll_close(devpollObject *self, PyObject *Py_UNUSED(ignored)) |
| 412 | { |
| 413 | return select_devpoll_close_impl(self); |
| 414 | } |
| 415 | |
| 416 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */ |
| 417 | |
| 418 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) |
| 419 | |
| 420 | PyDoc_STRVAR(select_devpoll_fileno__doc__, |
| 421 | "fileno($self, /)\n" |
| 422 | "--\n" |
| 423 | "\n" |
| 424 | "Return the file descriptor."); |
| 425 | |
| 426 | #define SELECT_DEVPOLL_FILENO_METHODDEF \ |
| 427 | {"fileno", (PyCFunction)select_devpoll_fileno, METH_NOARGS, select_devpoll_fileno__doc__}, |
| 428 | |
| 429 | static PyObject * |
| 430 | select_devpoll_fileno_impl(devpollObject *self); |
| 431 | |
| 432 | static PyObject * |
| 433 | select_devpoll_fileno(devpollObject *self, PyObject *Py_UNUSED(ignored)) |
| 434 | { |
| 435 | return select_devpoll_fileno_impl(self); |
| 436 | } |
| 437 | |
| 438 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */ |
| 439 | |
| 440 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) |
| 441 | |
| 442 | PyDoc_STRVAR(select_poll__doc__, |
| 443 | "poll($module, /)\n" |
| 444 | "--\n" |
| 445 | "\n" |
| 446 | "Returns a polling object.\n" |
| 447 | "\n" |
| 448 | "This object supports registering and unregistering file descriptors, and then\n" |
| 449 | "polling them for I/O events."); |
| 450 | |
| 451 | #define SELECT_POLL_METHODDEF \ |
| 452 | {"poll", (PyCFunction)select_poll, METH_NOARGS, select_poll__doc__}, |
| 453 | |
| 454 | static PyObject * |
| 455 | select_poll_impl(PyObject *module); |
| 456 | |
| 457 | static PyObject * |
| 458 | select_poll(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 459 | { |
| 460 | return select_poll_impl(module); |
| 461 | } |
| 462 | |
| 463 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */ |
| 464 | |
| 465 | #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) |
| 466 | |
| 467 | PyDoc_STRVAR(select_devpoll__doc__, |
| 468 | "devpoll($module, /)\n" |
| 469 | "--\n" |
| 470 | "\n" |
| 471 | "Returns a polling object.\n" |
| 472 | "\n" |
| 473 | "This object supports registering and unregistering file descriptors, and then\n" |
| 474 | "polling them for I/O events."); |
| 475 | |
| 476 | #define SELECT_DEVPOLL_METHODDEF \ |
| 477 | {"devpoll", (PyCFunction)select_devpoll, METH_NOARGS, select_devpoll__doc__}, |
| 478 | |
| 479 | static PyObject * |
| 480 | select_devpoll_impl(PyObject *module); |
| 481 | |
| 482 | static PyObject * |
| 483 | select_devpoll(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 484 | { |
| 485 | return select_devpoll_impl(module); |
| 486 | } |
| 487 | |
| 488 | #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */ |
| 489 | |
| 490 | #if defined(HAVE_EPOLL) |
| 491 | |
| 492 | PyDoc_STRVAR(select_epoll__doc__, |
| 493 | "epoll(sizehint=-1, flags=0)\n" |
| 494 | "--\n" |
| 495 | "\n" |
| 496 | "Returns an epolling object.\n" |
| 497 | "\n" |
| 498 | " sizehint\n" |
| 499 | " The expected number of events to be registered. It must be positive,\n" |
| 500 | " or -1 to use the default. It is only used on older systems where\n" |
| 501 | " epoll_create1() is not available; otherwise it has no effect (though its\n" |
| 502 | " value is still checked).\n" |
| 503 | " flags\n" |
| 504 | " Deprecated and completely ignored. However, when supplied, its value\n" |
| 505 | " must be 0 or select.EPOLL_CLOEXEC, otherwise OSError is raised."); |
| 506 | |
| 507 | static PyObject * |
| 508 | select_epoll_impl(PyTypeObject *type, int sizehint, int flags); |
| 509 | |
| 510 | static PyObject * |
| 511 | select_epoll(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 512 | { |
| 513 | PyObject *return_value = NULL; |
| 514 | static const char * const _keywords[] = {"sizehint", "flags", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 515 | static _PyArg_Parser _parser = {NULL, _keywords, "epoll", 0}; |
| 516 | PyObject *argsbuf[2]; |
| 517 | PyObject * const *fastargs; |
| 518 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 519 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 520 | int sizehint = -1; |
| 521 | int flags = 0; |
| 522 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 523 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf); |
| 524 | if (!fastargs) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 525 | goto exit; |
| 526 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 527 | if (!noptargs) { |
| 528 | goto skip_optional_pos; |
| 529 | } |
| 530 | if (fastargs[0]) { |
| 531 | if (PyFloat_Check(fastargs[0])) { |
| 532 | PyErr_SetString(PyExc_TypeError, |
| 533 | "integer argument expected, got float" ); |
| 534 | goto exit; |
| 535 | } |
| 536 | sizehint = _PyLong_AsInt(fastargs[0]); |
| 537 | if (sizehint == -1 && PyErr_Occurred()) { |
| 538 | goto exit; |
| 539 | } |
| 540 | if (!--noptargs) { |
| 541 | goto skip_optional_pos; |
| 542 | } |
| 543 | } |
| 544 | if (PyFloat_Check(fastargs[1])) { |
| 545 | PyErr_SetString(PyExc_TypeError, |
| 546 | "integer argument expected, got float" ); |
| 547 | goto exit; |
| 548 | } |
| 549 | flags = _PyLong_AsInt(fastargs[1]); |
| 550 | if (flags == -1 && PyErr_Occurred()) { |
| 551 | goto exit; |
| 552 | } |
| 553 | skip_optional_pos: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 554 | return_value = select_epoll_impl(type, sizehint, flags); |
| 555 | |
| 556 | exit: |
| 557 | return return_value; |
| 558 | } |
| 559 | |
| 560 | #endif /* defined(HAVE_EPOLL) */ |
| 561 | |
| 562 | #if defined(HAVE_EPOLL) |
| 563 | |
| 564 | PyDoc_STRVAR(select_epoll_close__doc__, |
| 565 | "close($self, /)\n" |
| 566 | "--\n" |
| 567 | "\n" |
| 568 | "Close the epoll control file descriptor.\n" |
| 569 | "\n" |
| 570 | "Further operations on the epoll object will raise an exception."); |
| 571 | |
| 572 | #define SELECT_EPOLL_CLOSE_METHODDEF \ |
| 573 | {"close", (PyCFunction)select_epoll_close, METH_NOARGS, select_epoll_close__doc__}, |
| 574 | |
| 575 | static PyObject * |
| 576 | select_epoll_close_impl(pyEpoll_Object *self); |
| 577 | |
| 578 | static PyObject * |
| 579 | select_epoll_close(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored)) |
| 580 | { |
| 581 | return select_epoll_close_impl(self); |
| 582 | } |
| 583 | |
| 584 | #endif /* defined(HAVE_EPOLL) */ |
| 585 | |
| 586 | #if defined(HAVE_EPOLL) |
| 587 | |
| 588 | PyDoc_STRVAR(select_epoll_fileno__doc__, |
| 589 | "fileno($self, /)\n" |
| 590 | "--\n" |
| 591 | "\n" |
| 592 | "Return the epoll control file descriptor."); |
| 593 | |
| 594 | #define SELECT_EPOLL_FILENO_METHODDEF \ |
| 595 | {"fileno", (PyCFunction)select_epoll_fileno, METH_NOARGS, select_epoll_fileno__doc__}, |
| 596 | |
| 597 | static PyObject * |
| 598 | select_epoll_fileno_impl(pyEpoll_Object *self); |
| 599 | |
| 600 | static PyObject * |
| 601 | select_epoll_fileno(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored)) |
| 602 | { |
| 603 | return select_epoll_fileno_impl(self); |
| 604 | } |
| 605 | |
| 606 | #endif /* defined(HAVE_EPOLL) */ |
| 607 | |
| 608 | #if defined(HAVE_EPOLL) |
| 609 | |
| 610 | PyDoc_STRVAR(select_epoll_fromfd__doc__, |
| 611 | "fromfd($type, fd, /)\n" |
| 612 | "--\n" |
| 613 | "\n" |
| 614 | "Create an epoll object from a given control fd."); |
| 615 | |
| 616 | #define SELECT_EPOLL_FROMFD_METHODDEF \ |
| 617 | {"fromfd", (PyCFunction)select_epoll_fromfd, METH_O|METH_CLASS, select_epoll_fromfd__doc__}, |
| 618 | |
| 619 | static PyObject * |
| 620 | select_epoll_fromfd_impl(PyTypeObject *type, int fd); |
| 621 | |
| 622 | static PyObject * |
| 623 | select_epoll_fromfd(PyTypeObject *type, PyObject *arg) |
| 624 | { |
| 625 | PyObject *return_value = NULL; |
| 626 | int fd; |
| 627 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 628 | if (PyFloat_Check(arg)) { |
| 629 | PyErr_SetString(PyExc_TypeError, |
| 630 | "integer argument expected, got float" ); |
| 631 | goto exit; |
| 632 | } |
| 633 | fd = _PyLong_AsInt(arg); |
| 634 | if (fd == -1 && PyErr_Occurred()) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 635 | goto exit; |
| 636 | } |
| 637 | return_value = select_epoll_fromfd_impl(type, fd); |
| 638 | |
| 639 | exit: |
| 640 | return return_value; |
| 641 | } |
| 642 | |
| 643 | #endif /* defined(HAVE_EPOLL) */ |
| 644 | |
| 645 | #if defined(HAVE_EPOLL) |
| 646 | |
| 647 | PyDoc_STRVAR(select_epoll_register__doc__, |
| 648 | "register($self, /, fd, eventmask=EPOLLIN | EPOLLPRI | EPOLLOUT)\n" |
| 649 | "--\n" |
| 650 | "\n" |
| 651 | "Registers a new fd or raises an OSError if the fd is already registered.\n" |
| 652 | "\n" |
| 653 | " fd\n" |
| 654 | " the target file descriptor of the operation\n" |
| 655 | " eventmask\n" |
| 656 | " a bit set composed of the various EPOLL constants\n" |
| 657 | "\n" |
| 658 | "The epoll interface supports all file descriptors that support poll."); |
| 659 | |
| 660 | #define SELECT_EPOLL_REGISTER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 661 | {"register", (PyCFunction)(void(*)(void))select_epoll_register, METH_FASTCALL|METH_KEYWORDS, select_epoll_register__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 662 | |
| 663 | static PyObject * |
| 664 | select_epoll_register_impl(pyEpoll_Object *self, int fd, |
| 665 | unsigned int eventmask); |
| 666 | |
| 667 | static PyObject * |
| 668 | select_epoll_register(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 669 | { |
| 670 | PyObject *return_value = NULL; |
| 671 | static const char * const _keywords[] = {"fd", "eventmask", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 672 | static _PyArg_Parser _parser = {NULL, _keywords, "register", 0}; |
| 673 | PyObject *argsbuf[2]; |
| 674 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 675 | int fd; |
| 676 | unsigned int eventmask = EPOLLIN | EPOLLPRI | EPOLLOUT; |
| 677 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 678 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 679 | if (!args) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 680 | goto exit; |
| 681 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 682 | if (!fildes_converter(args[0], &fd)) { |
| 683 | goto exit; |
| 684 | } |
| 685 | if (!noptargs) { |
| 686 | goto skip_optional_pos; |
| 687 | } |
| 688 | if (PyFloat_Check(args[1])) { |
| 689 | PyErr_SetString(PyExc_TypeError, |
| 690 | "integer argument expected, got float" ); |
| 691 | goto exit; |
| 692 | } |
| 693 | eventmask = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); |
| 694 | if (eventmask == (unsigned int)-1 && PyErr_Occurred()) { |
| 695 | goto exit; |
| 696 | } |
| 697 | skip_optional_pos: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 698 | return_value = select_epoll_register_impl(self, fd, eventmask); |
| 699 | |
| 700 | exit: |
| 701 | return return_value; |
| 702 | } |
| 703 | |
| 704 | #endif /* defined(HAVE_EPOLL) */ |
| 705 | |
| 706 | #if defined(HAVE_EPOLL) |
| 707 | |
| 708 | PyDoc_STRVAR(select_epoll_modify__doc__, |
| 709 | "modify($self, /, fd, eventmask)\n" |
| 710 | "--\n" |
| 711 | "\n" |
| 712 | "Modify event mask for a registered file descriptor.\n" |
| 713 | "\n" |
| 714 | " fd\n" |
| 715 | " the target file descriptor of the operation\n" |
| 716 | " eventmask\n" |
| 717 | " a bit set composed of the various EPOLL constants"); |
| 718 | |
| 719 | #define SELECT_EPOLL_MODIFY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 720 | {"modify", (PyCFunction)(void(*)(void))select_epoll_modify, METH_FASTCALL|METH_KEYWORDS, select_epoll_modify__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 721 | |
| 722 | static PyObject * |
| 723 | select_epoll_modify_impl(pyEpoll_Object *self, int fd, |
| 724 | unsigned int eventmask); |
| 725 | |
| 726 | static PyObject * |
| 727 | select_epoll_modify(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 728 | { |
| 729 | PyObject *return_value = NULL; |
| 730 | static const char * const _keywords[] = {"fd", "eventmask", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 731 | static _PyArg_Parser _parser = {NULL, _keywords, "modify", 0}; |
| 732 | PyObject *argsbuf[2]; |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 733 | int fd; |
| 734 | unsigned int eventmask; |
| 735 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 736 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 737 | if (!args) { |
| 738 | goto exit; |
| 739 | } |
| 740 | if (!fildes_converter(args[0], &fd)) { |
| 741 | goto exit; |
| 742 | } |
| 743 | if (PyFloat_Check(args[1])) { |
| 744 | PyErr_SetString(PyExc_TypeError, |
| 745 | "integer argument expected, got float" ); |
| 746 | goto exit; |
| 747 | } |
| 748 | eventmask = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); |
| 749 | if (eventmask == (unsigned int)-1 && PyErr_Occurred()) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 750 | goto exit; |
| 751 | } |
| 752 | return_value = select_epoll_modify_impl(self, fd, eventmask); |
| 753 | |
| 754 | exit: |
| 755 | return return_value; |
| 756 | } |
| 757 | |
| 758 | #endif /* defined(HAVE_EPOLL) */ |
| 759 | |
| 760 | #if defined(HAVE_EPOLL) |
| 761 | |
| 762 | PyDoc_STRVAR(select_epoll_unregister__doc__, |
| 763 | "unregister($self, /, fd)\n" |
| 764 | "--\n" |
| 765 | "\n" |
| 766 | "Remove a registered file descriptor from the epoll object.\n" |
| 767 | "\n" |
| 768 | " fd\n" |
| 769 | " the target file descriptor of the operation"); |
| 770 | |
| 771 | #define SELECT_EPOLL_UNREGISTER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 772 | {"unregister", (PyCFunction)(void(*)(void))select_epoll_unregister, METH_FASTCALL|METH_KEYWORDS, select_epoll_unregister__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 773 | |
| 774 | static PyObject * |
| 775 | select_epoll_unregister_impl(pyEpoll_Object *self, int fd); |
| 776 | |
| 777 | static PyObject * |
| 778 | select_epoll_unregister(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 779 | { |
| 780 | PyObject *return_value = NULL; |
| 781 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 782 | static _PyArg_Parser _parser = {NULL, _keywords, "unregister", 0}; |
| 783 | PyObject *argsbuf[1]; |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 784 | int fd; |
| 785 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 786 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 787 | if (!args) { |
| 788 | goto exit; |
| 789 | } |
| 790 | if (!fildes_converter(args[0], &fd)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 791 | goto exit; |
| 792 | } |
| 793 | return_value = select_epoll_unregister_impl(self, fd); |
| 794 | |
| 795 | exit: |
| 796 | return return_value; |
| 797 | } |
| 798 | |
| 799 | #endif /* defined(HAVE_EPOLL) */ |
| 800 | |
| 801 | #if defined(HAVE_EPOLL) |
| 802 | |
| 803 | PyDoc_STRVAR(select_epoll_poll__doc__, |
| 804 | "poll($self, /, timeout=None, maxevents=-1)\n" |
| 805 | "--\n" |
| 806 | "\n" |
| 807 | "Wait for events on the epoll file descriptor.\n" |
| 808 | "\n" |
| 809 | " timeout\n" |
| 810 | " the maximum time to wait in seconds (as float);\n" |
| 811 | " a timeout of None or -1 makes poll wait indefinitely\n" |
| 812 | " maxevents\n" |
| 813 | " the maximum number of events returned; -1 means no limit\n" |
| 814 | "\n" |
| 815 | "Returns a list containing any descriptors that have events to report,\n" |
| 816 | "as a list of (fd, events) 2-tuples."); |
| 817 | |
| 818 | #define SELECT_EPOLL_POLL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 819 | {"poll", (PyCFunction)(void(*)(void))select_epoll_poll, METH_FASTCALL|METH_KEYWORDS, select_epoll_poll__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 820 | |
| 821 | static PyObject * |
| 822 | select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj, |
| 823 | int maxevents); |
| 824 | |
| 825 | static PyObject * |
| 826 | select_epoll_poll(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 827 | { |
| 828 | PyObject *return_value = NULL; |
| 829 | static const char * const _keywords[] = {"timeout", "maxevents", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 830 | static _PyArg_Parser _parser = {NULL, _keywords, "poll", 0}; |
| 831 | PyObject *argsbuf[2]; |
| 832 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 833 | PyObject *timeout_obj = Py_None; |
| 834 | int maxevents = -1; |
| 835 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 836 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); |
| 837 | if (!args) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 838 | goto exit; |
| 839 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 840 | if (!noptargs) { |
| 841 | goto skip_optional_pos; |
| 842 | } |
| 843 | if (args[0]) { |
| 844 | timeout_obj = args[0]; |
| 845 | if (!--noptargs) { |
| 846 | goto skip_optional_pos; |
| 847 | } |
| 848 | } |
| 849 | if (PyFloat_Check(args[1])) { |
| 850 | PyErr_SetString(PyExc_TypeError, |
| 851 | "integer argument expected, got float" ); |
| 852 | goto exit; |
| 853 | } |
| 854 | maxevents = _PyLong_AsInt(args[1]); |
| 855 | if (maxevents == -1 && PyErr_Occurred()) { |
| 856 | goto exit; |
| 857 | } |
| 858 | skip_optional_pos: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 859 | return_value = select_epoll_poll_impl(self, timeout_obj, maxevents); |
| 860 | |
| 861 | exit: |
| 862 | return return_value; |
| 863 | } |
| 864 | |
| 865 | #endif /* defined(HAVE_EPOLL) */ |
| 866 | |
| 867 | #if defined(HAVE_EPOLL) |
| 868 | |
| 869 | PyDoc_STRVAR(select_epoll___enter____doc__, |
| 870 | "__enter__($self, /)\n" |
| 871 | "--\n" |
| 872 | "\n"); |
| 873 | |
| 874 | #define SELECT_EPOLL___ENTER___METHODDEF \ |
| 875 | {"__enter__", (PyCFunction)select_epoll___enter__, METH_NOARGS, select_epoll___enter____doc__}, |
| 876 | |
| 877 | static PyObject * |
| 878 | select_epoll___enter___impl(pyEpoll_Object *self); |
| 879 | |
| 880 | static PyObject * |
| 881 | select_epoll___enter__(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored)) |
| 882 | { |
| 883 | return select_epoll___enter___impl(self); |
| 884 | } |
| 885 | |
| 886 | #endif /* defined(HAVE_EPOLL) */ |
| 887 | |
| 888 | #if defined(HAVE_EPOLL) |
| 889 | |
| 890 | PyDoc_STRVAR(select_epoll___exit____doc__, |
| 891 | "__exit__($self, exc_type=None, exc_value=None, exc_tb=None, /)\n" |
| 892 | "--\n" |
| 893 | "\n"); |
| 894 | |
| 895 | #define SELECT_EPOLL___EXIT___METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 896 | {"__exit__", (PyCFunction)(void(*)(void))select_epoll___exit__, METH_FASTCALL, select_epoll___exit____doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 897 | |
| 898 | static PyObject * |
| 899 | select_epoll___exit___impl(pyEpoll_Object *self, PyObject *exc_type, |
| 900 | PyObject *exc_value, PyObject *exc_tb); |
| 901 | |
| 902 | static PyObject * |
| 903 | select_epoll___exit__(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs) |
| 904 | { |
| 905 | PyObject *return_value = NULL; |
| 906 | PyObject *exc_type = Py_None; |
| 907 | PyObject *exc_value = Py_None; |
| 908 | PyObject *exc_tb = Py_None; |
| 909 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 910 | if (!_PyArg_CheckPositional("__exit__", nargs, 0, 3)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 911 | goto exit; |
| 912 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 913 | if (nargs < 1) { |
| 914 | goto skip_optional; |
| 915 | } |
| 916 | exc_type = args[0]; |
| 917 | if (nargs < 2) { |
| 918 | goto skip_optional; |
| 919 | } |
| 920 | exc_value = args[1]; |
| 921 | if (nargs < 3) { |
| 922 | goto skip_optional; |
| 923 | } |
| 924 | exc_tb = args[2]; |
| 925 | skip_optional: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 926 | return_value = select_epoll___exit___impl(self, exc_type, exc_value, exc_tb); |
| 927 | |
| 928 | exit: |
| 929 | return return_value; |
| 930 | } |
| 931 | |
| 932 | #endif /* defined(HAVE_EPOLL) */ |
| 933 | |
| 934 | #if defined(HAVE_KQUEUE) |
| 935 | |
| 936 | PyDoc_STRVAR(select_kqueue__doc__, |
| 937 | "kqueue()\n" |
| 938 | "--\n" |
| 939 | "\n" |
| 940 | "Kqueue syscall wrapper.\n" |
| 941 | "\n" |
| 942 | "For example, to start watching a socket for input:\n" |
| 943 | ">>> kq = kqueue()\n" |
| 944 | ">>> sock = socket()\n" |
| 945 | ">>> sock.connect((host, port))\n" |
| 946 | ">>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n" |
| 947 | "\n" |
| 948 | "To wait one second for it to become writeable:\n" |
| 949 | ">>> kq.control(None, 1, 1000)\n" |
| 950 | "\n" |
| 951 | "To stop listening:\n" |
| 952 | ">>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"); |
| 953 | |
| 954 | static PyObject * |
| 955 | select_kqueue_impl(PyTypeObject *type); |
| 956 | |
| 957 | static PyObject * |
| 958 | select_kqueue(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 959 | { |
| 960 | PyObject *return_value = NULL; |
| 961 | |
Dino Viehland | f919054 | 2019-09-14 15:20:27 +0100 | [diff] [blame] | 962 | if ((type == _selectstate_global->kqueue_queue_Type) && |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 963 | !_PyArg_NoPositional("kqueue", args)) { |
| 964 | goto exit; |
| 965 | } |
Dino Viehland | f919054 | 2019-09-14 15:20:27 +0100 | [diff] [blame] | 966 | if ((type == _selectstate_global->kqueue_queue_Type) && |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 967 | !_PyArg_NoKeywords("kqueue", kwargs)) { |
| 968 | goto exit; |
| 969 | } |
| 970 | return_value = select_kqueue_impl(type); |
| 971 | |
| 972 | exit: |
| 973 | return return_value; |
| 974 | } |
| 975 | |
| 976 | #endif /* defined(HAVE_KQUEUE) */ |
| 977 | |
| 978 | #if defined(HAVE_KQUEUE) |
| 979 | |
| 980 | PyDoc_STRVAR(select_kqueue_close__doc__, |
| 981 | "close($self, /)\n" |
| 982 | "--\n" |
| 983 | "\n" |
| 984 | "Close the kqueue control file descriptor.\n" |
| 985 | "\n" |
| 986 | "Further operations on the kqueue object will raise an exception."); |
| 987 | |
| 988 | #define SELECT_KQUEUE_CLOSE_METHODDEF \ |
| 989 | {"close", (PyCFunction)select_kqueue_close, METH_NOARGS, select_kqueue_close__doc__}, |
| 990 | |
| 991 | static PyObject * |
| 992 | select_kqueue_close_impl(kqueue_queue_Object *self); |
| 993 | |
| 994 | static PyObject * |
| 995 | select_kqueue_close(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored)) |
| 996 | { |
| 997 | return select_kqueue_close_impl(self); |
| 998 | } |
| 999 | |
| 1000 | #endif /* defined(HAVE_KQUEUE) */ |
| 1001 | |
| 1002 | #if defined(HAVE_KQUEUE) |
| 1003 | |
| 1004 | PyDoc_STRVAR(select_kqueue_fileno__doc__, |
| 1005 | "fileno($self, /)\n" |
| 1006 | "--\n" |
| 1007 | "\n" |
| 1008 | "Return the kqueue control file descriptor."); |
| 1009 | |
| 1010 | #define SELECT_KQUEUE_FILENO_METHODDEF \ |
| 1011 | {"fileno", (PyCFunction)select_kqueue_fileno, METH_NOARGS, select_kqueue_fileno__doc__}, |
| 1012 | |
| 1013 | static PyObject * |
| 1014 | select_kqueue_fileno_impl(kqueue_queue_Object *self); |
| 1015 | |
| 1016 | static PyObject * |
| 1017 | select_kqueue_fileno(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored)) |
| 1018 | { |
| 1019 | return select_kqueue_fileno_impl(self); |
| 1020 | } |
| 1021 | |
| 1022 | #endif /* defined(HAVE_KQUEUE) */ |
| 1023 | |
| 1024 | #if defined(HAVE_KQUEUE) |
| 1025 | |
| 1026 | PyDoc_STRVAR(select_kqueue_fromfd__doc__, |
| 1027 | "fromfd($type, fd, /)\n" |
| 1028 | "--\n" |
| 1029 | "\n" |
| 1030 | "Create a kqueue object from a given control fd."); |
| 1031 | |
| 1032 | #define SELECT_KQUEUE_FROMFD_METHODDEF \ |
| 1033 | {"fromfd", (PyCFunction)select_kqueue_fromfd, METH_O|METH_CLASS, select_kqueue_fromfd__doc__}, |
| 1034 | |
| 1035 | static PyObject * |
| 1036 | select_kqueue_fromfd_impl(PyTypeObject *type, int fd); |
| 1037 | |
| 1038 | static PyObject * |
| 1039 | select_kqueue_fromfd(PyTypeObject *type, PyObject *arg) |
| 1040 | { |
| 1041 | PyObject *return_value = NULL; |
| 1042 | int fd; |
| 1043 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1044 | if (PyFloat_Check(arg)) { |
| 1045 | PyErr_SetString(PyExc_TypeError, |
| 1046 | "integer argument expected, got float" ); |
| 1047 | goto exit; |
| 1048 | } |
| 1049 | fd = _PyLong_AsInt(arg); |
| 1050 | if (fd == -1 && PyErr_Occurred()) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 1051 | goto exit; |
| 1052 | } |
| 1053 | return_value = select_kqueue_fromfd_impl(type, fd); |
| 1054 | |
| 1055 | exit: |
| 1056 | return return_value; |
| 1057 | } |
| 1058 | |
| 1059 | #endif /* defined(HAVE_KQUEUE) */ |
| 1060 | |
| 1061 | #if defined(HAVE_KQUEUE) |
| 1062 | |
| 1063 | PyDoc_STRVAR(select_kqueue_control__doc__, |
| 1064 | "control($self, changelist, maxevents, timeout=None, /)\n" |
| 1065 | "--\n" |
| 1066 | "\n" |
| 1067 | "Calls the kernel kevent function.\n" |
| 1068 | "\n" |
| 1069 | " changelist\n" |
| 1070 | " Must be an iterable of kevent objects describing the changes to be made\n" |
| 1071 | " to the kernel\'s watch list or None.\n" |
| 1072 | " maxevents\n" |
| 1073 | " The maximum number of events that the kernel will return.\n" |
| 1074 | " timeout\n" |
| 1075 | " The maximum time to wait in seconds, or else None to wait forever.\n" |
| 1076 | " This accepts floats for smaller timeouts, too."); |
| 1077 | |
| 1078 | #define SELECT_KQUEUE_CONTROL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1079 | {"control", (PyCFunction)(void(*)(void))select_kqueue_control, METH_FASTCALL, select_kqueue_control__doc__}, |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 1080 | |
| 1081 | static PyObject * |
| 1082 | select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist, |
| 1083 | int maxevents, PyObject *otimeout); |
| 1084 | |
| 1085 | static PyObject * |
| 1086 | select_kqueue_control(kqueue_queue_Object *self, PyObject *const *args, Py_ssize_t nargs) |
| 1087 | { |
| 1088 | PyObject *return_value = NULL; |
| 1089 | PyObject *changelist; |
| 1090 | int maxevents; |
| 1091 | PyObject *otimeout = Py_None; |
| 1092 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1093 | if (!_PyArg_CheckPositional("control", nargs, 2, 3)) { |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 1094 | goto exit; |
| 1095 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1096 | changelist = args[0]; |
| 1097 | if (PyFloat_Check(args[1])) { |
| 1098 | PyErr_SetString(PyExc_TypeError, |
| 1099 | "integer argument expected, got float" ); |
| 1100 | goto exit; |
| 1101 | } |
| 1102 | maxevents = _PyLong_AsInt(args[1]); |
| 1103 | if (maxevents == -1 && PyErr_Occurred()) { |
| 1104 | goto exit; |
| 1105 | } |
| 1106 | if (nargs < 3) { |
| 1107 | goto skip_optional; |
| 1108 | } |
| 1109 | otimeout = args[2]; |
| 1110 | skip_optional: |
Tal Einat | 6dc57e2 | 2018-06-30 23:02:48 +0300 | [diff] [blame] | 1111 | return_value = select_kqueue_control_impl(self, changelist, maxevents, otimeout); |
| 1112 | |
| 1113 | exit: |
| 1114 | return return_value; |
| 1115 | } |
| 1116 | |
| 1117 | #endif /* defined(HAVE_KQUEUE) */ |
| 1118 | |
| 1119 | #ifndef SELECT_POLL_REGISTER_METHODDEF |
| 1120 | #define SELECT_POLL_REGISTER_METHODDEF |
| 1121 | #endif /* !defined(SELECT_POLL_REGISTER_METHODDEF) */ |
| 1122 | |
| 1123 | #ifndef SELECT_POLL_MODIFY_METHODDEF |
| 1124 | #define SELECT_POLL_MODIFY_METHODDEF |
| 1125 | #endif /* !defined(SELECT_POLL_MODIFY_METHODDEF) */ |
| 1126 | |
| 1127 | #ifndef SELECT_POLL_UNREGISTER_METHODDEF |
| 1128 | #define SELECT_POLL_UNREGISTER_METHODDEF |
| 1129 | #endif /* !defined(SELECT_POLL_UNREGISTER_METHODDEF) */ |
| 1130 | |
| 1131 | #ifndef SELECT_POLL_POLL_METHODDEF |
| 1132 | #define SELECT_POLL_POLL_METHODDEF |
| 1133 | #endif /* !defined(SELECT_POLL_POLL_METHODDEF) */ |
| 1134 | |
| 1135 | #ifndef SELECT_DEVPOLL_REGISTER_METHODDEF |
| 1136 | #define SELECT_DEVPOLL_REGISTER_METHODDEF |
| 1137 | #endif /* !defined(SELECT_DEVPOLL_REGISTER_METHODDEF) */ |
| 1138 | |
| 1139 | #ifndef SELECT_DEVPOLL_MODIFY_METHODDEF |
| 1140 | #define SELECT_DEVPOLL_MODIFY_METHODDEF |
| 1141 | #endif /* !defined(SELECT_DEVPOLL_MODIFY_METHODDEF) */ |
| 1142 | |
| 1143 | #ifndef SELECT_DEVPOLL_UNREGISTER_METHODDEF |
| 1144 | #define SELECT_DEVPOLL_UNREGISTER_METHODDEF |
| 1145 | #endif /* !defined(SELECT_DEVPOLL_UNREGISTER_METHODDEF) */ |
| 1146 | |
| 1147 | #ifndef SELECT_DEVPOLL_POLL_METHODDEF |
| 1148 | #define SELECT_DEVPOLL_POLL_METHODDEF |
| 1149 | #endif /* !defined(SELECT_DEVPOLL_POLL_METHODDEF) */ |
| 1150 | |
| 1151 | #ifndef SELECT_DEVPOLL_CLOSE_METHODDEF |
| 1152 | #define SELECT_DEVPOLL_CLOSE_METHODDEF |
| 1153 | #endif /* !defined(SELECT_DEVPOLL_CLOSE_METHODDEF) */ |
| 1154 | |
| 1155 | #ifndef SELECT_DEVPOLL_FILENO_METHODDEF |
| 1156 | #define SELECT_DEVPOLL_FILENO_METHODDEF |
| 1157 | #endif /* !defined(SELECT_DEVPOLL_FILENO_METHODDEF) */ |
| 1158 | |
| 1159 | #ifndef SELECT_POLL_METHODDEF |
| 1160 | #define SELECT_POLL_METHODDEF |
| 1161 | #endif /* !defined(SELECT_POLL_METHODDEF) */ |
| 1162 | |
| 1163 | #ifndef SELECT_DEVPOLL_METHODDEF |
| 1164 | #define SELECT_DEVPOLL_METHODDEF |
| 1165 | #endif /* !defined(SELECT_DEVPOLL_METHODDEF) */ |
| 1166 | |
| 1167 | #ifndef SELECT_EPOLL_CLOSE_METHODDEF |
| 1168 | #define SELECT_EPOLL_CLOSE_METHODDEF |
| 1169 | #endif /* !defined(SELECT_EPOLL_CLOSE_METHODDEF) */ |
| 1170 | |
| 1171 | #ifndef SELECT_EPOLL_FILENO_METHODDEF |
| 1172 | #define SELECT_EPOLL_FILENO_METHODDEF |
| 1173 | #endif /* !defined(SELECT_EPOLL_FILENO_METHODDEF) */ |
| 1174 | |
| 1175 | #ifndef SELECT_EPOLL_FROMFD_METHODDEF |
| 1176 | #define SELECT_EPOLL_FROMFD_METHODDEF |
| 1177 | #endif /* !defined(SELECT_EPOLL_FROMFD_METHODDEF) */ |
| 1178 | |
| 1179 | #ifndef SELECT_EPOLL_REGISTER_METHODDEF |
| 1180 | #define SELECT_EPOLL_REGISTER_METHODDEF |
| 1181 | #endif /* !defined(SELECT_EPOLL_REGISTER_METHODDEF) */ |
| 1182 | |
| 1183 | #ifndef SELECT_EPOLL_MODIFY_METHODDEF |
| 1184 | #define SELECT_EPOLL_MODIFY_METHODDEF |
| 1185 | #endif /* !defined(SELECT_EPOLL_MODIFY_METHODDEF) */ |
| 1186 | |
| 1187 | #ifndef SELECT_EPOLL_UNREGISTER_METHODDEF |
| 1188 | #define SELECT_EPOLL_UNREGISTER_METHODDEF |
| 1189 | #endif /* !defined(SELECT_EPOLL_UNREGISTER_METHODDEF) */ |
| 1190 | |
| 1191 | #ifndef SELECT_EPOLL_POLL_METHODDEF |
| 1192 | #define SELECT_EPOLL_POLL_METHODDEF |
| 1193 | #endif /* !defined(SELECT_EPOLL_POLL_METHODDEF) */ |
| 1194 | |
| 1195 | #ifndef SELECT_EPOLL___ENTER___METHODDEF |
| 1196 | #define SELECT_EPOLL___ENTER___METHODDEF |
| 1197 | #endif /* !defined(SELECT_EPOLL___ENTER___METHODDEF) */ |
| 1198 | |
| 1199 | #ifndef SELECT_EPOLL___EXIT___METHODDEF |
| 1200 | #define SELECT_EPOLL___EXIT___METHODDEF |
| 1201 | #endif /* !defined(SELECT_EPOLL___EXIT___METHODDEF) */ |
| 1202 | |
| 1203 | #ifndef SELECT_KQUEUE_CLOSE_METHODDEF |
| 1204 | #define SELECT_KQUEUE_CLOSE_METHODDEF |
| 1205 | #endif /* !defined(SELECT_KQUEUE_CLOSE_METHODDEF) */ |
| 1206 | |
| 1207 | #ifndef SELECT_KQUEUE_FILENO_METHODDEF |
| 1208 | #define SELECT_KQUEUE_FILENO_METHODDEF |
| 1209 | #endif /* !defined(SELECT_KQUEUE_FILENO_METHODDEF) */ |
| 1210 | |
| 1211 | #ifndef SELECT_KQUEUE_FROMFD_METHODDEF |
| 1212 | #define SELECT_KQUEUE_FROMFD_METHODDEF |
| 1213 | #endif /* !defined(SELECT_KQUEUE_FROMFD_METHODDEF) */ |
| 1214 | |
| 1215 | #ifndef SELECT_KQUEUE_CONTROL_METHODDEF |
| 1216 | #define SELECT_KQUEUE_CONTROL_METHODDEF |
| 1217 | #endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */ |
Dino Viehland | f919054 | 2019-09-14 15:20:27 +0100 | [diff] [blame] | 1218 | /*[clinic end generated code: output=26bb05e5fba2bfd1 input=a9049054013a1b77]*/ |