Fix to timeout after 10 seconds in non-blocking mode if connect does not complete.

This commit is contained in:
David Garske
2019-01-10 17:12:37 -08:00
parent e1fd7b86f7
commit 3f46250994

View File

@@ -101,6 +101,8 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
int error; int error;
SOCKET_T sockfd; SOCKET_T sockfd;
int select_ret = 0; int select_ret = 0;
const int maxSec = 10;
int elapsedSec = 0;
#ifndef WOLFSSL_CALLBACKS #ifndef WOLFSSL_CALLBACKS
ret = wolfSSL_connect(ssl); ret = wolfSSL_connect(ssl);
@@ -151,9 +153,15 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
ret = wolfSSL_connect_ex(ssl, handShakeCB, timeoutCB, timeout); ret = wolfSSL_connect_ex(ssl, handShakeCB, timeoutCB, timeout);
#endif #endif
error = wolfSSL_get_error(ssl, 0); error = wolfSSL_get_error(ssl, 0);
elapsedSec = 0; /* reset elapsed */
} }
else if (select_ret == TEST_TIMEOUT && !wolfSSL_dtls(ssl)) { else if (select_ret == TEST_TIMEOUT && !wolfSSL_dtls(ssl)) {
error = WOLFSSL_ERROR_WANT_READ; error = WOLFSSL_ERROR_WANT_READ;
elapsedSec += currTimeout;
if (elapsedSec > maxSec) {
error = WOLFSSL_FATAL_ERROR;
}
} }
#ifdef WOLFSSL_DTLS #ifdef WOLFSSL_DTLS
else if (select_ret == TEST_TIMEOUT && wolfSSL_dtls(ssl) && else if (select_ret == TEST_TIMEOUT && wolfSSL_dtls(ssl) &&