Commit b690b9b0 authored by Berker Peksag's avatar Berker Peksag Committed by GitHub

bpo-29386: Pass -1 to epoll_wait() when timeout is < -1 (GH-9040)

Although the kernel accepts any negative value for timeout, the
documented value to block indefinitely is -1.

This commit also makes the code similar to select.poll.poll().
parent 0baa72f4
...@@ -1498,17 +1498,12 @@ select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj, ...@@ -1498,17 +1498,12 @@ select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj,
int nfds, i; int nfds, i;
PyObject *elist = NULL, *etuple = NULL; PyObject *elist = NULL, *etuple = NULL;
struct epoll_event *evs = NULL; struct epoll_event *evs = NULL;
_PyTime_t timeout, ms, deadline; _PyTime_t timeout = -1, ms = -1, deadline = 0;
if (self->epfd < 0) if (self->epfd < 0)
return pyepoll_err_closed(); return pyepoll_err_closed();
if (timeout_obj == Py_None) { if (timeout_obj != Py_None) {
timeout = -1;
ms = -1;
deadline = 0; /* initialize to prevent gcc warning */
}
else {
/* epoll_wait() has a resolution of 1 millisecond, round towards /* epoll_wait() has a resolution of 1 millisecond, round towards
infinity to wait at least timeout seconds. */ infinity to wait at least timeout seconds. */
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, if (_PyTime_FromSecondsObject(&timeout, timeout_obj,
...@@ -1525,9 +1520,21 @@ select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj, ...@@ -1525,9 +1520,21 @@ select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj,
PyErr_SetString(PyExc_OverflowError, "timeout is too large"); PyErr_SetString(PyExc_OverflowError, "timeout is too large");
return NULL; return NULL;
} }
/* epoll_wait(2) treats all arbitrary negative numbers the same
for the timeout argument, but -1 is the documented way to block
indefinitely in the epoll_wait(2) documentation, so we set ms
to -1 if the value of ms is a negative number.
Note that we didn't use INFTIM here since it's non-standard and
isn't available under Linux. */
if (ms < 0) {
ms = -1;
}
if (timeout >= 0) {
deadline = _PyTime_GetMonotonicClock() + timeout; deadline = _PyTime_GetMonotonicClock() + timeout;
} }
}
if (maxevents == -1) { if (maxevents == -1) {
maxevents = FD_SETSIZE-1; maxevents = FD_SETSIZE-1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment