Message: use shared_ptr.

NetworkConnection: Own the input and output queues.
This commit is contained in:
Peter Johnson
2015-07-15 21:20:18 -07:00
committed by Peter Johnson
parent beb92e6cbf
commit 13cbf4e288
4 changed files with 151 additions and 123 deletions

View File

@@ -15,11 +15,8 @@
using namespace ntimpl;
NetworkConnection::NetworkConnection(std::unique_ptr<TCPStream> stream,
BatchQueue& outgoing, Queue& incoming,
Message::GetEntryTypeFunc get_entry_type)
: m_stream(std::move(stream)),
m_outgoing(outgoing),
m_incoming(incoming),
m_get_entry_type(get_entry_type),
m_active(false),
m_proto_rev(0x0300) {}
@@ -49,8 +46,12 @@ void NetworkConnection::ReadThreadMain() {
break;
decoder.set_proto_rev(m_proto_rev);
decoder.Reset();
auto msg = std::make_shared<Message>();
if (!Message::Read(decoder, m_get_entry_type, &(*msg))) break;
auto msg = Message::Read(decoder, m_get_entry_type);
if (!msg) {
// terminate connection on bad message
m_stream->close();
break;
}
m_incoming.push(msg);
}
m_active = false;