From 0a107786977768a0854e9286c62e9ff8e1e8ded5 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 31 Jul 2015 23:40:16 -0700 Subject: [PATCH] NetworkConnection: Kill write thread when read dies and vice-versa. --- src/NetworkConnection.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/NetworkConnection.cpp b/src/NetworkConnection.cpp index dd725d366d..d9526159a2 100644 --- a/src/NetworkConnection.cpp +++ b/src/NetworkConnection.cpp @@ -103,6 +103,7 @@ void NetworkConnection::ReadThreadMain() { DEBUG3("read thread died"); m_state = static_cast(kDead); m_active = false; + m_outgoing.push(Outgoing()); // also kill write thread } void NetworkConnection::WriteThreadMain() { @@ -111,7 +112,7 @@ void NetworkConnection::WriteThreadMain() { while (m_active) { auto msgs = m_outgoing.pop(); DEBUG4("write thread woke up"); - if (msgs.empty()) break; + if (msgs.empty()) continue; encoder.set_proto_rev(m_proto_rev); encoder.Reset(); DEBUG4("sending " << msgs.size() << " messages"); @@ -127,4 +128,5 @@ void NetworkConnection::WriteThreadMain() { DEBUG3("write thread died"); m_state = static_cast(kDead); m_active = false; + if (m_stream) m_stream->close(); // also kill read thread }