Browse Source

check buffer first for async receive

pull/48/head
orignal 11 years ago
parent
commit
8728aa2840
  1. 10
      Streaming.h

10
Streaming.h

@ -200,6 +200,16 @@ namespace stream
template<typename Buffer, typename ReceiveHandler> template<typename Buffer, typename ReceiveHandler>
void Stream::AsyncReceive (const Buffer& buffer, ReceiveHandler handler, int timeout) 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.expires_from_now (boost::posix_time::seconds(timeout));
m_ReceiveTimer.async_wait (boost::bind (&Stream::HandleReceiveTimer<Buffer, ReceiveHandler>, m_ReceiveTimer.async_wait (boost::bind (&Stream::HandleReceiveTimer<Buffer, ReceiveHandler>,
this, boost::asio::placeholders::error, buffer, handler)); this, boost::asio::placeholders::error, buffer, handler));

Loading…
Cancel
Save