summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-10-18 12:05:16 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-10-18 12:05:16 (GMT)
commit97abcabc195b87d6a5562dbb867a469fac27d3f6 (patch)
tree89408afab9f30ae7c43ece4e0a60d29d98217bea /Modules
parentbe4e9cc769aac3cb46670c049b9f21e412be53d1 (diff)
downloadcpython-97abcabc195b87d6a5562dbb867a469fac27d3f6.zip
cpython-97abcabc195b87d6a5562dbb867a469fac27d3f6.tar.gz
cpython-97abcabc195b87d6a5562dbb867a469fac27d3f6.tar.bz2
[3.6] bpo-31334: Fix timeout in select.poll.poll() (GH-3277) (#4033)
Always pass -1, or INFTIM where defined, to the poll() system call when a negative timeout is passed to the poll.poll([timeout]) method in the select module. Various OSes throw an error with arbitrary negative values. (cherry picked from commit 6cfa927ceb931ad968b5b03e4a2bffb64a8a0604)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/selectmodule.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 9ae583b..1de8bf7 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -528,20 +528,14 @@ poll_poll(pollObject *self, PyObject *args)
PyObject *result_list = NULL, *timeout_obj = NULL;
int poll_result, i, j;
PyObject *value = NULL, *num = NULL;
- _PyTime_t timeout, ms, deadline;
+ _PyTime_t timeout = -1, ms = -1, deadline = 0;
int async_err = 0;
if (!PyArg_ParseTuple(args, "|O:poll", &timeout_obj)) {
return NULL;
}
- /* Check values for timeout */
- if (timeout_obj == NULL || timeout_obj == Py_None) {
- timeout = -1;
- ms = -1;
- deadline = 0; /* initialize to prevent gcc warning */
- }
- else {
+ if (timeout_obj != NULL && timeout_obj != Py_None) {
if (_PyTime_FromMillisecondsObject(&timeout, timeout_obj,
_PyTime_ROUND_TIMEOUT) < 0) {
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
@@ -557,7 +551,20 @@ poll_poll(pollObject *self, PyObject *args)
return NULL;
}
- deadline = _PyTime_GetMonotonicClock() + timeout;
+ if (timeout >= 0) {
+ deadline = _PyTime_GetMonotonicClock() + timeout;
+ }
+ }
+
+ /* On some OSes, typically BSD-based ones, the timeout parameter of the
+ poll() syscall, when negative, must be exactly INFTIM, where defined,
+ or -1. See issue 31334. */
+ if (ms < 0) {
+#ifdef INFTIM
+ ms = INFTIM;
+#else
+ ms = -1;
+#endif
}
/* Avoid concurrent poll() invocation, issue 8865 */