selectmodule.c 16.3 KB
Newer Older
1
/* select - Module containing unix select(2) call.
2 3 4
   Under Unix, the file descriptors are small integers.
   Under Win32, select only exists for sockets, and sockets may
   have any value except INVALID_SOCKET.
5 6
   Under BeOS, we suffer the same dichotomy as Win32; sockets can be anything
   >= 0.
7
*/
8

9
#include "Python.h"
10

11 12 13 14 15 16 17 18 19 20
/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
   64 is too small (too many people have bumped into that limit).
   Here we boost it.
   Users who want even more than the boosted limit should #define
   FD_SETSIZE higher before this; e.g., via compiler /D switch.
*/
#if defined(MS_WINDOWS) && !defined(FD_SETSIZE)
#define FD_SETSIZE 512
#endif 

Andrew M. Kuchling's avatar
Andrew M. Kuchling committed
21
#if defined(HAVE_POLL_H)
22
#include <poll.h>
Andrew M. Kuchling's avatar
Andrew M. Kuchling committed
23 24
#elif defined(HAVE_SYS_POLL_H)
#include <sys/poll.h>
25
#endif
Guido van Rossum's avatar
Guido van Rossum committed
26

27 28
#ifdef __sgi
/* This is missing from unistd.h */
29
extern void bzero(void *, int);
30 31
#endif

32
#ifndef DONT_HAVE_SYS_TYPES_H
33
#include <sys/types.h>
34
#endif
35

36
#if defined(PYOS_OS2) && !defined(PYCC_GCC)
37 38 39 40
#include <sys/time.h>
#include <utils.h>
#endif

41
#ifdef MS_WINDOWS
42
#include <winsock.h>
43
#else
44 45 46 47
#ifdef __BEOS__
#include <net/socket.h>
#define SOCKET int
#else
48 49
#define SOCKET int
#endif
50
#endif
51

52

53
static PyObject *SelectError;
54

55 56 57
/* list of Python objects and their file descriptor */
typedef struct {
	PyObject *obj;			     /* owned reference */
58
	SOCKET fd;
59
	int sentinel;			     /* -1 == sentinel */
60 61
} pylist;

62
static void
63
reap_obj(pylist fd2obj[FD_SETSIZE + 1])
64 65
{
	int i;
66
	for (i = 0; i < FD_SETSIZE + 1 && fd2obj[i].sentinel >= 0; i++) {
67 68 69 70 71 72 73
		Py_XDECREF(fd2obj[i].obj);
		fd2obj[i].obj = NULL;
	}
	fd2obj[0].sentinel = -1;
}


