summaryrefslogtreecommitdiff
path: root/lib/handshake.h
diff options
context:
space:
mode:
authorTim Rühsen <tim.ruehsen@gmx.de>2018-12-04 17:15:02 +0100
committerTim Rühsen <tim.ruehsen@gmx.de>2018-12-06 16:13:00 +0100
commit3507f23cec212506da3c6836dbb159df4b41439f (patch)
treeff2f02ed31c2473c6fc795864ba98d758cce5c49 /lib/handshake.h
parent493723ee38cd817a60f25bb0bea505c80b22407c (diff)
downloadgnutls-tmp-fix-timeout.tar.gz
Fix gnutls_handshake_set_timeout() for values < 1000tmp-fix-timeout
handshake-timeout.c now tests for <1000ms timeout and for >=1000ms timeout. The test duration decreased from 45s to 1.2s. Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
Diffstat (limited to 'lib/handshake.h')
-rw-r--r--lib/handshake.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/handshake.h b/lib/handshake.h
index a82263aad1..11c310f33c 100644
--- a/lib/handshake.h
+++ b/lib/handshake.h
@@ -112,16 +112,23 @@ int _gnutls13_handshake_hash_buffers_synth(gnutls_session_t session,
#define FAGAIN(target) (FINAL_STATE==target?1:0)
#define AGAIN2(state, target) (state==target?1:0)
+/* return the remaining time in ms */
inline static int handshake_remaining_time(gnutls_session_t session)
{
- if (session->internals.handshake_endtime) {
+ struct timespec *end = &session->internals.handshake_endtime;
+
+ if (end->tv_sec || end->tv_nsec) {
struct timespec now;
gnutls_gettime(&now);
- if (now.tv_sec < session->internals.handshake_endtime)
- return (session->internals.handshake_endtime -
- now.tv_sec) * 1000;
- else
+ if (now.tv_sec < end->tv_sec ||
+ (now.tv_sec == end->tv_sec && now.tv_nsec < end->tv_nsec))
+ {
+ long long now_ms = now.tv_sec * 1000LL + now.tv_nsec / 1000000;
+ long long end_ms = end->tv_sec * 1000LL + end->tv_nsec / 1000000;
+
+ return end_ms - now_ms;
+ } else
return gnutls_assert_val(GNUTLS_E_TIMEDOUT);
}
return 0;