Skip to content

Commit

Permalink
Allow set_option() to set timeout to infinity
Browse files Browse the repository at this point in the history
OPT_TIMEOUT and OPT_NETWORK_TIMEOUT now support -1 to set default back
to infinity.

Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed Dec 4, 2017
1 parent 6f53205 commit dcb5c00
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Modules/
* Fix memory leak in whoami
* Fix internal error handling of LDAPControl_to_List()
* Fix two memory leaks and release GIL in encode_assertion_control
* Allow set_option() to set timeouts to infinity
and, thanks to Michael Ströder:
* removed unused code schema.c
* moved code from version.c to ldapmodule.c
Expand Down
6 changes: 6 additions & 0 deletions Doc/reference/ldap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ following option identifiers are defined as constants:
.. py:data:: OPT_NETWORK_TIMEOUT
.. versionchanged:: 3.0
A timeout of ``-1`` resets timeout to infinity.

.. py:data:: OPT_PROTOCOL_VERSION
Sets the LDAP protocol version used for a connection. This is mapped to
Expand All @@ -180,6 +183,9 @@ following option identifiers are defined as constants:
.. py:data:: OPT_TIMEOUT
.. versionchanged:: 3.0
A timeout of ``-1`` resets timeout to infinity.

.. py:data:: OPT_URI
.. _ldap-sasl-options:
Expand Down
14 changes: 12 additions & 2 deletions Modules/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,20 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
if (!PyArg_Parse(value, "d:set_option", &doubleval))
return 0;
if (doubleval >= 0) {
set_timeval_from_double( &tv, doubleval );
set_timeval_from_double( &tv, doubleval );
ptr = &tv;
} else if (doubleval == -1) {
/* -1 is infinity timeout */
tv.tv_sec = -1;
tv.tv_usec = 0;
ptr = &tv;
} else {
ptr = NULL;
PyErr_Format(
PyExc_ValueError,
"timeout must be >= 0 or -1 for infinity, got %d",
option
);
return 0;
}
break;
case LDAP_OPT_SERVER_CONTROLS:
Expand Down

0 comments on commit dcb5c00

Please sign in to comment.