udp: Break out udp_destroy_socket
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 26 Sep 2014 18:26:49 +0000 (19:26 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 8 Oct 2014 17:25:18 +0000 (18:25 +0100)
polypath is are going to want this.  No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
comm-common.h
udp.c

index ed6a86b..baeb24e 100644 (file)
@@ -87,6 +87,9 @@ bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
                       int failmsgclass);
   /* Fills in us->fd.  Logs any errors with lg_[v]perror. */
 
+void udp_destroy_socket(struct udpcommon *uc, struct udpsock *us);
+  /* Idempotent.  No errors are possible. */
+
 void udp_socks_register(struct udpcommon *uc, struct udpsocks *socks);
 void udp_socks_deregister(struct udpcommon *uc, struct udpsocks *socks);
 
diff --git a/udp.c b/udp.c
index 838fd51..30bf73f 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -183,6 +183,14 @@ static bool_t udp_sendmsg(void *commst, struct buffer_if *buf,
     return True;
 }
 
+void udp_destroy_socket(struct udpcommon *uc, struct udpsock *us)
+{
+    if (us->fd>=0) {
+       close(us->fd);
+       us->fd=-1;
+    }
+}
+
 bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
                       int failmsgclass)
 {
@@ -276,10 +284,7 @@ bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
     return True;
 
 failed:
-    if (us->fd>=0) {
-       close(us->fd);
-       us->fd=-1;
-    }
+    udp_destroy_socket(uc,us);
     return False;
 
 #undef FAIL