Browse Source

fixed race condition

pull/177/head
orignal 10 years ago
parent
commit
19325d552a
  1. 12
      Streaming.h

12
Streaming.h

@ -227,21 +227,19 @@ 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.empty ())
{ {
auto s = shared_from_this(); auto s = shared_from_this();
m_Service.post ([=](void) { s->HandleReceiveTimer ( m_Service.post ([=](void)
boost::asio::error::make_error_code (boost::asio::error::operation_aborted), {
buffer, handler); }); if (!m_ReceiveQueue.empty () || m_Status == eStreamStatusReset)
} s->HandleReceiveTimer (boost::asio::error::make_error_code (boost::asio::error::operation_aborted), buffer, handler);
else else
{ {
m_ReceiveTimer.expires_from_now (boost::posix_time::seconds(timeout)); m_ReceiveTimer.expires_from_now (boost::posix_time::seconds(timeout));
auto s = shared_from_this();
m_ReceiveTimer.async_wait ([=](const boost::system::error_code& ecode) m_ReceiveTimer.async_wait ([=](const boost::system::error_code& ecode)
{ s->HandleReceiveTimer (ecode, buffer, handler); }); { s->HandleReceiveTimer (ecode, buffer, handler); });
} }
});
} }
template<typename Buffer, typename ReceiveHandler> template<typename Buffer, typename ReceiveHandler>

Loading…
Cancel
Save