1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-06 03:07:55 +02:00

Merge pull request #437 from JFreegman/master

make connection more robust for toxic
This commit is contained in:
irungentoo 2013-08-12 08:13:33 -07:00
commit 420858cb6f

17
main.c
View File

@ -159,8 +159,7 @@ int init_connection(void)
char line[MAXLINE]; char line[MAXLINE];
int linecnt = 0; int linecnt = 0;
while (fgets(line, sizeof(line), fp) && linecnt < MAXSERVERS) { while (fgets(line, sizeof(line), fp) && linecnt < MAXSERVERS) {
int len = strlen(line); if (strlen(line) > MINLINE)
if (len > MINLINE && len < MAXLINE)
strcpy(servers[linecnt++], line); strcpy(servers[linecnt++], line);
} }
if (linecnt < 1) { if (linecnt < 1) {
@ -250,14 +249,20 @@ static void init_windows()
static void do_tox() static void do_tox()
{ {
static int conn_try = 0;
static bool dht_on = false; static bool dht_on = false;
if (!dht_on && DHT_isconnected()) { if (!dht_on && !DHT_isconnected() && !(conn_try++ % 100)) {
init_connection();
wprintw(prompt->window, "\nEstablishing connection...\n");
}
else if (!dht_on && DHT_isconnected()) {
dht_on = true; dht_on = true;
wprintw(prompt->window, "\nDHT connected.\n"); wprintw(prompt->window, "\nDHT connected.\n");
} }
else if (dht_on && !DHT_isconnected()) { else if (dht_on && !DHT_isconnected()) {
dht_on = false; dht_on = false;
wprintw(prompt->window, "\nDHT disconnected.\n"); wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
init_connection();
} }
doMessenger(m); doMessenger(m);
} }
@ -442,10 +447,6 @@ int main(int argc, char *argv[])
load_data(DATA_FILE); load_data(DATA_FILE);
free(DATA_FILE); free(DATA_FILE);
int connected = init_connection();
if (connected != 0)
wprintw(prompt->window, "Auto-connect failed (error code %d)\n", connected);
if (f_flag == -1) { if (f_flag == -1) {
attron(COLOR_PAIR(3) | A_BOLD); attron(COLOR_PAIR(3) | A_BOLD);
wprintw(prompt->window, "You passed '-f' without giving an argument.\n" wprintw(prompt->window, "You passed '-f' without giving an argument.\n"