(*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) {
}
}
+/* 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)
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
void *user_data;
SilcProtocol protocol;
unsigned int flags;
+ int users;
char *hostname;
char *ip;
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,