When friend goes offline all his file transfers get removed.

This is now documented in the API.

Ported programs in testing/ to this behaviour.
This commit is contained in:
irungentoo 2015-03-18 14:39:52 -04:00
parent 5b7cbc8956
commit b9e747fd50
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 35 additions and 1 deletions

View File

@ -1195,6 +1195,22 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p
fclose(pFile);
}
void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata)
{
if (status)
printf("\nOther went online.\n");
else {
printf("\nOther went offline.\n");
unsigned int i;
for (i = 0; i < NUM_FILE_SENDERS; ++i)
if (file_senders[i].file != 0 && file_senders[i].friendnum == friend_number) {
fclose(file_senders[i].file);
file_senders[i].file = 0;
}
}
}
char timeout_getch(Tox *m)
{
char c;
@ -1274,6 +1290,7 @@ int main(int argc, char *argv[])
tox_callback_file_recv(m, file_request_accept, NULL);
tox_callback_file_request_chunk(m, tox_file_request_chunk, NULL);
tox_callback_group_namelist_change(m, print_groupnamelistchange, NULL);
tox_callback_friend_connection_status(tox, print_online, NULL);
initscr();
noecho();

View File

@ -211,8 +211,22 @@ void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *
{
if (status)
printf("\nOther went online.\n");
else
else {
printf("\nOther went offline.\n");
unsigned int i;
for (i = 0; i < NUM_FILE_SENDERS; ++i) {
if (file_senders[i].file != 0) {
fclose(file_senders[i].file);
file_senders[i].file = 0;
}
if (file_recv[i].file != 0) {
fclose(file_recv[i].file);
file_recv[i].file = 0;
}
}
}
}
int main(int argc, char *argv[])

View File

@ -1655,6 +1655,9 @@ typedef enum TOX_ERR_FILE_SEND {
* File transmission occurs in chunks, which are requested through the
* `file_request_chunk` event.
*
* When a friend goes offline, all file transfers associated with the friend are
* purged from core.
*
* If the file contents change during a transfer, the behaviour is unspecified
* in general. What will actually happen depends on the mode in which the file
* was modified and how the client determines the file size.