Reset ret in client and server after wolfSSL_dtls_got_timeout()

- Do UDP connect only with simulateWantWrite to accommodate macOS that doesn't like sendto being called on connected UDP sockets
- Call wolfSSL_dtls_get_current_timeout only on a DTLS connection
This commit is contained in:
Juliusz Sosinowicz 2022-05-12 16:48:04 +02:00
parent 9914da3046
commit 44be4e1cc8
3 changed files with 22 additions and 8 deletions

View File

@ -201,7 +201,8 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
else
{
#ifdef WOLFSSL_DTLS
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
if (wolfSSL_dtls(ssl))
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
#endif
select_ret = tcp_select(sockfd, currTimeout);
}
@ -238,6 +239,7 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
error = wolfSSL_get_error(ssl, ret);
else
error = WOLFSSL_ERROR_WANT_READ;
ret = WOLFSSL_FAILURE; /* Reset error so we loop */
}
#endif
else {
@ -3565,7 +3567,10 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
}
if (simulateWantWrite) {
wolfSSL_SetIOWriteCtx(ssl, (void*)&sockfd);
if (dtlsUDP) {
wolfSSL_SetIOWriteCtx(ssl, (void*)&sockfd);
udp_connect(&sockfd, host, port);
}
}
/* STARTTLS */
@ -4105,7 +4110,10 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
err_sys("error in setting fd");
}
if (simulateWantWrite) {
wolfSSL_SetIOWriteCtx(ssl, (void*)&sockfd);
if (dtlsUDP) {
wolfSSL_SetIOWriteCtx(ssl, (void*)&sockfd);
udp_connect(&sockfd, host, port);
}
}
#ifdef HAVE_ALPN
if (alpnList != NULL) {

View File

@ -330,7 +330,8 @@ static int NonBlockingSSL_Accept(SSL* ssl)
}
else {
#ifdef WOLFSSL_DTLS
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
if (wolfSSL_dtls(ssl))
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
#endif
select_ret = tcp_select(sockfd, currTimeout);
}
@ -360,6 +361,7 @@ static int NonBlockingSSL_Accept(SSL* ssl)
error = wolfSSL_get_error(ssl, ret);
else
error = WOLFSSL_ERROR_WANT_READ;
ret = WOLFSSL_FAILURE; /* Reset error so we loop */
}
#endif
else {

View File

@ -1847,16 +1847,20 @@ static WC_INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port,
}
tcp_socket(sockfd, udp, sctp);
if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
err_sys_with_errno("tcp connect failed");
if (!udp) {
if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
err_sys_with_errno("tcp connect failed");
}
}
#endif /* WOLFSSL_WOLFSENTRY_HOOKS */
static WC_INLINE void udp_connect(SOCKET_T* sockfd, void* addr, int addrSz)
static WC_INLINE void udp_connect(SOCKET_T* sockfd, const char* ip, word16 port)
{
if (connect(*sockfd, (const struct sockaddr*)addr, addrSz) != 0)
SOCKADDR_IN_T addr;
build_addr(&addr, ip, port, 1, 0);
if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
err_sys_with_errno("tcp connect failed");
}