updataes.
[silc.git] / lib / silccore / silcsockconn.c
index ebc2812e9a62caf1646f28ea9c1ecd809ad8ad34..3b5af11863b2af47aedecd6286bb3352a63c2469 100644 (file)
@@ -39,13 +39,17 @@ void silc_socket_alloc(int sock, SilcSocketType type, void *user_data,
   (*new_socket)->flags = 0;
   (*new_socket)->inbuf = NULL;
   (*new_socket)->outbuf = NULL;
+  (*new_socket)->users++;
 }
 
 /* Free's the Socket connection object. */
 
 void silc_socket_free(SilcSocketConnection sock)
 {
-  if (sock) {
+  sock->users--;
+  SILC_LOG_DEBUG(("Socket %p refcnt %d->%d", sock, sock->users + 1,
+                 sock->users));
+  if (sock->users < 1) {
     silc_buffer_free(sock->inbuf);
     silc_buffer_free(sock->outbuf);
     if (sock->hb) {
@@ -59,6 +63,16 @@ void silc_socket_free(SilcSocketConnection sock)
   }
 }
 
+/* Increase the reference counter. */
+
+SilcSocketConnection silc_socket_dup(SilcSocketConnection sock)
+{
+  sock->users++;
+  SILC_LOG_DEBUG(("Socket %p refcnt %d->%d", sock, sock->users - 1,
+                 sock->users));
+  return sock;
+}
+
 /* Internal timeout callback to perform heartbeat */
 
 SILC_TASK_CALLBACK(silc_socket_heartbeat)