From bf302d900e1658e664e4e7c05bb2748c4677dfc6 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 19 May 2018 20:49:27 +0100 Subject: [PATCH] server/peer.c, server/tripe.c: Add `p_unbind' to tear down the UDP sockets. Organization: Straylight/Edgeware From: Mark Wooding --- server/peer.c | 26 ++++++++++++++++++++++++++ server/tripe.c | 1 + server/tripe.h | 12 ++++++++++++ 3 files changed, 39 insertions(+) diff --git a/server/peer.c b/server/peer.c index 5855f2e1..f723cccb 100644 --- a/server/peer.c +++ b/server/peer.c @@ -894,6 +894,32 @@ void p_bind(struct addrinfo *ailist) } +/* --- @p_unbind@ --- * + * + * Arguments: --- + * + * Returns: --- + * + * Use: Unbinds the UDP sockets. There must not be any active peers, + * and none can be created until the sockets are rebound. + */ + +void p_unbind(void) +{ + int i; + +#ifndef NDEBUG + { peer_iter it; p_mkiter(&it); assert(!p_next(&it)); } +#endif + + for (i = 0; i < NADDRFAM; i++) { + if (udpsock[i].sf.fd == -1) continue; + sel_rmfile(&udpsock[i].sf); + close(udpsock[i].sf.fd); + udpsock[i].sf.fd = -1; + } +} + /* --- @p_init@ --- * * * Arguments: --- diff --git a/server/tripe.c b/server/tripe.c index 0252aa69..931c0fca 100644 --- a/server/tripe.c +++ b/server/tripe.c @@ -435,6 +435,7 @@ int main(int argc, char *argv[]) lp_run(); p_destroyall(); + p_unbind(); a_unlisten(); ps_quit(); return (0); diff --git a/server/tripe.h b/server/tripe.h index 720da1b5..ba47232b 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -1698,6 +1698,18 @@ extern const addr *p_addr(peer */*p*/); extern void p_bind(struct addrinfo */*ailist*/); +/* --- @p_unbind@ --- * + * + * Arguments: --- + * + * Returns: --- + * + * Use: Unbinds the UDP sockets. There must not be any active peers, + * and none can be created until the sockets are rebound. + */ + +extern void p_unbind(void); + /* --- @p_init@ --- * * * Arguments: --- -- [mdw]