aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Socket.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-11-18 10:32:14 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-11-18 10:32:14 +0100
commite619e89e6cf1c7bfe8199e2014d2c04c02c655c2 (patch)
treee19f0172a18c8c98db8805ec76cd9a2947ffccc2 /lib/Socket.cpp
parentf5253591512032b0724cc5cc1519cab24e9b14bb (diff)
downloaddabmod-e619e89e6cf1c7bfe8199e2014d2c04c02c655c2.tar.gz
dabmod-e619e89e6cf1c7bfe8199e2014d2c04c02c655c2.tar.bz2
dabmod-e619e89e6cf1c7bfe8199e2014d2c04c02c655c2.zip
Common 0a50ea0: Set SO_REUSEADDR for TCP sockets
Diffstat (limited to 'lib/Socket.cpp')
-rw-r--r--lib/Socket.cpp5
1 files changed, 5 insertions, 0 deletions
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;