summaryrefslogtreecommitdiffstats
path: root/src/socket_wrapper.c
diff options
context:
space:
mode:
authorAnoop C S <anoopcs@redhat.com>2017-08-29 14:34:28 +0530
committerAndreas Schneider <asn@samba.org>2018-05-02 14:23:34 +0200
commite30b080e3188c4498af322c8464569489365d0c3 (patch)
treef625c7beae24897b6ce1dc774c4d0106e7fd19d1 /src/socket_wrapper.c
parent9702a15c2560988fe87119aa45787f935bef66fd (diff)
downloadsocket_wrapper-e30b080e3188c4498af322c8464569489365d0c3.tar.gz
socket_wrapper-e30b080e3188c4498af322c8464569489365d0c3.tar.xz
socket_wrapper-e30b080e3188c4498af322c8464569489365d0c3.zip
swrap: Use swrap_create_socket within swrap_socket
Replace the current logic of socket creation within swrap_socket with more cleaner version using swrap_create_socket. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src/socket_wrapper.c')
-rw-r--r--src/socket_wrapper.c32
1 files changed, 5 insertions, 27 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a6d979b..65b7585 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -2883,10 +2883,8 @@ static int swrap_socket(int family, int type, int protocol)
{
struct socket_info *si = NULL;
struct socket_info _si = { 0 };
- struct socket_info *free_si = NULL;
- struct socket_info_fd *fi = NULL;
int fd;
- int idx;
+ int ret;
int real_type = type;
/*
@@ -3001,35 +2999,15 @@ static int swrap_socket(int family, int type, int protocol)
return -1;
}
- fi = (struct socket_info_fd *)calloc(1, sizeof(struct socket_info_fd));
- if (fi == NULL) {
- errno = ENOMEM;
- return -1;
- }
-
- idx = socket_wrapper_first_free_index();
- if (idx == -1) {
+ ret = swrap_create_socket(si, fd);
+ if (ret == -1) {
return -1;
}
- free_si = swrap_get_socket_info(idx);
-
- first_free = swrap_get_next_free(free_si);
-
- *free_si = _si;
-
- swrap_inc_refcount(free_si);
- swrap_set_next_free(free_si, 0);
-
- fi->fd = fd;
- fi->si_index = idx;
-
- SWRAP_DLIST_ADD(socket_fds, fi);
-
SWRAP_LOG(SWRAP_LOG_TRACE,
"Created %s socket for protocol %s",
- si->family == AF_INET ? "IPv4" : "IPv6",
- si->type == SOCK_DGRAM ? "UDP" : "TCP");
+ family == AF_INET ? "IPv4" : "IPv6",
+ real_type == SOCK_DGRAM ? "UDP" : "TCP");
return fd;
}