summaryrefslogtreecommitdiffstats
path: root/Modules/_multiprocessing/socket_connection.c
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2013-01-14 23:09:14 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2013-01-14 23:09:14 (GMT)
commit90b5d9288d2a25372471cbee9b49edc2e2193178 (patch)
tree7b48a9a0b0115c6ccd77076baaf637a4ae585ef3 /Modules/_multiprocessing/socket_connection.c
parent80a9fd77a0d63eed2f5d40e60437b5a465b7c1a5 (diff)
downloadcpython-90b5d9288d2a25372471cbee9b49edc2e2193178.zip
cpython-90b5d9288d2a25372471cbee9b49edc2e2193178.tar.gz
cpython-90b5d9288d2a25372471cbee9b49edc2e2193178.tar.bz2
Issue #10527: Use poll() instead of select() for multiprocessing pipes
Diffstat (limited to 'Modules/_multiprocessing/socket_connection.c')
-rw-r--r--Modules/_multiprocessing/socket_connection.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/Modules/_multiprocessing/socket_connection.c b/Modules/_multiprocessing/socket_connection.c
index 1169c0a..66bc377 100644
--- a/Modules/_multiprocessing/socket_connection.c
+++ b/Modules/_multiprocessing/socket_connection.c
@@ -8,6 +8,10 @@
#include "multiprocessing.h"
+#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)
+# include "poll.h"
+#endif
+
#ifdef MS_WINDOWS
# define WRITE(h, buffer, length) send((SOCKET)h, buffer, length, 0)
# define READ(h, buffer, length) recv((SOCKET)h, buffer, length, 0)
@@ -158,6 +162,34 @@ conn_recv_string(ConnectionObject *conn, char *buffer,
static int
conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
{
+#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)
+ int res;
+ struct pollfd p;
+
+ p.fd = (int)conn->handle;
+ p.events = POLLIN | POLLPRI;
+ p.revents = 0;
+
+ if (timeout < 0) {
+ res = poll(&p, 1, -1);
+ } else {
+ res = poll(&p, 1, (int)(timeout * 1000 + 0.5));
+ }
+
+ if (res < 0) {
+ return MP_SOCKET_ERROR;
+ } else if (p.revents & (POLLNVAL|POLLERR)) {
+ Py_BLOCK_THREADS
+ PyErr_SetString(PyExc_IOError, "poll() gave POLLNVAL or POLLERR");
+ Py_UNBLOCK_THREADS
+ return MP_EXCEPTION_HAS_BEEN_SET;
+ } else if (p.revents != 0) {
+ return TRUE;
+ } else {
+ assert(res == 0);
+ return FALSE;
+ }
+#else
int res;
fd_set rfds;
@@ -193,6 +225,7 @@ conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
assert(res == 0);
return FALSE;
}
+#endif
}
/*