mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
check buffer first for async receive
This commit is contained in:
parent
86e233d77a
commit
8728aa2840
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…
x
Reference in New Issue
Block a user