summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/buffers.c2
-rw-r--r--lib/dtls.c6
-rw-r--r--lib/handshake.c5
-rw-r--r--lib/includes/gnutls/gnutls.h.in1
-rw-r--r--lib/record.c3
-rw-r--r--lib/system.c11
-rw-r--r--lib/system_override.c4
7 files changed, 24 insertions, 8 deletions
diff --git a/lib/buffers.c b/lib/buffers.c
index cc340710ff..e43a0c4b5d 100644
--- a/lib/buffers.c
+++ b/lib/buffers.c
@@ -380,7 +380,7 @@ _gnutls_stream_read(gnutls_session_t session, mbuffer_st ** bufel,
left -= i;
(*bufel)->msg.size += i;
- if (ms && *ms > 0) {
+ if (ms && *ms > 0 && *ms != GNUTLS_INDEFINITE_TIMEOUT) {
gettime(&t2);
diff = timespec_sub_ms(&t2, &t1);
if (diff < *ms)
diff --git a/lib/dtls.c b/lib/dtls.c
index 26ddaf2b77..36728a4f14 100644
--- a/lib/dtls.c
+++ b/lib/dtls.c
@@ -557,8 +557,12 @@ void gnutls_dtls_set_timeouts(gnutls_session_t session,
unsigned int retrans_timeout,
unsigned int total_timeout)
{
+ if (total_timeout == GNUTLS_INDEFINITE_TIMEOUT)
+ session->internals.handshake_timeout_ms = 0;
+ else
+ session->internals.handshake_timeout_ms = total_timeout;
+
session->internals.dtls.retrans_timeout_ms = retrans_timeout;
- session->internals.handshake_timeout_ms = total_timeout;
}
/**
diff --git a/lib/handshake.c b/lib/handshake.c
index 776513b634..f9ffb14213 100644
--- a/lib/handshake.c
+++ b/lib/handshake.c
@@ -2630,6 +2630,11 @@ int gnutls_handshake(gnutls_session_t session)
void
gnutls_handshake_set_timeout(gnutls_session_t session, unsigned int ms)
{
+ if (ms == GNUTLS_INDEFINITE_TIMEOUT) {
+ session->internals.handshake_timeout_ms = 0;
+ return;
+ }
+
if (ms == GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT)
ms = DEFAULT_HANDSHAKE_TIMEOUT_MS;
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 6f5ba278c0..79c4949f34 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -834,6 +834,7 @@ int gnutls_bye(gnutls_session_t session, gnutls_close_request_t how);
int gnutls_handshake(gnutls_session_t session);
#define GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT ((unsigned int)-1)
+#define GNUTLS_INDEFINITE_TIMEOUT ((unsigned int)-2)
void gnutls_handshake_set_timeout(gnutls_session_t session,
unsigned int ms);
int gnutls_rehandshake(gnutls_session_t session);
diff --git a/lib/record.c b/lib/record.c
index ee13f23488..2ae3ca93c2 100644
--- a/lib/record.c
+++ b/lib/record.c
@@ -1738,7 +1738,8 @@ gnutls_record_recv_seq(gnutls_session_t session, void *data,
*
* This function sets the receive timeout for the record layer
* to the provided value. Use an @ms value of zero to disable
- * timeout (the default).
+ * timeout (the default), or %GNUTLS_INDEFINITE_TIMEOUT, to
+ * set an indefinite timeout.
*
* This function requires to set a pull timeout callback. See
* gnutls_transport_set_pull_timeout_function().
diff --git a/lib/system.c b/lib/system.c
index 4d72968f13..ab8d89df8e 100644
--- a/lib/system.c
+++ b/lib/system.c
@@ -160,17 +160,20 @@ system_read(gnutls_transport_ptr_t ptr, void *data, size_t data_size)
int gnutls_system_recv_timeout(gnutls_transport_ptr_t ptr, unsigned int ms)
{
fd_set rfds;
- struct timeval tv;
+ struct timeval _tv, *tv = NULL;
int ret;
int fd = GNUTLS_POINTER_TO_INT(ptr);
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
- tv.tv_sec = ms/1000;
- tv.tv_usec = (ms % 1000) * 1000;
+ if (ms != GNUTLS_INDEFINITE_TIMEOUT) {
+ _tv.tv_sec = ms/1000;
+ _tv.tv_usec = (ms % 1000) * 1000;
+ tv = &_tv;
+ }
- ret = select(fd + 1, &rfds, NULL, NULL, &tv);
+ ret = select(fd + 1, &rfds, NULL, NULL, tv);
if (ret <= 0)
return ret;
diff --git a/lib/system_override.c b/lib/system_override.c
index 79a4db0de4..27959c3af4 100644
--- a/lib/system_override.c
+++ b/lib/system_override.c
@@ -95,7 +95,9 @@ gnutls_transport_set_pull_function(gnutls_session_t session,
* for the provided transport calls.
*
* As with select(), if the timeout value is zero the callback should return
- * zero if no data are immediately available.
+ * zero if no data are immediately available. The special value
+ * %GNUTLS_INDEFINITE_TIMEOUT indicates that the callback should wait indefinitely
+ * for data.
*
* @gnutls_pull_timeout_func is of the form,
* int (*gnutls_pull_timeout_func)(gnutls_transport_ptr_t, unsigned int ms);