74 75 76
/* returns -1 and sets the Python exception if an error occurred, otherwise
   returns a number >= 0
*/
77
static int
78
list2set(PyObject *list, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
79
{
80 81 82 83 84
	int i;
	int max = -1;
	int index = 0;
	int len = PyList_Size(list);
	PyObject* o = NULL;
Guido van Rossum's avatar
Guido van Rossum committed
85

86 87
	fd2obj[0].obj = (PyObject*)0;	     /* set list to zero size */
	FD_ZERO(set);
88 89 90 91 92

	for (i = 0; i < len; i++)  {
		SOCKET v;

		/* any intervening fileno() calls could decr this refcnt */
93
		if (!(o = PyList_GetItem(list, i)))
94
                    return -1;
95

96
		Py_INCREF(o);
97 98
		v = PyObject_AsFileDescriptor( o );
		if (v == -1) goto finally;
99

100
#if defined(_MSC_VER)
101 102
		max = 0;		     /* not used for Win32 */
#else  /* !_MSC_VER */
103
		if (v < 0 || v >= FD_SETSIZE) {
104 105 106
			PyErr_SetString(PyExc_ValueError,
				    "filedescriptor out of range in select()");
			goto finally;
107 108 109
		}
		if (v > max)
			max = v;
110
#endif /* _MSC_VER */
111
		FD_SET(v, set);
112

113 114
		/* add object and its file descriptor to the list */
		if (index >= FD_SETSIZE) {
115 116 117
			PyErr_SetString(PyExc_ValueError,
				      "too many file descriptors in select()");
			goto finally;
118 119 120
		}
		fd2obj[index].obj = o;
		fd2obj[index].fd = v;
121 122
		fd2obj[index].sentinel = 0;
		fd2obj[++index].sentinel = -1;
123
	}
124
	return max+1;
125 126 127 128

  finally:
	Py_XDECREF(o);
	return -1;
129 130
}

131 132
/* returns NULL and sets the Python exception if an error occurred */
static PyObject *
133
set2list(fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
134
{
135
	int i, j, count=0;
136 137 138
	PyObject *list, *o;
	SOCKET fd;

139
	for (j = 0; fd2obj[j].sentinel >= 0; j++) {
140
		if (FD_ISSET(fd2obj[j].fd, set))
141 142 143
			count++;
	}
	list = PyList_New(count);
144 145 146
	if (!list)
		return NULL;

147 148
	i = 0;
	for (j = 0; fd2obj[j].sentinel >= 0; j++) {
149 150
		fd = fd2obj[j].fd;
		if (FD_ISSET(fd, set)) {
151
#ifndef _MSC_VER
152 153 154
			if (fd > FD_SETSIZE) {
				PyErr_SetString(PyExc_SystemError,
			   "filedescriptor out of range returned in select()");
155
				goto finally;
156
			}
157
#endif
158
			o = fd2obj[j].obj;
159 160 161 162 163 164
			fd2obj[j].obj = NULL;
			/* transfer ownership */
			if (PyList_SetItem(list, i, o) < 0)
				goto finally;

			i++;
165 166 167
		}
	}
	return list;
168 169 170
  finally:
	Py_DECREF(list);
	return NULL;
171
}
172

173 174 175 176 177
#undef SELECT_USES_HEAP
#if FD_SETSIZE > 1024
#define SELECT_USES_HEAP
#endif /* FD_SETSIZE > 1024 */

178
static PyObject *
Peter Schneider-Kamp's avatar
Peter Schneider-Kamp committed
179
select_select(PyObject *self, PyObject *args)
180
{
181
#ifdef SELECT_USES_HEAP
182
	pylist *rfd2obj, *wfd2obj, *efd2obj;
183
#else  /* !SELECT_USES_HEAP */
184
	/* XXX: All this should probably be implemented as follows:
185 186 187 188 189
	 * - find the highest descriptor we're interested in
	 * - add one
	 * - that's the size
	 * See: Stevens, APitUE, $12.5.1
	 */
190 191 192
	pylist rfd2obj[FD_SETSIZE + 1];
	pylist wfd2obj[FD_SETSIZE + 1];
	pylist efd2obj[FD_SETSIZE + 1];
193
#endif /* SELECT_USES_HEAP */
194
	PyObject *ifdlist, *ofdlist, *efdlist;
195
	PyObject *ret = NULL;
196 197 198 199
	PyObject *tout = Py_None;
	fd_set ifdset, ofdset, efdset;
	double timeout;
	struct timeval tv, *tvp;
Guido van Rossum's avatar
Guido van Rossum committed
200
	long seconds;
201 202 203 204
	int imax, omax, emax, max;
	int n;

	/* convert arguments */
205
	if (!PyArg_ParseTuple(args, "OOO|O:select",
206 207 208 209 210
			      &ifdlist, &ofdlist, &efdlist, &tout))
		return NULL;

	if (tout == Py_None)
		tvp = (struct timeval *)0;
211
	else if (!PyNumber_Check(tout)) {
212 213
		PyErr_SetString(PyExc_TypeError,
				"timeout must be a float or None");
214
		return NULL;
215
	}
216
	else {
217 218
		timeout = PyFloat_AsDouble(tout);
		if (timeout == -1 && PyErr_Occurred())
219
			return NULL;
Guido van Rossum's avatar
Guido van Rossum committed
220
		if (timeout > (double)LONG_MAX) {
221 222
			PyErr_SetString(PyExc_OverflowError,
					"timeout period too long");
Guido van Rossum's avatar
Guido van Rossum committed
223 224 225
			return NULL;
		}
		seconds = (long)timeout;
226 227
		timeout = timeout - (double)seconds;
		tv.tv_sec = seconds;
Guido van Rossum's avatar
Guido van Rossum committed
228
		tv.tv_usec = (long)(timeout*1000000.0);
229
		tvp = &tv;
230
	}
231 232 233 234 235 236 237 238 239 240 241

	/* sanity check first three arguments */
	if (!PyList_Check(ifdlist) ||
	    !PyList_Check(ofdlist) ||
	    !PyList_Check(efdlist))
	{
		PyErr_SetString(PyExc_TypeError,
				"arguments 1-3 must be lists");
		return NULL;
	}

242
#ifdef SELECT_USES_HEAP
243
	/* Allocate memory for the lists */
244 245 246
	rfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);
	wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);
	efd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);
