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