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