diff options
author | Michael Adam <obnox@samba.org> | 2017-07-13 01:01:57 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2018-05-02 14:23:34 +0200 |
commit | aec1e1207d70f1b2a12a3cb3641691bb99ba7581 (patch) | |
tree | 90fcb399a28c943786a366c6e8c8763330b111bc /src | |
parent | 10b6cc0ff0891b345d7f71dac44be963792ca32d (diff) | |
download | socket_wrapper-aec1e1207d70f1b2a12a3cb3641691bb99ba7581.tar.gz socket_wrapper-aec1e1207d70f1b2a12a3cb3641691bb99ba7581.tar.xz socket_wrapper-aec1e1207d70f1b2a12a3cb3641691bb99ba7581.zip |
swrap: New helper functions to treat next_free
- swrap_get_next_free
- swrap_set_next_free
to avoid accessing socket_info.next_free directly
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/socket_wrapper.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index b25a33a..61f0f6e 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -1213,6 +1213,16 @@ static void swrap_dec_refcount(struct socket_info *si) si->refcount -= 1; } +static int swrap_get_next_free(struct socket_info *si) +{ + return si->next_free; +} + +static void swrap_set_next_free(struct socket_info *si, int next_free) +{ + si->next_free = next_free; +} + static const char *socket_wrapper_dir(void) { const char *s = getenv("SOCKET_WRAPPER_DIR"); @@ -1315,10 +1325,10 @@ static void socket_wrapper_init_sockets(void) first_free = 0; for (i = 0; i < max_sockets; i++) { - sockets[i].next_free = i+1; + swrap_set_next_free(&sockets[i], i+1); } - sockets[max_sockets-1].next_free = -1; + swrap_set_next_free(&sockets[max_sockets-1], -1); } bool socket_wrapper_enabled(void) @@ -1361,9 +1371,9 @@ static int socket_wrapper_first_free_index(void) return -1; } - next_free = sockets[first_free].next_free; + next_free = swrap_get_next_free(&sockets[first_free]); ZERO_STRUCT(sockets[first_free]); - sockets[first_free].next_free = next_free; + swrap_set_next_free(&sockets[first_free], next_free); return first_free; } @@ -1889,7 +1899,7 @@ static void swrap_remove_stale(int fd) unlink(si->un_addr.sun_path); } - si->next_free = first_free; + swrap_set_next_free(si, first_free); first_free = si_index; } @@ -2939,8 +2949,8 @@ static int swrap_socket(int family, int type, int protocol) * zeroed the si, so we are starting from refcount 0 */ swrap_inc_refcount(si); - first_free = si->next_free; - si->next_free = 0; + first_free = swrap_get_next_free(si); + swrap_set_next_free(si, 0); fi->fd = fd; fi->si_index = idx; @@ -3169,8 +3179,8 @@ static int swrap_accept(int s, memcpy(&child_si->myname.sa.ss, &in_my_addr.sa.ss, in_my_addr.sa_socklen); swrap_inc_refcount(child_si); - first_free = child_si->next_free; - child_si->next_free = 0; + first_free = swrap_get_next_free(child_si); + swrap_set_next_free(child_si, 0); child_fi->si_index = idx; @@ -5701,7 +5711,7 @@ static int swrap_close(int fd) unlink(si->un_addr.sun_path); } - si->next_free = first_free; + swrap_set_next_free(si, first_free); first_free = si_index; return ret; |