mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 20:24:39 +02:00
Merge pull request #2024 from dgarske/nb_timeout_det
Nonblocking connect timeout check
This commit is contained in:
@@ -54,6 +54,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_TIMEOUT_SEC 2
|
#define DEFAULT_TIMEOUT_SEC 2
|
||||||
|
#ifndef MAX_NON_BLOCK_SEC
|
||||||
|
#define MAX_NON_BLOCK_SEC 10
|
||||||
|
#endif
|
||||||
|
|
||||||
#define OCSP_STAPLING 1
|
#define OCSP_STAPLING 1
|
||||||
#define OCSP_STAPLINGV2 2
|
#define OCSP_STAPLINGV2 2
|
||||||
@@ -101,6 +104,7 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
|
|||||||
int error;
|
int error;
|
||||||
SOCKET_T sockfd;
|
SOCKET_T sockfd;
|
||||||
int select_ret = 0;
|
int select_ret = 0;
|
||||||
|
int elapsedSec = 0;
|
||||||
|
|
||||||
#ifndef WOLFSSL_CALLBACKS
|
#ifndef WOLFSSL_CALLBACKS
|
||||||
ret = wolfSSL_connect(ssl);
|
ret = wolfSSL_connect(ssl);
|
||||||
@@ -151,9 +155,16 @@ 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 > MAX_NON_BLOCK_SEC) {
|
||||||
|
printf("Nonblocking connect timeout\n");
|
||||||
|
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) &&
|
||||||
@@ -516,7 +527,7 @@ static int ClientBenchmarkThroughput(WOLFSSL_CTX* ctx, char* host, word16 port,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compare TX and RX buffers */
|
/* Compare TX and RX buffers */
|
||||||
if(XMEMCMP(tx_buffer, rx_buffer, len) != 0) {
|
if (XMEMCMP(tx_buffer, rx_buffer, len) != 0) {
|
||||||
free(tx_buffer);
|
free(tx_buffer);
|
||||||
tx_buffer = NULL;
|
tx_buffer = NULL;
|
||||||
free(rx_buffer);
|
free(rx_buffer);
|
||||||
@@ -713,6 +724,7 @@ static void ClientRead(WOLFSSL* ssl, char* reply, int replyLen, int mustRead)
|
|||||||
{
|
{
|
||||||
int ret, err;
|
int ret, err;
|
||||||
char buffer[WOLFSSL_MAX_ERROR_SZ];
|
char buffer[WOLFSSL_MAX_ERROR_SZ];
|
||||||
|
double start = current_time(1), elapsed;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
err = 0; /* reset error */
|
err = 0; /* reset error */
|
||||||
@@ -732,6 +744,15 @@ static void ClientRead(WOLFSSL* ssl, char* reply, int replyLen, int mustRead)
|
|||||||
err_sys("SSL_read failed");
|
err_sys("SSL_read failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mustRead && err == WOLFSSL_ERROR_WANT_READ) {
|
||||||
|
elapsed = current_time(0) - start;
|
||||||
|
if (elapsed > MAX_NON_BLOCK_SEC) {
|
||||||
|
printf("Nonblocking read timeout\n");
|
||||||
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} while ((mustRead && err == WOLFSSL_ERROR_WANT_READ)
|
} while ((mustRead && err == WOLFSSL_ERROR_WANT_READ)
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|| err == WC_PENDING_E
|
|| err == WC_PENDING_E
|
||||||
@@ -861,7 +882,7 @@ static const char* client_usage_msg[][59] = {
|
|||||||
"-N Use Non-blocking sockets\n", /* 24 */
|
"-N Use Non-blocking sockets\n", /* 24 */
|
||||||
#ifndef NO_SESSION_CACHE
|
#ifndef NO_SESSION_CACHE
|
||||||
"-r Resume session\n", /* 25 */
|
"-r Resume session\n", /* 25 */
|
||||||
#endif
|
#endif
|
||||||
"-w Wait for bidirectional shutdown\n", /* 26 */
|
"-w Wait for bidirectional shutdown\n", /* 26 */
|
||||||
"-M <prot> Use STARTTLS, using <prot> protocol (smtp)\n", /* 27 */
|
"-M <prot> Use STARTTLS, using <prot> protocol (smtp)\n", /* 27 */
|
||||||
#ifdef HAVE_SECURE_RENEGOTIATION
|
#ifdef HAVE_SECURE_RENEGOTIATION
|
||||||
@@ -911,7 +932,7 @@ static const char* client_usage_msg[][59] = {
|
|||||||
"-E <file> Path to load trusted peer cert\n", /* 46 */
|
"-E <file> Path to load trusted peer cert\n", /* 46 */
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_WNR
|
#ifdef HAVE_WNR
|
||||||
"-q <file> Whitewood config file, defaults\n", /* 47 */
|
"-q <file> Whitewood config file, defaults\n", /* 47 */
|
||||||
#endif
|
#endif
|
||||||
"-H <arg> Internal tests"
|
"-H <arg> Internal tests"
|
||||||
" [defCipherList, exitWithRet, verifyFail]\n", /* 48 */
|
" [defCipherList, exitWithRet, verifyFail]\n", /* 48 */
|
||||||
@@ -1007,7 +1028,7 @@ static const char* client_usage_msg[][59] = {
|
|||||||
"-N ノンブロッキング・ソケットを使用する\n", /* 24 */
|
"-N ノンブロッキング・ソケットを使用する\n", /* 24 */
|
||||||
#ifndef NO_SESSION_CACHE
|
#ifndef NO_SESSION_CACHE
|
||||||
"-r セッションを継続する\n", /* 25 */
|
"-r セッションを継続する\n", /* 25 */
|
||||||
#endif
|
#endif
|
||||||
"-w 双方向シャットダウンを待つ\n", /* 26 */
|
"-w 双方向シャットダウンを待つ\n", /* 26 */
|
||||||
"-M <prot> STARTTLSを使用する, <prot>プロトコル(smtp)を"
|
"-M <prot> STARTTLSを使用する, <prot>プロトコル(smtp)を"
|
||||||
"使用する\n", /* 27 */
|
"使用する\n", /* 27 */
|
||||||
@@ -1061,7 +1082,7 @@ static const char* client_usage_msg[][59] = {
|
|||||||
"-E <file> 信頼出来るピアの証明書ロードの為のパス\n", /* 46 */
|
"-E <file> 信頼出来るピアの証明書ロードの為のパス\n", /* 46 */
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_WNR
|
#ifdef HAVE_WNR
|
||||||
"-q <file> Whitewood コンフィグファイル, 既定値\n", /* 47 */
|
"-q <file> Whitewood コンフィグファイル, 既定値\n", /* 47 */
|
||||||
#endif
|
#endif
|
||||||
"-H <arg> 内部テスト"
|
"-H <arg> 内部テスト"
|
||||||
" [defCipherList, exitWithRet, verifyFail]\n", /* 48 */
|
" [defCipherList, exitWithRet, verifyFail]\n", /* 48 */
|
||||||
|
Reference in New Issue
Block a user