sftp_write: polished and simplified

Removed unnecessary struct fields and state changes within the function.

Made the loop that checks for ACKs only check chunks that were fully
sent.
This commit is contained in:
Daniel Stenberg 2010-11-10 23:29:16 +01:00
parent 160453cee4
commit 2f5a2ff8e6
2 changed files with 9 additions and 18 deletions

View File

@ -760,10 +760,6 @@ sftp_shutdown(LIBSSH2_SFTP *sftp)
LIBSSH2_FREE(session, sftp->readdir_packet);
sftp->readdir_packet = NULL;
}
if (sftp->write_packet) {
LIBSSH2_FREE(session, sftp->write_packet);
sftp->write_packet = NULL;
}
if (sftp->fstat_packet) {
LIBSSH2_FREE(session, sftp->fstat_packet);
sftp->fstat_packet = NULL;
@ -1511,15 +1507,10 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
if(chunk->lefttosend)
/* data left to send, get out of loop */
break;
chunk = _libssh2_list_next(&chunk->node);
sftp->write_state = libssh2_NB_state_sent;
}
else {
/* move on to the next chunk with data to send */
chunk = _libssh2_list_next(&chunk->node);
}
/* move on to the next chunk with data to send */
chunk = _libssh2_list_next(&chunk->node);
}
/*
@ -1528,7 +1519,12 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
chunk = _libssh2_list_first(&handle->write_list);
while(chunk) {
/* we can expect the packets to be ACKed in order */
if(chunk->lefttosend)
/* if the chunk still has data left to send, we shouldn't wait for
an ACK for it just yet */
break;
/* we check the packets in order */
rc = sftp_packet_require(sftp, SSH_FXP_STATUS,
chunk->request_id, &data, &data_len);
if (rc == LIBSSH2_ERROR_EAGAIN) {
@ -1536,7 +1532,6 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
break;
}
else if (rc) {
sftp->write_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, "Waiting for SFTP status");
}
retcode = _libssh2_ntohu32(data + 5);
@ -1563,8 +1558,6 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
}
}
sftp->write_state = libssh2_NB_state_idle;
if(acked)
/* we got data acked so return that amount, but no more than what
was asked to get sent! */

View File

@ -142,8 +142,6 @@ struct _LIBSSH2_SFTP
uint32_t readdir_request_id;
/* State variables used in libssh2_sftp_write() */
libssh2_nonblocking_states write_state;
unsigned char *write_packet;
uint32_t write_request_id;
/* State variables used in libssh2_sftp_fstat_ex() */