diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-11-12 16:30:30 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-11-12 16:30:30 +0100 |
commit | 96b4dc4efca1b164f79a7f7394449866f034ac31 (patch) | |
tree | 101b796f40fee444c8193ccc3e13cf5644c83d5f /src/dabOutput/dabOutputTcp.cpp | |
parent | 5132756f09c7a0dafe4644db92718ee3d1a58d6c (diff) | |
parent | fedab89cd4625617b3e481f1f59ba0fc97b7305b (diff) | |
download | dabmux-96b4dc4efca1b164f79a7f7394449866f034ac31.tar.gz dabmux-96b4dc4efca1b164f79a7f7394449866f034ac31.tar.bz2 dabmux-96b4dc4efca1b164f79a7f7394449866f034ac31.zip |
Merge branch 'next' into servicelinking
Diffstat (limited to 'src/dabOutput/dabOutputTcp.cpp')
-rw-r--r-- | src/dabOutput/dabOutputTcp.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/dabOutput/dabOutputTcp.cpp b/src/dabOutput/dabOutputTcp.cpp index 8696bec..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,22 +125,28 @@ 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: void process(long) { - m_listener_socket.listen(); + try { + m_listener_socket.listen(); - const int timeout_ms = 1000; + const int timeout_ms = 1000; - while (m_running) { - // Add a new TCPConnection to the list, constructing it from the client socket - auto optional_sock = m_listener_socket.accept(timeout_ms); - if (optional_sock) { - m_connections.emplace(m_connections.begin(), std::move(*optional_sock)); + while (m_running) { + // Add a new TCPConnection to the list, constructing it from the client socket + auto sock = m_listener_socket.accept(timeout_ms); + if (sock.isValid()) { + m_connections.emplace(m_connections.begin(), move(sock)); + } } } + catch (std::runtime_error& e) { + etiLog.level(error) << "TCPDataDispatcher caught runtime error: " << e.what(); + m_running = false; + } } atomic<bool> m_running; @@ -145,14 +155,6 @@ class TCPDataDispatcher std::list<TCPConnection> m_connections; }; -DabOutputTcp::~DabOutputTcp() -{ - if (dispatcher_) { - delete dispatcher_; - dispatcher_ = nullptr; - } -} - static bool parse_uri(const char *uri, long *port, string& addr) { char* const hostport = strdup(uri); // the uri is actually an tuple host:port @@ -199,7 +201,7 @@ int DabOutputTcp::Open(const char* name) uri_ = name; if (success) { - dispatcher_ = new TCPDataDispatcher(); + dispatcher_ = make_shared<TCPDataDispatcher>(); try { dispatcher_->start(port, address); } |