chiark / gitweb /
server/peer.c, server/tripe.c: Add `p_unbind' to tear down the UDP sockets.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 19 May 2018 19:49:27 +0000 (20:49 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 25 Jan 2019 12:10:32 +0000 (12:10 +0000)
server/peer.c
server/tripe.c
server/tripe.h

index 5855f2e18fde5a1208b71c0aef5776662b563339..f723cccb4da1ce81a1ef1378739936b82d1d1584 100644 (file)
@@ -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:  ---
index 0252aa691c950cd8e76d4902ae9d8bfce1316104..931c0fca2a304296fb022dd4937d9d87348c2423 100644 (file)
@@ -435,6 +435,7 @@ int main(int argc, char *argv[])
   lp_run();
 
   p_destroyall();
+  p_unbind();
   a_unlisten();
   ps_quit();
   return (0);
index 720da1b5c548c236002f16e4a56e83e837fc32c9..ba47232bd898cfa7ae7b0f0695718d861358ca2c 100644 (file)
@@ -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:  ---