server/: Split peer and admin initialization into smaller pieces.
[tripe] / server / peer.c
index d415567..27ac4a7 100644 (file)
@@ -816,7 +816,7 @@ void p_setifname(peer *p, const char *name)
 
 const addr *p_addr(peer *p) { return (&p->spec.sa); }
 
-/* --- @p_init@ --- *
+/* --- @p_bind@ --- *
  *
  * Arguments:  @struct addrinfo *ailist@ = addresses to bind to
  *
@@ -825,7 +825,7 @@ const addr *p_addr(peer *p) { return (&p->spec.sa); }
  * Use:                Initializes the peer system; creates the socket.
  */
 
-void p_init(struct addrinfo *ailist)
+void p_bind(struct addrinfo *ailist)
 {
   int fd;
   int len = PKBUFSZ;
@@ -871,35 +871,33 @@ void p_init(struct addrinfo *ailist)
     sel_initfile(&sel, &udpsock[i].sf, fd, SEL_READ, p_read, 0);
     sel_addfile(&udpsock[i].sf);
     T( trace(T_PEER, "peer: created %s socket", aftab[i].name); )
-    if (!port) {
+    if (port)
+      udpsock[i].port = port;
+    else {
       sz = sizeof(a);
       if (getsockname(fd, &a.sa, &sz)) {
        die(EXIT_FAILURE, "failed to read local socket address: %s",
            strerror(errno));
       }
-      lastport = getport(&a);
+      udpsock[i].port = lastport = getport(&a);
     }
   }
 
-  sym_create(&byname);
-  am_create(&byaddr);
 }
 
-/* --- @p_port@ --- *
+/* --- @p_init@ --- *
+ *
+ * Arguments:  ---
  *
- * Arguments:  @int i@ = address family index to retrieve
+ * Returns:    ---
  *
- * Returns:    Port number used for socket.
+ * Use:                Initializes the peer system.
  */
 
-unsigned p_port(int i)
+void p_init(void)
 {
-  addr a;
-  socklen_t sz = sizeof(addr);
-
-  if (getsockname(udpsock[i].sf.fd, &a.sa, &sz))
-    die(EXIT_FAILURE, "couldn't read port number: %s", strerror(errno));
-  return (getport(&a));
+  sym_create(&byname);
+  am_create(&byaddr);
 }
 
 /* --- @p_keepalive@ --- *