summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/TcpSocket.cpp33
-rw-r--r--src/dabOutput/dabOutputTcp.cpp6
2 files changed, 21 insertions, 18 deletions
diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp
index 6791286..b9824fa 100644
--- a/src/TcpSocket.cpp
+++ b/src/TcpSocket.cpp
@@ -39,31 +39,30 @@ using namespace std;
TcpSocket::TcpSocket() :
m_sock(INVALID_SOCKET)
{
- if ((m_sock = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
- throw std::runtime_error("Can't create socket");
- }
}
TcpSocket::TcpSocket(int port, const string& name) :
m_sock(INVALID_SOCKET)
{
- if ((m_sock = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
- throw std::runtime_error("Can't create socket");
- }
+ if (port) {
+ if ((m_sock = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
+ throw std::runtime_error("Can't create socket");
+ }
- reuseopt_t reuse = 1;
- if (setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))
- == SOCKET_ERROR) {
- throw std::runtime_error("Can't reuse address");
- }
+ reuseopt_t reuse = 1;
+ if (setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))
+ == SOCKET_ERROR) {
+ throw std::runtime_error("Can't reuse address");
+ }
- m_own_address.setAddress(name);
- m_own_address.setPort(port);
+ m_own_address.setAddress(name);
+ m_own_address.setPort(port);
- if (bind(m_sock, m_own_address.getAddress(), sizeof(sockaddr_in)) == SOCKET_ERROR) {
- ::close(m_sock);
- m_sock = INVALID_SOCKET;
- throw std::runtime_error("Can't bind socket");
+ if (bind(m_sock, m_own_address.getAddress(), sizeof(sockaddr_in)) == SOCKET_ERROR) {
+ ::close(m_sock);
+ m_sock = INVALID_SOCKET;
+ throw std::runtime_error("Can't bind socket");
+ }
}
}
diff --git a/src/dabOutput/dabOutputTcp.cpp b/src/dabOutput/dabOutputTcp.cpp
index 975fdff..2aab48a 100644
--- a/src/dabOutput/dabOutputTcp.cpp
+++ b/src/dabOutput/dabOutputTcp.cpp
@@ -95,6 +95,10 @@ class TCPConnection
m_running = false;
}
}
+
+ auto addr = m_sock.getRemoteAddress();
+ etiLog.level(debug) << "Dropping TCP Connection from " <<
+ addr.getHostAddress() << ":" << addr.getPort();
}
};
@@ -121,7 +125,7 @@ class TCPDataDispatcher
connection.queue.push(data);
}
- m_connections.remove_if([](TCPConnection& conn){ return conn.is_overloaded(); });
+ m_connections.remove_if([](const TCPConnection& conn){ return conn.is_overloaded(); });
}
private: