From c06bb7db560a8862ffa59c9a5065760d1e0f8080 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 28 Dec 2018 11:02:25 -0700 Subject: [PATCH] modify wolfSSH_stream_send behavior with non blocking want write case --- src/internal.c | 1 + src/ssh.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/internal.c b/src/internal.c index 599b27c..ae87690 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1371,6 +1371,7 @@ int wolfSSH_SendPacket(WOLFSSH* ssh) if (sent < 0) { switch (sent) { case WS_CBIO_ERR_WANT_WRITE: /* want write, would block */ + ssh->error = WS_WANT_WRITE; return WS_WANT_WRITE; case WS_CBIO_ERR_CONN_RST: /* connection reset */ diff --git a/src/ssh.c b/src/ssh.c index 4af7ce4..f9df2ff 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -753,6 +753,21 @@ int wolfSSH_stream_send(WOLFSSH* ssh, byte* buf, word32 bufSz) if (ssh == NULL || buf == NULL || ssh->channelList == NULL) return WS_BAD_ARGUMENT; + + /* case of WANT WRITE and data stored in output buffer */ + if (ssh->error == WS_WANT_WRITE && ssh->outputBuffer.length != 0) { + int ret; + + bytesTxd = ssh->outputBuffer.length; + WLOG(WS_LOG_DEBUG, "Trying to resend %d bytes\n", bytesTxd); + ssh->error = WS_SUCCESS; + ret = wolfSSH_SendPacket(ssh); + + /* return the amount sent on success otherwise return error found */ + return (ret == WS_SUCCESS)? + bytesTxd - (int)ssh->outputBuffer.length : ret; + } + bytesTxd = SendChannelData(ssh, ssh->channelList->peerChannel, buf, bufSz); WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_stream_send(), txd = %d", bytesTxd);