Added function to get the piece size for sending files.

This commit is contained in:
irungentoo 2013-10-08 18:55:35 -04:00
parent 3658c372a4
commit 4aa507b664
4 changed files with 28 additions and 6 deletions

View File

@ -91,7 +91,8 @@ void send_filesenders(Tox *m)
file_senders[i].piecelength))
break;
file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, 1000, file_senders[i].file);
file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_filedata_size(m, file_senders[i].friendnum),
file_senders[i].file);
if (file_senders[i].piecelength == 0) {
fclose(file_senders[i].file);
@ -121,7 +122,8 @@ int add_filesender(Tox *m, uint16_t friendnum, char *filename)
return -1;
file_senders[numfilesenders].file = tempfile;
file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, 1000,
file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, tox_filedata_size(m,
file_senders[numfilesenders].friendnum),
file_senders[numfilesenders].file);
file_senders[numfilesenders].friendnum = friendnum;
file_senders[numfilesenders].filenumber = filenum;

View File

@ -66,7 +66,8 @@ void send_filesenders(Tox *m)
file_senders[i].piecelength))
break;
file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, 1000, file_senders[i].file);
file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_filedata_size(m, file_senders[i].friendnum),
file_senders[i].file);
if (file_senders[i].piecelength == 0) {
fclose(file_senders[i].file);
@ -95,7 +96,8 @@ int add_filesender(Tox *m, uint16_t friendnum, char *filename)
return -1;
file_senders[numfilesenders].file = tempfile;
file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, 1000,
file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, tox_filedata_size(m,
file_senders[numfilesenders].friendnum),
file_senders[numfilesenders].file);
file_senders[numfilesenders].friendnum = friendnum;
file_senders[numfilesenders].filenumber = filenum;

View File

@ -359,7 +359,7 @@ void tox_callback_statusmessage(Tox *tox, void (*function)(Messenger *tox, int,
void tox_callback_userstatus(Tox *tox, void (*_function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata)
{
Messenger *m = tox;
typedef void (*function_type)(Messenger *, int, USERSTATUS, void *);
typedef void (*function_type)(Messenger *, int, USERSTATUS, void *);
function_type function = (function_type)_function;
m_callback_userstatus(m, function, userdata);
}
@ -551,6 +551,17 @@ int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *d
Messenger *m = tox;
return file_data(m, friendnumber, filenumber, data, length);
}
/* Returns the recommended/maximum size of the filedata you send with tox_file_senddata()
*
* return size on success
* return 0 on failure (currently will never return 0)
*/
int tox_filedata_size(Tox *tox, int friendnumber)
{
return MAX_DATA_SIZE - crypto_box_MACBYTES - 3;
}
/* Give the number of bytes left to be sent/received.
*
* send_receive is 0 if we want the sending files, 1 if we want the receiving.

View File

@ -435,7 +435,7 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t
* HOW TO SEND FILES CORRECTLY:
* 1. Use tox_new_filesender(...) to create a new file sender.
* 2. Wait for the callback set with tox_callback_file_control(...) to be called with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT
* 3. Send the data with tox_file_senddata(...)
* 3. Send the data with tox_file_senddata(...) with chunk size tox_filedata_size(...)
* 4. When sending is done, send a tox_file_sendcontrol(...) with send_receive = 0 and message_id = TOX_FILECONTROL_FINISHED
*
* HOW TO RECEIVE FILES CORRECTLY:
@ -508,6 +508,13 @@ int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8
*/
int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length);
/* Returns the recommended/maximum size of the filedata you send with tox_file_senddata()
*
* return size on success
* return 0 on failure (currently will never return 0)
*/
int tox_filedata_size(Tox *tox, int friendnumber);
/* Give the number of bytes left to be sent/received.
*
* send_receive is 0 if we want the sending files, 1 if we want the receiving.