diff network.c @ 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 019a54b07f60
children 1fc22e8efd26
line wrap: on
line diff
--- 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);
+    }
 }