summaryrefslogtreecommitdiff
path: root/source4/libcli/raw/clisocket.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/libcli/raw/clisocket.c')
-rw-r--r--source4/libcli/raw/clisocket.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c
index 8481bc73e2..37188f4e77 100644
--- a/source4/libcli/raw/clisocket.c
+++ b/source4/libcli/raw/clisocket.c
@@ -21,6 +21,18 @@
#include "includes.h"
+/*
+ destroy a socket
+ */
+static int sock_destructor(void *ptr)
+{
+ struct smbcli_socket *sock = ptr;
+ if (sock->fd != -1) {
+ close(sock->fd);
+ sock->fd = -1;
+ }
+ return 0;
+}
/*
create a smbcli_socket context
@@ -37,11 +49,13 @@ struct smbcli_socket *smbcli_sock_init(void)
ZERO_STRUCTP(sock);
sock->fd = -1;
sock->port = 0;
+
/* 20 second default timeout */
sock->timeout = 20000;
-
sock->hostname = NULL;
+ talloc_set_destructor(sock, sock_destructor);
+
return sock;
}
@@ -97,18 +111,6 @@ void smbcli_sock_dead(struct smbcli_socket *sock)
}
/****************************************************************************
- reduce socket reference count - if it becomes zero then close
-****************************************************************************/
-void smbcli_sock_close(struct smbcli_socket *sock)
-{
- sock->reference_count--;
- if (sock->reference_count <= 0) {
- smbcli_sock_dead(sock);
- talloc_free(sock);
- }
-}
-
-/****************************************************************************
Set socket options on a open connection.
****************************************************************************/
void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options)