Browse Source

read more data from socket if available

pull/158/head
orignal 10 years ago
parent
commit
1ad04bf8bf
  1. 29
      NTCPSession.cpp

29
NTCPSession.cpp

@ -488,6 +488,9 @@ namespace transport @@ -488,6 +488,9 @@ namespace transport
m_ReceiveBufferOffset += bytes_transferred;
if (m_ReceiveBufferOffset >= 16)
{
int numReloads = 0;
do
{
uint8_t * nextBlock = m_ReceiveBuffer;
while (m_ReceiveBufferOffset >= 16)
@ -502,6 +505,32 @@ namespace transport @@ -502,6 +505,32 @@ namespace transport
}
if (m_ReceiveBufferOffset > 0)
memcpy (m_ReceiveBuffer, nextBlock, m_ReceiveBufferOffset);
// try to read more
if (numReloads < 5)
{
boost::asio::socket_base::bytes_readable command (true);
m_Socket.io_control (command);
size_t moreBytes = command.get();
if (moreBytes)
{
if (moreBytes > NTCP_BUFFER_SIZE - m_ReceiveBufferOffset)
moreBytes = NTCP_BUFFER_SIZE - m_ReceiveBufferOffset;
boost::system::error_code ec;
moreBytes = m_Socket.read_some (boost::asio::buffer (m_ReceiveBuffer + m_ReceiveBufferOffset, moreBytes));
if (ec)
{
LogPrint (eLogError, "Read more bytes error: ", ec.message ());
Terminate ();
return;
}
m_NumReceivedBytes += moreBytes;
m_ReceiveBufferOffset += moreBytes;
numReloads++;
}
}
}
while (m_ReceiveBufferOffset >= 16);
m_Handler.Flush ();
}

Loading…
Cancel
Save