mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Don't assume tox_file_send_chunk() is called in the request chunk
callback.
This commit is contained in:
parent
8dc2db2025
commit
7e5ca487b5
|
@ -1078,10 +1078,14 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
|
|||
if (file_sendrequest(m, friendnumber, i, file_type, filesize, filename, filename_length) == 0)
|
||||
return -4;
|
||||
|
||||
m->friendlist[friendnumber].file_sending[i].status = FILESTATUS_NOT_ACCEPTED;
|
||||
m->friendlist[friendnumber].file_sending[i].size = filesize;
|
||||
m->friendlist[friendnumber].file_sending[i].transferred = 0;
|
||||
m->friendlist[friendnumber].file_sending[i].paused = FILE_PAUSE_NOT;
|
||||
struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i];
|
||||
ft->status = FILESTATUS_NOT_ACCEPTED;
|
||||
ft->size = filesize;
|
||||
ft->transferred = 0;
|
||||
ft->requested = 0;
|
||||
ft->slots_allocated = 0;
|
||||
ft->paused = FILE_PAUSE_NOT;
|
||||
|
||||
++m->friendlist[friendnumber].num_sending_files;
|
||||
|
||||
return i;
|
||||
|
@ -1254,6 +1258,10 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
|
|||
//TODO record packet ids to check if other received complete file.
|
||||
ft->transferred += length;
|
||||
|
||||
if (ft->slots_allocated) {
|
||||
--ft->slots_allocated;
|
||||
}
|
||||
|
||||
if (length == 0 || ft->size == ft->transferred) {
|
||||
ft->status = FILESTATUS_FINISHED;
|
||||
ft->last_packet_number = ret;
|
||||
|
@ -1324,6 +1332,13 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber)
|
|||
--m->friendlist[friendnumber].num_sending_files;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: if file is too slow, switch to the next. */
|
||||
if (ft->slots_allocated > free_slots) {
|
||||
free_slots = 0;
|
||||
} else {
|
||||
free_slots -= ft->slots_allocated;
|
||||
}
|
||||
}
|
||||
|
||||
while (ft->status == FILESTATUS_TRANSFERRING && (ft->paused == FILE_PAUSE_NOT)) {
|
||||
|
@ -1333,18 +1348,21 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber)
|
|||
uint16_t length = MAX_CRYPTO_DATA_SIZE - 2;
|
||||
|
||||
if (ft->size) {
|
||||
if (ft->size == ft->transferred) {
|
||||
if (ft->size == ft->requested) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ft->size - ft->transferred < length) {
|
||||
length = ft->size - ft->transferred;
|
||||
if (ft->size - ft->requested < length) {
|
||||
length = ft->size - ft->requested;
|
||||
}
|
||||
}
|
||||
|
||||
if (m->file_reqchunk)
|
||||
(*m->file_reqchunk)(m, friendnumber, i, ft->transferred, length, m->file_reqchunk_userdata);
|
||||
(*m->file_reqchunk)(m, friendnumber, i, ft->requested, length, m->file_reqchunk_userdata);
|
||||
|
||||
ft->requested += length;
|
||||
|
||||
++ft->slots_allocated;
|
||||
--free_slots;
|
||||
}
|
||||
|
||||
|
|
|
@ -131,6 +131,8 @@ struct File_Transfers {
|
|||
uint8_t status; /* 0 == no transfer, 1 = not accepted, 3 = transferring, 4 = broken, 5 = finished */
|
||||
uint8_t paused; /* 0: not paused, 1 = paused by us, 2 = paused by other, 3 = paused by both. */
|
||||
uint32_t last_packet_number; /* number of the last packet sent. */
|
||||
uint64_t requested; /* total data requested by the request chunk callback */
|
||||
unsigned int slots_allocated; /* number of slots allocated to this transfer. */
|
||||
};
|
||||
enum {
|
||||
FILESTATUS_NONE,
|
||||
|
|
Loading…
Reference in New Issue
Block a user