From 19325d552a73dd2355db1e7fe521bcf7f84cd305 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 2 Apr 2015 15:10:02 -0400 Subject: [PATCH] fixed race condition --- Streaming.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Streaming.h b/Streaming.h index d36da2aa..d1de1e41 100644 --- a/Streaming.h +++ b/Streaming.h @@ -228,20 +228,18 @@ namespace stream template void Stream::AsyncReceive (const Buffer& buffer, ReceiveHandler handler, int timeout) { - if (!m_ReceiveQueue.empty ()) + auto s = shared_from_this(); + m_Service.post ([=](void) { - auto s = shared_from_this(); - m_Service.post ([=](void) { s->HandleReceiveTimer ( - boost::asio::error::make_error_code (boost::asio::error::operation_aborted), - buffer, handler); }); - } - else - { - 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) - { s->HandleReceiveTimer (ecode, 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 + { + m_ReceiveTimer.expires_from_now (boost::posix_time::seconds(timeout)); + m_ReceiveTimer.async_wait ([=](const boost::system::error_code& ecode) + { s->HandleReceiveTimer (ecode, buffer, handler); }); + } + }); } template