From 0d67598aedda1ca144e9eddaf7cde6efe196df78 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 12 Mar 2015 18:01:08 -0400 Subject: File transfer fixes and improvements. --- toxcore/Messenger.c | 14 ++++++++------ toxcore/net_crypto.c | 8 +++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index b062dcc9..2914cf36 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1196,7 +1196,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, return 0; } -#define MIN_SLOTS_FREE (CRYPTO_MIN_QUEUE_LENGTH / 2) +#define MIN_SLOTS_FREE (CRYPTO_MIN_QUEUE_LENGTH / 4) /* Send file data. * * return 0 on success @@ -1309,10 +1309,11 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber) int free_slots = crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id)); - if (free_slots <= MIN_SLOTS_FREE) - return; - - free_slots -= MIN_SLOTS_FREE; + if (free_slots < MIN_SLOTS_FREE) { + free_slots = 0; + } else { + free_slots -= MIN_SLOTS_FREE; + } unsigned int i, num = m->friendlist[friendnumber].num_sending_files; @@ -1357,12 +1358,13 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber) } } + ++ft->slots_allocated; + if (m->file_reqchunk) (*m->file_reqchunk)(m, friendnumber, i, ft->requested, length, m->file_reqchunk_userdata); ft->requested += length; - ++ft->slots_allocated; --free_slots; } diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index bd5616a2..4be3a098 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -2586,7 +2586,13 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti if (conn == 0) return 0; - return conn->packets_left; + uint32_t max_packets = CRYPTO_PACKET_BUFFER_SIZE - num_packets_array(&conn->send_array); + + if (conn->packets_left < max_packets) { + return conn->packets_left; + } else { + return max_packets; + } } /* Sends a lossless cryptopacket. -- cgit v1.2.3