247
	if (rfd2obj == NULL || wfd2obj == NULL || efd2obj == NULL) {
248 249 250
		if (rfd2obj) PyMem_DEL(rfd2obj);
		if (wfd2obj) PyMem_DEL(wfd2obj);
		if (efd2obj) PyMem_DEL(efd2obj);
251 252
		return NULL;
	}
253
#endif /* SELECT_USES_HEAP */
254 255 256
	/* Convert lists to fd_sets, and get maximum fd number
	 * propagates the Python exception set in list2set()
	 */
257 258 259
	rfd2obj[0].sentinel = -1;
	wfd2obj[0].sentinel = -1;
	efd2obj[0].sentinel = -1;
260
	if ((imax=list2set(ifdlist, &ifdset, rfd2obj)) < 0) 
261
		goto finally;
262
	if ((omax=list2set(ofdlist, &ofdset, wfd2obj)) < 0) 
263
		goto finally;
264
	if ((emax=list2set(efdlist, &efdset, efd2obj)) < 0) 
265
		goto finally;
266 267 268 269 270 271 272 273
	max = imax;
	if (omax > max) max = omax;
	if (emax > max) max = emax;

	Py_BEGIN_ALLOW_THREADS
	n = select(max, &ifdset, &ofdset, &efdset, tvp);
	Py_END_ALLOW_THREADS

274 275 276 277 278
#ifdef MS_WINDOWS
	if (n == SOCKET_ERROR) {
		PyErr_SetExcFromWindowsErr(SelectError, WSAGetLastError());
	}
#else
279 280 281
	if (n < 0) {
		PyErr_SetFromErrno(SelectError);
	}
282
#endif
283 284
	else if (n == 0) {
                /* optimization */
285
		ifdlist = PyList_New(0);
286 287 288 289
		if (ifdlist) {
			ret = Py_BuildValue("OOO", ifdlist, ifdlist, ifdlist);
			Py_DECREF(ifdlist);
		}
290
	}
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
	else {
		/* any of these three calls can raise an exception.  it's more
		   convenient to test for this after all three calls... but
		   is that acceptable?
		*/
		ifdlist = set2list(&ifdset, rfd2obj);
		ofdlist = set2list(&ofdset, wfd2obj);
		efdlist = set2list(&efdset, efd2obj);
		if (PyErr_Occurred())
			ret = NULL;
		else
			ret = Py_BuildValue("OOO", ifdlist, ofdlist, efdlist);

		Py_DECREF(ifdlist);
		Py_DECREF(ofdlist);
		Py_DECREF(efdlist);
	}
	
  finally:
	reap_obj(rfd2obj);
	reap_obj(wfd2obj);
	reap_obj(efd2obj);
313
#ifdef SELECT_USES_HEAP
314 315 316
	PyMem_DEL(rfd2obj);
	PyMem_DEL(wfd2obj);
	PyMem_DEL(efd2obj);
317
#endif /* SELECT_USES_HEAP */
318
	return ret;
319 320
}

321 322 323 324 325 326 327 328 329 330 331 332 333
#ifdef HAVE_POLL
/* 
 * poll() support
 */

typedef struct {
	PyObject_HEAD
	PyObject *dict;
	int ufd_uptodate; 
	int ufd_len;
        struct pollfd *ufds;
} pollObject;

334
static PyTypeObject poll_Type;
335 336 337 338 339 340 341 342

/* Update the malloc'ed array of pollfds to match the dictionary 
   contained within a pollObject.  Return 1 on success, 0 on an error.
*/

