From 46209d958f9bac05d83a9ebaeb8d11c3cd6c9c41 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 12 Aug 2013 03:10:47 -0400 Subject: [PATCH 1/2] make connection more robust --- testing/toxic/main.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 752453f2..9bf0b9f6 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -157,8 +157,7 @@ int init_connection(void) char line[MAXLINE]; int linecnt = 0; while (fgets(line, sizeof(line), fp) && linecnt < MAXSERVERS) { - int len = strlen(line); - if (len > MINLINE && len < MAXLINE) + if (strlen(line) > MINLINE) strcpy(servers[linecnt++], line); } if (linecnt < 1) { @@ -248,14 +247,21 @@ static void init_windows() static void do_tox() { + static int conn_try = 1; static bool dht_on = false; - if (!dht_on && DHT_isconnected()) { + if (!dht_on && !DHT_isconnected()) { + init_connection(); + if (!(conn_try++ % 100)) + wprintw(prompt->window, "\nAttempting to connect...\n"); + } + else if (!dht_on && DHT_isconnected()) { dht_on = true; wprintw(prompt->window, "\nDHT connected.\n"); } else if (dht_on && !DHT_isconnected()) { dht_on = false; - wprintw(prompt->window, "\nDHT disconnected.\n"); + wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n"); + init_connection(); } doMessenger(); } @@ -440,10 +446,6 @@ int main(int argc, char *argv[]) load_data(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) { attron(COLOR_PAIR(3) | A_BOLD); wprintw(prompt->window, "You passed '-f' without giving an argument.\n" From d87b79d368c3acf24c518f7e0f8e9e976d94b731 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 12 Aug 2013 05:59:08 -0400 Subject: [PATCH 2/2] a little overkill --- testing/toxic/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 9bf0b9f6..3550ac6e 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -247,12 +247,11 @@ static void init_windows() static void do_tox() { - static int conn_try = 1; + static int conn_try = 0; static bool dht_on = false; - if (!dht_on && !DHT_isconnected()) { + if (!dht_on && !DHT_isconnected() && !(conn_try++ % 100)) { init_connection(); - if (!(conn_try++ % 100)) - wprintw(prompt->window, "\nAttempting to connect...\n"); + wprintw(prompt->window, "\nEstablishing connection...\n"); } else if (!dht_on && DHT_isconnected()) { dht_on = true;