blob: bb69d957c6975108254eb7db5c7f86034b6a5490 [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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200156 if (!fildes_converter(arg, &fd)) {
Tal Einat6dc57e22018-06-30 23:02:48 +0300157 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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200303 if (!fildes_converter(arg, &fd)) {
Tal Einat6dc57e22018-06-30 23:02:48 +0300304 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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200553 if (PyFloat_Check(arg)) {
554 PyErr_SetString(PyExc_TypeError,
555 "integer argument expected, got float" );
556 goto exit;
557 }
558 fd = _PyLong_AsInt(arg);
559 if (fd == -1 && PyErr_Occurred()) {
Tal Einat6dc57e22018-06-30 23:02:48 +0300560 goto exit;
561 }
562 return_value = select_epoll_fromfd_impl(type, fd);
563
564exit:
565 return return_value;
566}
567
568#endif /* defined(HAVE_EPOLL) */
569
570#if defined(HAVE_EPOLL)
571
572PyDoc_STRVAR(select_epoll_register__doc__,
573"register($self, /, fd, eventmask=EPOLLIN | EPOLLPRI | EPOLLOUT)\n"
574"--\n"
575"\n"
576"Registers a new fd or raises an OSError if the fd is already registered.\n"
577"\n"
578" fd\n"
579" the target file descriptor of the operation\n"
580" eventmask\n"
581" a bit set composed of the various EPOLL constants\n"
582"\n"
583"The epoll interface supports all file descriptors that support poll.");
584
585#define SELECT_EPOLL_REGISTER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200586 {"register", (PyCFunction)(void(*)(void))select_epoll_register, METH_FASTCALL|METH_KEYWORDS, select_epoll_register__doc__},
Tal Einat6dc57e22018-06-30 23:02:48 +0300587
588static PyObject *
589select_epoll_register_impl(pyEpoll_Object *self, int fd,
590 unsigned int eventmask);
591
592static PyObject *
593select_epoll_register(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
594{
595 PyObject *return_value = NULL;
596 static const char * const _keywords[] = {"fd", "eventmask", NULL};
597 static _PyArg_Parser _parser = {"O&|I:register", _keywords, 0};
598 int fd;
599 unsigned int eventmask = EPOLLIN | EPOLLPRI | EPOLLOUT;
600
601 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
602 fildes_converter, &fd, &eventmask)) {
603 goto exit;
604 }
605 return_value = select_epoll_register_impl(self, fd, eventmask);
606
607exit:
608 return return_value;
609}
610
611#endif /* defined(HAVE_EPOLL) */
612
613#if defined(HAVE_EPOLL)
614
615PyDoc_STRVAR(select_epoll_modify__doc__,
616"modify($self, /, fd, eventmask)\n"
617"--\n"
618"\n"
619"Modify event mask for a registered file descriptor.\n"
620"\n"
621" fd\n"
622" the target file descriptor of the operation\n"
623" eventmask\n"
624" a bit set composed of the various EPOLL constants");
625
626#define SELECT_EPOLL_MODIFY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200627 {"modify", (PyCFunction)(void(*)(void))select_epoll_modify, METH_FASTCALL|METH_KEYWORDS, select_epoll_modify__doc__},
Tal Einat6dc57e22018-06-30 23:02:48 +0300628
629static PyObject *
630select_epoll_modify_impl(pyEpoll_Object *self, int fd,
631 unsigned int eventmask);
632
633static PyObject *
634select_epoll_modify(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
635{
636 PyObject *return_value = NULL;
637 static const char * const _keywords[] = {"fd", "eventmask", NULL};
638 static _PyArg_Parser _parser = {"O&I:modify", _keywords, 0};
639 int fd;
640 unsigned int eventmask;
641
642 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
643 fildes_converter, &fd, &eventmask)) {
644 goto exit;
645 }
646 return_value = select_epoll_modify_impl(self, fd, eventmask);
647
648exit:
649 return return_value;
650}
651
652#endif /* defined(HAVE_EPOLL) */
653
654#if defined(HAVE_EPOLL)
655
656PyDoc_STRVAR(select_epoll_unregister__doc__,
657"unregister($self, /, fd)\n"
658"--\n"
659"\n"
660"Remove a registered file descriptor from the epoll object.\n"
661"\n"
662" fd\n"
663" the target file descriptor of the operation");
664
665#define SELECT_EPOLL_UNREGISTER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200666 {"unregister", (PyCFunction)(void(*)(void))select_epoll_unregister, METH_FASTCALL|METH_KEYWORDS, select_epoll_unregister__doc__},
Tal Einat6dc57e22018-06-30 23:02:48 +0300667
668static PyObject *
669select_epoll_unregister_impl(pyEpoll_Object *self, int fd);
670
671static PyObject *
672select_epoll_unregister(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
673{
674 PyObject *return_value = NULL;
675 static const char * const _keywords[] = {"fd", NULL};
676 static _PyArg_Parser _parser = {"O&:unregister", _keywords, 0};
677 int fd;
678
679 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
680 fildes_converter, &fd)) {
681 goto exit;
682 }
683 return_value = select_epoll_unregister_impl(self, fd);
684
685exit:
686 return return_value;
687}
688
689#endif /* defined(HAVE_EPOLL) */
690
691#if defined(HAVE_EPOLL)
692
693PyDoc_STRVAR(select_epoll_poll__doc__,
694"poll($self, /, timeout=None, maxevents=-1)\n"
695"--\n"
696"\n"
697"Wait for events on the epoll file descriptor.\n"
698"\n"
699" timeout\n"
700" the maximum time to wait in seconds (as float);\n"
701" a timeout of None or -1 makes poll wait indefinitely\n"
702" maxevents\n"
703" the maximum number of events returned; -1 means no limit\n"
704"\n"
705"Returns a list containing any descriptors that have events to report,\n"
706"as a list of (fd, events) 2-tuples.");
707
708#define SELECT_EPOLL_POLL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200709 {"poll", (PyCFunction)(void(*)(void))select_epoll_poll, METH_FASTCALL|METH_KEYWORDS, select_epoll_poll__doc__},
Tal Einat6dc57e22018-06-30 23:02:48 +0300710
711static PyObject *
712select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj,
713 int maxevents);
714
715static PyObject *
716select_epoll_poll(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
717{
718 PyObject *return_value = NULL;
719 static const char * const _keywords[] = {"timeout", "maxevents", NULL};
720 static _PyArg_Parser _parser = {"|Oi:poll", _keywords, 0};
721 PyObject *timeout_obj = Py_None;
722 int maxevents = -1;
723
724 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
725 &timeout_obj, &maxevents)) {
726 goto exit;
727 }
728 return_value = select_epoll_poll_impl(self, timeout_obj, maxevents);
729
730exit:
731 return return_value;
732}
733
734#endif /* defined(HAVE_EPOLL) */
735
736#if defined(HAVE_EPOLL)
737
738PyDoc_STRVAR(select_epoll___enter____doc__,
739"__enter__($self, /)\n"
740"--\n"
741"\n");
742
743#define SELECT_EPOLL___ENTER___METHODDEF \
744 {"__enter__", (PyCFunction)select_epoll___enter__, METH_NOARGS, select_epoll___enter____doc__},
745
746static PyObject *
747select_epoll___enter___impl(pyEpoll_Object *self);
748
749static PyObject *
750select_epoll___enter__(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored))
751{
752 return select_epoll___enter___impl(self);
753}
754
755#endif /* defined(HAVE_EPOLL) */
756
757#if defined(HAVE_EPOLL)
758
759PyDoc_STRVAR(select_epoll___exit____doc__,
760"__exit__($self, exc_type=None, exc_value=None, exc_tb=None, /)\n"
761"--\n"
762"\n");
763
764#define SELECT_EPOLL___EXIT___METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200765 {"__exit__", (PyCFunction)(void(*)(void))select_epoll___exit__, METH_FASTCALL, select_epoll___exit____doc__},
Tal Einat6dc57e22018-06-30 23:02:48 +0300766
767static PyObject *
768select_epoll___exit___impl(pyEpoll_Object *self, PyObject *exc_type,
769 PyObject *exc_value, PyObject *exc_tb);
770
771static PyObject *
772select_epoll___exit__(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs)
773{
774 PyObject *return_value = NULL;
775 PyObject *exc_type = Py_None;
776 PyObject *exc_value = Py_None;
777 PyObject *exc_tb = Py_None;
778
779 if (!_PyArg_UnpackStack(args, nargs, "__exit__",
780 0, 3,
781 &exc_type, &exc_value, &exc_tb)) {
782 goto exit;
783 }
784 return_value = select_epoll___exit___impl(self, exc_type, exc_value, exc_tb);
785
786exit:
787 return return_value;
788}
789
790#endif /* defined(HAVE_EPOLL) */
791
792#if defined(HAVE_KQUEUE)
793
794PyDoc_STRVAR(select_kqueue__doc__,
795"kqueue()\n"
796"--\n"
797"\n"
798"Kqueue syscall wrapper.\n"
799"\n"
800"For example, to start watching a socket for input:\n"
801">>> kq = kqueue()\n"
802">>> sock = socket()\n"
803">>> sock.connect((host, port))\n"
804">>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n"
805"\n"
806"To wait one second for it to become writeable:\n"
807">>> kq.control(None, 1, 1000)\n"
808"\n"
809"To stop listening:\n"
810">>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)");
811
812static PyObject *
813select_kqueue_impl(PyTypeObject *type);
814
815static PyObject *
816select_kqueue(PyTypeObject *type, PyObject *args, PyObject *kwargs)
817{
818 PyObject *return_value = NULL;
819
820 if ((type == &kqueue_queue_Type) &&
821 !_PyArg_NoPositional("kqueue", args)) {
822 goto exit;
823 }
824 if ((type == &kqueue_queue_Type) &&
825 !_PyArg_NoKeywords("kqueue", kwargs)) {
826 goto exit;
827 }
828 return_value = select_kqueue_impl(type);
829
830exit:
831 return return_value;
832}
833
834#endif /* defined(HAVE_KQUEUE) */
835
836#if defined(HAVE_KQUEUE)
837
838PyDoc_STRVAR(select_kqueue_close__doc__,
839"close($self, /)\n"
840"--\n"
841"\n"
842"Close the kqueue control file descriptor.\n"
843"\n"
844"Further operations on the kqueue object will raise an exception.");
845
846#define SELECT_KQUEUE_CLOSE_METHODDEF \
847 {"close", (PyCFunction)select_kqueue_close, METH_NOARGS, select_kqueue_close__doc__},
848
849static PyObject *
850select_kqueue_close_impl(kqueue_queue_Object *self);
851
852static PyObject *
853select_kqueue_close(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored))
854{
855 return select_kqueue_close_impl(self);
856}
857
858#endif /* defined(HAVE_KQUEUE) */
859
860#if defined(HAVE_KQUEUE)
861
862PyDoc_STRVAR(select_kqueue_fileno__doc__,
863"fileno($self, /)\n"
864"--\n"
865"\n"
866"Return the kqueue control file descriptor.");
867
868#define SELECT_KQUEUE_FILENO_METHODDEF \
869 {"fileno", (PyCFunction)select_kqueue_fileno, METH_NOARGS, select_kqueue_fileno__doc__},
870
871static PyObject *
872select_kqueue_fileno_impl(kqueue_queue_Object *self);
873
874static PyObject *
875select_kqueue_fileno(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored))
876{
877 return select_kqueue_fileno_impl(self);
878}
879
880#endif /* defined(HAVE_KQUEUE) */
881
882#if defined(HAVE_KQUEUE)
883
884PyDoc_STRVAR(select_kqueue_fromfd__doc__,
885"fromfd($type, fd, /)\n"
886"--\n"
887"\n"
888"Create a kqueue object from a given control fd.");
889
890#define SELECT_KQUEUE_FROMFD_METHODDEF \
891 {"fromfd", (PyCFunction)select_kqueue_fromfd, METH_O|METH_CLASS, select_kqueue_fromfd__doc__},
892
893static PyObject *
894select_kqueue_fromfd_impl(PyTypeObject *type, int fd);
895
896static PyObject *
897select_kqueue_fromfd(PyTypeObject *type, PyObject *arg)
898{
899 PyObject *return_value = NULL;
900 int fd;
901
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200902 if (PyFloat_Check(arg)) {
903 PyErr_SetString(PyExc_TypeError,
904 "integer argument expected, got float" );
905 goto exit;
906 }
907 fd = _PyLong_AsInt(arg);
908 if (fd == -1 && PyErr_Occurred()) {
Tal Einat6dc57e22018-06-30 23:02:48 +0300909 goto exit;
910 }
911 return_value = select_kqueue_fromfd_impl(type, fd);
912
913exit:
914 return return_value;
915}
916
917#endif /* defined(HAVE_KQUEUE) */
918
919#if defined(HAVE_KQUEUE)
920
921PyDoc_STRVAR(select_kqueue_control__doc__,
922"control($self, changelist, maxevents, timeout=None, /)\n"
923"--\n"
924"\n"
925"Calls the kernel kevent function.\n"
926"\n"
927" changelist\n"
928" Must be an iterable of kevent objects describing the changes to be made\n"
929" to the kernel\'s watch list or None.\n"
930" maxevents\n"
931" The maximum number of events that the kernel will return.\n"
932" timeout\n"
933" The maximum time to wait in seconds, or else None to wait forever.\n"
934" This accepts floats for smaller timeouts, too.");
935
936#define SELECT_KQUEUE_CONTROL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200937 {"control", (PyCFunction)(void(*)(void))select_kqueue_control, METH_FASTCALL, select_kqueue_control__doc__},
Tal Einat6dc57e22018-06-30 23:02:48 +0300938
939static PyObject *
940select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist,
941 int maxevents, PyObject *otimeout);
942
943static PyObject *
944select_kqueue_control(kqueue_queue_Object *self, PyObject *const *args, Py_ssize_t nargs)
945{
946 PyObject *return_value = NULL;
947 PyObject *changelist;
948 int maxevents;
949 PyObject *otimeout = Py_None;
950
951 if (!_PyArg_ParseStack(args, nargs, "Oi|O:control",
952 &changelist, &maxevents, &otimeout)) {
953 goto exit;
954 }
955 return_value = select_kqueue_control_impl(self, changelist, maxevents, otimeout);
956
957exit:
958 return return_value;
959}
960
961#endif /* defined(HAVE_KQUEUE) */
962
963#ifndef SELECT_POLL_REGISTER_METHODDEF
964 #define SELECT_POLL_REGISTER_METHODDEF
965#endif /* !defined(SELECT_POLL_REGISTER_METHODDEF) */
966
967#ifndef SELECT_POLL_MODIFY_METHODDEF
968 #define SELECT_POLL_MODIFY_METHODDEF
969#endif /* !defined(SELECT_POLL_MODIFY_METHODDEF) */
970
971#ifndef SELECT_POLL_UNREGISTER_METHODDEF
972 #define SELECT_POLL_UNREGISTER_METHODDEF
973#endif /* !defined(SELECT_POLL_UNREGISTER_METHODDEF) */
974
975#ifndef SELECT_POLL_POLL_METHODDEF
976 #define SELECT_POLL_POLL_METHODDEF
977#endif /* !defined(SELECT_POLL_POLL_METHODDEF) */
978
979#ifndef SELECT_DEVPOLL_REGISTER_METHODDEF
980 #define SELECT_DEVPOLL_REGISTER_METHODDEF
981#endif /* !defined(SELECT_DEVPOLL_REGISTER_METHODDEF) */
982
983#ifndef SELECT_DEVPOLL_MODIFY_METHODDEF
984 #define SELECT_DEVPOLL_MODIFY_METHODDEF
985#endif /* !defined(SELECT_DEVPOLL_MODIFY_METHODDEF) */
986
987#ifndef SELECT_DEVPOLL_UNREGISTER_METHODDEF
988 #define SELECT_DEVPOLL_UNREGISTER_METHODDEF
989#endif /* !defined(SELECT_DEVPOLL_UNREGISTER_METHODDEF) */
990
991#ifndef SELECT_DEVPOLL_POLL_METHODDEF
992 #define SELECT_DEVPOLL_POLL_METHODDEF
993#endif /* !defined(SELECT_DEVPOLL_POLL_METHODDEF) */
994
995#ifndef SELECT_DEVPOLL_CLOSE_METHODDEF
996 #define SELECT_DEVPOLL_CLOSE_METHODDEF
997#endif /* !defined(SELECT_DEVPOLL_CLOSE_METHODDEF) */
998
999#ifndef SELECT_DEVPOLL_FILENO_METHODDEF
1000 #define SELECT_DEVPOLL_FILENO_METHODDEF
1001#endif /* !defined(SELECT_DEVPOLL_FILENO_METHODDEF) */
1002
1003#ifndef SELECT_POLL_METHODDEF
1004 #define SELECT_POLL_METHODDEF
1005#endif /* !defined(SELECT_POLL_METHODDEF) */
1006
1007#ifndef SELECT_DEVPOLL_METHODDEF
1008 #define SELECT_DEVPOLL_METHODDEF
1009#endif /* !defined(SELECT_DEVPOLL_METHODDEF) */
1010
1011#ifndef SELECT_EPOLL_CLOSE_METHODDEF
1012 #define SELECT_EPOLL_CLOSE_METHODDEF
1013#endif /* !defined(SELECT_EPOLL_CLOSE_METHODDEF) */
1014
1015#ifndef SELECT_EPOLL_FILENO_METHODDEF
1016 #define SELECT_EPOLL_FILENO_METHODDEF
1017#endif /* !defined(SELECT_EPOLL_FILENO_METHODDEF) */
1018
1019#ifndef SELECT_EPOLL_FROMFD_METHODDEF
1020 #define SELECT_EPOLL_FROMFD_METHODDEF
1021#endif /* !defined(SELECT_EPOLL_FROMFD_METHODDEF) */
1022
1023#ifndef SELECT_EPOLL_REGISTER_METHODDEF
1024 #define SELECT_EPOLL_REGISTER_METHODDEF
1025#endif /* !defined(SELECT_EPOLL_REGISTER_METHODDEF) */
1026
1027#ifndef SELECT_EPOLL_MODIFY_METHODDEF
1028 #define SELECT_EPOLL_MODIFY_METHODDEF
1029#endif /* !defined(SELECT_EPOLL_MODIFY_METHODDEF) */
1030
1031#ifndef SELECT_EPOLL_UNREGISTER_METHODDEF
1032 #define SELECT_EPOLL_UNREGISTER_METHODDEF
1033#endif /* !defined(SELECT_EPOLL_UNREGISTER_METHODDEF) */
1034
1035#ifndef SELECT_EPOLL_POLL_METHODDEF
1036 #define SELECT_EPOLL_POLL_METHODDEF
1037#endif /* !defined(SELECT_EPOLL_POLL_METHODDEF) */
1038
1039#ifndef SELECT_EPOLL___ENTER___METHODDEF
1040 #define SELECT_EPOLL___ENTER___METHODDEF
1041#endif /* !defined(SELECT_EPOLL___ENTER___METHODDEF) */
1042
1043#ifndef SELECT_EPOLL___EXIT___METHODDEF
1044 #define SELECT_EPOLL___EXIT___METHODDEF
1045#endif /* !defined(SELECT_EPOLL___EXIT___METHODDEF) */
1046
1047#ifndef SELECT_KQUEUE_CLOSE_METHODDEF
1048 #define SELECT_KQUEUE_CLOSE_METHODDEF
1049#endif /* !defined(SELECT_KQUEUE_CLOSE_METHODDEF) */
1050
1051#ifndef SELECT_KQUEUE_FILENO_METHODDEF
1052 #define SELECT_KQUEUE_FILENO_METHODDEF
1053#endif /* !defined(SELECT_KQUEUE_FILENO_METHODDEF) */
1054
1055#ifndef SELECT_KQUEUE_FROMFD_METHODDEF
1056 #define SELECT_KQUEUE_FROMFD_METHODDEF
1057#endif /* !defined(SELECT_KQUEUE_FROMFD_METHODDEF) */
1058
1059#ifndef SELECT_KQUEUE_CONTROL_METHODDEF
1060 #define SELECT_KQUEUE_CONTROL_METHODDEF
1061#endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001062/*[clinic end generated code: output=122a49f131cdd9d9 input=a9049054013a1b77]*/