1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-01 16:27:45 +02:00

improve file sending

This commit is contained in:
Jfreegman 2013-11-18 18:52:46 -05:00
parent 1ed6d83ed3
commit 140b8b4690
4 changed files with 20 additions and 11 deletions

View File

@ -115,7 +115,7 @@ static void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num)
memset(friends[i].pending_groupchat, 0, TOX_CLIENT_ID_SIZE);
if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
strcpy((char *) friends[i].name, UNKNOWN_NAME);
strcpy(friends[i].name, (uint8_t *) UNKNOWN_NAME);
friends[i].namelength = strlen(UNKNOWN_NAME) + 1;
} else { /* Enforce toxic's maximum name length */
friends[i].name[TOXIC_MAX_NAME_LENGTH] = '\0';

View File

@ -371,12 +371,15 @@ static void do_file_senders(Tox *m)
if (!file_senders[i].active)
continue;
while (true) {
uint8_t *pathname = file_senders[i].pathname;
uint8_t filenum = file_senders[i].filenum;
uint64_t current_time = (uint64_t)time(NULL);
int friendnum = file_senders[i].friendnum;
uint8_t *pathname = file_senders[i].pathname;
uint8_t filenum = file_senders[i].filenum;
int friendnum = file_senders[i].friendnum;
uint64_t current_time = (uint64_t) time(NULL);
bool piece_sent = false; /* true if at least one file piece is successfuly sent */
int pieces = 0;
while (pieces++ < MAX_PIECES_SEND) {
if (!tox_file_senddata(m, friendnum, filenum, file_senders[i].nextpiece,
file_senders[i].piecelen)) {
@ -391,7 +394,7 @@ static void do_file_senders(Tox *m)
break;
}
file_senders[i].timestamp = current_time;
piece_sent = true;
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1, tox_filedata_size(m,
friendnum), file_senders[i].file);
@ -402,6 +405,9 @@ static void do_file_senders(Tox *m)
break;
}
}
if (piece_sent)
file_senders[i].timestamp = current_time;
}
}

View File

@ -157,7 +157,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
} else {
wattron(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, "%s ", statusbar->nick);
wprintw(statusbar->topline, " %s ", statusbar->nick);
wattroff(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, "[Offline]");
}

View File

@ -15,6 +15,8 @@
#include <tox/tox.h>
#define UNKNOWN_NAME "Unknown"
#define MAX_WINDOWS_NUM 32
#define MAX_FRIENDS_NUM 100
#define MAX_GROUPCHAT_NUM MAX_WINDOWS_NUM - N_DEFAULT_WINS
@ -22,10 +24,10 @@
#define KEY_SIZE_BYTES 32
#define TOXIC_MAX_NAME_LENGTH 30 /* Must be <= TOX_MAX_NAME_LENGTH */
#define N_DEFAULT_WINS 2 /* number of permanent default windows */
#define UNKNOWN_NAME "Unknown"
#define CURS_Y_OFFSET 3 /* y-axis cursor offset for chat contexts */
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#define CURS_Y_OFFSET 3 /* y-axis cursor offset for chat contexts */
/* Curses foreground colours (background is black) */
enum {
@ -102,7 +104,8 @@ typedef struct {
#define MAX_FILES 256
#define FILE_PIECE_SIZE 1024
#define TIMEOUT_FILESENDER 300
#define TIMEOUT_FILESENDER 10
#define MAX_PIECES_SEND 100 /* Max number of pieces to send per file per call to do_file_senders() */
typedef struct {
FILE *file;