Bug Summary

File:Modules/selectmodule.c
Location:line 1619, column 17
Description:Array access (from variable 'evl') results in a null pointer dereference

Annotated Source Code

1/* select - Module containing unix select(2) call.
2 Under Unix, the file descriptors are small integers.
3 Under Win32, select only exists for sockets, and sockets may
4 have any value except INVALID_SOCKET.
5*/
6
7#include "Python.h"
8#include <structmember.h>
9
10#ifdef __APPLE__1
11 /* Perform runtime testing for a broken poll on OSX to make it easier
12 * to use the same binary on multiple releases of the OS.
13 */
14#undef HAVE_BROKEN_POLL
15#endif
16
17/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
18 64 is too small (too many people have bumped into that limit).
19 Here we boost it.
20 Users who want even more than the boosted limit should #define
21 FD_SETSIZE higher before this; e.g., via compiler /D switch.
22*/
23#if defined(MS_WINDOWS) && !defined(FD_SETSIZE1024)
24#define FD_SETSIZE1024 512
25#endif
26
27#if defined(HAVE_POLL_H1)
28#include <poll.h>
29#elif defined(HAVE_SYS_POLL_H1)
30#include <sys/poll.h>
31#endif
32
33#ifdef __sgi
34/* This is missing from unistd.h */
35extern void bzero(void *, int);
36#endif
37
38#ifdef HAVE_SYS_TYPES_H1
39#include <sys/types.h>
40#endif
41
42#if defined(PYOS_OS2) && !defined(PYCC_GCC)
43#include <sys/time.h>
44#include <utils.h>
45#endif
46
47#ifdef MS_WINDOWS
48# define WIN32_LEAN_AND_MEAN
49# include <winsock.h>
50#else
51# define SOCKETint int
52# if defined(__VMS)
53# include <socket.h>
54# endif
55#endif
56
57static PyObject *SelectError;
58
59/* list of Python objects and their file descriptor */
60typedef struct {
61 PyObject *obj; /* owned reference */
62 SOCKETint fd;
63 int sentinel; /* -1 == sentinel */
64} pylist;
65
66static void
67reap_obj(pylist fd2obj[FD_SETSIZE1024 + 1])
68{
69 int i;
70 for (i = 0; i < FD_SETSIZE1024 + 1 && fd2obj[i].sentinel >= 0; i++) {
71 Py_XDECREF(fd2obj[i].obj)do { if ((fd2obj[i].obj) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(fd2obj[i].obj))->ob_refcnt != 0) { if (
((PyObject*)fd2obj[i].obj)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 71
, (PyObject *)(fd2obj[i].obj)); } else _Py_Dealloc((PyObject *
)(fd2obj[i].obj)); } while (0); } while (0)
;
72 fd2obj[i].obj = NULL((void*)0);
73 }
74 fd2obj[0].sentinel = -1;
75}
76
77
78/* returns -1 and sets the Python exception if an error occurred, otherwise
79 returns a number >= 0
80*/
81static int
82seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE1024 + 1])
83{
84 int max = -1;
85 int index = 0;
86 Py_ssize_t i, len = -1;
87 PyObject* fast_seq = NULL((void*)0);
88 PyObject* o = NULL((void*)0);
89
90 fd2obj[0].obj = (PyObject*)0; /* set list to zero size */
91 FD_ZERO(set)__builtin_bzero(set, sizeof(*(set)));
92
93 fast_seq = PySequence_Fast(seq, "arguments 1-3 must be sequences");
94 if (!fast_seq)
95 return -1;
96
97 len = PySequence_Fast_GET_SIZE(fast_seq)(((((((PyObject*)(fast_seq))->ob_type))->tp_flags &
((1L<<25))) != 0) ? (((PyVarObject*)(fast_seq))->ob_size
) : (((PyVarObject*)(fast_seq))->ob_size))
;
98
99 for (i = 0; i < len; i++) {
100 SOCKETint v;
101
102 /* any intervening fileno() calls could decr this refcnt */
103 if (!(o = PySequence_Fast_GET_ITEM(fast_seq, i)(((((((PyObject*)(fast_seq))->ob_type))->tp_flags &
((1L<<25))) != 0) ? (((PyListObject *)(fast_seq))->
ob_item[i]) : (((PyTupleObject *)(fast_seq))->ob_item[i]))
))
104 return -1;
105
106 Py_INCREF(o)( _Py_RefTotal++ , ((PyObject*)(o))->ob_refcnt++);
107 v = PyObject_AsFileDescriptor( o );
108 if (v == -1) goto finally;
109
110#if defined(_MSC_VER)
111 max = 0; /* not used for Win32 */
112#else /* !_MSC_VER */
113 if (v < 0 || v >= FD_SETSIZE1024) {
114 PyErr_SetString(PyExc_ValueError,
115 "filedescriptor out of range in select()");
116 goto finally;
117 }
118 if (v > max)
119 max = v;
120#endif /* _MSC_VER */
121 FD_SET(v, set)do { int __fd = (v); ((set)->fds_bits[__fd/(sizeof(__int32_t
) * 8)] |= (1<<(__fd % (sizeof(__int32_t) * 8)))); } while
(0)
;
122
123 /* add object and its file descriptor to the list */
124 if (index >= FD_SETSIZE1024) {
125 PyErr_SetString(PyExc_ValueError,
126 "too many file descriptors in select()");
127 goto finally;
128 }
129 fd2obj[index].obj = o;
130 fd2obj[index].fd = v;
131 fd2obj[index].sentinel = 0;
132 fd2obj[++index].sentinel = -1;
133 }
134 Py_DECREF(fast_seq)do { if (_Py_RefTotal-- , --((PyObject*)(fast_seq))->ob_refcnt
!= 0) { if (((PyObject*)fast_seq)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 134
, (PyObject *)(fast_seq)); } else _Py_Dealloc((PyObject *)(fast_seq
)); } while (0)
;
135 return max+1;
136
137 finally:
138 Py_XDECREF(o)do { if ((o) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --
((PyObject*)(o))->ob_refcnt != 0) { if (((PyObject*)o)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c"
, 138, (PyObject *)(o)); } else _Py_Dealloc((PyObject *)(o));
} while (0); } while (0)
;
139 Py_DECREF(fast_seq)do { if (_Py_RefTotal-- , --((PyObject*)(fast_seq))->ob_refcnt
!= 0) { if (((PyObject*)fast_seq)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 139
, (PyObject *)(fast_seq)); } else _Py_Dealloc((PyObject *)(fast_seq
)); } while (0)
;
140 return -1;
141}
142
143/* returns NULL and sets the Python exception if an error occurred */
144static PyObject *
145set2list(fd_set *set, pylist fd2obj[FD_SETSIZE1024 + 1])
146{
147 int i, j, count=0;
148 PyObject *list, *o;
149 SOCKETint fd;
150
151 for (j = 0; fd2obj[j].sentinel >= 0; j++) {
152 if (FD_ISSET(fd2obj[j].fd, set)__darwin_fd_isset((fd2obj[j].fd), (set)))
153 count++;
154 }
155 list = PyList_New(count);
156 if (!list)
157 return NULL((void*)0);
158
159 i = 0;
160 for (j = 0; fd2obj[j].sentinel >= 0; j++) {
161 fd = fd2obj[j].fd;
162 if (FD_ISSET(fd, set)__darwin_fd_isset((fd), (set))) {
163#ifndef _MSC_VER
164 if (fd > FD_SETSIZE1024) {
165 PyErr_SetString(PyExc_SystemError,
166 "filedescriptor out of range returned in select()");
167 goto finally;
168 }
169#endif
170 o = fd2obj[j].obj;
171 fd2obj[j].obj = NULL((void*)0);
172 /* transfer ownership */
173 if (PyList_SetItem(list, i, o) < 0)
174 goto finally;
175
176 i++;
177 }
178 }
179 return list;
180 finally:
181 Py_DECREF(list)do { if (_Py_RefTotal-- , --((PyObject*)(list))->ob_refcnt
!= 0) { if (((PyObject*)list)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 181
, (PyObject *)(list)); } else _Py_Dealloc((PyObject *)(list))
; } while (0)
;
182 return NULL((void*)0);
183}
184
185#undef SELECT_USES_HEAP
186#if FD_SETSIZE1024 > 1024
187#define SELECT_USES_HEAP
188#endif /* FD_SETSIZE > 1024 */
189
190static PyObject *
191select_select(PyObject *self, PyObject *args)
192{
193#ifdef SELECT_USES_HEAP
194 pylist *rfd2obj, *wfd2obj, *efd2obj;
195#else /* !SELECT_USES_HEAP */
196 /* XXX: All this should probably be implemented as follows:
197 * - find the highest descriptor we're interested in
198 * - add one
199 * - that's the size
200 * See: Stevens, APitUE, $12.5.1
201 */
202 pylist rfd2obj[FD_SETSIZE1024 + 1];
203 pylist wfd2obj[FD_SETSIZE1024 + 1];
204 pylist efd2obj[FD_SETSIZE1024 + 1];
205#endif /* SELECT_USES_HEAP */
206 PyObject *ifdlist, *ofdlist, *efdlist;
207 PyObject *ret = NULL((void*)0);
208 PyObject *tout = Py_None(&_Py_NoneStruct);
209 fd_set ifdset, ofdset, efdset;
210 double timeout;
211 struct timeval tv, *tvp;
212 long seconds;
213 int imax, omax, emax, max;
214 int n;
215
216 /* convert arguments */
217 if (!PyArg_UnpackTuple(args, "select", 3, 4,
218 &ifdlist, &ofdlist, &efdlist, &tout))
219 return NULL((void*)0);
220
221 if (tout == Py_None(&_Py_NoneStruct))
222 tvp = (struct timeval *)0;
223 else if (!PyNumber_Check(tout)) {
224 PyErr_SetString(PyExc_TypeError,
225 "timeout must be a float or None");
226 return NULL((void*)0);
227 }
228 else {
229 timeout = PyFloat_AsDouble(tout);
230 if (timeout == -1 && PyErr_Occurred())
231 return NULL((void*)0);
232 if (timeout > (double)LONG_MAX9223372036854775807L) {
233 PyErr_SetString(PyExc_OverflowError,
234 "timeout period too long");
235 return NULL((void*)0);
236 }
237 seconds = (long)timeout;
238 timeout = timeout - (double)seconds;
239 tv.tv_sec = seconds;
240 tv.tv_usec = (long)(timeout * 1E6);
241 tvp = &tv;
242 }
243
244
245#ifdef SELECT_USES_HEAP
246 /* Allocate memory for the lists */
247 rfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1)( ((size_t)(1024 + 1) > ((Py_ssize_t)(((size_t)-1)>>
1)) / sizeof(pylist)) ? ((void*)0) : ( (pylist *) _PyMem_DebugMalloc
((1024 + 1) * sizeof(pylist)) ) )
;
248 wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1)( ((size_t)(1024 + 1) > ((Py_ssize_t)(((size_t)-1)>>
1)) / sizeof(pylist)) ? ((void*)0) : ( (pylist *) _PyMem_DebugMalloc
((1024 + 1) * sizeof(pylist)) ) )
;
249 efd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1)( ((size_t)(1024 + 1) > ((Py_ssize_t)(((size_t)-1)>>
1)) / sizeof(pylist)) ? ((void*)0) : ( (pylist *) _PyMem_DebugMalloc
((1024 + 1) * sizeof(pylist)) ) )
;
250 if (rfd2obj == NULL((void*)0) || wfd2obj == NULL((void*)0) || efd2obj == NULL((void*)0)) {
251 if (rfd2obj) PyMem_DEL_PyMem_DebugFree(rfd2obj);
252 if (wfd2obj) PyMem_DEL_PyMem_DebugFree(wfd2obj);
253 if (efd2obj) PyMem_DEL_PyMem_DebugFree(efd2obj);
254 return PyErr_NoMemory();
255 }
256#endif /* SELECT_USES_HEAP */
257 /* Convert sequences to fd_sets, and get maximum fd number
258 * propagates the Python exception set in seq2set()
259 */
260 rfd2obj[0].sentinel = -1;
261 wfd2obj[0].sentinel = -1;
262 efd2obj[0].sentinel = -1;
263 if ((imax=seq2set(ifdlist, &ifdset, rfd2obj)) < 0)
264 goto finally;
265 if ((omax=seq2set(ofdlist, &ofdset, wfd2obj)) < 0)
266 goto finally;
267 if ((emax=seq2set(efdlist, &efdset, efd2obj)) < 0)
268 goto finally;
269 max = imax;
270 if (omax > max) max = omax;
271 if (emax > max) max = emax;
272
273 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
274 n = select(max, &ifdset, &ofdset, &efdset, tvp);
275 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
276
277#ifdef MS_WINDOWS
278 if (n == SOCKET_ERROR) {
279 PyErr_SetExcFromWindowsErr(SelectError, WSAGetLastError());
280 }
281#else
282 if (n < 0) {
283 PyErr_SetFromErrno(SelectError);
284 }
285#endif
286 else {
287 /* any of these three calls can raise an exception. it's more
288 convenient to test for this after all three calls... but
289 is that acceptable?
290 */
291 ifdlist = set2list(&ifdset, rfd2obj);
292 ofdlist = set2list(&ofdset, wfd2obj);
293 efdlist = set2list(&efdset, efd2obj);
294 if (PyErr_Occurred())
295 ret = NULL((void*)0);
296 else
297 ret = PyTuple_Pack(3, ifdlist, ofdlist, efdlist);
298
299 Py_DECREF(ifdlist)do { if (_Py_RefTotal-- , --((PyObject*)(ifdlist))->ob_refcnt
!= 0) { if (((PyObject*)ifdlist)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 299
, (PyObject *)(ifdlist)); } else _Py_Dealloc((PyObject *)(ifdlist
)); } while (0)
;
300 Py_DECREF(ofdlist)do { if (_Py_RefTotal-- , --((PyObject*)(ofdlist))->ob_refcnt
!= 0) { if (((PyObject*)ofdlist)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 300
, (PyObject *)(ofdlist)); } else _Py_Dealloc((PyObject *)(ofdlist
)); } while (0)
;
301 Py_DECREF(efdlist)do { if (_Py_RefTotal-- , --((PyObject*)(efdlist))->ob_refcnt
!= 0) { if (((PyObject*)efdlist)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 301
, (PyObject *)(efdlist)); } else _Py_Dealloc((PyObject *)(efdlist
)); } while (0)
;
302 }
303
304 finally:
305 reap_obj(rfd2obj);
306 reap_obj(wfd2obj);
307 reap_obj(efd2obj);
308#ifdef SELECT_USES_HEAP
309 PyMem_DEL_PyMem_DebugFree(rfd2obj);
310 PyMem_DEL_PyMem_DebugFree(wfd2obj);
311 PyMem_DEL_PyMem_DebugFree(efd2obj);
312#endif /* SELECT_USES_HEAP */
313 return ret;
314}
315
316#if defined(HAVE_POLL1) && !defined(HAVE_BROKEN_POLL)
317/*
318 * poll() support
319 */
320
321typedef struct {
322 PyObject_HEADPyObject ob_base;
323 PyObject *dict;
324 int ufd_uptodate;
325 int ufd_len;
326 struct pollfd *ufds;
327} pollObject;
328
329static PyTypeObject poll_Type;
330
331/* Update the malloc'ed array of pollfds to match the dictionary
332 contained within a pollObject. Return 1 on success, 0 on an error.
333*/
334
335static int
336update_ufd_array(pollObject *self)
337{
338 Py_ssize_t i, pos;
339 PyObject *key, *value;
340 struct pollfd *old_ufds = self->ufds;
341
342 self->ufd_len = PyDict_Size(self->dict);
343 PyMem_RESIZE(self->ufds, struct pollfd, self->ufd_len)( (self->ufds) = ((size_t)(self->ufd_len) > ((Py_ssize_t
)(((size_t)-1)>>1)) / sizeof(struct pollfd)) ? ((void*)
0) : (struct pollfd *) _PyMem_DebugRealloc((self->ufds), (
self->ufd_len) * sizeof(struct pollfd)) )
;
344 if (self->ufds == NULL((void*)0)) {
345 self->ufds = old_ufds;
346 PyErr_NoMemory();
347 return 0;
348 }
349
350 i = pos = 0;
351 while (PyDict_Next(self->dict, &pos, &key, &value)) {
352 self->ufds[i].fd = PyLong_AsLong(key);
353 self->ufds[i].events = (short)PyLong_AsLong(value);
354 i++;
355 }
356 self->ufd_uptodate = 1;
357 return 1;
358}
359
360PyDoc_STRVAR(poll_register_doc,static char poll_register_doc[] = "register(fd [, eventmask] ) -> None\n\nRegister a file descriptor with the polling object.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
361"register(fd [, eventmask] ) -> None\n\n\static char poll_register_doc[] = "register(fd [, eventmask] ) -> None\n\nRegister a file descriptor with the polling object.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
362Register a file descriptor with the polling object.\n\static char poll_register_doc[] = "register(fd [, eventmask] ) -> None\n\nRegister a file descriptor with the polling object.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
363fd -- either an integer, or an object with a fileno() method returning an\n\static char poll_register_doc[] = "register(fd [, eventmask] ) -> None\n\nRegister a file descriptor with the polling object.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
364 int.\n\static char poll_register_doc[] = "register(fd [, eventmask] ) -> None\n\nRegister a file descriptor with the polling object.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
365events -- an optional bitmask describing the type of events to check for")static char poll_register_doc[] = "register(fd [, eventmask] ) -> None\n\nRegister a file descriptor with the polling object.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for";
366
367static PyObject *
368poll_register(pollObject *self, PyObject *args)
369{
370 PyObject *o, *key, *value;
371 int fd, events = POLLIN0x0001 | POLLPRI0x0002 | POLLOUT0x0004;
372 int err;
373
374 if (!PyArg_ParseTuple(args, "O|i:register", &o, &events)) {
375 return NULL((void*)0);
376 }
377
378 fd = PyObject_AsFileDescriptor(o);
379 if (fd == -1) return NULL((void*)0);
380
381 /* Add entry to the internal dictionary: the key is the
382 file descriptor, and the value is the event mask. */
383 key = PyLong_FromLong(fd);
384 if (key == NULL((void*)0))
385 return NULL((void*)0);
386 value = PyLong_FromLong(events);
387 if (value == NULL((void*)0)) {
388 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 388
, (PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); }
while (0)
;
389 return NULL((void*)0);
390 }
391 err = PyDict_SetItem(self->dict, key, value);
392 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 392
, (PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); }
while (0)
;
393 Py_DECREF(value)do { if (_Py_RefTotal-- , --((PyObject*)(value))->ob_refcnt
!= 0) { if (((PyObject*)value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 393
, (PyObject *)(value)); } else _Py_Dealloc((PyObject *)(value
)); } while (0)
;
394 if (err < 0)
395 return NULL((void*)0);
396
397 self->ufd_uptodate = 0;
398
399 Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt
++)
;
400 return Py_None(&_Py_NoneStruct);
401}
402
403PyDoc_STRVAR(poll_modify_doc,static char poll_modify_doc[] = "modify(fd, eventmask) -> None\n\nModify an already registered file descriptor.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
404"modify(fd, eventmask) -> None\n\n\static char poll_modify_doc[] = "modify(fd, eventmask) -> None\n\nModify an already registered file descriptor.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
405Modify an already registered file descriptor.\n\static char poll_modify_doc[] = "modify(fd, eventmask) -> None\n\nModify an already registered file descriptor.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
406fd -- either an integer, or an object with a fileno() method returning an\n\static char poll_modify_doc[] = "modify(fd, eventmask) -> None\n\nModify an already registered file descriptor.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
407 int.\n\static char poll_modify_doc[] = "modify(fd, eventmask) -> None\n\nModify an already registered file descriptor.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for"
408events -- an optional bitmask describing the type of events to check for")static char poll_modify_doc[] = "modify(fd, eventmask) -> None\n\nModify an already registered file descriptor.\nfd -- either an integer, or an object with a fileno() method returning an\n int.\nevents -- an optional bitmask describing the type of events to check for";
409
410static PyObject *
411poll_modify(pollObject *self, PyObject *args)
412{
413 PyObject *o, *key, *value;
414 int fd, events;
415 int err;
416
417 if (!PyArg_ParseTuple(args, "Oi:modify", &o, &events)) {
418 return NULL((void*)0);
419 }
420
421 fd = PyObject_AsFileDescriptor(o);
422 if (fd == -1) return NULL((void*)0);
423
424 /* Modify registered fd */
425 key = PyLong_FromLong(fd);
426 if (key == NULL((void*)0))
427 return NULL((void*)0);
428 if (PyDict_GetItem(self->dict, key) == NULL((void*)0)) {
429 errno(*__error()) = ENOENT2;
430 PyErr_SetFromErrno(PyExc_IOError);
431 return NULL((void*)0);
432 }
433 value = PyLong_FromLong(events);
434 if (value == NULL((void*)0)) {
435 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 435
, (PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); }
while (0)
;
436 return NULL((void*)0);
437 }
438 err = PyDict_SetItem(self->dict, key, value);
439 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 439
, (PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); }
while (0)
;
440 Py_DECREF(value)do { if (_Py_RefTotal-- , --((PyObject*)(value))->ob_refcnt
!= 0) { if (((PyObject*)value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 440
, (PyObject *)(value)); } else _Py_Dealloc((PyObject *)(value
)); } while (0)
;
441 if (err < 0)
442 return NULL((void*)0);
443
444 self->ufd_uptodate = 0;
445
446 Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt
++)
;
447 return Py_None(&_Py_NoneStruct);
448}
449
450
451PyDoc_STRVAR(poll_unregister_doc,static char poll_unregister_doc[] = "unregister(fd) -> None\n\nRemove a file descriptor being tracked by the polling object."
452"unregister(fd) -> None\n\n\static char poll_unregister_doc[] = "unregister(fd) -> None\n\nRemove a file descriptor being tracked by the polling object."
453Remove a file descriptor being tracked by the polling object.")static char poll_unregister_doc[] = "unregister(fd) -> None\n\nRemove a file descriptor being tracked by the polling object.";
454
455static PyObject *
456poll_unregister(pollObject *self, PyObject *o)
457{
458 PyObject *key;
459 int fd;
460
461 fd = PyObject_AsFileDescriptor( o );
462 if (fd == -1)
463 return NULL((void*)0);
464
465 /* Check whether the fd is already in the array */
466 key = PyLong_FromLong(fd);
467 if (key == NULL((void*)0))
468 return NULL((void*)0);
469
470 if (PyDict_DelItem(self->dict, key) == -1) {
471 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 471
, (PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); }
while (0)
;
472 /* This will simply raise the KeyError set by PyDict_DelItem
473 if the file descriptor isn't registered. */
474 return NULL((void*)0);
475 }
476
477 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 477
, (PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); }
while (0)
;
478 self->ufd_uptodate = 0;
479
480 Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt
++)
;
481 return Py_None(&_Py_NoneStruct);
482}
483
484PyDoc_STRVAR(poll_poll_doc,static char poll_poll_doc[] = "poll( [timeout] ) -> list of (fd, event) 2-tuples\n\nPolls the set of registered file descriptors, returning a list containing \nany descriptors that have events or errors to report."
485"poll( [timeout] ) -> list of (fd, event) 2-tuples\n\n\static char poll_poll_doc[] = "poll( [timeout] ) -> list of (fd, event) 2-tuples\n\nPolls the set of registered file descriptors, returning a list containing \nany descriptors that have events or errors to report."
486Polls the set of registered file descriptors, returning a list containing \n\static char poll_poll_doc[] = "poll( [timeout] ) -> list of (fd, event) 2-tuples\n\nPolls the set of registered file descriptors, returning a list containing \nany descriptors that have events or errors to report."
487any descriptors that have events or errors to report.")static char poll_poll_doc[] = "poll( [timeout] ) -> list of (fd, event) 2-tuples\n\nPolls the set of registered file descriptors, returning a list containing \nany descriptors that have events or errors to report.";
488
489static PyObject *
490poll_poll(pollObject *self, PyObject *args)
491{
492 PyObject *result_list = NULL((void*)0), *tout = NULL((void*)0);
493 int timeout = 0, poll_result, i, j;
494 PyObject *value = NULL((void*)0), *num = NULL((void*)0);
495
496 if (!PyArg_UnpackTuple(args, "poll", 0, 1, &tout)) {
497 return NULL((void*)0);
498 }
499
500 /* Check values for timeout */
501 if (tout == NULL((void*)0) || tout == Py_None(&_Py_NoneStruct))
502 timeout = -1;
503 else if (!PyNumber_Check(tout)) {
504 PyErr_SetString(PyExc_TypeError,
505 "timeout must be an integer or None");
506 return NULL((void*)0);
507 }
508 else {
509 tout = PyNumber_Long(tout);
510 if (!tout)
511 return NULL((void*)0);
512 timeout = PyLong_AsLong(tout);
513 Py_DECREF(tout)do { if (_Py_RefTotal-- , --((PyObject*)(tout))->ob_refcnt
!= 0) { if (((PyObject*)tout)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 513
, (PyObject *)(tout)); } else _Py_Dealloc((PyObject *)(tout))
; } while (0)
;
514 if (timeout == -1 && PyErr_Occurred())
515 return NULL((void*)0);
516 }
517
518 /* Ensure the ufd array is up to date */
519 if (!self->ufd_uptodate)
520 if (update_ufd_array(self) == 0)
521 return NULL((void*)0);
522
523 /* call poll() */
524 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
525 poll_result = poll(self->ufds, self->ufd_len, timeout);
526 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
527
528 if (poll_result < 0) {
529 PyErr_SetFromErrno(SelectError);
530 return NULL((void*)0);
531 }
532
533 /* build the result list */
534
535 result_list = PyList_New(poll_result);
536 if (!result_list)
537 return NULL((void*)0);
538 else {
539 for (i = 0, j = 0; j < poll_result; j++) {
540 /* skip to the next fired descriptor */
541 while (!self->ufds[i].revents) {
542 i++;
543 }
544 /* if we hit a NULL return, set value to NULL
545 and break out of loop; code at end will
546 clean up result_list */
547 value = PyTuple_New(2);
548 if (value == NULL((void*)0))
549 goto error;
550 num = PyLong_FromLong(self->ufds[i].fd);
551 if (num == NULL((void*)0)) {
552 Py_DECREF(value)do { if (_Py_RefTotal-- , --((PyObject*)(value))->ob_refcnt
!= 0) { if (((PyObject*)value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 552
, (PyObject *)(value)); } else _Py_Dealloc((PyObject *)(value
)); } while (0)
;
553 goto error;
554 }
555 PyTuple_SET_ITEM(value, 0, num)(((PyTupleObject *)(value))->ob_item[0] = num);
556
557 /* The &0xffff is a workaround for AIX. 'revents'
558 is a 16-bit short, and IBM assigned POLLNVAL
559 to be 0x8000, so the conversion to int results
560 in a negative number. See SF bug #923315. */
561 num = PyLong_FromLong(self->ufds[i].revents & 0xffff);
562 if (num == NULL((void*)0)) {
563 Py_DECREF(value)do { if (_Py_RefTotal-- , --((PyObject*)(value))->ob_refcnt
!= 0) { if (((PyObject*)value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 563
, (PyObject *)(value)); } else _Py_Dealloc((PyObject *)(value
)); } while (0)
;
564 goto error;
565 }
566 PyTuple_SET_ITEM(value, 1, num)(((PyTupleObject *)(value))->ob_item[1] = num);
567 if ((PyList_SetItem(result_list, j, value)) == -1) {
568 Py_DECREF(value)do { if (_Py_RefTotal-- , --((PyObject*)(value))->ob_refcnt
!= 0) { if (((PyObject*)value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 568
, (PyObject *)(value)); } else _Py_Dealloc((PyObject *)(value
)); } while (0)
;
569 goto error;
570 }
571 i++;
572 }
573 }
574 return result_list;
575
576 error:
577 Py_DECREF(result_list)do { if (_Py_RefTotal-- , --((PyObject*)(result_list))->ob_refcnt
!= 0) { if (((PyObject*)result_list)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 577
, (PyObject *)(result_list)); } else _Py_Dealloc((PyObject *)
(result_list)); } while (0)
;
578 return NULL((void*)0);
579}
580
581static PyMethodDef poll_methods[] = {
582 {"register", (PyCFunction)poll_register,
583 METH_VARARGS0x0001, poll_register_doc},
584 {"modify", (PyCFunction)poll_modify,
585 METH_VARARGS0x0001, poll_modify_doc},
586 {"unregister", (PyCFunction)poll_unregister,
587 METH_O0x0008, poll_unregister_doc},
588 {"poll", (PyCFunction)poll_poll,
589 METH_VARARGS0x0001, poll_poll_doc},
590 {NULL((void*)0), NULL((void*)0)} /* sentinel */
591};
592
593static pollObject *
594newPollObject(void)
595{
596 pollObject *self;
597 self = PyObject_New(pollObject, &poll_Type)( (pollObject *) _PyObject_New(&poll_Type) );
598 if (self == NULL((void*)0))
599 return NULL((void*)0);
600 /* ufd_uptodate is a Boolean, denoting whether the
601 array pointed to by ufds matches the contents of the dictionary. */
602 self->ufd_uptodate = 0;
603 self->ufds = NULL((void*)0);
604 self->dict = PyDict_New();
605 if (self->dict == NULL((void*)0)) {
606 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 606
, (PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self))
; } while (0)
;
607 return NULL((void*)0);
608 }
609 return self;
610}
611
612static void
613poll_dealloc(pollObject *self)
614{
615 if (self->ufds != NULL((void*)0))
616 PyMem_DEL_PyMem_DebugFree(self->ufds);
617 Py_XDECREF(self->dict)do { if ((self->dict) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->dict))->ob_refcnt != 0) { if (
((PyObject*)self->dict)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 617
, (PyObject *)(self->dict)); } else _Py_Dealloc((PyObject *
)(self->dict)); } while (0); } while (0)
;
618 PyObject_Del_PyObject_DebugFree(self);
619}
620
621static PyTypeObject poll_Type = {
622 /* The ob_type field must be initialized in the module init function
623 * to be portable to Windows without using C++. */
624 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
625 "select.poll", /*tp_name*/
626 sizeof(pollObject), /*tp_basicsize*/
627 0, /*tp_itemsize*/
628 /* methods */
629 (destructor)poll_dealloc, /*tp_dealloc*/
630 0, /*tp_print*/
631 0, /*tp_getattr*/
632 0, /*tp_setattr*/
633 0, /*tp_reserved*/
634 0, /*tp_repr*/
635 0, /*tp_as_number*/
636 0, /*tp_as_sequence*/
637 0, /*tp_as_mapping*/
638 0, /*tp_hash*/
639 0, /*tp_call*/
640 0, /*tp_str*/
641 0, /*tp_getattro*/
642 0, /*tp_setattro*/
643 0, /*tp_as_buffer*/
644 Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0), /*tp_flags*/
645 0, /*tp_doc*/
646 0, /*tp_traverse*/
647 0, /*tp_clear*/
648 0, /*tp_richcompare*/
649 0, /*tp_weaklistoffset*/
650 0, /*tp_iter*/
651 0, /*tp_iternext*/
652 poll_methods, /*tp_methods*/
653};
654
655PyDoc_STRVAR(poll_doc,static char poll_doc[] = "Returns a polling object, which supports registering and\nunregistering file descriptors, and then polling them for I/O events."
656"Returns a polling object, which supports registering and\n\static char poll_doc[] = "Returns a polling object, which supports registering and\nunregistering file descriptors, and then polling them for I/O events."
657unregistering file descriptors, and then polling them for I/O events.")static char poll_doc[] = "Returns a polling object, which supports registering and\nunregistering file descriptors, and then polling them for I/O events.";
658
659static PyObject *
660select_poll(PyObject *self, PyObject *unused)
661{
662 return (PyObject *)newPollObject();
663}
664
665#ifdef __APPLE__1
666/*
667 * On some systems poll() sets errno on invalid file descriptors. We test
668 * for this at runtime because this bug may be fixed or introduced between
669 * OS releases.
670 */
671static int select_have_broken_poll(void)
672{
673 int poll_test;
674 int filedes[2];
675
676 struct pollfd poll_struct = { 0, POLLIN0x0001|POLLPRI0x0002|POLLOUT0x0004, 0 };
677
678 /* Create a file descriptor to make invalid */
679 if (pipe(filedes) < 0) {
680 return 1;
681 }
682 poll_struct.fd = filedes[0];
683 close(filedes[0]);
684 close(filedes[1]);
685 poll_test = poll(&poll_struct, 1, 0);
686 if (poll_test < 0) {
687 return 1;
688 } else if (poll_test == 0 && poll_struct.revents != POLLNVAL0x0020) {
689 return 1;
690 }
691 return 0;
692}
693#endif /* __APPLE__ */
694
695#endif /* HAVE_POLL */
696
697#ifdef HAVE_EPOLL
698/* **************************************************************************
699 * epoll interface for Linux 2.6
700 *
701 * Written by Christian Heimes
702 * Inspired by Twisted's _epoll.pyx and select.poll()
703 */
704
705#ifdef HAVE_SYS_EPOLL_H
706#include <sys/epoll.h>
707#endif
708
709typedef struct {
710 PyObject_HEADPyObject ob_base;
711 SOCKETint epfd; /* epoll control file descriptor */
712} pyEpoll_Object;
713
714static PyTypeObject pyEpoll_Type;
715#define pyepoll_CHECK(op) (PyObject_TypeCheck((op), &pyEpoll_Type)((((PyObject*)((op)))->ob_type) == (&pyEpoll_Type) || PyType_IsSubtype
((((PyObject*)((op)))->ob_type), (&pyEpoll_Type)))
)
716
717static PyObject *
718pyepoll_err_closed(void)
719{
720 PyErr_SetString(PyExc_ValueError, "I/O operation on closed epoll fd");
721 return NULL((void*)0);
722}
723
724static int
725pyepoll_internal_close(pyEpoll_Object *self)
726{
727 int save_errno = 0;
728 if (self->epfd >= 0) {
729 int epfd = self->epfd;
730 self->epfd = -1;
731 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
732 if (close(epfd) < 0)
733 save_errno = errno(*__error());
734 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
735 }
736 return save_errno;
737}
738
739static PyObject *
740newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKETint fd)
741{
742 pyEpoll_Object *self;
743
744 if (sizehint == -1) {
745 sizehint = FD_SETSIZE1024-1;
746 }
747 else if (sizehint < 1) {
748 PyErr_Format(PyExc_ValueError,
749 "sizehint must be greater zero, got %d",
750 sizehint);
751 return NULL((void*)0);
752 }
753
754 assert(type != NULL && type->tp_alloc != NULL)(__builtin_expect(!(type != ((void*)0) && type->tp_alloc
!= ((void*)0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c"
, 754, "type != NULL && type->tp_alloc != NULL") :
(void)0)
;
755 self = (pyEpoll_Object *) type->tp_alloc(type, 0);
756 if (self == NULL((void*)0))
757 return NULL((void*)0);
758
759 if (fd == -1) {
760 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
761 self->epfd = epoll_create(sizehint);
762 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
763 }
764 else {
765 self->epfd = fd;
766 }
767 if (self->epfd < 0) {
768 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 768
, (PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self))
; } while (0)
;
769 PyErr_SetFromErrno(PyExc_IOError);
770 return NULL((void*)0);
771 }
772 return (PyObject *)self;
773}
774
775
776static PyObject *
777pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
778{
779 int sizehint = -1;
780 static char *kwlist[] = {"sizehint", NULL((void*)0)};
781
782 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:epoll", kwlist,
783 &sizehint))
784 return NULL((void*)0);
785
786 return newPyEpoll_Object(type, sizehint, -1);
787}
788
789
790static void
791pyepoll_dealloc(pyEpoll_Object *self)
792{
793 (void)pyepoll_internal_close(self);
794 Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_free(self);
795}
796
797static PyObject*
798pyepoll_close(pyEpoll_Object *self)
799{
800 errno(*__error()) = pyepoll_internal_close(self);
801 if (errno(*__error()) < 0) {
802 PyErr_SetFromErrno(PyExc_IOError);
803 return NULL((void*)0);
804 }
805 Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct))
)->ob_refcnt++), (&_Py_NoneStruct)
;
806}
807
808PyDoc_STRVAR(pyepoll_close_doc,static char pyepoll_close_doc[] = "close() -> None\n\nClose the epoll control file descriptor. Further operations on the epoll\nobject will raise an exception."
809"close() -> None\n\static char pyepoll_close_doc[] = "close() -> None\n\nClose the epoll control file descriptor. Further operations on the epoll\nobject will raise an exception."
810\n\static char pyepoll_close_doc[] = "close() -> None\n\nClose the epoll control file descriptor. Further operations on the epoll\nobject will raise an exception."
811Close the epoll control file descriptor. Further operations on the epoll\n\static char pyepoll_close_doc[] = "close() -> None\n\nClose the epoll control file descriptor. Further operations on the epoll\nobject will raise an exception."
812object will raise an exception.")static char pyepoll_close_doc[] = "close() -> None\n\nClose the epoll control file descriptor. Further operations on the epoll\nobject will raise an exception.";
813
814static PyObject*
815pyepoll_get_closed(pyEpoll_Object *self)
816{
817 if (self->epfd < 0)
818 Py_RETURN_TRUEreturn ( _Py_RefTotal++ , ((PyObject*)(((PyObject *) &_Py_TrueStruct
)))->ob_refcnt++), ((PyObject *) &_Py_TrueStruct)
;
819 else
820 Py_RETURN_FALSEreturn ( _Py_RefTotal++ , ((PyObject*)(((PyObject *) &_Py_FalseStruct
)))->ob_refcnt++), ((PyObject *) &_Py_FalseStruct)
;
821}
822
823static PyObject*
824pyepoll_fileno(pyEpoll_Object *self)
825{
826 if (self->epfd < 0)
827 return pyepoll_err_closed();
828 return PyLong_FromLong(self->epfd);
829}
830
831PyDoc_STRVAR(pyepoll_fileno_doc,static char pyepoll_fileno_doc[] = "fileno() -> int\n\nReturn the epoll control file descriptor."
832"fileno() -> int\n\static char pyepoll_fileno_doc[] = "fileno() -> int\n\nReturn the epoll control file descriptor."
833\n\static char pyepoll_fileno_doc[] = "fileno() -> int\n\nReturn the epoll control file descriptor."
834Return the epoll control file descriptor.")static char pyepoll_fileno_doc[] = "fileno() -> int\n\nReturn the epoll control file descriptor.";
835
836static PyObject*
837pyepoll_fromfd(PyObject *cls, PyObject *args)
838{
839 SOCKETint fd;
840
841 if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
842 return NULL((void*)0);
843
844 return newPyEpoll_Object((PyTypeObject*)cls, -1, fd);
845}
846
847PyDoc_STRVAR(pyepoll_fromfd_doc,static char pyepoll_fromfd_doc[] = "fromfd(fd) -> epoll\n\nCreate an epoll object from a given control fd."
848"fromfd(fd) -> epoll\n\static char pyepoll_fromfd_doc[] = "fromfd(fd) -> epoll\n\nCreate an epoll object from a given control fd."
849\n\static char pyepoll_fromfd_doc[] = "fromfd(fd) -> epoll\n\nCreate an epoll object from a given control fd."
850Create an epoll object from a given control fd.")static char pyepoll_fromfd_doc[] = "fromfd(fd) -> epoll\n\nCreate an epoll object from a given control fd.";
851
852static PyObject *
853pyepoll_internal_ctl(int epfd, int op, PyObject *pfd, unsigned int events)
854{
855 struct epoll_event ev;
856 int result;
857 int fd;
858
859 if (epfd < 0)
860 return pyepoll_err_closed();
861
862 fd = PyObject_AsFileDescriptor(pfd);
863 if (fd == -1) {
864 return NULL((void*)0);
865 }
866
867 switch(op) {
868 case EPOLL_CTL_ADD:
869 case EPOLL_CTL_MOD:
870 ev.events = events;
871 ev.data.fd = fd;
872 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
873 result = epoll_ctl(epfd, op, fd, &ev);
874 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
875 break;
876 case EPOLL_CTL_DEL:
877 /* In kernel versions before 2.6.9, the EPOLL_CTL_DEL
878 * operation required a non-NULL pointer in event, even
879 * though this argument is ignored. */
880 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
881 result = epoll_ctl(epfd, op, fd, &ev);
882 if (errno(*__error()) == EBADF9) {
883 /* fd already closed */
884 result = 0;
885 errno(*__error()) = 0;
886 }
887 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
888 break;
889 default:
890 result = -1;
891 errno(*__error()) = EINVAL22;
892 }
893
894 if (result < 0) {
895 PyErr_SetFromErrno(PyExc_IOError);
896 return NULL((void*)0);
897 }
898 Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct))
)->ob_refcnt++), (&_Py_NoneStruct)
;
899}
900
901static PyObject *
902pyepoll_register(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
903{
904 PyObject *pfd;
905 unsigned int events = EPOLLIN | EPOLLOUT | EPOLLPRI;
906 static char *kwlist[] = {"fd", "eventmask", NULL((void*)0)};
907
908 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|I:register", kwlist,
909 &pfd, &events)) {
910 return NULL((void*)0);
911 }
912
913 return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_ADD, pfd, events);
914}
915
916PyDoc_STRVAR(pyepoll_register_doc,static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll."
917"register(fd[, eventmask]) -> None\n\static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll."
918\n\static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll."
919Registers a new fd or modifies an already registered fd.\n\static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll."
920fd is the target file descriptor of the operation.\n\static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll."
921events is a bit set composed of the various EPOLL constants; the default\n\static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll."
922is EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll."
923\n\static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll."
924The epoll interface supports all file descriptors that support poll.")static char pyepoll_register_doc[] = "register(fd[, eventmask]) -> None\n\nRegisters a new fd or modifies an already registered fd.\nfd is the target file descriptor of the operation.\nevents is a bit set composed of the various EPOLL constants; the default\nis EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\nThe epoll interface supports all file descriptors that support poll.";
925
926static PyObject *
927pyepoll_modify(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
928{
929 PyObject *pfd;
930 unsigned int events;
931 static char *kwlist[] = {"fd", "eventmask", NULL((void*)0)};
932
933 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OI:modify", kwlist,
934 &pfd, &events)) {
935 return NULL((void*)0);
936 }
937
938 return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_MOD, pfd, events);
939}
940
941PyDoc_STRVAR(pyepoll_modify_doc,static char pyepoll_modify_doc[] = "modify(fd, eventmask) -> None\n\nfd is the target file descriptor of the operation\nevents is a bit set composed of the various EPOLL constants"
942"modify(fd, eventmask) -> None\n\static char pyepoll_modify_doc[] = "modify(fd, eventmask) -> None\n\nfd is the target file descriptor of the operation\nevents is a bit set composed of the various EPOLL constants"
943\n\static char pyepoll_modify_doc[] = "modify(fd, eventmask) -> None\n\nfd is the target file descriptor of the operation\nevents is a bit set composed of the various EPOLL constants"
944fd is the target file descriptor of the operation\n\static char pyepoll_modify_doc[] = "modify(fd, eventmask) -> None\n\nfd is the target file descriptor of the operation\nevents is a bit set composed of the various EPOLL constants"
945events is a bit set composed of the various EPOLL constants")static char pyepoll_modify_doc[] = "modify(fd, eventmask) -> None\n\nfd is the target file descriptor of the operation\nevents is a bit set composed of the various EPOLL constants";
946
947static PyObject *
948pyepoll_unregister(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
949{
950 PyObject *pfd;
951 static char *kwlist[] = {"fd", NULL((void*)0)};
952
953 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:unregister", kwlist,
954 &pfd)) {
955 return NULL((void*)0);
956 }
957
958 return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_DEL, pfd, 0);
959}
960
961PyDoc_STRVAR(pyepoll_unregister_doc,static char pyepoll_unregister_doc[] = "unregister(fd) -> None\n\nfd is the target file descriptor of the operation."
962"unregister(fd) -> None\n\static char pyepoll_unregister_doc[] = "unregister(fd) -> None\n\nfd is the target file descriptor of the operation."
963\n\static char pyepoll_unregister_doc[] = "unregister(fd) -> None\n\nfd is the target file descriptor of the operation."
964fd is the target file descriptor of the operation.")static char pyepoll_unregister_doc[] = "unregister(fd) -> None\n\nfd is the target file descriptor of the operation.";
965
966static PyObject *
967pyepoll_poll(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
968{
969 double dtimeout = -1.;
970 int timeout;
971 int maxevents = -1;
972 int nfds, i;
973 PyObject *elist = NULL((void*)0), *etuple = NULL((void*)0);
974 struct epoll_event *evs = NULL((void*)0);
975 static char *kwlist[] = {"timeout", "maxevents", NULL((void*)0)};
976
977 if (self->epfd < 0)
978 return pyepoll_err_closed();
979
980 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|di:poll", kwlist,
981 &dtimeout, &maxevents)) {
982 return NULL((void*)0);
983 }
984
985 if (dtimeout < 0) {
986 timeout = -1;
987 }
988 else if (dtimeout * 1000.0 > INT_MAX2147483647) {
989 PyErr_SetString(PyExc_OverflowError,
990 "timeout is too large");
991 return NULL((void*)0);
992 }
993 else {
994 timeout = (int)(dtimeout * 1000.0);
995 }
996
997 if (maxevents == -1) {
998 maxevents = FD_SETSIZE1024-1;
999 }
1000 else if (maxevents < 1) {
1001 PyErr_Format(PyExc_ValueError,
1002 "maxevents must be greater than 0, got %d",
1003 maxevents);
1004 return NULL((void*)0);
1005 }
1006
1007 evs = PyMem_New(struct epoll_event, maxevents)( ((size_t)(maxevents) > ((Py_ssize_t)(((size_t)-1)>>
1)) / sizeof(struct epoll_event)) ? ((void*)0) : ( (struct epoll_event
*) PyMem_Malloc((maxevents) * sizeof(struct epoll_event)) ) )
;
1008 if (evs == NULL((void*)0)) {
1009 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 1009
, (PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self))
; } while (0)
;
1010 PyErr_NoMemory();
1011 return NULL((void*)0);
1012 }
1013
1014 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
1015 nfds = epoll_wait(self->epfd, evs, maxevents, timeout);
1016 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
1017 if (nfds < 0) {
1018 PyErr_SetFromErrno(PyExc_IOError);
1019 goto error;
1020 }
1021
1022 elist = PyList_New(nfds);
1023 if (elist == NULL((void*)0)) {
1024 goto error;
1025 }
1026
1027 for (i = 0; i < nfds; i++) {
1028 etuple = Py_BuildValue("iI", evs[i].data.fd, evs[i].events);
1029 if (etuple == NULL((void*)0)) {
1030 Py_CLEAR(elist)do { if (elist) { PyObject *_py_tmp = (PyObject *)(elist); (elist
) = ((void*)0); do { if (_Py_RefTotal-- , --((PyObject*)(_py_tmp
))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->ob_refcnt
< 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c"
, 1030, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
1031 goto error;
1032 }
1033 PyList_SET_ITEM(elist, i, etuple)(((PyListObject *)(elist))->ob_item[i] = (etuple));
1034 }
1035
1036 error:
1037 PyMem_Free(evs);
1038 return elist;
1039}
1040
1041PyDoc_STRVAR(pyepoll_poll_doc,static char pyepoll_poll_doc[] = "poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\nWait for events on the epoll file descriptor for a maximum time of timeout\nin seconds (as float). -1 makes poll wait indefinitely.\nUp to maxevents are returned to the caller."
1042"poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\static char pyepoll_poll_doc[] = "poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\nWait for events on the epoll file descriptor for a maximum time of timeout\nin seconds (as float). -1 makes poll wait indefinitely.\nUp to maxevents are returned to the caller."
1043\n\static char pyepoll_poll_doc[] = "poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\nWait for events on the epoll file descriptor for a maximum time of timeout\nin seconds (as float). -1 makes poll wait indefinitely.\nUp to maxevents are returned to the caller."
1044Wait for events on the epoll file descriptor for a maximum time of timeout\n\static char pyepoll_poll_doc[] = "poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\nWait for events on the epoll file descriptor for a maximum time of timeout\nin seconds (as float). -1 makes poll wait indefinitely.\nUp to maxevents are returned to the caller."
1045in seconds (as float). -1 makes poll wait indefinitely.\n\static char pyepoll_poll_doc[] = "poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\nWait for events on the epoll file descriptor for a maximum time of timeout\nin seconds (as float). -1 makes poll wait indefinitely.\nUp to maxevents are returned to the caller."
1046Up to maxevents are returned to the caller.")static char pyepoll_poll_doc[] = "poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\nWait for events on the epoll file descriptor for a maximum time of timeout\nin seconds (as float). -1 makes poll wait indefinitely.\nUp to maxevents are returned to the caller.";
1047
1048static PyMethodDef pyepoll_methods[] = {
1049 {"fromfd", (PyCFunction)pyepoll_fromfd,
1050 METH_VARARGS0x0001 | METH_CLASS0x0010, pyepoll_fromfd_doc},
1051 {"close", (PyCFunction)pyepoll_close, METH_NOARGS0x0004,
1052 pyepoll_close_doc},
1053 {"fileno", (PyCFunction)pyepoll_fileno, METH_NOARGS0x0004,
1054 pyepoll_fileno_doc},
1055 {"modify", (PyCFunction)pyepoll_modify,
1056 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, pyepoll_modify_doc},
1057 {"register", (PyCFunction)pyepoll_register,
1058 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, pyepoll_register_doc},
1059 {"unregister", (PyCFunction)pyepoll_unregister,
1060 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, pyepoll_unregister_doc},
1061 {"poll", (PyCFunction)pyepoll_poll,
1062 METH_VARARGS0x0001 | METH_KEYWORDS0x0002, pyepoll_poll_doc},
1063 {NULL((void*)0), NULL((void*)0)},
1064};
1065
1066static PyGetSetDef pyepoll_getsetlist[] = {
1067 {"closed", (getter)pyepoll_get_closed, NULL((void*)0),
1068 "True if the epoll handler is closed"},
1069 {0},
1070};
1071
1072PyDoc_STRVAR(pyepoll_doc,static char pyepoll_doc[] = "select.epoll([sizehint=-1])\n\nReturns an epolling object\n\nsizehint must be a positive integer or -1 for the default size. The\nsizehint is used to optimize internal data structures. It doesn't limit\nthe maximum number of monitored events."
1073"select.epoll([sizehint=-1])\n\static char pyepoll_doc[] = "select.epoll([sizehint=-1])\n\nReturns an epolling object\n\nsizehint must be a positive integer or -1 for the default size. The\nsizehint is used to optimize internal data structures. It doesn't limit\nthe maximum number of monitored events."
1074\n\static char pyepoll_doc[] = "select.epoll([sizehint=-1])\n\nReturns an epolling object\n\nsizehint must be a positive integer or -1 for the default size. The\nsizehint is used to optimize internal data structures. It doesn't limit\nthe maximum number of monitored events."
1075Returns an epolling object\n\static char pyepoll_doc[] = "select.epoll([sizehint=-1])\n\nReturns an epolling object\n\nsizehint must be a positive integer or -1 for the default size. The\nsizehint is used to optimize internal data structures. It doesn't limit\nthe maximum number of monitored events."
1076\n\static char pyepoll_doc[] = "select.epoll([sizehint=-1])\n\nReturns an epolling object\n\nsizehint must be a positive integer or -1 for the default size. The\nsizehint is used to optimize internal data structures. It doesn't limit\nthe maximum number of monitored events."
1077sizehint must be a positive integer or -1 for the default size. The\n\static char pyepoll_doc[] = "select.epoll([sizehint=-1])\n\nReturns an epolling object\n\nsizehint must be a positive integer or -1 for the default size. The\nsizehint is used to optimize internal data structures. It doesn't limit\nthe maximum number of monitored events."
1078sizehint is used to optimize internal data structures. It doesn't limit\n\static char pyepoll_doc[] = "select.epoll([sizehint=-1])\n\nReturns an epolling object\n\nsizehint must be a positive integer or -1 for the default size. The\nsizehint is used to optimize internal data structures. It doesn't limit\nthe maximum number of monitored events."
1079the maximum number of monitored events.")static char pyepoll_doc[] = "select.epoll([sizehint=-1])\n\nReturns an epolling object\n\nsizehint must be a positive integer or -1 for the default size. The\nsizehint is used to optimize internal data structures. It doesn't limit\nthe maximum number of monitored events.";
1080
1081static PyTypeObject pyEpoll_Type = {
1082 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
1083 "select.epoll", /* tp_name */
1084 sizeof(pyEpoll_Object), /* tp_basicsize */
1085 0, /* tp_itemsize */
1086 (destructor)pyepoll_dealloc, /* tp_dealloc */
1087 0, /* tp_print */
1088 0, /* tp_getattr */
1089 0, /* tp_setattr */
1090 0, /* tp_reserved */
1091 0, /* tp_repr */
1092 0, /* tp_as_number */
1093 0, /* tp_as_sequence */
1094 0, /* tp_as_mapping */
1095 0, /* tp_hash */
1096 0, /* tp_call */
1097 0, /* tp_str */
1098 PyObject_GenericGetAttr, /* tp_getattro */
1099 0, /* tp_setattro */
1100 0, /* tp_as_buffer */
1101 Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0), /* tp_flags */
1102 pyepoll_doc, /* tp_doc */
1103 0, /* tp_traverse */
1104 0, /* tp_clear */
1105 0, /* tp_richcompare */
1106 0, /* tp_weaklistoffset */
1107 0, /* tp_iter */
1108 0, /* tp_iternext */
1109 pyepoll_methods, /* tp_methods */
1110 0, /* tp_members */
1111 pyepoll_getsetlist, /* tp_getset */
1112 0, /* tp_base */
1113 0, /* tp_dict */
1114 0, /* tp_descr_get */
1115 0, /* tp_descr_set */
1116 0, /* tp_dictoffset */
1117 0, /* tp_init */
1118 0, /* tp_alloc */
1119 pyepoll_new, /* tp_new */
1120 0, /* tp_free */
1121};
1122
1123#endif /* HAVE_EPOLL */
1124
1125#ifdef HAVE_KQUEUE1
1126/* **************************************************************************
1127 * kqueue interface for BSD
1128 *
1129 * Copyright (c) 2000 Doug White, 2006 James Knight, 2007 Christian Heimes
1130 * All rights reserved.
1131 *
1132 * Redistribution and use in source and binary forms, with or without
1133 * modification, are permitted provided that the following conditions
1134 * are met:
1135 * 1. Redistributions of source code must retain the above copyright
1136 * notice, this list of conditions and the following disclaimer.
1137 * 2. Redistributions in binary form must reproduce the above copyright
1138 * notice, this list of conditions and the following disclaimer in the
1139 * documentation and/or other materials provided with the distribution.
1140 *
1141 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1142 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1143 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1144 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1145 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1146 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1147 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1148 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1149 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1150 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1151 * SUCH DAMAGE.
1152 */
1153
1154#ifdef HAVE_SYS_EVENT_H1
1155#include <sys/event.h>
1156#endif
1157
1158PyDoc_STRVAR(kqueue_event_doc,static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1159"kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1160\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1161This object is the equivalent of the struct kevent for the C API.\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1162\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1163See the kqueue manpage for more detailed information about the meaning\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1164of the arguments.\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1165\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1166One minor note: while you might hope that udata could store a\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1167reference to a python object, it cannot, because it is impossible to\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1168keep a proper reference count of the object once it's passed into the\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1169kernel. Therefore, I have restricted it to only storing an integer. I\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1170recommend ignoring it and simply using the 'ident' field to key off\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1171of. You could also set up a dictionary on the python side to store a\n\static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping."
1172udata->object mapping.")static char kqueue_event_doc[] = "kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\nThis object is the equivalent of the struct kevent for the C API.\n\nSee the kqueue manpage for more detailed information about the meaning\nof the arguments.\n\nOne minor note: while you might hope that udata could store a\nreference to a python object, it cannot, because it is impossible to\nkeep a proper reference count of the object once it's passed into the\nkernel. Therefore, I have restricted it to only storing an integer. I\nrecommend ignoring it and simply using the 'ident' field to key off\nof. You could also set up a dictionary on the python side to store a\nudata->object mapping.";
1173
1174typedef struct {
1175 PyObject_HEADPyObject ob_base;
1176 struct kevent e;
1177} kqueue_event_Object;
1178
1179static PyTypeObject kqueue_event_Type;
1180
1181#define kqueue_event_Check(op)(((((PyObject*)((op)))->ob_type) == (&kqueue_event_Type
) || PyType_IsSubtype((((PyObject*)((op)))->ob_type), (&
kqueue_event_Type))))
(PyObject_TypeCheck((op), &kqueue_event_Type)((((PyObject*)((op)))->ob_type) == (&kqueue_event_Type
) || PyType_IsSubtype((((PyObject*)((op)))->ob_type), (&
kqueue_event_Type)))
)
1182
1183typedef struct {
1184 PyObject_HEADPyObject ob_base;
1185 SOCKETint kqfd; /* kqueue control fd */
1186} kqueue_queue_Object;
1187
1188static PyTypeObject kqueue_queue_Type;
1189
1190#define kqueue_queue_Check(op)(((((PyObject*)((op)))->ob_type) == (&kqueue_queue_Type
) || PyType_IsSubtype((((PyObject*)((op)))->ob_type), (&
kqueue_queue_Type))))
(PyObject_TypeCheck((op), &kqueue_queue_Type)((((PyObject*)((op)))->ob_type) == (&kqueue_queue_Type
) || PyType_IsSubtype((((PyObject*)((op)))->ob_type), (&
kqueue_queue_Type)))
)
1191
1192#if (SIZEOF_UINTPTR_T8 != SIZEOF_VOID_P8)
1193# error uintptr_t does not match void *!
1194#elif (SIZEOF_UINTPTR_T8 == SIZEOF_LONG_LONG8)
1195# define T_UINTPTRT18 T_ULONGLONG18
1196# define T_INTPTRT17 T_LONGLONG17
1197# define PyLong_AsUintptr_tPyLong_AsUnsignedLongLong PyLong_AsUnsignedLongLong
1198# define UINTPTRT_FMT_UNIT"K" "K"
1199# define INTPTRT_FMT_UNIT"L" "L"
1200#elif (SIZEOF_UINTPTR_T8 == SIZEOF_LONG8)
1201# define T_UINTPTRT18 T_ULONG12
1202# define T_INTPTRT17 T_LONG2
1203# define PyLong_AsUintptr_tPyLong_AsUnsignedLongLong PyLong_AsUnsignedLong
1204# define UINTPTRT_FMT_UNIT"K" "k"
1205# define INTPTRT_FMT_UNIT"L" "l"
1206#elif (SIZEOF_UINTPTR_T8 == SIZEOF_INT4)
1207# define T_UINTPTRT18 T_UINT11
1208# define T_INTPTRT17 T_INT1
1209# define PyLong_AsUintptr_tPyLong_AsUnsignedLongLong PyLong_AsUnsignedLong
1210# define UINTPTRT_FMT_UNIT"K" "I"
1211# define INTPTRT_FMT_UNIT"L" "i"
1212#else
1213# error uintptr_t does not match int, long, or long long!
1214#endif
1215
1216/* Unfortunately, we can't store python objects in udata, because
1217 * kevents in the kernel can be removed without warning, which would
1218 * forever lose the refcount on the object stored with it.
1219 */
1220
1221#define KQ_OFF(x) offsetof(kqueue_event_Object, x)__builtin_offsetof(kqueue_event_Object, x)
1222static struct PyMemberDef kqueue_event_members[] = {
1223 {"ident", T_UINTPTRT18, KQ_OFF(e.ident)},
1224 {"filter", T_SHORT0, KQ_OFF(e.filter)},
1225 {"flags", T_USHORT10, KQ_OFF(e.flags)},
1226 {"fflags", T_UINT11, KQ_OFF(e.fflags)},
1227 {"data", T_INTPTRT17, KQ_OFF(e.data)},
1228 {"udata", T_UINTPTRT18, KQ_OFF(e.udata)},
1229 {NULL((void*)0)} /* Sentinel */
1230};
1231#undef KQ_OFF
1232
1233static PyObject *
1234
1235kqueue_event_repr(kqueue_event_Object *s)
1236{
1237 char buf[1024];
1238 PyOS_snprintf(
1239 buf, sizeof(buf),
1240 "<select.kevent ident=%zu filter=%d flags=0x%x fflags=0x%x "
1241 "data=0x%zd udata=%p>",
1242 (size_t)(s->e.ident), s->e.filter, s->e.flags,
1243 s->e.fflags, (Py_ssize_t)(s->e.data), s->e.udata);
1244 return PyUnicode_FromStringPyUnicodeUCS2_FromString(buf);
1245}
1246
1247static int
1248kqueue_event_init(kqueue_event_Object *self, PyObject *args, PyObject *kwds)
1249{
1250 PyObject *pfd;
1251 static char *kwlist[] = {"ident", "filter", "flags", "fflags",
1252 "data", "udata", NULL((void*)0)};
1253 static char *fmt = "O|hhi" INTPTRT_FMT_UNIT"L" UINTPTRT_FMT_UNIT"K" ":kevent";
1254
1255 EV_SET(&(self->e), 0, EVFILT_READ, EV_ADD, 0, 0, 0)do { struct kevent *__kevp__ = (&(self->e)); __kevp__->
ident = (0); __kevp__->filter = ((-1)); __kevp__->flags
= (0x0001); __kevp__->fflags = (0); __kevp__->data = (
0); __kevp__->udata = (0); } while(0)
; /* defaults */
1256
1257 if (!PyArg_ParseTupleAndKeywords(args, kwds, fmt, kwlist,
1258 &pfd, &(self->e.filter), &(self->e.flags),
1259 &(self->e.fflags), &(self->e.data), &(self->e.udata))) {
1260 return -1;
1261 }
1262
1263 if (PyLong_Check(pfd)((((((PyObject*)(pfd))->ob_type))->tp_flags & ((1L<<
24))) != 0)
) {
1264 self->e.ident = PyLong_AsUintptr_tPyLong_AsUnsignedLongLong(pfd);
1265 }
1266 else {
1267 self->e.ident = PyObject_AsFileDescriptor(pfd);
1268 }
1269 if (PyErr_Occurred()) {
1270 return -1;
1271 }
1272 return 0;
1273}
1274
1275static PyObject *
1276kqueue_event_richcompare(kqueue_event_Object *s, kqueue_event_Object *o,
1277 int op)
1278{
1279 Py_intptr_t result = 0;
1280
1281 if (!kqueue_event_Check(o)(((((PyObject*)((o)))->ob_type) == (&kqueue_event_Type
) || PyType_IsSubtype((((PyObject*)((o)))->ob_type), (&
kqueue_event_Type))))
) {
1282 if (op == Py_EQ2 || op == Py_NE3) {
1283 PyObject *res = op == Py_EQ2 ? Py_False((PyObject *) &_Py_FalseStruct) : Py_True((PyObject *) &_Py_TrueStruct);
1284 Py_INCREF(res)( _Py_RefTotal++ , ((PyObject*)(res))->ob_refcnt++);
1285 return res;
1286 }
1287 PyErr_Format(PyExc_TypeError,
1288 "can't compare %.200s to %.200s",
1289 Py_TYPE(s)(((PyObject*)(s))->ob_type)->tp_name, Py_TYPE(o)(((PyObject*)(o))->ob_type)->tp_name);
1290 return NULL((void*)0);
1291 }
1292 if (((result = s->e.ident - o->e.ident) == 0) &&
1293 ((result = s->e.filter - o->e.filter) == 0) &&
1294 ((result = s->e.flags - o->e.flags) == 0) &&
1295 ((result = s->e.fflags - o->e.fflags) == 0) &&
1296 ((result = s->e.data - o->e.data) == 0) &&
1297 ((result = s->e.udata - o->e.udata) == 0)
1298 ) {
1299 result = 0;
1300 }
1301
1302 switch (op) {
1303 case Py_EQ2:
1304 result = (result == 0);
1305 break;
1306 case Py_NE3:
1307 result = (result != 0);
1308 break;
1309 case Py_LE1:
1310 result = (result <= 0);
1311 break;
1312 case Py_GE5:
1313 result = (result >= 0);
1314 break;
1315 case Py_LT0:
1316 result = (result < 0);
1317 break;
1318 case Py_GT4:
1319 result = (result > 0);
1320 break;
1321 }
1322 return PyBool_FromLong((long)result);
1323}
1324
1325static PyTypeObject kqueue_event_Type = {
1326 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
1327 "select.kevent", /* tp_name */
1328 sizeof(kqueue_event_Object), /* tp_basicsize */
1329 0, /* tp_itemsize */
1330 0, /* tp_dealloc */
1331 0, /* tp_print */
1332 0, /* tp_getattr */
1333 0, /* tp_setattr */
1334 0, /* tp_reserved */
1335 (reprfunc)kqueue_event_repr, /* tp_repr */
1336 0, /* tp_as_number */
1337 0, /* tp_as_sequence */
1338 0, /* tp_as_mapping */
1339 0, /* tp_hash */
1340 0, /* tp_call */
1341 0, /* tp_str */
1342 0, /* tp_getattro */
1343 0, /* tp_setattro */
1344 0, /* tp_as_buffer */
1345 Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0), /* tp_flags */
1346 kqueue_event_doc, /* tp_doc */
1347 0, /* tp_traverse */
1348 0, /* tp_clear */
1349 (richcmpfunc)kqueue_event_richcompare, /* tp_richcompare */
1350 0, /* tp_weaklistoffset */
1351 0, /* tp_iter */
1352 0, /* tp_iternext */
1353 0, /* tp_methods */
1354 kqueue_event_members, /* tp_members */
1355 0, /* tp_getset */
1356 0, /* tp_base */
1357 0, /* tp_dict */
1358 0, /* tp_descr_get */
1359 0, /* tp_descr_set */
1360 0, /* tp_dictoffset */
1361 (initproc)kqueue_event_init, /* tp_init */
1362 0, /* tp_alloc */
1363 0, /* tp_new */
1364 0, /* tp_free */
1365};
1366
1367static PyObject *
1368kqueue_queue_err_closed(void)
1369{
1370 PyErr_SetString(PyExc_ValueError, "I/O operation on closed kqueue fd");
1371 return NULL((void*)0);
1372}
1373
1374static int
1375kqueue_queue_internal_close(kqueue_queue_Object *self)
1376{
1377 int save_errno = 0;
1378 if (self->kqfd >= 0) {
1379 int kqfd = self->kqfd;
1380 self->kqfd = -1;
1381 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
1382 if (close(kqfd) < 0)
1383 save_errno = errno(*__error());
1384 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
1385 }
1386 return save_errno;
1387}
1388
1389static PyObject *
1390newKqueue_Object(PyTypeObject *type, SOCKETint fd)
1391{
1392 kqueue_queue_Object *self;
1393 assert(type != NULL && type->tp_alloc != NULL)(__builtin_expect(!(type != ((void*)0) && type->tp_alloc
!= ((void*)0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c"
, 1393, "type != NULL && type->tp_alloc != NULL") :
(void)0)
;
1394 self = (kqueue_queue_Object *) type->tp_alloc(type, 0);
1395 if (self == NULL((void*)0)) {
1396 return NULL((void*)0);
1397 }
1398
1399 if (fd == -1) {
1400 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
1401 self->kqfd = kqueue();
1402 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
1403 }
1404 else {
1405 self->kqfd = fd;
1406 }
1407 if (self->kqfd < 0) {
1408 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 1408
, (PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self))
; } while (0)
;
1409 PyErr_SetFromErrno(PyExc_IOError);
1410 return NULL((void*)0);
1411 }
1412 return (PyObject *)self;
1413}
1414
1415static PyObject *
1416kqueue_queue_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1417{
1418
1419 if ((args != NULL((void*)0) && PyObject_Size(args)) ||
1420 (kwds != NULL((void*)0) && PyObject_Size(kwds))) {
1421 PyErr_SetString(PyExc_ValueError,
1422 "select.kqueue doesn't accept arguments");
1423 return NULL((void*)0);
1424 }
1425
1426 return newKqueue_Object(type, -1);
1427}
1428
1429static void
1430kqueue_queue_dealloc(kqueue_queue_Object *self)
1431{
1432 kqueue_queue_internal_close(self);
1433 Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_free(self);
1434}
1435
1436static PyObject*
1437kqueue_queue_close(kqueue_queue_Object *self)
1438{
1439 errno(*__error()) = kqueue_queue_internal_close(self);
1440 if (errno(*__error()) < 0) {
1441 PyErr_SetFromErrno(PyExc_IOError);
1442 return NULL((void*)0);
1443 }
1444 Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct))
)->ob_refcnt++), (&_Py_NoneStruct)
;
1445}
1446
1447PyDoc_STRVAR(kqueue_queue_close_doc,static char kqueue_queue_close_doc[] = "close() -> None\n\nClose the kqueue control file descriptor. Further operations on the kqueue\nobject will raise an exception."
1448"close() -> None\n\static char kqueue_queue_close_doc[] = "close() -> None\n\nClose the kqueue control file descriptor. Further operations on the kqueue\nobject will raise an exception."
1449\n\static char kqueue_queue_close_doc[] = "close() -> None\n\nClose the kqueue control file descriptor. Further operations on the kqueue\nobject will raise an exception."
1450Close the kqueue control file descriptor. Further operations on the kqueue\n\static char kqueue_queue_close_doc[] = "close() -> None\n\nClose the kqueue control file descriptor. Further operations on the kqueue\nobject will raise an exception."
1451object will raise an exception.")static char kqueue_queue_close_doc[] = "close() -> None\n\nClose the kqueue control file descriptor. Further operations on the kqueue\nobject will raise an exception.";
1452
1453static PyObject*
1454kqueue_queue_get_closed(kqueue_queue_Object *self)
1455{
1456 if (self->kqfd < 0)
1457 Py_RETURN_TRUEreturn ( _Py_RefTotal++ , ((PyObject*)(((PyObject *) &_Py_TrueStruct
)))->ob_refcnt++), ((PyObject *) &_Py_TrueStruct)
;
1458 else
1459 Py_RETURN_FALSEreturn ( _Py_RefTotal++ , ((PyObject*)(((PyObject *) &_Py_FalseStruct
)))->ob_refcnt++), ((PyObject *) &_Py_FalseStruct)
;
1460}
1461
1462static PyObject*
1463kqueue_queue_fileno(kqueue_queue_Object *self)
1464{
1465 if (self->kqfd < 0)
1466 return kqueue_queue_err_closed();
1467 return PyLong_FromLong(self->kqfd);
1468}
1469
1470PyDoc_STRVAR(kqueue_queue_fileno_doc,static char kqueue_queue_fileno_doc[] = "fileno() -> int\n\nReturn the kqueue control file descriptor."
1471"fileno() -> int\n\static char kqueue_queue_fileno_doc[] = "fileno() -> int\n\nReturn the kqueue control file descriptor."
1472\n\static char kqueue_queue_fileno_doc[] = "fileno() -> int\n\nReturn the kqueue control file descriptor."
1473Return the kqueue control file descriptor.")static char kqueue_queue_fileno_doc[] = "fileno() -> int\n\nReturn the kqueue control file descriptor.";
1474
1475static PyObject*
1476kqueue_queue_fromfd(PyObject *cls, PyObject *args)
1477{
1478 SOCKETint fd;
1479
1480 if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
1481 return NULL((void*)0);
1482
1483 return newKqueue_Object((PyTypeObject*)cls, fd);
1484}
1485
1486PyDoc_STRVAR(kqueue_queue_fromfd_doc,static char kqueue_queue_fromfd_doc[] = "fromfd(fd) -> kqueue\n\nCreate a kqueue object from a given control fd."
1487"fromfd(fd) -> kqueue\n\static char kqueue_queue_fromfd_doc[] = "fromfd(fd) -> kqueue\n\nCreate a kqueue object from a given control fd."
1488\n\static char kqueue_queue_fromfd_doc[] = "fromfd(fd) -> kqueue\n\nCreate a kqueue object from a given control fd."
1489Create a kqueue object from a given control fd.")static char kqueue_queue_fromfd_doc[] = "fromfd(fd) -> kqueue\n\nCreate a kqueue object from a given control fd.";
1490
1491static PyObject *
1492kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
1493{
1494 int nevents = 0;
1495 int gotevents = 0;
1496 int nchanges = 0;
1497 int i = 0;
1498 PyObject *otimeout = NULL((void*)0);
1499 PyObject *ch = NULL((void*)0);
1500 PyObject *it = NULL((void*)0), *ei = NULL((void*)0);
1501 PyObject *result = NULL((void*)0);
1502 struct kevent *evl = NULL((void*)0);
1503 struct kevent *chl = NULL((void*)0);
1504 struct timespec timeoutspec;
1505 struct timespec *ptimeoutspec;
1506
1507 if (self->kqfd < 0)
1
Taking false branch
1508 return kqueue_queue_err_closed();
1509
1510 if (!PyArg_ParseTuple(args, "Oi|O:control", &ch, &nevents, &otimeout))
2
Taking false branch
1511 return NULL((void*)0);
1512
1513 if (nevents < 0) {
3
Taking false branch
1514 PyErr_Format(PyExc_ValueError,
1515 "Length of eventlist must be 0 or positive, got %d",
1516 nevents);
1517 return NULL((void*)0);
1518 }
1519
1520 if (otimeout == Py_None(&_Py_NoneStruct) || otimeout == NULL((void*)0)) {
4
Taking false branch
1521 ptimeoutspec = NULL((void*)0);
1522 }
1523 else if (PyNumber_Check(otimeout)) {
5
Taking true branch
1524 double timeout;
1525 long seconds;
1526
1527 timeout = PyFloat_AsDouble(otimeout);
1528 if (timeout == -1 && PyErr_Occurred())
6
Taking false branch
1529 return NULL((void*)0);
1530 if (timeout > (double)LONG_MAX9223372036854775807L) {
7
Taking false branch
1531 PyErr_SetString(PyExc_OverflowError,
1532 "timeout period too long");
1533 return NULL((void*)0);
1534 }
1535 if (timeout < 0) {
8
Taking false branch
1536 PyErr_SetString(PyExc_ValueError,
1537 "timeout must be positive or None");
1538 return NULL((void*)0);
1539 }
1540
1541 seconds = (long)timeout;
1542 timeout = timeout - (double)seconds;
1543 timeoutspec.tv_sec = seconds;
1544 timeoutspec.tv_nsec = (long)(timeout * 1E9);
1545 ptimeoutspec = &timeoutspec;
1546 }
1547 else {
1548 PyErr_Format(PyExc_TypeError,
1549 "timeout argument must be an number "
1550 "or None, got %.200s",
1551 Py_TYPE(otimeout)(((PyObject*)(otimeout))->ob_type)->tp_name);
1552 return NULL((void*)0);
1553 }
1554
1555 if (ch != NULL((void*)0) && ch != Py_None(&_Py_NoneStruct)) {
9
Taking false branch
1556 it = PyObject_GetIter(ch);
1557 if (it == NULL((void*)0)) {
1558 PyErr_SetString(PyExc_TypeError,
1559 "changelist is not iterable");
1560 return NULL((void*)0);
1561 }
1562 nchanges = PyObject_Size(ch);
1563 if (nchanges < 0) {
1564 goto error;
1565 }
1566
1567 chl = PyMem_New(struct kevent, nchanges)( ((size_t)(nchanges) > ((Py_ssize_t)(((size_t)-1)>>
1)) / sizeof(struct kevent)) ? ((void*)0) : ( (struct kevent *
) PyMem_Malloc((nchanges) * sizeof(struct kevent)) ) )
;
1568 if (chl == NULL((void*)0)) {
1569 PyErr_NoMemory();
1570 goto error;
1571 }
1572 i = 0;
1573 while ((ei = PyIter_Next(it)) != NULL((void*)0)) {
1574 if (!kqueue_event_Check(ei)(((((PyObject*)((ei)))->ob_type) == (&kqueue_event_Type
) || PyType_IsSubtype((((PyObject*)((ei)))->ob_type), (&
kqueue_event_Type))))
) {
1575 Py_DECREF(ei)do { if (_Py_RefTotal-- , --((PyObject*)(ei))->ob_refcnt !=
0) { if (((PyObject*)ei)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 1575
, (PyObject *)(ei)); } else _Py_Dealloc((PyObject *)(ei)); } while
(0)
;
1576 PyErr_SetString(PyExc_TypeError,
1577 "changelist must be an iterable of "
1578 "select.kevent objects");
1579 goto error;
1580 } else {
1581 chl[i++] = ((kqueue_event_Object *)ei)->e;
1582 }
1583 Py_DECREF(ei)do { if (_Py_RefTotal-- , --((PyObject*)(ei))->ob_refcnt !=
0) { if (((PyObject*)ei)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c", 1583
, (PyObject *)(ei)); } else _Py_Dealloc((PyObject *)(ei)); } while
(0)
;
1584 }
1585 }
1586 Py_CLEAR(it)do { if (it) { PyObject *_py_tmp = (PyObject *)(it); (it) = (
(void*)0); do { if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))
->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->ob_refcnt
< 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c"
, 1586, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
1587
1588 /* event list */
1589 if (nevents) {
10
Taking false branch
1590 evl = PyMem_New(struct kevent, nevents)( ((size_t)(nevents) > ((Py_ssize_t)(((size_t)-1)>>1
)) / sizeof(struct kevent)) ? ((void*)0) : ( (struct kevent *
) PyMem_Malloc((nevents) * sizeof(struct kevent)) ) )
;
1591 if (evl == NULL((void*)0)) {
1592 PyErr_NoMemory();
1593 goto error;
1594 }
1595 }
1596
1597 Py_BEGIN_ALLOW_THREADS{ PyThreadState *_save; _save = PyEval_SaveThread();
1598 gotevents = kevent(self->kqfd, chl, nchanges,
1599 evl, nevents, ptimeoutspec);
1600 Py_END_ALLOW_THREADSPyEval_RestoreThread(_save); }
1601
1602 if (gotevents == -1) {
11
Taking false branch
1603 PyErr_SetFromErrno(PyExc_OSError);
1604 goto error;
1605 }
1606
1607 result = PyList_New(gotevents);
1608 if (result == NULL((void*)0)) {
12
Taking false branch
1609 goto error;
1610 }
1611
1612 for (i = 0; i < gotevents; i++) {
13
Loop condition is true. Entering loop body
1613 kqueue_event_Object *ch;
1614
1615 ch = PyObject_New(kqueue_event_Object, &kqueue_event_Type)( (kqueue_event_Object *) _PyObject_New(&kqueue_event_Type
) )
;
1616 if (ch == NULL((void*)0)) {
14
Taking false branch
1617 goto error;
1618 }
1619 ch->e = evl[i];
15
Array access (from variable 'evl') results in a null pointer dereference
1620 PyList_SET_ITEM(result, i, (PyObject *)ch)(((PyListObject *)(result))->ob_item[i] = ((PyObject *)ch)
)
;
1621 }
1622 PyMem_Free(chl);
1623 PyMem_Free(evl);
1624 return result;
1625
1626 error:
1627 PyMem_Free(chl);
1628 PyMem_Free(evl);
1629 Py_XDECREF(result)do { if ((result) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(result))->ob_refcnt != 0) { if (((PyObject
*)result)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c"
, 1629, (PyObject *)(result)); } else _Py_Dealloc((PyObject *
)(result)); } while (0); } while (0)
;
1630 Py_XDECREF(it)do { if ((it) == ((void*)0)) ; else do { if (_Py_RefTotal-- ,
--((PyObject*)(it))->ob_refcnt != 0) { if (((PyObject*)it
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/selectmodule.c"
, 1630, (PyObject *)(it)); } else _Py_Dealloc((PyObject *)(it
)); } while (0); } while (0)
;
1631 return NULL((void*)0);
1632}
1633
1634PyDoc_STRVAR(kqueue_queue_control_doc,static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1635"control(changelist, max_events[, timeout=None]) -> eventlist\n\static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1636\n\static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1637Calls the kernel kevent function.\n\static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1638- changelist must be a list of kevent objects describing the changes\n\static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1639 to be made to the kernel's watch list or None.\n\static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1640- max_events lets you specify the maximum number of events that the\n\static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1641 kernel will return.\n\static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1642- timeout is the maximum time to wait in seconds, or else None,\n\static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too."
1643 to wait forever. timeout accepts floats for smaller timeouts, too.")static char kqueue_queue_control_doc[] = "control(changelist, max_events[, timeout=None]) -> eventlist\n\nCalls the kernel kevent function.\n- changelist must be a list of kevent objects describing the changes\n to be made to the kernel's watch list or None.\n- max_events lets you specify the maximum number of events that the\n kernel will return.\n- timeout is the maximum time to wait in seconds, or else None,\n to wait forever. timeout accepts floats for smaller timeouts, too.";
1644
1645
1646static PyMethodDef kqueue_queue_methods[] = {
1647 {"fromfd", (PyCFunction)kqueue_queue_fromfd,
1648 METH_VARARGS0x0001 | METH_CLASS0x0010, kqueue_queue_fromfd_doc},
1649 {"close", (PyCFunction)kqueue_queue_close, METH_NOARGS0x0004,
1650 kqueue_queue_close_doc},
1651 {"fileno", (PyCFunction)kqueue_queue_fileno, METH_NOARGS0x0004,
1652 kqueue_queue_fileno_doc},
1653 {"control", (PyCFunction)kqueue_queue_control,
1654 METH_VARARGS0x0001 , kqueue_queue_control_doc},
1655 {NULL((void*)0), NULL((void*)0)},
1656};
1657
1658static PyGetSetDef kqueue_queue_getsetlist[] = {
1659 {"closed", (getter)kqueue_queue_get_closed, NULL((void*)0),
1660 "True if the kqueue handler is closed"},
1661 {0},
1662};
1663
1664PyDoc_STRVAR(kqueue_queue_doc,static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1665"Kqueue syscall wrapper.\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1666\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1667For example, to start watching a socket for input:\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1668>>> kq = kqueue()\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1669>>> sock = socket()\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1670>>> sock.connect((host, port))\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1671>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1672\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1673To wait one second for it to become writeable:\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1674>>> kq.control(None, 1, 1000)\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1675\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1676To stop listening:\n\static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)"
1677>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)")static char kqueue_queue_doc[] = "Kqueue syscall wrapper.\n\nFor example, to start watching a socket for input:\n>>> kq = kqueue()\n>>> sock = socket()\n>>> sock.connect((host, port))\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\nTo wait one second for it to become writeable:\n>>> kq.control(None, 1, 1000)\n\nTo stop listening:\n>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)";
1678
1679static PyTypeObject kqueue_queue_Type = {
1680 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
1681 "select.kqueue", /* tp_name */
1682 sizeof(kqueue_queue_Object), /* tp_basicsize */
1683 0, /* tp_itemsize */
1684 (destructor)kqueue_queue_dealloc, /* tp_dealloc */
1685 0, /* tp_print */
1686 0, /* tp_getattr */
1687 0, /* tp_setattr */
1688 0, /* tp_reserved */
1689 0, /* tp_repr */
1690 0, /* tp_as_number */
1691 0, /* tp_as_sequence */
1692 0, /* tp_as_mapping */
1693 0, /* tp_hash */
1694 0, /* tp_call */
1695 0, /* tp_str */
1696 0, /* tp_getattro */
1697 0, /* tp_setattro */
1698 0, /* tp_as_buffer */
1699 Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0), /* tp_flags */
1700 kqueue_queue_doc, /* tp_doc */
1701 0, /* tp_traverse */
1702 0, /* tp_clear */
1703 0, /* tp_richcompare */
1704 0, /* tp_weaklistoffset */
1705 0, /* tp_iter */
1706 0, /* tp_iternext */
1707 kqueue_queue_methods, /* tp_methods */
1708 0, /* tp_members */
1709 kqueue_queue_getsetlist, /* tp_getset */
1710 0, /* tp_base */
1711 0, /* tp_dict */
1712 0, /* tp_descr_get */
1713 0, /* tp_descr_set */
1714 0, /* tp_dictoffset */
1715 0, /* tp_init */
1716 0, /* tp_alloc */
1717 kqueue_queue_new, /* tp_new */
1718 0, /* tp_free */
1719};
1720
1721#endif /* HAVE_KQUEUE */
1722/* ************************************************************************ */
1723
1724PyDoc_STRVAR(select_doc,static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1725"select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1726\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1727Wait until one or more file descriptors are ready for some kind of I/O.\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1728The first three arguments are sequences of file descriptors to be waited for:\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1729rlist -- wait until ready for reading\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1730wlist -- wait until ready for writing\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1731xlist -- wait for an ``exceptional condition''\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1732If only one kind of condition is required, pass [] for the other lists.\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1733A file descriptor is either a socket or file object, or a small integer\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1734gotten from a fileno() method call on one of those.\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1735\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1736The optional 4th argument specifies a timeout in seconds; it may be\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1737a floating point number to specify fractions of seconds. If it is absent\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1738or None, the call will never time out.\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1739\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1740The return value is a tuple of three lists corresponding to the first three\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1741arguments; each contains the subset of the corresponding file descriptors\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1742that are ready.\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1743\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1744*** IMPORTANT NOTICE ***\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1745On Windows and OpenVMS, only sockets are supported; on Unix, all file\n\static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used."
1746descriptors can be used.")static char select_doc[] = "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\nWait until one or more file descriptors are ready for some kind of I/O.\nThe first three arguments are sequences of file descriptors to be waited for:\nrlist -- wait until ready for reading\nwlist -- wait until ready for writing\nxlist -- wait for an ``exceptional condition''\nIf only one kind of condition is required, pass [] for the other lists.\nA file descriptor is either a socket or file object, or a small integer\ngotten from a fileno() method call on one of those.\n\nThe optional 4th argument specifies a timeout in seconds; it may be\na floating point number to specify fractions of seconds. If it is absent\nor None, the call will never time out.\n\nThe return value is a tuple of three lists corresponding to the first three\narguments; each contains the subset of the corresponding file descriptors\nthat are ready.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file\ndescriptors can be used.";
1747
1748static PyMethodDef select_methods[] = {
1749 {"select", select_select, METH_VARARGS0x0001, select_doc},
1750#ifdef HAVE_POLL1
1751 {"poll", select_poll, METH_NOARGS0x0004, poll_doc},
1752#endif /* HAVE_POLL */
1753 {0, 0}, /* sentinel */
1754};
1755
1756PyDoc_STRVAR(module_doc,static char module_doc[] = "This module supports asynchronous I/O on multiple file descriptors.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors."
1757"This module supports asynchronous I/O on multiple file descriptors.\n\static char module_doc[] = "This module supports asynchronous I/O on multiple file descriptors.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors."
1758\n\static char module_doc[] = "This module supports asynchronous I/O on multiple file descriptors.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors."
1759*** IMPORTANT NOTICE ***\n\static char module_doc[] = "This module supports asynchronous I/O on multiple file descriptors.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors."
1760On Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.")static char module_doc[] = "This module supports asynchronous I/O on multiple file descriptors.\n\n*** IMPORTANT NOTICE ***\nOn Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.";
1761
1762
1763static struct PyModuleDef selectmodule = {
1764 PyModuleDef_HEAD_INIT{ { 0, 0, 1, ((void*)0) }, ((void*)0), 0, ((void*)0), },
1765 "select",
1766 module_doc,
1767 -1,
1768 select_methods,
1769 NULL((void*)0),
1770 NULL((void*)0),
1771 NULL((void*)0),
1772 NULL((void*)0)
1773};
1774
1775PyMODINIT_FUNCPyObject*
1776PyInit_select(void)
1777{
1778 PyObject *m;
1779 m = PyModule_Create(&selectmodule)PyModule_Create2TraceRefs(&selectmodule, 1013);
1780 if (m == NULL((void*)0))
1781 return NULL((void*)0);
1782
1783 SelectError = PyErr_NewException("select.error", NULL((void*)0), NULL((void*)0));
1784 Py_INCREF(SelectError)( _Py_RefTotal++ , ((PyObject*)(SelectError))->ob_refcnt++
)
;
1785 PyModule_AddObject(m, "error", SelectError);
1786
1787#ifdef PIPE_BUF512
1788#ifdef HAVE_BROKEN_PIPE_BUF
1789#undef PIPE_BUF512
1790#define PIPE_BUF512 512
1791#endif
1792 PyModule_AddIntConstant(m, "PIPE_BUF", PIPE_BUF512);
1793#endif
1794
1795#if defined(HAVE_POLL1)
1796#ifdef __APPLE__1
1797 if (select_have_broken_poll()) {
1798 if (PyObject_DelAttrString(m, "poll")PyObject_SetAttrString((m),("poll"),((void*)0)) == -1) {
1799 PyErr_Clear();
1800 }
1801 } else {
1802#else
1803 {
1804#endif
1805 if (PyType_Ready(&poll_Type) < 0)
1806 return NULL((void*)0);
1807 PyModule_AddIntConstant(m, "POLLIN", POLLIN0x0001);
1808 PyModule_AddIntConstant(m, "POLLPRI", POLLPRI0x0002);
1809 PyModule_AddIntConstant(m, "POLLOUT", POLLOUT0x0004);
1810 PyModule_AddIntConstant(m, "POLLERR", POLLERR0x0008);
1811 PyModule_AddIntConstant(m, "POLLHUP", POLLHUP0x0010);
1812 PyModule_AddIntConstant(m, "POLLNVAL", POLLNVAL0x0020);
1813
1814#ifdef POLLRDNORM0x0040
1815 PyModule_AddIntConstant(m, "POLLRDNORM", POLLRDNORM0x0040);
1816#endif
1817#ifdef POLLRDBAND0x0080
1818 PyModule_AddIntConstant(m, "POLLRDBAND", POLLRDBAND0x0080);
1819#endif
1820#ifdef POLLWRNORM0x0004
1821 PyModule_AddIntConstant(m, "POLLWRNORM", POLLWRNORM0x0004);
1822#endif
1823#ifdef POLLWRBAND0x0100
1824 PyModule_AddIntConstant(m, "POLLWRBAND", POLLWRBAND0x0100);
1825#endif
1826#ifdef POLLMSG
1827 PyModule_AddIntConstant(m, "POLLMSG", POLLMSG);
1828#endif
1829 }
1830#endif /* HAVE_POLL */
1831
1832#ifdef HAVE_EPOLL
1833 Py_TYPE(&pyEpoll_Type)(((PyObject*)(&pyEpoll_Type))->ob_type) = &PyType_Type;
1834 if (PyType_Ready(&pyEpoll_Type) < 0)
1835 return NULL((void*)0);
1836
1837 Py_INCREF(&pyEpoll_Type)( _Py_RefTotal++ , ((PyObject*)(&pyEpoll_Type))->ob_refcnt
++)
;
1838 PyModule_AddObject(m, "epoll", (PyObject *) &pyEpoll_Type);
1839
1840 PyModule_AddIntConstant(m, "EPOLLIN", EPOLLIN);
1841 PyModule_AddIntConstant(m, "EPOLLOUT", EPOLLOUT);
1842 PyModule_AddIntConstant(m, "EPOLLPRI", EPOLLPRI);
1843 PyModule_AddIntConstant(m, "EPOLLERR", EPOLLERR);
1844 PyModule_AddIntConstant(m, "EPOLLHUP", EPOLLHUP);
1845 PyModule_AddIntConstant(m, "EPOLLET", EPOLLET);
1846#ifdef EPOLLONESHOT
1847 /* Kernel 2.6.2+ */
1848 PyModule_AddIntConstant(m, "EPOLLONESHOT", EPOLLONESHOT);
1849#endif
1850 /* PyModule_AddIntConstant(m, "EPOLL_RDHUP", EPOLLRDHUP); */
1851 PyModule_AddIntConstant(m, "EPOLLRDNORM", EPOLLRDNORM);
1852 PyModule_AddIntConstant(m, "EPOLLRDBAND", EPOLLRDBAND);
1853 PyModule_AddIntConstant(m, "EPOLLWRNORM", EPOLLWRNORM);
1854 PyModule_AddIntConstant(m, "EPOLLWRBAND", EPOLLWRBAND);
1855 PyModule_AddIntConstant(m, "EPOLLMSG", EPOLLMSG);
1856#endif /* HAVE_EPOLL */
1857
1858#ifdef HAVE_KQUEUE1
1859 kqueue_event_Type.tp_new = PyType_GenericNew;
1860 Py_TYPE(&kqueue_event_Type)(((PyObject*)(&kqueue_event_Type))->ob_type) = &PyType_Type;
1861 if(PyType_Ready(&kqueue_event_Type) < 0)
1862 return NULL((void*)0);
1863
1864 Py_INCREF(&kqueue_event_Type)( _Py_RefTotal++ , ((PyObject*)(&kqueue_event_Type))->
ob_refcnt++)
;
1865 PyModule_AddObject(m, "kevent", (PyObject *)&kqueue_event_Type);
1866
1867 Py_TYPE(&kqueue_queue_Type)(((PyObject*)(&kqueue_queue_Type))->ob_type) = &PyType_Type;
1868 if(PyType_Ready(&kqueue_queue_Type) < 0)
1869 return NULL((void*)0);
1870 Py_INCREF(&kqueue_queue_Type)( _Py_RefTotal++ , ((PyObject*)(&kqueue_queue_Type))->
ob_refcnt++)
;
1871 PyModule_AddObject(m, "kqueue", (PyObject *)&kqueue_queue_Type);
1872
1873 /* event filters */
1874 PyModule_AddIntConstant(m, "KQ_FILTER_READ", EVFILT_READ(-1));
1875 PyModule_AddIntConstant(m, "KQ_FILTER_WRITE", EVFILT_WRITE(-2));
1876 PyModule_AddIntConstant(m, "KQ_FILTER_AIO", EVFILT_AIO(-3));
1877 PyModule_AddIntConstant(m, "KQ_FILTER_VNODE", EVFILT_VNODE(-4));
1878 PyModule_AddIntConstant(m, "KQ_FILTER_PROC", EVFILT_PROC(-5));
1879#ifdef EVFILT_NETDEV
1880 PyModule_AddIntConstant(m, "KQ_FILTER_NETDEV", EVFILT_NETDEV);
1881#endif
1882 PyModule_AddIntConstant(m, "KQ_FILTER_SIGNAL", EVFILT_SIGNAL(-6));
1883 PyModule_AddIntConstant(m, "KQ_FILTER_TIMER", EVFILT_TIMER(-7));
1884
1885 /* event flags */
1886 PyModule_AddIntConstant(m, "KQ_EV_ADD", EV_ADD0x0001);
1887 PyModule_AddIntConstant(m, "KQ_EV_DELETE", EV_DELETE0x0002);
1888 PyModule_AddIntConstant(m, "KQ_EV_ENABLE", EV_ENABLE0x0004);
1889 PyModule_AddIntConstant(m, "KQ_EV_DISABLE", EV_DISABLE0x0008);
1890 PyModule_AddIntConstant(m, "KQ_EV_ONESHOT", EV_ONESHOT0x0010);
1891 PyModule_AddIntConstant(m, "KQ_EV_CLEAR", EV_CLEAR0x0020);
1892
1893 PyModule_AddIntConstant(m, "KQ_EV_SYSFLAGS", EV_SYSFLAGS0xF000);
1894 PyModule_AddIntConstant(m, "KQ_EV_FLAG1", EV_FLAG10x2000);
1895
1896 PyModule_AddIntConstant(m, "KQ_EV_EOF", EV_EOF0x8000);
1897 PyModule_AddIntConstant(m, "KQ_EV_ERROR", EV_ERROR0x4000);
1898
1899 /* READ WRITE filter flag */
1900 PyModule_AddIntConstant(m, "KQ_NOTE_LOWAT", NOTE_LOWAT0x00000001);
1901
1902 /* VNODE filter flags */
1903 PyModule_AddIntConstant(m, "KQ_NOTE_DELETE", NOTE_DELETE0x00000001);
1904 PyModule_AddIntConstant(m, "KQ_NOTE_WRITE", NOTE_WRITE0x00000002);
1905 PyModule_AddIntConstant(m, "KQ_NOTE_EXTEND", NOTE_EXTEND0x00000004);
1906 PyModule_AddIntConstant(m, "KQ_NOTE_ATTRIB", NOTE_ATTRIB0x00000008);
1907 PyModule_AddIntConstant(m, "KQ_NOTE_LINK", NOTE_LINK0x00000010);
1908 PyModule_AddIntConstant(m, "KQ_NOTE_RENAME", NOTE_RENAME0x00000020);
1909 PyModule_AddIntConstant(m, "KQ_NOTE_REVOKE", NOTE_REVOKE0x00000040);
1910
1911 /* PROC filter flags */
1912 PyModule_AddIntConstant(m, "KQ_NOTE_EXIT", NOTE_EXIT0x80000000);
1913 PyModule_AddIntConstant(m, "KQ_NOTE_FORK", NOTE_FORK0x40000000);
1914 PyModule_AddIntConstant(m, "KQ_NOTE_EXEC", NOTE_EXEC0x20000000);
1915 PyModule_AddIntConstant(m, "KQ_NOTE_PCTRLMASK", NOTE_PCTRLMASK(~0x000fffff));
1916 PyModule_AddIntConstant(m, "KQ_NOTE_PDATAMASK", NOTE_PDATAMASK0x000fffff);
1917
1918 PyModule_AddIntConstant(m, "KQ_NOTE_TRACK", NOTE_TRACK0x00000001);
1919 PyModule_AddIntConstant(m, "KQ_NOTE_CHILD", NOTE_CHILD0x00000004);
1920 PyModule_AddIntConstant(m, "KQ_NOTE_TRACKERR", NOTE_TRACKERR0x00000002);
1921
1922 /* NETDEV filter flags */
1923#ifdef EVFILT_NETDEV
1924 PyModule_AddIntConstant(m, "KQ_NOTE_LINKUP", NOTE_LINKUP);
1925 PyModule_AddIntConstant(m, "KQ_NOTE_LINKDOWN", NOTE_LINKDOWN);
1926 PyModule_AddIntConstant(m, "KQ_NOTE_LINKINV", NOTE_LINKINV);
1927#endif
1928
1929#endif /* HAVE_KQUEUE */
1930 return m;
1931}