static int
update_ufd_array(pollObject *self)
{
343
	int i, pos;
344 345 346 347 348 349 350 351 352 353
	PyObject *key, *value;

	self->ufd_len = PyDict_Size(self->dict);
	PyMem_Resize(self->ufds, struct pollfd, self->ufd_len);
	if (self->ufds == NULL) {
		PyErr_NoMemory();
		return 0;
	}

	i = pos = 0;
354
	while (PyDict_Next(self->dict, &pos, &key, &value)) {
355
		self->ufds[i].fd = PyInt_AsLong(key);
356
		self->ufds[i].events = (short)PyInt_AsLong(value);
357 358 359 360 361 362
		i++;
	}
	self->ufd_uptodate = 1;
	return 1;
}

363
PyDoc_STRVAR(poll_register_doc,
364 365
"register(fd [, eventmask] ) -> None\n\n\
Register a file descriptor with the polling object.\n\
366 367
fd -- either an integer, or an object with a fileno() method returning an\n\
      int.\n\
368
events -- an optional bitmask describing the type of events to check for");
369 370 371 372 373 374

static PyObject *
poll_register(pollObject *self, PyObject *args) 
{
	PyObject *o, *key, *value;
	int fd, events = POLLIN | POLLPRI | POLLOUT;
375
	int err;
376

377
	if (!PyArg_ParseTuple(args, "O|i:register", &o, &events)) {
378 379 380 381 382 383 384 385
		return NULL;
	}
  
	fd = PyObject_AsFileDescriptor(o);
	if (fd == -1) return NULL;

	/* Add entry to the internal dictionary: the key is the 
	   file descriptor, and the value is the event mask. */
386 387 388 389 390 391
	key = PyInt_FromLong(fd);
	if (key == NULL)
		return NULL;
	value = PyInt_FromLong(events);
	if (value == NULL) {
		Py_DECREF(key);
392 393
		return NULL;
	}
394 395 396 397 398 399
	err = PyDict_SetItem(self->dict, key, value);
	Py_DECREF(key);
	Py_DECREF(value);
	if (err < 0)
		return NULL;

400 401 402 403 404 405
	self->ufd_uptodate = 0;
		       
	Py_INCREF(Py_None);
	return Py_None;
}

406
PyDoc_STRVAR(poll_unregister_doc,
407
"unregister(fd) -> None\n\n\
408
Remove a file descriptor being tracked by the polling object.");
409 410 411 412 413 414 415

static PyObject *
poll_unregister(pollObject *self, PyObject *args) 
{
	PyObject *o, *key;
	int fd;

416
	if (!PyArg_ParseTuple(args, "O:unregister", &o)) {
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
		return NULL;
	}
  
	fd = PyObject_AsFileDescriptor( o );
	if (fd == -1) 
		return NULL;

	/* Check whether the fd is already in the array */
	key = PyInt_FromLong(fd);
	if (key == NULL) 
		return NULL;

	if (PyDict_DelItem(self->dict, key) == -1) {
		Py_DECREF(key);
		/* This will simply raise the KeyError set by PyDict_DelItem
		   if the file descriptor isn't registered. */
		return NULL;
	}

	Py_DECREF(key);
	self->ufd_uptodate = 0;

	Py_INCREF(Py_None);
	return Py_None;
}

443
PyDoc_STRVAR(poll_poll_doc,
444 445
"poll( [timeout] ) -> list of (fd, event) 2-tuples\n\n\
Polls the set of registered file descriptors, returning a list containing \n\
446
any descriptors that have events or errors to report.");
447 448 449 450 451 452 453 454

static PyObject *
poll_poll(pollObject *self, PyObject *args) 
{
	PyObject *result_list = NULL, *tout = NULL;
	int timeout = 0, poll_result, i, j;
	PyObject *value = NULL, *num = NULL;

455
	if (!PyArg_ParseTuple(args, "|O:poll", &tout)) {
456 457 458 459 460 461
		return NULL;
	}

	/* Check values for timeout */
	if (tout == NULL || tout == Py_None)
		timeout = -1;
462
	else if (!PyNumber_Check(tout)) {
463 464 465 466
		PyErr_SetString(PyExc_TypeError,
				"timeout must be an integer or None");
		return NULL;
	}
467 468 469 470
	else {
		tout = PyNumber_Int(tout);
		if (!tout)
			return NULL;
471
		timeout = PyInt_AsLong(tout);
472 473
		Py_DECREF(tout);
	}
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544

	/* Ensure the ufd array is up to date */
	if (!self->ufd_uptodate) 
		if (update_ufd_array(self) == 0)
			return NULL;

	/* call poll() */
	Py_BEGIN_ALLOW_THREADS;
	poll_result = poll(self->ufds, self->ufd_len, timeout);
	Py_END_ALLOW_THREADS;
 
	if (poll_result < 0) {
		PyErr_SetFromErrno(SelectError);
		return NULL;
	} 
       
	/* build the result list */
  
	result_list = PyList_New(poll_result);
	if (!result_list) 
		return NULL;
	else {
		for (i = 0, j = 0; j < poll_result; j++) {
 			/* skip to the next fired descriptor */
 			while (!self->ufds[i].revents) {
 				i++;
 			}
			/* if we hit a NULL return, set value to NULL
			   and break out of loop; code at end will
			   clean up result_list */
			value = PyTuple_New(2);
			if (value == NULL)
				goto error;
			num = PyInt_FromLong(self->ufds[i].fd);
			if (num == NULL) {
				Py_DECREF(value);
				goto error;
			}
			PyTuple_SET_ITEM(value, 0, num);

			num = PyInt_FromLong(self->ufds[i].revents);
			if (num == NULL) {
				Py_DECREF(value);
				goto error;
			}
			PyTuple_SET_ITEM(value, 1, num);
 			if ((PyList_SetItem(result_list, j, value)) == -1) {
				Py_DECREF(value);
				goto error;
 			}
 			i++;
 		}
 	}
 	return result_list;

  error:
	Py_DECREF(result_list);
	return NULL;
}

static PyMethodDef poll_methods[] = {
	{"register",	(PyCFunction)poll_register,	
	 METH_VARARGS,  poll_register_doc},
	{"unregister",	(PyCFunction)poll_unregister,	
	 METH_VARARGS,  poll_unregister_doc},
	{"poll",	(PyCFunction)poll_poll,	
	 METH_VARARGS,  poll_poll_doc},
	{NULL,		NULL}		/* sentinel */
};

static pollObject *
545
newPollObject(void)
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
{
        pollObject *self;
	self = PyObject_New(pollObject, &poll_Type);
	if (self == NULL)
		return NULL;
	/* ufd_uptodate is a Boolean, denoting whether the 
	   array pointed to by ufds matches the contents of the dictionary. */
	self->ufd_uptodate = 0;
	self->ufds = NULL;
	self->dict = PyDict_New();
	if (self->dict == NULL) {
		Py_DECREF(self);
		return NULL;
	}
	return self;
}

static void
poll_dealloc(pollObject *self)
{
	if (self->ufds != NULL)
		PyMem_DEL(self->ufds);
	Py_XDECREF(self->dict);
  	PyObject_Del(self);
}

static PyObject *
poll_getattr(pollObject *self, char *name)
{
	return Py_FindMethod(poll_methods, (PyObject *)self, name);
}

578
static PyTypeObject poll_Type = {
579 580 581 582
	/* The ob_type field must be initialized in the module init function
	 * to be portable to Windows without using C++. */
	PyObject_HEAD_INIT(NULL)
	0,			/*ob_size*/
583
	"select.poll",		/*tp_name*/
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
	sizeof(pollObject),	/*tp_basicsize*/
	0,			/*tp_itemsize*/
	/* methods */
	(destructor)poll_dealloc, /*tp_dealloc*/
	0,			/*tp_print*/
	(getattrfunc)poll_getattr, /*tp_getattr*/
	0,                      /*tp_setattr*/
	0,			/*tp_compare*/
	0,			/*tp_repr*/
	0,			/*tp_as_number*/
	0,			/*tp_as_sequence*/
	0,			/*tp_as_mapping*/
	0,			/*tp_hash*/
};

599
PyDoc_STRVAR(poll_doc,
600
"Returns a polling object, which supports registering and\n\
601
unregistering file descriptors, and then polling them for I/O events.");
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616

static PyObject *
select_poll(PyObject *self, PyObject *args)
{
	pollObject *rv;
	
	if (!PyArg_ParseTuple(args, ":poll"))
		return NULL;
	rv = newPollObject();
	if ( rv == NULL )
		return NULL;
	return (PyObject *)rv;
}
#endif /* HAVE_POLL */

617
PyDoc_STRVAR(select_doc,
Guido van Rossum's avatar
Guido van Rossum committed
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
"select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\
\n\
Wait until one or more file descriptors are ready for some kind of I/O.\n\
The first three arguments are lists of file descriptors to be waited for:\n\
rlist -- wait until ready for reading\n\
wlist -- wait until ready for writing\n\
xlist -- wait for an ``exceptional condition''\n\
If only one kind of condition is required, pass [] for the other lists.\n\
A file descriptor is either a socket or file object, or a small integer\n\
gotten from a fileno() method call on one of those.\n\
\n\
The optional 4th argument specifies a timeout in seconds; it may be\n\
a floating point number to specify fractions of seconds.  If it is absent\n\
or None, the call will never time out.\n\
\n\
The return value is a tuple of three lists corresponding to the first three\n\
arguments; each contains the subset of the corresponding file descriptors\n\
that are ready.\n\
\n\
*** IMPORTANT NOTICE ***\n\
638
On Windows, only sockets are supported; on Unix, all file descriptors.");
Guido van Rossum's avatar
Guido van Rossum committed
639

640
static PyMethodDef select_methods[] = {
641 642 643 644
    {"select",	select_select, METH_VARARGS, select_doc},
#ifdef HAVE_POLL
    {"poll",    select_poll,   METH_VARARGS, poll_doc},
#endif /* HAVE_POLL */
645
    {0,  	0},			     /* sentinel */
646 647
};

648
PyDoc_STRVAR(module_doc,
Guido van Rossum's avatar
Guido van Rossum committed
649 650 651
"This module supports asynchronous I/O on multiple file descriptors.\n\
\n\
*** IMPORTANT NOTICE ***\n\
652
On Windows, only sockets are supported; on Unix, all file descriptors.");
653

654
PyMODINIT_FUNC
655
initselect(void)
656
{
657
	PyObject *m;
Guido van Rossum's avatar
Guido van Rossum committed
658
	m = Py_InitModule3("select", select_methods, module_doc);
659

660
	SelectError = PyErr_NewException("select.error", NULL, NULL);
661 662
	Py_INCREF(SelectError);
	PyModule_AddObject(m, "error", SelectError);
663 664
#ifdef HAVE_POLL
	poll_Type.ob_type = &PyType_Type;
665 666 667 668 669 670
	PyModule_AddIntConstant(m, "POLLIN", POLLIN);
	PyModule_AddIntConstant(m, "POLLPRI", POLLPRI);
	PyModule_AddIntConstant(m, "POLLOUT", POLLOUT);
	PyModule_AddIntConstant(m, "POLLERR", POLLERR);
	PyModule_AddIntConstant(m, "POLLHUP", POLLHUP);
	PyModule_AddIntConstant(m, "POLLNVAL", POLLNVAL);
671

672
#ifdef POLLRDNORM
673
	PyModule_AddIntConstant(m, "POLLRDNORM", POLLRDNORM);
674 675
#endif
#ifdef POLLRDBAND
676
	PyModule_AddIntConstant(m, "POLLRDBAND", POLLRDBAND);
677 678
#endif
#ifdef POLLWRNORM
679
	PyModule_AddIntConstant(m, "POLLWRNORM", POLLWRNORM);
680 681
#endif
#ifdef POLLWRBAND
682
	PyModule_AddIntConstant(m, "POLLWRBAND", POLLWRBAND);
683
#endif
684
#ifdef POLLMSG
685
	PyModule_AddIntConstant(m, "POLLMSG", POLLMSG);
686
#endif
687
#endif /* HAVE_POLL */
688
}