From 5cac6ca8bb63cd0ea4df51a597c60d518ee65735 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 17 Sep 2018 13:08:49 -0400 Subject: [PATCH] read message body immediatly after length --- libi2pd/NTCP2.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index 2a32f7ee..0fc6e16d 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -806,7 +806,16 @@ namespace transport { if (m_NextReceivedBuffer) delete[] m_NextReceivedBuffer; m_NextReceivedBuffer = new uint8_t[m_NextReceivedLen]; - Receive (); + boost::system::error_code ec; + size_t moreBytes = m_Socket.available(ec); + if (!ec && moreBytes >= m_NextReceivedLen) + { + // read and process messsage immediately if avaliable + moreBytes = boost::asio::read (m_Socket, boost::asio::buffer(m_NextReceivedBuffer, m_NextReceivedLen), boost::asio::transfer_all (), ec); + HandleReceived (ec, moreBytes); + } + else + Receive (); } else {