mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added position parameter to tox_file_send_chunk().
This is done so that the function now has the same parameters as the request chunk callback.
This commit is contained in:
parent
28d707662b
commit
8dc2db2025
|
@ -169,7 +169,7 @@ void tox_file_request_chunk(Tox *tox, uint32_t friend_number, uint32_t file_numb
|
|||
uint8_t f_data[length];
|
||||
memset(f_data, sending_num, length);
|
||||
|
||||
if (tox_file_send_chunk(tox, friend_number, file_number, f_data, length, &error)) {
|
||||
if (tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error)) {
|
||||
++sending_num;
|
||||
sending_pos += length;
|
||||
} else {
|
||||
|
@ -296,9 +296,14 @@ END_TEST
|
|||
START_TEST(test_few_clients)
|
||||
{
|
||||
long long unsigned int con_time, cur_time = time(NULL);
|
||||
Tox *tox1 = tox_new(0, 0, 0, 0);
|
||||
Tox *tox2 = tox_new(0, 0, 0, 0);
|
||||
Tox *tox3 = tox_new(0, 0, 0, 0);
|
||||
TOX_ERR_NEW t_n_error;
|
||||
Tox *tox1 = tox_new(0, 0, 0, &t_n_error);
|
||||
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
|
||||
Tox *tox2 = tox_new(0, 0, 0, &t_n_error);
|
||||
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
|
||||
Tox *tox3 = tox_new(0, 0, 0, &t_n_error);
|
||||
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
|
||||
|
||||
ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
|
||||
|
||||
{
|
||||
|
|
|
@ -141,7 +141,7 @@ void tox_file_request_chunk(Tox *tox, uint32_t friend_number, uint32_t file_numb
|
|||
fseek(file_senders[i].file, position, SEEK_SET);
|
||||
uint8_t data[length];
|
||||
int len = fread(data, 1, length, file_senders[i].file);
|
||||
tox_file_send_chunk(tox, friend_number, file_number, data, len, 0);
|
||||
tox_file_send_chunk(tox, friend_number, file_number, position, data, len, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ void tox_file_request_chunk(Tox *tox, uint32_t friend_number, uint32_t file_numb
|
|||
fseek(file_senders[i].file, position, SEEK_SET);
|
||||
uint8_t data[length];
|
||||
int len = fread(data, 1, length, file_senders[i].file);
|
||||
tox_file_send_chunk(tox, friend_number, file_number, data, len, 0);
|
||||
tox_file_send_chunk(tox, friend_number, file_number, position, data, len, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1202,8 +1202,10 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
|
|||
* return -4 if file transfer not transferring.
|
||||
* return -5 if trying to send too much data.
|
||||
* return -6 if packet queue full.
|
||||
* return -7 if wrong position.
|
||||
*/
|
||||
int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, const uint8_t *data, uint16_t length)
|
||||
int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
|
||||
uint16_t length)
|
||||
{
|
||||
if (friend_not_valid(m, friendnumber))
|
||||
return -1;
|
||||
|
@ -1231,6 +1233,10 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, con
|
|||
}
|
||||
}
|
||||
|
||||
if (position != ft->transferred) {
|
||||
return -7;
|
||||
}
|
||||
|
||||
/* Prevent file sending from filling up the entire buffer preventing messages from being sent. TODO: remove */
|
||||
if (crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||
m->friendlist[friendnumber].friendcon_id)) < MIN_SLOTS_FREE)
|
||||
|
|
|
@ -637,8 +637,10 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
|
|||
* return -4 if file transfer not transferring.
|
||||
* return -5 if trying to send too much data.
|
||||
* return -6 if packet queue full.
|
||||
* return -7 if wrong position.
|
||||
*/
|
||||
int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, const uint8_t *data, uint16_t length);
|
||||
int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
|
||||
uint16_t length);
|
||||
|
||||
/* Give the number of bytes left to be sent/received.
|
||||
*
|
||||
|
|
|
@ -932,11 +932,11 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_KIND kind, uin
|
|||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, const uint8_t *data, size_t length,
|
||||
TOX_ERR_FILE_SEND_CHUNK *error)
|
||||
bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data,
|
||||
size_t length, TOX_ERR_FILE_SEND_CHUNK *error)
|
||||
{
|
||||
Messenger *m = tox;
|
||||
int ret = file_data(m, friend_number, file_number, data, length);
|
||||
int ret = file_data(m, friend_number, file_number, position, data, length);
|
||||
|
||||
if (ret == 0) {
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_CHUNK_OK);
|
||||
|
@ -967,6 +967,10 @@ bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number,
|
|||
case -6:
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_CHUNK_QUEUE_FULL);
|
||||
return 0;
|
||||
|
||||
case -7:
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_CHUNK_WRONG_POSITION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* can't happen */
|
||||
|
|
|
@ -1654,7 +1654,11 @@ typedef enum TOX_ERR_FILE_SEND_CHUNK {
|
|||
/**
|
||||
* Packet queue is full.
|
||||
*/
|
||||
TOX_ERR_FILE_SEND_CHUNK_QUEUE_FULL
|
||||
TOX_ERR_FILE_SEND_CHUNK_QUEUE_FULL,
|
||||
/**
|
||||
* Position parameter was wrong.
|
||||
*/
|
||||
TOX_ERR_FILE_SEND_CHUNK_WRONG_POSITION
|
||||
} TOX_ERR_FILE_SEND_CHUNK;
|
||||
|
||||
/**
|
||||
|
@ -1670,8 +1674,8 @@ typedef enum TOX_ERR_FILE_SEND_CHUNK {
|
|||
*
|
||||
* @return true on success.
|
||||
*/
|
||||
bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, const uint8_t *data, size_t length,
|
||||
TOX_ERR_FILE_SEND_CHUNK *error);
|
||||
bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data,
|
||||
size_t length, TOX_ERR_FILE_SEND_CHUNK *error);
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user