From 7512c84d0cd7d9b1a3733e84280864f5a989b51e Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 30 Oct 2016 12:18:14 +0100 Subject: Catch runtime_error in TCPDataDispatcher thread --- src/dabOutput/dabOutputTcp.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/dabOutput/dabOutputTcp.cpp b/src/dabOutput/dabOutputTcp.cpp index 8696bec..6485d15 100644 --- a/src/dabOutput/dabOutputTcp.cpp +++ b/src/dabOutput/dabOutputTcp.cpp @@ -126,17 +126,23 @@ class TCPDataDispatcher 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 optional_sock = m_listener_socket.accept(timeout_ms); + if (optional_sock) { + m_connections.emplace(m_connections.begin(), std::move(*optional_sock)); + } } } + catch (std::runtime_error& e) { + etiLog.level(error) << "TCPDataDispatcher caught runtime error: " << e.what(); + m_running = false; + } } atomic m_running; -- cgit v1.2.3