mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-23 01:22:37 +03:00
sftp.c: ensure minimum read packet size
For optimum performance we need to ensure we don't request tiny packets.
This commit is contained in:
committed by
Daniel Stenberg
parent
d7e25b4729
commit
85dbd4c136
11
src/sftp.c
11
src/sftp.c
@@ -1367,13 +1367,18 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
||||
|
||||
while(count > 0) {
|
||||
unsigned char *s;
|
||||
uint32_t size = MIN(MAX_SFTP_READ_SIZE, count);
|
||||
|
||||
/* 25 = packet_len(4) + packet_type(1) + request_id(4) +
|
||||
handle_len(4) + offset(8) + count(4) */
|
||||
uint32_t packet_len = (uint32_t)handle->handle_len + 25;
|
||||
uint32_t request_id;
|
||||
|
||||
uint32_t size = count;
|
||||
if (size < buffer_size)
|
||||
size = buffer_size;
|
||||
if (size > MAX_SFTP_READ_SIZE)
|
||||
size = MAX_SFTP_READ_SIZE;
|
||||
|
||||
chunk = LIBSSH2_ALLOC(session, packet_len +
|
||||
sizeof(struct sftp_pipeline_chunk));
|
||||
if (!chunk)
|
||||
@@ -1399,8 +1404,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
||||
|
||||
/* add this new entry LAST in the list */
|
||||
_libssh2_list_add(&handle->packet_list, &chunk->node);
|
||||
count -= size; /* deduct the size we used, as we might have
|
||||
to create more packets */
|
||||
count -= MIN(size,count); /* deduct the size we used, as we might
|
||||
* have to create more packets */
|
||||
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
|
||||
"read request id %d sent (offset: %d, size: %d)",
|
||||
request_id, (int)chunk->offset, (int)chunk->len);
|
||||
|
||||
Reference in New Issue
Block a user