modify wolfSSH_stream_send behavior with non blocking want write case

pull/134/head
Jacob Barthelmeh 2018-12-28 11:02:25 -07:00
parent af32ee760f
commit c06bb7db56
2 changed files with 16 additions and 0 deletions

View File

@ -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 */

View File

@ -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);