aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2017-07-15 14:40:07 +0530
committerAndreas Schneider <asn@samba.org>2018-05-02 14:23:34 +0200
commit327cb50d8370833bad9d260b9dc8f5c70fb5e2ce (patch)
treefa479f79da827505a6dc2f4d51c1fb618b152ac0 /src
parentb1728e6754a0b864f70653fea8d91aa8f57ada6e (diff)
downloadsocket_wrapper-327cb50d8370833bad9d260b9dc8f5c70fb5e2ce.tar.gz
socket_wrapper-327cb50d8370833bad9d260b9dc8f5c70fb5e2ce.tar.xz
socket_wrapper-327cb50d8370833bad9d260b9dc8f5c70fb5e2ce.zip
swrap: Internal reorganization of core socket_info structures
The change basically splits socket_info structure into two structures, namely, - socket_info: to store the core information corresponding to a socket entry. - socket_info_container: wrapping structure to hold the socket_info data as well as metadata(currently refcount and next_free). Pair-Programmed-With: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src')
-rw-r--r--src/socket_wrapper.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 4db4bb9..8daa75e 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -185,6 +185,9 @@ enum swrap_dbglvl_e {
# define SWRAP_UNLOCK_ALL \
SWRAP_UNLOCK(libc_symbol_binding); \
+#define SOCKET_INFO_CONTAINER(si) \
+ (struct socket_info_container *)(si)
+
#define SWRAP_DLIST_ADD(list,item) do { \
if (!(list)) { \
(item)->prev = NULL; \
@@ -301,10 +304,6 @@ int first_free;
struct socket_info
{
- unsigned int refcount;
-
- int next_free;
-
int family;
int type;
int protocol;
@@ -329,7 +328,14 @@ struct socket_info
} io;
};
-static struct socket_info *sockets;
+struct socket_info_container
+{
+ struct socket_info info;
+ unsigned int refcount;
+ int next_free;
+};
+
+static struct socket_info_container *sockets;
static size_t max_sockets = 0;
/*
@@ -1200,27 +1206,35 @@ static struct socket_info *swrap_get_socket_info(int si_index)
static int swrap_get_refcount(struct socket_info *si)
{
- return si->refcount;
+ struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
+ return sic->refcount;
}
static void swrap_inc_refcount(struct socket_info *si)
{
- si->refcount += 1;
+ struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
+
+ sic->refcount += 1;
}
static void swrap_dec_refcount(struct socket_info *si)
{
- si->refcount -= 1;
+ struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
+
+ sic->refcount -= 1;
}
static int swrap_get_next_free(struct socket_info *si)
{
- return si->next_free;
+ struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
+
+ return sic->next_free;
}
static void swrap_set_next_free(struct socket_info *si, int next_free)
{
- si->next_free = next_free;
+ struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
+ sic->next_free = next_free;
}
static const char *socket_wrapper_dir(void)
@@ -1313,8 +1327,8 @@ static void socket_wrapper_init_sockets(void)
max_sockets = socket_wrapper_max_sockets();
- sockets = (struct socket_info *)calloc(max_sockets,
- sizeof(struct socket_info));
+ sockets = (struct socket_info_container *)calloc(max_sockets,
+ sizeof(struct socket_info_container));
if (sockets == NULL) {
SWRAP_LOG(SWRAP_LOG_ERROR,
@@ -1325,10 +1339,11 @@ static void socket_wrapper_init_sockets(void)
first_free = 0;
for (i = 0; i < max_sockets; i++) {
- swrap_set_next_free(&sockets[i], i+1);
+ swrap_set_next_free(&sockets[i].info, i+1);
}
- swrap_set_next_free(&sockets[max_sockets-1], -1);
+ /* mark the end of the free list */
+ swrap_set_next_free(&sockets[max_sockets-1].info, -1);
}
bool socket_wrapper_enabled(void)