forked from wolfSSL/wolfssl
Modify example server to be resilient to WANT_WRITE errors.
This commit is contained in:
@@ -184,15 +184,15 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef WOLFSSL_DTLS
|
|
||||||
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
|
||||||
#endif
|
|
||||||
if (error == WOLFSSL_ERROR_WANT_WRITE) {
|
if (error == WOLFSSL_ERROR_WANT_WRITE) {
|
||||||
select_ret = tcp_select_tx(sockfd, currTimeout);
|
select_ret = tcp_select_tx(sockfd, currTimeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef WOLFSSL_DTLS
|
||||||
|
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
||||||
|
#endif
|
||||||
select_ret = tcp_select(sockfd, currTimeout);
|
select_ret = tcp_select(sockfd, currTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -137,7 +137,6 @@ static int lng_index = 0;
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void err_sys_ex(int out, const char* msg)
|
static void err_sys_ex(int out, const char* msg)
|
||||||
{
|
{
|
||||||
if (out == 1) { /* if server is running w/ -x flag, print error w/o exit */
|
if (out == 1) { /* if server is running w/ -x flag, print error w/o exit */
|
||||||
@@ -312,7 +311,11 @@ static int NonBlockingSSL_Accept(SSL* ssl)
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (error != WOLFSSL_ERROR_WANT_WRITE) {
|
if (error == WOLFSSL_ERROR_WANT_WRITE)
|
||||||
|
{
|
||||||
|
select_ret = tcp_select_tx(sockfd, currTimeout);
|
||||||
|
}
|
||||||
|
else {
|
||||||
#ifdef WOLFSSL_DTLS
|
#ifdef WOLFSSL_DTLS
|
||||||
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
||||||
#endif
|
#endif
|
||||||
@@ -333,12 +336,6 @@ static int NonBlockingSSL_Accept(SSL* ssl)
|
|||||||
srvHandShakeCB, srvTimeoutCB, srvTo);
|
srvHandShakeCB, srvTimeoutCB, srvTo);
|
||||||
#endif
|
#endif
|
||||||
error = SSL_get_error(ssl, 0);
|
error = SSL_get_error(ssl, 0);
|
||||||
if (error == WOLFSSL_ERROR_WANT_WRITE) {
|
|
||||||
/* Do a 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;
|
||||||
@@ -694,6 +691,7 @@ static const char* server_usage_msg[][56] = {
|
|||||||
#ifdef HAVE_TRUSTED_CA
|
#ifdef HAVE_TRUSTED_CA
|
||||||
"-5 Use Trusted CA Key Indication\n", /* 53 */
|
"-5 Use Trusted CA Key Indication\n", /* 53 */
|
||||||
#endif
|
#endif
|
||||||
|
"-6 Simulate WANT_WRITE errors on every other IO send\n",
|
||||||
#ifdef HAVE_CURVE448
|
#ifdef HAVE_CURVE448
|
||||||
"-8 Pre-generate Key share using Curve448 only\n", /* 55 */
|
"-8 Pre-generate Key share using Curve448 only\n", /* 55 */
|
||||||
#endif
|
#endif
|
||||||
@@ -984,6 +982,7 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
|
|||||||
int needDH = 0;
|
int needDH = 0;
|
||||||
int useNtruKey = 0;
|
int useNtruKey = 0;
|
||||||
int nonBlocking = 0;
|
int nonBlocking = 0;
|
||||||
|
int simulateWantWrite = 0;
|
||||||
int fewerPackets = 0;
|
int fewerPackets = 0;
|
||||||
#ifdef HAVE_PK_CALLBACKS
|
#ifdef HAVE_PK_CALLBACKS
|
||||||
int pkCallbacks = 0;
|
int pkCallbacks = 0;
|
||||||
@@ -1157,7 +1156,7 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
|
|||||||
while ((ch = mygetopt(argc, argv, "?:"
|
while ((ch = mygetopt(argc, argv, "?:"
|
||||||
"abc:defgijk:l:mnop:q:rstuv:wxy"
|
"abc:defgijk:l:mnop:q:rstuv:wxy"
|
||||||
"A:B:C:D:E:FGH:IJKL:MNO:PQR:S:TUVYZ:"
|
"A:B:C:D:E:FGH:IJKL:MNO:PQR:S:TUVYZ:"
|
||||||
"01:23:4:58"
|
"01:23:4:568"
|
||||||
"@#")) != -1) {
|
"@#")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '?' :
|
case '?' :
|
||||||
@@ -1549,6 +1548,11 @@ THREAD_RETURN WOLFSSL_THREAD server_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;
|
||||||
@@ -1730,6 +1734,11 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
|
|||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
err_sys_ex(catastrophic, "unable to get ctx");
|
err_sys_ex(catastrophic, "unable to get ctx");
|
||||||
|
|
||||||
|
if (simulateWantWrite)
|
||||||
|
{
|
||||||
|
wolfSSL_CTX_SetIOSend(ctx, SimulateWantWriteIOSendCb);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(HAVE_SESSION_TICKET) && defined(HAVE_CHACHA) && \
|
#if defined(HAVE_SESSION_TICKET) && defined(HAVE_CHACHA) && \
|
||||||
defined(HAVE_POLY1305)
|
defined(HAVE_POLY1305)
|
||||||
if (TicketInit() != 0)
|
if (TicketInit() != 0)
|
||||||
|
Reference in New Issue
Block a user