Browse Source

Check Python version to determine proper timeout rounding mode

pull/8/head
Joseph Henry 5 years ago
parent
commit
d49667a55f
No known key found for this signature in database
GPG Key ID: C45B33FF5EBC9344
  1. 9
      src/bindings/python/PythonSockets.cxx

9
src/bindings/python/PythonSockets.cxx

@ -327,13 +327,18 @@ PyObject* zts_py_select(PyObject* module, PyObject* rlist, PyObject* wlist, PyOb
tvp = (struct timeval*)NULL;
}
else {
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, _PyTime_ROUND_UP) < 0) {
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 5
_PyTime_round_t roundingMode = _PyTime_ROUND_CEILING;
#else
_PyTime_round_t roundingMode = _PyTime_ROUND_UP;
#endif
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, roundingMode) < 0) {
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_SetString(PyExc_TypeError, "timeout must be a float or None");
}
return NULL;
}
if (_PyTime_AsTimeval(timeout, &tv, _PyTime_ROUND_UP) == -1) {
if (_PyTime_AsTimeval(timeout, &tv, roundingMode) == -1) {
return NULL;
}
if (tv.tv_sec < 0) {

Loading…
Cancel
Save