@@ -145,8 +145,13 @@ enum WS_SFTP_LSTAT_STATE_ID {
145145 STATE_LSTAT_CLEANUP
146146};
147147
148- /* WS_SFTP_BUFFER is defined in wolfsftp.h for use with nonblocking state.
148+ /* SFTP buffer for nonblocking state tracking .
149149 * If adding any read/writes use the wolfSSH_SFTP_buffer_read/send functions */
150+ typedef struct WS_SFTP_BUFFER {
151+ byte * data ;
152+ word32 sz ;
153+ word32 idx ;
154+ } WS_SFTP_BUFFER ;
150155
151156typedef struct WS_SFTP_CHMOD_STATE {
152157 enum WS_SFTP_CHMOD_STATE_ID state ;
@@ -508,7 +513,7 @@ static void wolfSSH_SFTP_buffer_rewind(WS_SFTP_BUFFER* buffer)
508513
509514/* try to send the rest of the buffer (buffer.sz - buffer.idx)
510515 * increments idx with amount sent */
511- WOLFSSH_LOCAL int wolfSSH_SFTP_buffer_send (WOLFSSH * ssh , WS_SFTP_BUFFER * buffer )
516+ static int wolfSSH_SFTP_buffer_send (WOLFSSH * ssh , WS_SFTP_BUFFER * buffer )
512517{
513518 int ret = WS_SUCCESS ;
514519 int err ;
@@ -524,7 +529,7 @@ WOLFSSH_LOCAL int wolfSSH_SFTP_buffer_send(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer)
524529 /* Flush any pending data in SSH output buffer first.
525530 * Handles case where previous send returned WS_WANT_WRITE
526531 * and data is still buffered at the SSH layer. */
527- if (ssh -> outputBuffer . length > ssh -> outputBuffer . idx ) {
532+ if (wolfSSH_OutputPending ( ssh ) ) {
528533 ret = wolfSSH_SendPacket (ssh );
529534 if (ret == WS_WANT_WRITE ) {
530535 return ret ;
@@ -554,6 +559,20 @@ WOLFSSH_LOCAL int wolfSSH_SFTP_buffer_send(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer)
554559}
555560
556561
562+ #ifdef WOLFSSH_TEST_INTERNAL
563+ int wolfSSH_TestSftpBufferSend (WOLFSSH * ssh ,
564+ byte * data , word32 sz , word32 idx )
565+ {
566+ WS_SFTP_BUFFER buffer ;
567+
568+ buffer .data = data ;
569+ buffer .sz = sz ;
570+ buffer .idx = idx ;
571+ return wolfSSH_SFTP_buffer_send (ssh , & buffer );
572+ }
573+ #endif
574+
575+
557576/* returns the amount read on success */
558577static int wolfSSH_SFTP_buffer_read (WOLFSSH * ssh , WS_SFTP_BUFFER * buffer ,
559578 int readSz )
@@ -1614,8 +1633,7 @@ int wolfSSH_SFTP_read(WOLFSSH* ssh)
16141633 /* Check if SSH layer still has pending data from WS_WANT_WRITE.
16151634 * Even if SFTP buffer is fully consumed, the data may still be
16161635 * sitting in the SSH output buffer waiting to be sent. */
1617- if (ssh -> error == WS_WANT_WRITE ||
1618- ssh -> outputBuffer .length > ssh -> outputBuffer .idx ) {
1636+ if (wolfSSH_OutputPending (ssh )) {
16191637 ssh -> error = WS_WANT_WRITE ;
16201638 return WS_FATAL_ERROR ;
16211639 }
0 commit comments