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

restructure main toxic loop

This commit is contained in:
Jfreegman 2014-02-21 00:45:29 -05:00
parent 69c467fa5f
commit d9142eb355

View File

@ -232,7 +232,7 @@ int init_connection(Tox *m)
return 5; return 5;
} }
static void do_tox(Tox *m, ToxWindow *prompt) static void do_connection(Tox *m, ToxWindow *prompt)
{ {
static int conn_try = 0; static int conn_try = 0;
static int conn_err = 0; static int conn_err = 0;
@ -258,8 +258,6 @@ static void do_tox(Tox *m, ToxWindow *prompt)
prep_prompt_win(); prep_prompt_win();
wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n"); wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
} }
tox_do(m);
} }
int f_loadfromfile; int f_loadfromfile;
@ -405,8 +403,6 @@ static void do_file_senders(Tox *m)
continue; continue;
} }
int pieces = 0;
while (true) { while (true) {
if (tox_file_send_data(m, friendnum, filenum, file_senders[i].nextpiece, if (tox_file_send_data(m, friendnum, filenum, file_senders[i].nextpiece,
file_senders[i].piecelen) == -1) file_senders[i].piecelen) == -1)
@ -432,21 +428,17 @@ static void do_file_senders(Tox *m)
} }
} }
/* This should only be called on exit */ void exit_toxic(Tox *m)
static void close_file_transfers(Tox *m)
{ {
store_data(m, DATA_FILE);
int i; int i;
for (i = 0; i < max_file_senders_index; ++i) { for (i = 0; i < max_file_senders_index; ++i) {
if (file_senders[i].active) if (file_senders[i].active)
fclose(file_senders[i].file); fclose(file_senders[i].file);
} }
}
void exit_toxic(Tox *m)
{
store_data(m, DATA_FILE);
close_file_transfers(m);
free(DATA_FILE); free(DATA_FILE);
free(SRVLIST_FILE); free(SRVLIST_FILE);
free(prompt->stb); free(prompt->stb);
@ -456,6 +448,16 @@ void exit_toxic(Tox *m)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
static void do_toxic(Tox *m, ToxWindow *prompt)
{
do_connection(m, prompt);
do_file_senders(m);
draw_active_window(m);
/* main toxcore loop */
tox_do(m);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *user_config_dir = get_user_config_dir(); char *user_config_dir = get_user_config_dir();
@ -549,12 +551,8 @@ int main(int argc, char *argv[])
prompt_init_statusbar(prompt, m); prompt_init_statusbar(prompt, m);
sort_friendlist_index(m); sort_friendlist_index(m);
while (true) { while (true)
do_tox(m, prompt); do_toxic(m, prompt);
do_file_senders(m);
draw_active_window(m);
}
exit_toxic(m);
return 0; return 0;
} }