From: Ian Jackson Date: Fri, 26 Sep 2014 18:26:49 +0000 (+0100) Subject: udp: Break out udp_destroy_socket X-Git-Tag: proposed.polypath.v1~14 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=cc1258e84391946d19c9900f64ad3a39bd31f57f;p=secnet.git udp: Break out udp_destroy_socket polypath is are going to want this. No functional change. Signed-off-by: Ian Jackson --- diff --git a/comm-common.h b/comm-common.h index 9748855..a9445e0 100644 --- a/comm-common.h +++ b/comm-common.h @@ -78,6 +78,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 5a363e0..85de961 100644 --- a/udp.c +++ b/udp.c @@ -174,11 +174,20 @@ 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) { const union iaddr *addr=&us->addr; struct commcommon *cc=&uc->cc; + us->fd=-1; #define FAIL_LG 0, cc->cl.description, &cc->loc, failmsgclass #define FAIL(...) do{ \ @@ -259,10 +268,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