]> git.sesse.net Git - vlc/commitdiff
gnutls: retry handshake if it returns a non-fatal error
authorLudovic Fauvet <etix@videolan.org>
Thu, 7 Feb 2013 16:21:06 +0000 (17:21 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 8 Feb 2013 12:26:04 +0000 (13:26 +0100)
Based on the gnutls_handshake manual the function must be called again
until it returns 0 (or a fatal error).

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/misc/gnutls.c

index 312c682422381570b50c5077d9a7afab4e7e6ba9..e4702809bcfc23bc5bfd1b3a5ec6d0ab0973220e 100644 (file)
@@ -229,9 +229,16 @@ static int gnutls_ContinueHandshake (vlc_tls_t *session, const char *host,
 #ifdef WIN32
     WSASetLastError (0);
 #endif
-    val = gnutls_handshake (sys->session);
-    if ((val == GNUTLS_E_AGAIN) || (val == GNUTLS_E_INTERRUPTED))
-        return 1 + gnutls_record_get_direction (sys->session);
+    do
+    {
+        val = gnutls_handshake (sys->session);
+        msg_Dbg (session, "TLS handshake: %s", gnutls_strerror (val));
+
+        if ((val == GNUTLS_E_AGAIN) || (val == GNUTLS_E_INTERRUPTED))
+            /* I/O event: return to caller's poll() loop */
+            return 1 + gnutls_record_get_direction (sys->session);
+    }
+    while (val < 0 && !gnutls_error_is_fatal (val));
 
     if (val < 0)
     {