mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
async receive
This commit is contained in:
parent
3ae225fb41
commit
06b2500347
@ -248,7 +248,12 @@ namespace stream
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// either non-empty or we have received empty
|
// either non-empty or we have received something
|
||||||
|
return ConcatenatePackets (buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Stream::ConcatenatePackets (uint8_t * buf, size_t len)
|
||||||
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
while (pos < len)
|
while (pos < len)
|
||||||
{
|
{
|
||||||
|
@ -97,6 +97,7 @@ namespace stream
|
|||||||
|
|
||||||
void SavePacket (Packet * packet);
|
void SavePacket (Packet * packet);
|
||||||
void ProcessPacket (Packet * packet);
|
void ProcessPacket (Packet * packet);
|
||||||
|
size_t ConcatenatePackets (uint8_t * buf, size_t len);
|
||||||
|
|
||||||
void UpdateCurrentRemoteLease ();
|
void UpdateCurrentRemoteLease ();
|
||||||
|
|
||||||
@ -207,13 +208,13 @@ namespace stream
|
|||||||
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)
|
||||||
{
|
{
|
||||||
// TODO:
|
size_t received = ConcatenatePackets (boost::asio::buffer_cast<uint8_t *>(buffer), boost::asio::buffer_size(buffer));
|
||||||
if (ecode == boost::asio::error::operation_aborted)
|
if (ecode == boost::asio::error::operation_aborted)
|
||||||
// timeout not expired
|
// timeout not expired
|
||||||
handler (boost::system::error_code (), 0);
|
handler (boost::system::error_code (), received);
|
||||||
else
|
else
|
||||||
// timeout expired
|
// timeout expired
|
||||||
handler (boost::asio::error::make_error_code (boost::asio::error::timed_out), 0);
|
handler (boost::asio::error::make_error_code (boost::asio::error::timed_out), received);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user