[Python-checkins] r74020 - in python/trunk: Lib/test/test_kqueue.py Modules/selectmodule.c
georg.brandl
python-checkins at python.org
Thu Jul 16 09:18:07 CEST 2009
Author: georg.brandl
Date: Thu Jul 16 09:18:07 2009
New Revision: 74020
Log:
#5910: fix kqueue for calls with more than one event.
Modified:
python/trunk/Lib/test/test_kqueue.py
python/trunk/Modules/selectmodule.c
Modified: python/trunk/Lib/test/test_kqueue.py
==============================================================================
--- python/trunk/Lib/test/test_kqueue.py (original)
+++ python/trunk/Lib/test/test_kqueue.py Thu Jul 16 09:18:07 2009
@@ -162,6 +162,22 @@
server.close()
serverSocket.close()
+ def testPair(self):
+ kq = select.kqueue()
+ a, b = socket.socketpair()
+
+ a.send(b'foo')
+ event1 = select.kevent(a, select.KQ_FILTER_READ, select.KQ_EV_ADD | select.KQ_EV_ENABLE)
+ event2 = select.kevent(b, select.KQ_FILTER_READ, select.KQ_EV_ADD | select.KQ_EV_ENABLE)
+ r = kq.control([event1, event2], 1, 1)
+ self.assertTrue(r)
+ self.assertFalse(r[0].flags & select.KQ_EV_ERROR)
+ self.assertEquals(b.recv(r[0].data), b'foo')
+
+ a.close()
+ b.close()
+ kq.close()
+
def test_main():
test_support.run_unittest(TestKQueue)
Modified: python/trunk/Modules/selectmodule.c
==============================================================================
--- python/trunk/Modules/selectmodule.c (original)
+++ python/trunk/Modules/selectmodule.c Thu Jul 16 09:18:07 2009
@@ -1487,7 +1487,7 @@
if (nevents < 0) {
PyErr_Format(PyExc_ValueError,
"Length of eventlist must be 0 or positive, got %d",
- nchanges);
+ nevents);
return NULL;
}
@@ -1545,6 +1545,7 @@
PyErr_NoMemory();
return NULL;
}
+ i = 0;
while ((ei = PyIter_Next(it)) != NULL) {
if (!kqueue_event_Check(ei)) {
Py_DECREF(ei);
@@ -1553,7 +1554,7 @@
"select.kevent objects");
goto error;
} else {
- chl[i] = ((kqueue_event_Object *)ei)->e;
+ chl[i++] = ((kqueue_event_Object *)ei)->e;
}
Py_DECREF(ei);
}
@@ -1584,7 +1585,7 @@
goto error;
}
- for (i=0; i < gotevents; i++) {
+ for (i = 0; i < gotevents; i++) {
kqueue_event_Object *ch;
ch = PyObject_New(kqueue_event_Object, &kqueue_event_Type);
More information about the Python-checkins
mailing list