Skip to content

Commit dcb5c00

Browse files
tiranencukou
authored andcommitted
Allow set_option() to set timeout to infinity
OPT_TIMEOUT and OPT_NETWORK_TIMEOUT now support -1 to set default back to infinity. Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 6f53205 commit dcb5c00

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Modules/
3636
* Fix memory leak in whoami
3737
* Fix internal error handling of LDAPControl_to_List()
3838
* Fix two memory leaks and release GIL in encode_assertion_control
39+
* Allow set_option() to set timeouts to infinity
3940
and, thanks to Michael Ströder:
4041
* removed unused code schema.c
4142
* moved code from version.c to ldapmodule.c

Doc/reference/ldap.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ following option identifiers are defined as constants:
156156
157157
.. py:data:: OPT_NETWORK_TIMEOUT
158158
159+
.. versionchanged:: 3.0
160+
A timeout of ``-1`` resets timeout to infinity.
161+
159162
.. py:data:: OPT_PROTOCOL_VERSION
160163
161164
Sets the LDAP protocol version used for a connection. This is mapped to
@@ -180,6 +183,9 @@ following option identifiers are defined as constants:
180183
181184
.. py:data:: OPT_TIMEOUT
182185
186+
.. versionchanged:: 3.0
187+
A timeout of ``-1`` resets timeout to infinity.
188+
183189
.. py:data:: OPT_URI
184190
185191
.. _ldap-sasl-options:

Modules/options.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,20 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
140140
if (!PyArg_Parse(value, "d:set_option", &doubleval))
141141
return 0;
142142
if (doubleval >= 0) {
143-
set_timeval_from_double( &tv, doubleval );
143+
set_timeval_from_double( &tv, doubleval );
144+
ptr = &tv;
145+
} else if (doubleval == -1) {
146+
/* -1 is infinity timeout */
147+
tv.tv_sec = -1;
148+
tv.tv_usec = 0;
144149
ptr = &tv;
145150
} else {
146-
ptr = NULL;
151+
PyErr_Format(
152+
PyExc_ValueError,
153+
"timeout must be >= 0 or -1 for infinity, got %d",
154+
option
155+
);
156+
return 0;
147157
}
148158
break;
149159
case LDAP_OPT_SERVER_CONTROLS:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy