improved dtls retry on connect
This commit is contained in:
parent
08a3423f43
commit
c3aedc940f
@ -46,6 +46,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)
|
||||
@ -55,7 +56,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);
|
||||
@ -63,6 +68,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");
|
||||
|
7
src/io.c
7
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;
|
||||
|
Loading…
Reference in New Issue
Block a user