File transfer fixes and improvements.

This commit is contained in:
irungentoo 2015-03-12 18:01:08 -04:00
parent 7e5ca487b5
commit 0d67598aed
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 15 additions and 7 deletions

View File

@ -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;
}

View File

@ -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.