From f35a92fd4897791db65f3ae30c72738a09630b72 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 13 Sep 2023 09:26:29 -0700 Subject: [PATCH] Nonblock Client Login Failure When the example client is using non-blocking sockets, sometimes they don't block. The monitor thread on the socket wasn't handling WS_WANT_READ explicitly, and treated it as a fatal error. It should be reset to WS_SUCCESS. --- examples/client/client.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/client/client.c b/examples/client/client.c index 58f7fc80..b1e807fb 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -396,10 +396,14 @@ static THREAD_RET readPeer(void* in) } while (ret > 0); } else if (ret <= 0) { - #ifdef WOLFSSH_AGENT if (ret == WS_FATAL_ERROR) { ret = wolfSSH_get_error(args->ssh); - if (ret == WS_CHAN_RXD) { + if (ret == WS_WANT_READ) { + /* If WANT_READ, not an error. */ + ret = WS_SUCCESS; + } + #ifdef WOLFSSH_AGENT + else if (ret == WS_CHAN_RXD) { byte agentBuf[512]; int rxd, txd; word32 channel = 0; @@ -430,9 +434,9 @@ static THREAD_RET readPeer(void* in) WMEMSET(agentBuf, 0, sizeof(agentBuf)); continue; } + #endif /* WOLFSSH_AGENT */ } - #endif - if (ret != WS_EOF) { + else if (ret != WS_EOF) { err_sys("Stream read failed."); } }