1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 08:13:02 +01:00

get unix time more efficiently

This commit is contained in:
Jfreegman 2014-03-13 23:56:46 -04:00
parent c2d417c78b
commit d29836845c
6 changed files with 35 additions and 19 deletions

View File

@ -221,7 +221,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
file_senders[i].file = file_to_send;
file_senders[i].filenum = (uint8_t) filenum;
file_senders[i].friendnum = self->num;
file_senders[i].timestamp = (uint64_t) time(NULL);
file_senders[i].timestamp = get_unix_time();
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
tox_file_data_size(m, self->num), file_to_send);

View File

@ -71,7 +71,7 @@ void do_file_senders(Tox *m)
uint8_t filenum = file_senders[i].filenum;
int friendnum = file_senders[i].friendnum;
FILE *fp = file_senders[i].file;
uint64_t current_time = (uint64_t) time(NULL);
uint64_t current_time = get_unix_time();
/* If file transfer has timed out kill transfer and send kill control */
if (timed_out(file_senders[i].timestamp, current_time, TIMEOUT_FILESENDER)) {

View File

@ -346,6 +346,8 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
int x2, y2;
getmaxyx(self->window, y2, x2);
uint64_t cur_time = get_unix_time();
bool fix_statuses = x2 != self->x; /* true if window x axis has changed */
wattron(self->window, COLOR_PAIR(CYAN));
@ -454,15 +456,11 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
if (f_selected)
wattron(self->window, A_BOLD);
wprintw(self->window, "%s\n", friends[f].name);
wprintw(self->window, "%s", friends[f].name);
if (f_selected)
wattroff(self->window, A_BOLD);
// wprintw(self->window, "Last seen ");
// uint64_t last_seen = friends[f].last_online;
}
}
}

View File

@ -550,6 +550,7 @@ int main(int argc, char *argv[])
prompt_init_statusbar(prompt, m);
while (true) {
update_unix_time();
do_toxic(m, prompt);
usleep(10000);
}

View File

@ -33,6 +33,27 @@
extern ToxWindow *prompt;
static uint64_t current_unix_time;
void update_unix_time(void)
{
current_unix_time = (uint64_t) time(NULL);
}
uint64_t get_unix_time(void)
{
return current_unix_time;
}
/* Get the current local time */
struct tm *get_time(void)
{
struct tm *timeinfo;
uint64_t t = get_unix_time();
timeinfo = localtime(&t);
return timeinfo;
}
/* XXX: FIX */
unsigned char *hex_string_to_bin(char hex_string[])
{
@ -54,16 +75,6 @@ unsigned char *hex_string_to_bin(char hex_string[])
return val;
}
/* Get the current local time */
struct tm *get_time(void)
{
struct tm *timeinfo;
time_t now;
time(&now);
timeinfo = localtime(&now);
return timeinfo;
}
/* Prints the time to given window */
void print_time(WINDOW *window)
{

View File

@ -26,12 +26,18 @@
/* convert a hex string to binary */
unsigned char *hex_string_to_bin(char hex_string[]);
/* get the current local time */
struct tm *get_time(void);
/* get the current unix time */
uint64_t get_unix_time(void);
/* Prints the time to given window */
void print_time(WINDOW *window);
/* get the current local time */
struct tm *get_time(void);
/* updates current unix time (should be run once per do_toxic loop) */
void update_unix_time(void);
/* Returns 1 if the string is empty, 0 otherwise */
int string_is_empty(char *string);