@@ -515,6 +515,7 @@ static void wolfSSH_SFTP_buffer_rewind(WS_SFTP_BUFFER* buffer)
515515static int wolfSSH_SFTP_buffer_send (WOLFSSH * ssh , WS_SFTP_BUFFER * buffer )
516516{
517517 int ret = WS_SUCCESS ;
518+ int err ;
518519
519520 if (buffer == NULL ) {
520521 return WS_BAD_ARGUMENT ;
@@ -524,6 +525,12 @@ static int wolfSSH_SFTP_buffer_send(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer)
524525 return WS_BUFFER_E ;
525526 }
526527
528+ /* Call wolfSSH worker if rekeying or adjusting window size */
529+ err = wolfSSH_get_error (ssh );
530+ if (err == WS_WINDOW_FULL || err == WS_REKEYING ) {
531+ (void )wolfSSH_worker (ssh , NULL );
532+ }
533+
527534 if (buffer -> idx < buffer -> sz ) {
528535 ret = wolfSSH_stream_send (ssh , buffer -> data + buffer -> idx ,
529536 buffer -> sz - buffer -> idx );
@@ -1411,8 +1418,9 @@ int wolfSSH_SFTP_read(WOLFSSH* ssh)
14111418 ret = wolfSSH_SFTP_buffer_read (ssh , & state -> buffer ,
14121419 state -> buffer .sz );
14131420 if (ret < 0 ) {
1414- if (ssh -> error != WS_WANT_READ && ssh -> error != WS_WANT_WRITE )
1415- wolfSSH_SFTP_ClearState (ssh , STATE_ID_RECV );
1421+ if (!NoticeError (ssh )) {
1422+ wolfSSH_SFTP_ClearState (ssh , STATE_ID_RECV );
1423+ }
14161424 return ret ;
14171425 }
14181426
@@ -5919,14 +5927,7 @@ int SendPacketType(WOLFSSH* ssh, byte type, byte* buf, word32 bufSz)
59195927 * because channel could have restrictions on how much
59205928 * state->data can be sent at one time */
59215929 do {
5922- int err ;
59235930 ret = wolfSSH_SFTP_buffer_send (ssh , & state -> buffer );
5924-
5925- /* check for adjust window packet */
5926- err = wolfSSH_get_error (ssh );
5927- if (err == WS_WINDOW_FULL || err == WS_REKEYING )
5928- ret = wolfSSH_worker (ssh , NULL );
5929- ssh -> error = err ; /* don't save potential want read here */
59305931 } while (ret > 0 &&
59315932 wolfSSH_SFTP_buffer_idx (& state -> buffer ) <
59325933 wolfSSH_SFTP_buffer_size (& state -> buffer ));
@@ -6560,8 +6561,7 @@ static int wolfSSH_SFTP_GetHandle(WOLFSSH* ssh, byte* handle, word32* handleSz)
65606561 WLOG (WS_LOG_SFTP , "SFTP GET HANDLE STATE: GET_HEADER" );
65616562 ret = SFTP_GetHeader (ssh , & state -> reqId , & type , & state -> buffer );
65626563 if (ret <= 0 ) {
6563- if (ssh -> error == WS_WANT_READ ||
6564- ssh -> error == WS_WANT_WRITE ) {
6564+ if (NoticeError (ssh )) {
65656565 return WS_FATAL_ERROR ;
65666566 }
65676567 else {
@@ -8082,9 +8082,8 @@ int wolfSSH_SFTP_Close(WOLFSSH* ssh, byte* handle, word32 handleSz)
80828082 case STATE_CLOSE_SEND :
80838083 WLOG (WS_LOG_SFTP , "SFTP CLOSE STATE: SEND" );
80848084 ret = SendPacketType (ssh , WOLFSSH_FTP_CLOSE , handle , handleSz );
8085- if (ssh -> error == WS_WANT_WRITE || ssh -> error == WS_WANT_READ )
8086- {
8087- return ret ;
8085+ if (NoticeError (ssh )) {
8086+ return WS_FATAL_ERROR ;
80888087 }
80898088
80908089 if (ret != WS_SUCCESS ) {
@@ -8097,10 +8096,9 @@ int wolfSSH_SFTP_Close(WOLFSSH* ssh, byte* handle, word32 handleSz)
80978096 case STATE_CLOSE_GET_HEADER :
80988097 WLOG (WS_LOG_SFTP , "SFTP CLOSE STATE: GET_HEADER" );
80998098 ret = SFTP_GetHeader (ssh , & state -> reqId , & type , & state -> buffer );
8100- if (ret <= 0 &&
8101- (ssh -> error == WS_WANT_WRITE ||
8102- ssh -> error == WS_WANT_READ ))
8103- return ret ;
8099+ if (ret <= 0 && NoticeError (ssh )) {
8100+ return WS_FATAL_ERROR ;
8101+ }
81048102
81058103 if (type != WOLFSSH_FTP_STATUS || ret <= 0 ) {
81068104 WLOG (WS_LOG_SFTP , "Unexpected packet type" );
@@ -9204,9 +9202,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
92049202 ret = wolfSSH_SFTP_Close (ssh , state -> handle ,
92059203 state -> handleSz );
92069204 if (ret != WS_SUCCESS ) {
9207- if (ssh -> error == WS_WANT_READ ||
9208- ssh -> error == WS_WANT_WRITE ||
9209- ssh -> error == WS_REKEYING ) {
9205+ if (NoticeError (ssh )) {
92109206 return WS_FATAL_ERROR ;
92119207 }
92129208 WLOG (WS_LOG_SFTP , "Error closing handle" );
0 commit comments