changeset 489:ba48840b8525

Move network initialization/shutdown flag checking to network module.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 27 May 2012 03:31:35 +0300
parents bbe05594f29d
children 9141f13be70c
files main.c network.c
diffstat 2 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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");
 
--- 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 <errno.h>
 
+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;
 }