Whoops, missed that. Another patch attached. On Fri, Jan 25, 2019 at 6:49 AM Rob Landley <[email protected]> wrote:
> On 1/24/19 7:38 PM, Josh Gao via Toybox wrote: > > Set SO_REUSEADDR when listening so that we can immediately reuse ports > > that are no longer being listened upon, instead of having to wait 60 > > seconds for the socket to be shutdown after being closed (even on > > localhost!). > > This only applies to the else fork when they didn't specify TT.s. Was that > intentional? > > Rob >
From b438cf7fe5b88ce085ab745a7d91690be7325ddb Mon Sep 17 00:00:00 2001 From: Josh Gao <[email protected]> Date: Fri, 25 Jan 2019 12:50:58 -0800 Subject: [PATCH] xconnbind: allow immediate reuse of ports. --- lib/net.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/net.c b/lib/net.c index 346d17e9..83baed1a 100644 --- a/lib/net.c +++ b/lib/net.c @@ -42,9 +42,20 @@ int xconnbind(struct addrinfo *ai_arg, int dobind) // Try all the returned addresses. Report errors if last entry can't connect. for (ai = ai_arg; ai; ai = ai->ai_next) { + int rc; + fd = (ai->ai_next ? socket : xsocket)(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (!(dobind ? bind : connect)(fd, ai->ai_addr, ai->ai_addrlen)) break; + + if (dobind) { + int val = 1; + xsetsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); + rc = bind(fd, ai->ai_addr, ai->ai_addrlen); + } else { + rc = connect(fd, ai->ai_addr, ai->ai_addrlen); + } + + if (!rc) break; else if (!ai->ai_next) perror_exit_raw(dobind ? "bind" : "connect"); close(fd); } -- 2.20.1.495.gaa96b0ce6b-goog
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
