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