This allows to specify an indefinite timeout to gnutls_record_set_timeout().
In addition this flag is accepted by gnutls_handshake_set_timeout() and
cancels out a previously set timeout.
Resolves #41
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)
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;
}
/**
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;
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);
*
* 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().
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;
* 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);