From 5d65f87e6cdedc294f391b38f75f4b9e6913bcd8 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 19 Feb 2001 14:49:45 +0000 Subject: [PATCH] updataes. --- lib/silccore/silcsockconn.c | 16 +++++++++++++++- lib/silccore/silcsockconn.h | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/silccore/silcsockconn.c b/lib/silccore/silcsockconn.c index ebc2812e..3b5af118 100644 --- a/lib/silccore/silcsockconn.c +++ b/lib/silccore/silcsockconn.c @@ -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) diff --git a/lib/silccore/silcsockconn.h b/lib/silccore/silcsockconn.h index 9b190d1b..8a7967eb 100644 --- a/lib/silccore/silcsockconn.h +++ b/lib/silccore/silcsockconn.h @@ -86,6 +86,11 @@ typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock, indicate several different status that can affect the use of the socket object. + int users + + Reference counter. When allocated it is set to one (1) and it won't + be freed until it hits zero (0). + char *hostname char *ip unsigned short port @@ -112,6 +117,7 @@ struct SilcSocketConnectionStruct { void *user_data; SilcProtocol protocol; unsigned int flags; + int users; char *hostname; char *ip; @@ -160,6 +166,7 @@ struct SilcSocketConnectionHB { void silc_socket_alloc(int sock, SilcSocketType type, void *user_data, SilcSocketConnection *new_socket); void silc_socket_free(SilcSocketConnection sock); +SilcSocketConnection silc_socket_dup(SilcSocketConnection sock); void silc_socket_set_heartbeat(SilcSocketConnection sock, unsigned long heartbeat, void *hb_context, -- 2.24.0