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