# HG changeset patch # User Matti Hamalainen # Date 1338078695 -10800 # Node ID ba48840b8525896983ee4e49e66903f1286cd372 # Parent bbe05594f29dae37430f9f82b6a700b0dc017b55 Move network initialization/shutdown flag checking to network module. diff -r bbe05594f29d -r ba48840b8525 main.c --- a/main.c Sat May 26 17:49:06 2012 +0300 +++ b/main.c Sun May 27 03:31:35 2012 +0300 @@ -1345,7 +1345,6 @@ BOOL argsOK, isError = FALSE, exitProg = FALSE, colorSet = FALSE, - networkInit = FALSE, insertMode = TRUE, firstUpdate = TRUE; time_t prevTime; @@ -1482,8 +1481,6 @@ THERR("Could not initialize network subsystem.\n"); goto err_exit; } - else - networkInit = TRUE; // Initialize curses windowing if (!optDaemon && !nnwin_init(SET_DELAY)) @@ -2003,8 +2000,6 @@ for (index = 0; index <= SET_MAX_HISTORY; index++) nn_editbuf_free(histBuf[index]); - nnwin_shutdown(); - #ifdef __WIN32 if (errorMessages) { @@ -2015,6 +2010,7 @@ } #endif + nnwin_shutdown(); #ifndef __WIN32 if (errorMessages) @@ -2022,11 +2018,8 @@ #endif th_free(optUserNameEnc); - nn_conn_close(conn); - - if (networkInit) - nn_network_close(); + nn_network_close(); THMSG(1, "Connection terminated.\n"); diff -r bbe05594f29d -r ba48840b8525 network.c --- a/network.c Sat May 26 17:49:06 2012 +0300 +++ b/network.c Sun May 27 03:31:35 2012 +0300 @@ -6,6 +6,7 @@ #include "network.h" #include +static BOOL nn_network_inited = FALSE; static const char *nn_proxy_types[] = { @@ -461,15 +462,22 @@ return FALSE; } #endif + + nn_network_inited = TRUE; return TRUE; } void nn_network_close(void) { + if (nn_network_inited) + { #ifdef __WIN32 - WSACleanup(); + WSACleanup(); #endif + } + + nn_network_inited = FALSE; }