From 3de4010a47b66268acdc9c301003b9463efe8218 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 9 Oct 2014 15:55:58 -0400 Subject: [PATCH] always call receive handler from a streaming thread --- HTTPServer.cpp | 2 +- Streaming.h | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 1d19dd14..7e643177 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -878,7 +878,7 @@ namespace util void HTTPConnection::HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred) { - if (bytes_transferred) + if (!ecode) { boost::asio::async_write (*m_Socket, boost::asio::buffer (m_StreamBuffer, bytes_transferred), boost::bind (&HTTPConnection::HandleWrite, this, boost::asio::placeholders::error)); diff --git a/Streaming.h b/Streaming.h index 197dba05..37d37d28 100644 --- a/Streaming.h +++ b/Streaming.h @@ -140,22 +140,16 @@ namespace stream { if (!m_ReceiveQueue.empty ()) { - size_t received = ConcatenatePackets (boost::asio::buffer_cast(buffer), boost::asio::buffer_size(buffer)); - if (received) - { - // TODO: post to stream's thread - handler (boost::system::error_code (), received); - return; - } + m_Service.post ([=](void) { this->HandleReceiveTimer ( + boost::asio::error::make_error_code (boost::asio::error::operation_aborted), + buffer, handler); }); } - if (!m_IsOpen) + else { - handler (boost::asio::error::make_error_code (boost::asio::error::connection_reset), 0); - return; + m_ReceiveTimer.expires_from_now (boost::posix_time::seconds(timeout)); + m_ReceiveTimer.async_wait ([=](const boost::system::error_code& ecode) + { this->HandleReceiveTimer (ecode, buffer, handler); }); } - m_ReceiveTimer.expires_from_now (boost::posix_time::seconds(timeout)); - m_ReceiveTimer.async_wait ([=](const boost::system::error_code& ecode) - { this->HandleReceiveTimer (ecode, buffer, handler); }); } template