@@ -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
@@ -5924,14 +5932,7 @@ int SendPacketType(WOLFSSH* ssh, byte type, byte* buf, word32 bufSz)
59245932 * because channel could have restrictions on how much
59255933 * state->data can be sent at one time */
59265934 do {
5927- int err ;
59285935 ret = wolfSSH_SFTP_buffer_send (ssh , & state -> buffer );
5929-
5930- /* check for adjust window packet */
5931- err = wolfSSH_get_error (ssh );
5932- if (err == WS_WINDOW_FULL || err == WS_REKEYING )
5933- ret = wolfSSH_worker (ssh , NULL );
5934- ssh -> error = err ; /* don't save potential want read here */
59355936 } while (ret > 0 &&
59365937 wolfSSH_SFTP_buffer_idx (& state -> buffer ) <
59375938 wolfSSH_SFTP_buffer_size (& state -> buffer ));
@@ -6565,8 +6566,7 @@ static int wolfSSH_SFTP_GetHandle(WOLFSSH* ssh, byte* handle, word32* handleSz)
65656566 WLOG (WS_LOG_SFTP , "SFTP GET HANDLE STATE: GET_HEADER" );
65666567 ret = SFTP_GetHeader (ssh , & state -> reqId , & type , & state -> buffer );
65676568 if (ret <= 0 ) {
6568- if (ssh -> error == WS_WANT_READ ||
6569- ssh -> error == WS_WANT_WRITE ) {
6569+ if (NoticeError (ssh )) {
65706570 return WS_FATAL_ERROR ;
65716571 }
65726572 else {
@@ -8087,9 +8087,8 @@ int wolfSSH_SFTP_Close(WOLFSSH* ssh, byte* handle, word32 handleSz)
80878087 case STATE_CLOSE_SEND :
80888088 WLOG (WS_LOG_SFTP , "SFTP CLOSE STATE: SEND" );
80898089 ret = SendPacketType (ssh , WOLFSSH_FTP_CLOSE , handle , handleSz );
8090- if (ssh -> error == WS_WANT_WRITE || ssh -> error == WS_WANT_READ )
8091- {
8092- return ret ;
8090+ if (NoticeError (ssh )) {
8091+ return WS_FATAL_ERROR ;
80938092 }
80948093
80958094 if (ret != WS_SUCCESS ) {
@@ -8102,10 +8101,9 @@ int wolfSSH_SFTP_Close(WOLFSSH* ssh, byte* handle, word32 handleSz)
81028101 case STATE_CLOSE_GET_HEADER :
81038102 WLOG (WS_LOG_SFTP , "SFTP CLOSE STATE: GET_HEADER" );
81048103 ret = SFTP_GetHeader (ssh , & state -> reqId , & type , & state -> buffer );
8105- if (ret <= 0 &&
8106- (ssh -> error == WS_WANT_WRITE ||
8107- ssh -> error == WS_WANT_READ ))
8108- return ret ;
8104+ if (ret <= 0 && NoticeError (ssh )) {
8105+ return WS_FATAL_ERROR ;
8106+ }
81098107
81108108 if (type != WOLFSSH_FTP_STATUS || ret <= 0 ) {
81118109 WLOG (WS_LOG_SFTP , "Unexpected packet type" );
@@ -9209,9 +9207,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
92099207 ret = wolfSSH_SFTP_Close (ssh , state -> handle ,
92109208 state -> handleSz );
92119209 if (ret != WS_SUCCESS ) {
9212- if (ssh -> error == WS_WANT_READ ||
9213- ssh -> error == WS_WANT_WRITE ||
9214- ssh -> error == WS_REKEYING ) {
9210+ if (NoticeError (ssh )) {
92159211 return WS_FATAL_ERROR ;
92169212 }
92179213 WLOG (WS_LOG_SFTP , "Error closing handle" );
0 commit comments