examples, ide, tests: classify the worker's status at the call site

- ssh_worker() in both echoservers maps a WS_FATAL_ERROR return from
  wolfSSH_worker() to WS_WANT_READ or WS_WANT_WRITE at the call site,
  off a new local err, and keeps the result in rc.
- The terminal arm tests rc in place of re-reading wolfSSH_get_error():
  rc != WS_WANT_READ in examples/echoserver, and rc != WS_WANT_READ &&
  rc != WS_WANT_WRITE in the Espressif copy, whose empty WS_WANT_WRITE
  arm is removed.
- ssh_worker() in examples/echoserver sets wantWrite from
  wolfSSH_OutputPending() before it builds writeFds.
- The comment above rc = cnt_r in both echoservers names cnt_r and
  ssh->error as the values that are reused.
- scripts/sshclient.test and scripts/fwd-bulk.test name the client's
  missing non-blocking mode in the skip message where they echoed the
  macro name, and the comments above both skips are removed.
pull/1253/merge
Yosuke Shimizu 2026-09-15 09:23:53 +09:00 committed by John Safranek
parent 47cea34929
commit 1a195cb1ec
4 changed files with 24 additions and 22 deletions

View File

@ -1222,6 +1222,9 @@ static int ssh_worker(thread_ctx_t* threadCtx)
}
#endif
if (wolfSSH_OutputPending(ssh))
wantWrite = 1;
FD_ZERO(&writeFds);
if (wantWrite)
FD_SET(sshFd, &writeFds);
@ -1297,9 +1300,15 @@ static int ssh_worker(thread_ctx_t* threadCtx)
break;
}
#endif
/* The channel reads below overwrite cnt_r with a byte
* count, so keep the worker's status. */
/* rc keeps the worker's status: cnt_r and ssh->error are
* both reused. */
rc = cnt_r;
if (rc == WS_FATAL_ERROR) {
int err = wolfSSH_get_error(ssh);
if (err == WS_WANT_READ || err == WS_WANT_WRITE)
rc = err;
}
/* The peer is done sending: hand back the backlog and answer
* its EOF, since the library no longer answers for us. Off
@ -1515,9 +1524,7 @@ static int ssh_worker(thread_ctx_t* threadCtx)
wantWrite = 1;
continue;
}
else if (rc != WS_FATAL_ERROR
|| (wolfSSH_get_error(ssh) != WS_WANT_READ
&& wolfSSH_get_error(ssh) != WS_WANT_WRITE)) {
else if (rc != WS_WANT_READ) {
#ifdef SHELL_DEBUG
printf("Break:read sshFd returns %d: errno =%x\n",
cnt_r, errno);

View File

@ -995,9 +995,15 @@ static int ssh_worker(thread_ctx_t* threadCtx)
channel. The additional channel is only used with the
agent. */
cnt_r = wolfSSH_worker(ssh, &lastChannel);
/* The channel reads below overwrite cnt_r with a byte
* count, so keep the worker's status. */
/* rc keeps the worker's status: cnt_r and ssh->error are
* both reused. */
rc = cnt_r;
if (rc == WS_FATAL_ERROR) {
int err = wolfSSH_get_error(ssh);
if (err == WS_WANT_READ || err == WS_WANT_WRITE)
rc = err;
}
/* The peer is done sending: hand back the backlog and answer
* its EOF, since the library no longer answers for us. Off
@ -1167,12 +1173,7 @@ static int ssh_worker(thread_ctx_t* threadCtx)
* above, which has already run this pass. */
continue;
}
else if (rc == WS_WANT_WRITE) {
/* Transient; the queue drives the write side. */
}
else if (rc != WS_FATAL_ERROR
|| (wolfSSH_get_error(ssh) != WS_WANT_READ
&& wolfSSH_get_error(ssh) != WS_WANT_WRITE)) {
else if (rc != WS_WANT_READ && rc != WS_WANT_WRITE) {
#ifdef SHELL_DEBUG
printf("Break:read sshFd returns %d: errno =%x\n",
cnt_r, errno);

View File

@ -80,15 +80,13 @@ stall_limit=15
./examples/portfwd/portfwd '-?' 2>&1 | grep -q "does not exist" \
&& { echo "forwarding not compiled in, skipping"; exit 77; }
# A WOLFSSH_TEST_BLOCK build fails writes at random, which stalls the
# echoserver regardless of what the peer does. The other echoserver scripts
# skip it for the same reason.
WOLFSSH_OPTIONS=`./apps/wolfssh-options` || {
echo "fail: could not run ./apps/wolfssh-options"
exit 1
}
echo "$WOLFSSH_OPTIONS" | grep -qx "TEST_BLOCK" \
&& { echo "macro WOLFSSH_TEST_BLOCK was used, skipping"; exit 77; }
&& { echo "portfwd does not support non-blocking mode, skipping test"
exit 77; }
do_cleanup() {
for pid in $nc_client_pid $portfwd_pid $server_pid $nc_server_pid \

View File

@ -30,14 +30,10 @@ client_limit=60
./examples/echoserver/echoserver '-?' 2>&1 | grep -q "^echoserver " \
|| { echo "echoserver doesn't run, skipping"; exit 77; }
# A WOLFSSH_TEST_BLOCK build fails writes at random. The echoserver leaves a
# failed write queued and then waits on the peer for a reply to the message
# it never sent, so a session stalls no matter what the client does. The
# other echoserver scripts skip this build for the same reason.
if [ -x ./examples/client/client ] \
&& ./examples/client/client -h 2>&1 | grep -q "WOLFSSH_TEST_BLOCK"
then
echo "macro WOLFSSH_TEST_BLOCK was used, skipping"
echo "wolfssh client does not support non-blocking mode, skipping test"
exit 77
fi