selectmodule.c.h 37 KB

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