Skip to content

Commit a47b9ab

Browse files
committed
portfwd: drain the buffer before leaving on EOF
A zero read on the local socket left the loop at once, and anything read but not yet accepted by wolfSSH_ChannelSend() went with it. With the peer's window full that tail is up to a buffer's worth, so a transfer that ends while the window is being credited comes out short. - stop polling the socket on end-of-input and keep looping until the buffer is empty
1 parent 557f3df commit a47b9ab

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

examples/portfwd/portfwd.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ THREAD_RETURN WOLFSSH_THREAD portfwd_worker(void* args)
432432
int ch;
433433
int appFdSet = 0;
434434
int appFdHalfClosed = 0;
435+
int appEof = 0;
435436
int reverse = 0;
436437
int fwdFromPortSet = 0;
437438
PortfwdState fwdState;
@@ -728,8 +729,12 @@ THREAD_RETURN WOLFSSH_THREAD portfwd_worker(void* args)
728729
appBuffer + appBufferUsed, appBufferSz - appBufferUsed, 0);
729730
if (rxd > 0)
730731
appBufferUsed += rxd;
731-
else
732-
break;
732+
else {
733+
/* Local end-of-input. Stop polling the socket and leave once
734+
* what is buffered has gone out; leaving now would drop it. */
735+
appEof = 1;
736+
FD_CLR(appFd, &templateFds);
737+
}
733738
}
734739
if (FD_ISSET(sshFd, &rxFds)) {
735740
word32 channelId = 0;
@@ -868,6 +873,8 @@ THREAD_RETURN WOLFSSH_THREAD portfwd_worker(void* args)
868873
#endif
869874
}
870875
}
876+
if (appEof && appBufferUsed == 0)
877+
break;
871878
}
872879

873880
if (reverse) {

0 commit comments

Comments
 (0)