From bf5bda37cffa3734fb65db1a818806daf9a65f06 Mon Sep 17 00:00:00 2001 From: Steven Valdez Date: Wed, 28 Dec 2016 10:51:01 -0500 Subject: [PATCH] Adding socket reuse to bssl server. This allows a server to be restarted immediately with the same port without having to wait for socket timeout on crash/failure. Change-Id: Ifcf58d46067f157dd504946f71b0b99d7fbad10c Reviewed-on: https://boringssl-review.googlesource.com/13044 Reviewed-by: David Benjamin Commit-Queue: David Benjamin CQ-Verified: CQ bot account: commit-bot@chromium.org --- tool/transport_common.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tool/transport_common.cc b/tool/transport_common.cc index 9b8715d9..50173159 100644 --- a/tool/transport_common.cc +++ b/tool/transport_common.cc @@ -159,6 +159,7 @@ bool Accept(int *out_sock, const std::string &port) { addr.sin6_port = htons(atoi(port.c_str())); bool ok = false; + const char enable = 1; int server_sock = -1; server_sock = @@ -168,6 +169,12 @@ bool Accept(int *out_sock, const std::string &port) { goto out; } + if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &enable, + sizeof(enable)) < 0) { + perror("setsockopt"); + goto out; + } + if (bind(server_sock, (struct sockaddr*)&addr, sizeof(addr)) != 0) { perror("connect"); goto out;