forked from wolfSSL/wolfssl
Add an option to the example client to simulate WANT_WRITE errors.
- Add this option as "-6." - Turn on non-blocking mode if WANT_WRITE simulation is enabled. - Create a send IO callback that gets registered when this option is turned on. This callback alternates between letting the TX through and returning a WANT_WRITE error.
This commit is contained in:
@ -184,10 +184,15 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (error != WOLFSSL_ERROR_WANT_WRITE) {
|
#ifdef WOLFSSL_DTLS
|
||||||
#ifdef WOLFSSL_DTLS
|
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
||||||
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
#endif
|
||||||
#endif
|
if (error == WOLFSSL_ERROR_WANT_WRITE) {
|
||||||
|
select_ret = tcp_select_tx(sockfd, currTimeout);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
select_ret = tcp_select(sockfd, currTimeout);
|
select_ret = tcp_select(sockfd, currTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,13 +211,6 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
|
|||||||
#endif
|
#endif
|
||||||
error = wolfSSL_get_error(ssl, 0);
|
error = wolfSSL_get_error(ssl, 0);
|
||||||
elapsedSec = 0; /* reset elapsed */
|
elapsedSec = 0; /* reset elapsed */
|
||||||
if (error == WOLFSSL_ERROR_WANT_WRITE) {
|
|
||||||
/* Do a send select here. */
|
|
||||||
select_ret = tcp_select_tx(sockfd, 1);
|
|
||||||
if (select_ret == TEST_TIMEOUT) {
|
|
||||||
error = WOLFSSL_FATAL_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
@ -1108,6 +1106,7 @@ static const char* client_usage_msg[][66] = {
|
|||||||
#ifdef HAVE_TRUSTED_CA
|
#ifdef HAVE_TRUSTED_CA
|
||||||
"-5 Use Trusted CA Key Indication\n", /* 63 */
|
"-5 Use Trusted CA Key Indication\n", /* 63 */
|
||||||
#endif
|
#endif
|
||||||
|
"-6 Simulate WANT_WRITE errors on every other IO send\n",
|
||||||
#ifdef HAVE_CURVE448
|
#ifdef HAVE_CURVE448
|
||||||
"-8 Use X448 for key exchange\n", /* 66 */
|
"-8 Use X448 for key exchange\n", /* 66 */
|
||||||
#endif
|
#endif
|
||||||
@ -1485,6 +1484,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
int matchName = 0;
|
int matchName = 0;
|
||||||
int doPeerCheck = 1;
|
int doPeerCheck = 1;
|
||||||
int nonBlocking = 0;
|
int nonBlocking = 0;
|
||||||
|
int simulateWantWrite = 0;
|
||||||
int resumeSession = 0;
|
int resumeSession = 0;
|
||||||
int wc_shutdown = 0;
|
int wc_shutdown = 0;
|
||||||
int disableCRL = 0;
|
int disableCRL = 0;
|
||||||
@ -1660,7 +1660,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
while ((ch = mygetopt(argc, argv, "?:"
|
while ((ch = mygetopt(argc, argv, "?:"
|
||||||
"ab:c:defgh:i;jk:l:mnop:q:rstuv:wxyz"
|
"ab:c:defgh:i;jk:l:mnop:q:rstuv:wxyz"
|
||||||
"A:B:CDE:F:GH:IJKL:M:NO:PQRS:TUVW:XYZ:"
|
"A:B:CDE:F:GH:IJKL:M:NO:PQRS:TUVW:XYZ:"
|
||||||
"01:23:458"
|
"01:23:4568"
|
||||||
"@#")) != -1) {
|
"@#")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '?' :
|
case '?' :
|
||||||
@ -2116,6 +2116,11 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
#endif /* HAVE_TRUSTED_CA */
|
#endif /* HAVE_TRUSTED_CA */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '6' :
|
||||||
|
nonBlocking = 1;
|
||||||
|
simulateWantWrite = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case '8' :
|
case '8' :
|
||||||
#ifdef HAVE_CURVE448
|
#ifdef HAVE_CURVE448
|
||||||
useX448 = 1;
|
useX448 = 1;
|
||||||
@ -2387,6 +2392,11 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
err_sys("unable to get ctx");
|
err_sys("unable to get ctx");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (simulateWantWrite)
|
||||||
|
{
|
||||||
|
wolfSSL_CTX_SetIOSend(ctx, SimulateWantWriteIOSendCb);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SINGLE_THREADED
|
#ifdef SINGLE_THREADED
|
||||||
if (wolfSSL_CTX_new_rng(ctx) != WOLFSSL_SUCCESS) {
|
if (wolfSSL_CTX_new_rng(ctx) != WOLFSSL_SUCCESS) {
|
||||||
wolfSSL_CTX_free(ctx); ctx = NULL;
|
wolfSSL_CTX_free(ctx); ctx = NULL;
|
||||||
|
@ -3805,8 +3805,48 @@ static WC_INLINE void SetupPkCallbackContexts(WOLFSSL* ssl, void* myCtx)
|
|||||||
|
|
||||||
#endif /* HAVE_PK_CALLBACKS */
|
#endif /* HAVE_PK_CALLBACKS */
|
||||||
|
|
||||||
|
static WC_INLINE int SimulateWantWriteIOSendCb(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
||||||
|
{
|
||||||
|
static int wantWriteFlag = 1;
|
||||||
|
|
||||||
|
int sent;
|
||||||
|
int sd = *(int*)ctx;
|
||||||
|
|
||||||
|
(void)ssl;
|
||||||
|
|
||||||
|
if (!wantWriteFlag)
|
||||||
|
{
|
||||||
|
wantWriteFlag = 1;
|
||||||
|
|
||||||
|
sent = wolfIO_Send(sd, buf, sz, 0);
|
||||||
|
if (sent < 0) {
|
||||||
|
int err = errno;
|
||||||
|
|
||||||
|
if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
|
||||||
|
return WOLFSSL_CBIO_ERR_WANT_WRITE;
|
||||||
|
}
|
||||||
|
else if (err == SOCKET_ECONNRESET) {
|
||||||
|
return WOLFSSL_CBIO_ERR_CONN_RST;
|
||||||
|
}
|
||||||
|
else if (err == SOCKET_EINTR) {
|
||||||
|
return WOLFSSL_CBIO_ERR_ISR;
|
||||||
|
}
|
||||||
|
else if (err == SOCKET_EPIPE) {
|
||||||
|
return WOLFSSL_CBIO_ERR_CONN_CLOSE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return WOLFSSL_CBIO_ERR_GENERAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sent;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wantWriteFlag = 0;
|
||||||
|
return WOLFSSL_CBIO_ERR_WANT_WRITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(__hpux__) || defined(__MINGW32__) || defined (WOLFSSL_TIRTOS) \
|
#if defined(__hpux__) || defined(__MINGW32__) || defined (WOLFSSL_TIRTOS) \
|
||||||
|| defined(_MSC_VER)
|
|| defined(_MSC_VER)
|
||||||
|
Reference in New Issue
Block a user