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