From e619e89e6cf1c7bfe8199e2014d2c04c02c655c2 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 18 Nov 2019 10:32:14 +0100 Subject: Common 0a50ea0: Set SO_REUSEADDR for TCP sockets --- lib/Socket.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/Socket.cpp b/lib/Socket.cpp index 0c3cbb4..cba2767 100644 --- a/lib/Socket.cpp +++ b/lib/Socket.cpp @@ -490,6 +490,11 @@ void TCPSocket::listen(int port, const string& name) continue; } + int reuse_setting = 1; + if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &reuse_setting, sizeof(reuse_setting)) == -1) { + throw runtime_error("Can't reuse address"); + } + if (::bind(sfd, rp->ai_addr, rp->ai_addrlen) == 0) { m_sock = sfd; break; -- cgit v1.2.3