changeset 613:2cd71b7c1e8e

Repurpose nn_conn_close() to only close the socket, but not free the connection structure. Add new function nn_conn_free() to do the freeing (also calls nn_conn_close()).
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 20 May 2014 06:50:12 +0300
parents 59588bbf8d55
children 1fc22e8efd26
files main.c network.c network.h
diffstat 3 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Tue May 20 06:20:43 2014 +0300
+++ b/main.c	Tue May 20 06:50:12 2014 +0300
@@ -2226,7 +2226,7 @@
             printMsg(currWin, "Could not get policy probe.\n");
         }
     }
-    nn_conn_close(conn);
+    nn_conn_free(conn);
 #endif
 
     // Okay, now do the proper connection ...
@@ -2352,7 +2352,7 @@
 #endif
 
     th_free(optUserNameEnc);
-    nn_conn_close(conn);
+    nn_conn_free(conn);
     nn_network_close();
 
     THMSG(1, "Connection terminated.\n");
--- a/network.c	Tue May 20 06:20:43 2014 +0300
+++ b/network.c	Tue May 20 06:50:12 2014 +0300
@@ -361,15 +361,15 @@
     return 0;
 
 error:
-    conn->status = NN_CONN_CLOSED;
+    nn_conn_close(conn);
     return -2;
 }
 
 
-void nn_conn_close(nn_conn_t *conn)
+int nn_conn_close(nn_conn_t *conn)
 {
     if (conn == NULL)
-        return;
+        return -1;
 
     if (conn->socket >= 0)
     {
@@ -381,12 +381,20 @@
         conn->socket = -1;
     }
 
-    th_free(conn->host);
-    th_free(conn->proxy.host);
+    conn->status = NN_CONN_CLOSED;
+    return 0;
+}
+
 
-    conn->status = NN_CONN_CLOSED;
-
-    th_free(conn);
+void nn_conn_free(nn_conn_t *conn)
+{
+    if (conn != NULL)
+    {
+        nn_conn_close(conn);
+        th_free(conn->host);
+        th_free(conn->proxy.host);
+        th_free(conn);
+    }
 }
 
 
--- a/network.h	Tue May 20 06:20:43 2014 +0300
+++ b/network.h	Tue May 20 06:50:12 2014 +0300
@@ -109,7 +109,8 @@
 int         nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, int auth_type);
 int         nn_conn_set_proxy_auth_user(nn_conn_t *conn, const char *userid, const char *passwd);
 int         nn_conn_open(nn_conn_t *conn, const int port, const char *host);
-void        nn_conn_close(nn_conn_t *);
+int         nn_conn_close(nn_conn_t *);
+void        nn_conn_free(nn_conn_t *);
 void        nn_conn_reset(nn_conn_t *);
 int         nn_conn_pull(nn_conn_t *);
 BOOL        nn_conn_send_buf(nn_conn_t *, const char *buf, const size_t len);