diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-11-18 10:31:44 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-11-18 10:31:44 +0100 |
commit | db0ecfb183922eae77bda977efb8c0c037ca045e (patch) | |
tree | c1d8e47e09931092412442c1f9896ca1dfc5a30f /lib | |
parent | 4ba22087556e8967c1efdeb6f8872ffddcdbf59b (diff) | |
download | ODR-SourceCompanion-db0ecfb183922eae77bda977efb8c0c037ca045e.tar.gz ODR-SourceCompanion-db0ecfb183922eae77bda977efb8c0c037ca045e.tar.bz2 ODR-SourceCompanion-db0ecfb183922eae77bda977efb8c0c037ca045e.zip |
Common 0a50ea0: Set SO_REUSEADDR for TCP sockets
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Socket.cpp | 5 |
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; |