check buffer first for async receive

This commit is contained in:
orignal 2014-03-27 15:56:13 -04:00
parent 86e233d77a
commit 8728aa2840

View File

@ -200,6 +200,16 @@ namespace stream
template<typename Buffer, typename ReceiveHandler>
void Stream::AsyncReceive (const Buffer& buffer, ReceiveHandler handler, int timeout)
{
if (!m_ReceiveQueue.IsEmpty ())
{
size_t received = ConcatenatePackets (boost::asio::buffer_cast<uint8_t *>(buffer), boost::asio::buffer_size(buffer));
if (received)
{
// TODO: post to stream's thread
handler (boost::system::error_code (), received);
return;
}
}
m_ReceiveTimer.expires_from_now (boost::posix_time::seconds(timeout));
m_ReceiveTimer.async_wait (boost::bind (&Stream::HandleReceiveTimer<Buffer, ReceiveHandler>,
this, boost::asio::placeholders::error, buffer, handler));