mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
always call receive handler from a streaming thread
This commit is contained in:
parent
0e6b7712a9
commit
3de4010a47
2 changed files with 8 additions and 14 deletions
|
@ -878,7 +878,7 @@ namespace util
|
||||||
|
|
||||||
void HTTPConnection::HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
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::asio::async_write (*m_Socket, boost::asio::buffer (m_StreamBuffer, bytes_transferred),
|
||||||
boost::bind (&HTTPConnection::HandleWrite, this, boost::asio::placeholders::error));
|
boost::bind (&HTTPConnection::HandleWrite, this, boost::asio::placeholders::error));
|
||||||
|
|
18
Streaming.h
18
Streaming.h
|
@ -140,23 +140,17 @@ namespace stream
|
||||||
{
|
{
|
||||||
if (!m_ReceiveQueue.empty ())
|
if (!m_ReceiveQueue.empty ())
|
||||||
{
|
{
|
||||||
size_t received = ConcatenatePackets (boost::asio::buffer_cast<uint8_t *>(buffer), boost::asio::buffer_size(buffer));
|
m_Service.post ([=](void) { this->HandleReceiveTimer (
|
||||||
if (received)
|
boost::asio::error::make_error_code (boost::asio::error::operation_aborted),
|
||||||
|
buffer, handler); });
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// TODO: post to stream's thread
|
|
||||||
handler (boost::system::error_code (), received);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!m_IsOpen)
|
|
||||||
{
|
|
||||||
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.expires_from_now (boost::posix_time::seconds(timeout));
|
||||||
m_ReceiveTimer.async_wait ([=](const boost::system::error_code& ecode)
|
m_ReceiveTimer.async_wait ([=](const boost::system::error_code& ecode)
|
||||||
{ this->HandleReceiveTimer (ecode, buffer, handler); });
|
{ this->HandleReceiveTimer (ecode, buffer, handler); });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Buffer, typename ReceiveHandler>
|
template<typename Buffer, typename ReceiveHandler>
|
||||||
void Stream::HandleReceiveTimer (const boost::system::error_code& ecode, const Buffer& buffer, ReceiveHandler handler)
|
void Stream::HandleReceiveTimer (const boost::system::error_code& ecode, const Buffer& buffer, ReceiveHandler handler)
|
||||||
|
|
Loading…
Add table
Reference in a new issue