diff --git a/cyassl/test.h b/cyassl/test.h index 6794ef985..5ab2ed1c6 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -496,7 +496,6 @@ static INLINE void tcp_accept(SOCKET_T* sockfd, int* clientfd, func_args* args, static INLINE void tcp_set_nonblocking(SOCKET_T* sockfd) { - (void)sockfd; #ifdef NON_BLOCKING #ifdef USE_WINDOWS_API unsigned long blocking = 1; @@ -506,6 +505,7 @@ static INLINE void tcp_set_nonblocking(SOCKET_T* sockfd) int ret = fcntl(*sockfd, F_SETFL, flags | O_NONBLOCK); #endif #endif + (void)sockfd; } diff --git a/examples/client/client.c b/examples/client/client.c index ad4b3782f..d51c0f863 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -48,6 +48,7 @@ int ret = CyaSSL_connect_ex(ssl, handShakeCB, timeoutCB, timeout); #endif int error = CyaSSL_get_error(ssl, 0); + int timeout_count = CyaSSL_dtls_get_current_timeout(ssl) * 10; while (ret != SSL_SUCCESS && (error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_WRITE)) { if (error == SSL_ERROR_WANT_READ) @@ -57,7 +58,11 @@ #ifdef USE_WINDOWS_API Sleep(100); #else - sleep(1); + #ifdef CYASSL_DTLS + usleep(100000); /* 100ms */ + #else + sleep(1); + #endif #endif #ifndef CYASSL_CALLBACKS ret = CyaSSL_connect(ssl); @@ -65,6 +70,19 @@ ret = CyaSSL_connect_ex(ssl, handShakeCB, timeoutCB, timeout); #endif error = CyaSSL_get_error(ssl, 0); + #ifdef CYASSL_DTLS + if (timeout_count-- <= 0) { + timeout_count = CyaSSL_dtls_got_timeout(ssl); + if (timeout_count < 0) { + error = SSL_FATAL_ERROR; + } + else { + printf("... updating timeout\n"); + timeout_count = + CyaSSL_dtls_get_current_timeout(ssl) * 10; + } + } + #endif } if (ret != SSL_SUCCESS) err_sys("SSL_connect failed"); diff --git a/src/internal.c b/src/internal.c index 304425e20..339b92da4 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1588,6 +1588,11 @@ retry: return WANT_READ; case IO_ERR_CONN_RST: /* connection reset */ + #ifdef USE_WINDOWS_API + if (ssl->options.dtls) { + return WANT_READ; + } + #endif ssl->options.connReset = 1; return -1; diff --git a/src/io.c b/src/io.c index 5fefbe051..1c146e5ab 100644 --- a/src/io.c +++ b/src/io.c @@ -90,18 +90,21 @@ #define SOCKET_ECONNRESET WSAECONNRESET #define SOCKET_EINTR WSAEINTR #define SOCKET_EPIPE WSAEPIPE + #define SOCKET_ECONNREFUSED WSAENOTCONN #elif defined(__PPU) #define SOCKET_EWOULDBLOCK SYS_NET_EWOULDBLOCK #define SOCKET_EAGAIN SYS_NET_EAGAIN #define SOCKET_ECONNRESET SYS_NET_ECONNRESET #define SOCKET_EINTR SYS_NET_EINTR #define SOCKET_EPIPE SYS_NET_EPIPE + #define SOCKET_ECONNREFUSED SYS_NET_ECONNREFUSED #else #define SOCKET_EWOULDBLOCK EWOULDBLOCK #define SOCKET_EAGAIN EAGAIN #define SOCKET_ECONNRESET ECONNRESET #define SOCKET_EINTR EINTR #define SOCKET_EPIPE EPIPE + #define SOCKET_ECONNREFUSED ECONNREFUSED #endif /* USE_WINDOWS_API */ @@ -176,6 +179,10 @@ int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx) CYASSL_MSG(" Socket interrupted"); return IO_ERR_ISR; } + else if (err == SOCKET_ECONNREFUSED) { + CYASSL_MSG(" Connection refused"); + return IO_ERR_WANT_READ; + } else { CYASSL_MSG(" General error"); return IO_ERR_GENERAL;