diff options
author | irungentoo <irungentoo@gmail.com> | 2015-03-12 18:01:08 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-03-12 18:01:08 -0400 |
commit | 0d67598aedda1ca144e9eddaf7cde6efe196df78 (patch) | |
tree | a344f1eec0c9df63765367a773769d3a49f34dc4 | |
parent | 7e5ca487b5ad1b3482c731d7b26e3e8bfee619f4 (diff) |
File transfer fixes and improvements.
-rw-r--r-- | toxcore/Messenger.c | 14 | ||||
-rw-r--r-- | 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, | |||
1196 | return 0; | 1196 | return 0; |
1197 | } | 1197 | } |
1198 | 1198 | ||
1199 | #define MIN_SLOTS_FREE (CRYPTO_MIN_QUEUE_LENGTH / 2) | 1199 | #define MIN_SLOTS_FREE (CRYPTO_MIN_QUEUE_LENGTH / 4) |
1200 | /* Send file data. | 1200 | /* Send file data. |
1201 | * | 1201 | * |
1202 | * return 0 on success | 1202 | * return 0 on success |
@@ -1309,10 +1309,11 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber) | |||
1309 | int free_slots = crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | 1309 | int free_slots = crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, |
1310 | m->friendlist[friendnumber].friendcon_id)); | 1310 | m->friendlist[friendnumber].friendcon_id)); |
1311 | 1311 | ||
1312 | if (free_slots <= MIN_SLOTS_FREE) | 1312 | if (free_slots < MIN_SLOTS_FREE) { |
1313 | return; | 1313 | free_slots = 0; |
1314 | 1314 | } else { | |
1315 | free_slots -= MIN_SLOTS_FREE; | 1315 | free_slots -= MIN_SLOTS_FREE; |
1316 | } | ||
1316 | 1317 | ||
1317 | unsigned int i, num = m->friendlist[friendnumber].num_sending_files; | 1318 | unsigned int i, num = m->friendlist[friendnumber].num_sending_files; |
1318 | 1319 | ||
@@ -1357,12 +1358,13 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber) | |||
1357 | } | 1358 | } |
1358 | } | 1359 | } |
1359 | 1360 | ||
1361 | ++ft->slots_allocated; | ||
1362 | |||
1360 | if (m->file_reqchunk) | 1363 | if (m->file_reqchunk) |
1361 | (*m->file_reqchunk)(m, friendnumber, i, ft->requested, length, m->file_reqchunk_userdata); | 1364 | (*m->file_reqchunk)(m, friendnumber, i, ft->requested, length, m->file_reqchunk_userdata); |
1362 | 1365 | ||
1363 | ft->requested += length; | 1366 | ft->requested += length; |
1364 | 1367 | ||
1365 | ++ft->slots_allocated; | ||
1366 | --free_slots; | 1368 | --free_slots; |
1367 | } | 1369 | } |
1368 | 1370 | ||
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 | |||
2586 | if (conn == 0) | 2586 | if (conn == 0) |
2587 | return 0; | 2587 | return 0; |
2588 | 2588 | ||
2589 | return conn->packets_left; | 2589 | uint32_t max_packets = CRYPTO_PACKET_BUFFER_SIZE - num_packets_array(&conn->send_array); |
2590 | |||
2591 | if (conn->packets_left < max_packets) { | ||
2592 | return conn->packets_left; | ||
2593 | } else { | ||
2594 | return max_packets; | ||
2595 | } | ||
2590 | } | 2596 | } |
2591 | 2597 | ||
2592 | /* Sends a lossless cryptopacket. | 2598 | /* Sends a lossless cryptopacket. |