Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions examples/echoserver/echoserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,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);
Expand Down Expand Up @@ -1295,9 +1298,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
Expand Down Expand Up @@ -1513,9 +1522,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions scripts/fwd-bulk.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
33 changes: 13 additions & 20 deletions scripts/sftp.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ no_pid=-1
server_pid="$no_pid"
ready_file="$PWD/wolfssh_sftp_ready$$"
nonblockingOnly=0
blockBuild=0

[ ! -x ./examples/sftpclient/wolfsftp ] && echo && echo "wolfSFTP client doesn't exist" && exit 1

Expand All @@ -28,7 +27,6 @@ if echo "$WOLFSSH_OPTIONS" | grep -qx "TEST_BLOCK"
then
echo "macro WOLFSSH_TEST_BLOCK was used"
nonblockingOnly=1
blockBuild=1
fi

#echo "ready file $ready_file"
Expand Down Expand Up @@ -134,24 +132,19 @@ if [ "$nonblockingOnly" = 0 ]; then
fi

# The same handoff on a non-blocking server, which reaches the accept call's
# want-read and want-write retries. Held out of a forced-blocking build: the
# two ends deadlock there, the server parked in DoReceive with output it owes
# still queued, which is a defect of its own rather than this case failing.
if [ "$blockBuild" = 0 ]; then
echo "Test non blocking connection to an app-driven server"
./examples/echoserver/echoserver -A -N -1 -R "$ready_file" &
server_pid=$!
create_port
echo "exit" | ./examples/sftpclient/wolfsftp -N -u jill -P upthehill \
-p "$port"
RESULT=$?
remove_ready_file
if [ $RESULT -ne 0 ]; then
echo
echo "failed to connect to non blocking app-driven server"
do_cleanup
exit 1
fi
# want-read and want-write retries.
echo "Test non blocking connection to an app-driven server"
./examples/echoserver/echoserver -A -N -1 -R "$ready_file" &
server_pid=$!
create_port
echo "exit" | ./examples/sftpclient/wolfsftp -N -u jill -P upthehill -p "$port"
RESULT=$?
remove_ready_file
if [ $RESULT -ne 0 ]; then
echo
echo "failed to connect to non blocking app-driven server"
do_cleanup
exit 1
fi

# Test want write return from highwater callback
Expand Down
6 changes: 1 addition & 5 deletions scripts/sshclient.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading