From 44aad3ddd3dd8638b7623b53cbca9f59d886ba1d Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 18 Nov 2019 10:31:53 +0100 Subject: Common 0a50ea0: Set SO_REUSEADDR for TCP sockets --- contrib/Socket.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'contrib') diff --git a/contrib/Socket.cpp b/contrib/Socket.cpp index 0c3cbb4..cba2767 100644 --- a/contrib/Socket.cpp +++ b/contrib/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 From aafa06fa15f1ef274fef2df9e939323ed61e670e Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 18 Nov 2019 10:49:52 +0100 Subject: Common 27ac70f: Initialise InetAddress::addr --- contrib/Socket.cpp | 3 ++- contrib/Socket.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'contrib') diff --git a/contrib/Socket.cpp b/contrib/Socket.cpp index cba2767..50a12ba 100644 --- a/contrib/Socket.cpp +++ b/contrib/Socket.cpp @@ -69,7 +69,8 @@ void InetAddress::resolveUdpDestination(const std::string& destination, int port UDPPacket::UDPPacket() { } UDPPacket::UDPPacket(size_t initSize) : - buffer(initSize) + buffer(initSize), + address() { } diff --git a/contrib/Socket.h b/contrib/Socket.h index c3c37e1..df80b08 100644 --- a/contrib/Socket.h +++ b/contrib/Socket.h @@ -50,7 +50,7 @@ namespace Socket { struct InetAddress { - struct sockaddr_storage addr; + struct sockaddr_storage addr = {}; struct sockaddr *as_sockaddr() { return reinterpret_cast(&addr); }; -- cgit v1.2.3 From e4b4e7c28d4767d29b4348227948e5bd28e13a64 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 18 Nov 2019 11:35:21 +0100 Subject: Apply common 23752f6 and e10272e --- contrib/Socket.cpp | 2 +- contrib/Socket.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/Socket.cpp b/contrib/Socket.cpp index 50a12ba..bfbef93 100644 --- a/contrib/Socket.cpp +++ b/contrib/Socket.cpp @@ -650,7 +650,7 @@ ssize_t TCPSocket::recv(void *buffer, size_t length, int flags, int timeout_ms) std::string errstr(strerror(errno)); throw std::runtime_error("TCP receive with poll() error: " + errstr); } - else if (retval > 0 and (fds[0].revents | POLLIN)) { + else if (retval > 0 and (fds[0].revents & POLLIN)) { ssize_t ret = ::recv(m_sock, buffer, length, flags); if (ret == -1) { if (errno == ECONNREFUSED) { diff --git a/contrib/Socket.h b/contrib/Socket.h index df80b08..b9f6317 100644 --- a/contrib/Socket.h +++ b/contrib/Socket.h @@ -258,7 +258,7 @@ class TCPDataDispatcher size_t m_max_queue_size; - std::atomic m_running; + std::atomic m_running = ATOMIC_VAR_INIT(false); std::string m_exception_data; std::thread m_listener_thread; TCPSocket m_listener_socket; @@ -285,7 +285,7 @@ class TCPReceiveServer { size_t m_blocksize = 0; ThreadsafeQueue > m_queue; - std::atomic m_running; + std::atomic m_running = ATOMIC_VAR_INIT(false); std::string m_exception_data; std::thread m_listener_thread; TCPSocket m_listener_socket; -- cgit v1.2.3