diff --git a/libi2pd/Streaming.cpp b/libi2pd/Streaming.cpp index 9eb5bed6..aba07a90 100644 --- a/libi2pd/Streaming.cpp +++ b/libi2pd/Streaming.cpp @@ -962,7 +962,7 @@ namespace stream else { if (handler) - handler(boost::system::error_code ()); + handler(boost::system::error_code (), 0); return; } Send (std::move (buffer)); diff --git a/libi2pd/Streaming.h b/libi2pd/Streaming.h index d7978991..9a91ac14 100644 --- a/libi2pd/Streaming.h +++ b/libi2pd/Streaming.h @@ -122,9 +122,9 @@ namespace stream }; #ifdef __cpp_lib_move_only_function // with C++23 - typedef std::move_only_function SendHandler; + typedef std::move_only_function SendHandler; #else - typedef std::function SendHandler; + typedef std::function SendHandler; #endif struct SendBuffer @@ -148,11 +148,11 @@ namespace stream ~SendBuffer () { delete[] buf; - if (handler) handler(boost::system::error_code ()); + if (handler) handler(boost::system::error_code (), len); } size_t GetRemainingSize () const { return len - offset; }; const uint8_t * GetRemaningBuffer () const { return buf + offset; }; - void Cancel () { if (handler) handler (boost::asio::error::make_error_code (boost::asio::error::operation_aborted)); handler = nullptr; }; + void Cancel () { if (handler) handler (boost::asio::error::make_error_code (boost::asio::error::operation_aborted), offset); handler = nullptr; }; }; class SendBufferQueue diff --git a/libi2pd_client/BoostStream.h b/libi2pd_client/BoostStream.h index 48c53e69..7968560a 100644 --- a/libi2pd_client/BoostStream.h +++ b/libi2pd_client/BoostStream.h @@ -44,7 +44,7 @@ namespace client if (received > 0) // we have some data handler (boost::system::error_code (), received); else if (bufs.size () > 0) // wait for incoming data - m_Stream->AsyncReceive (*boost::asio::buffer_sequence_begin (bufs), handler); + m_Stream->AsyncReceive (*boost::asio::buffer_sequence_begin (bufs), std::move (handler)); else handler (boost::system::error_code (), 0); } @@ -66,11 +66,7 @@ namespace client { #ifdef __cpp_lib_move_only_function // with C++23 // we can save handler with SendBuffer - auto sendBuffer = std::make_shared(bufsToSend, sent, - [handler = std::move (handler), sent](const boost::system::error_code& ecode) mutable - { - handler (ecode, sent); - }); + auto sendBuffer = std::make_shared(bufsToSend, sent, std::move (handler)); #else // we can't save handler with SendBuffer due to lack of std::move_only_function auto sendBuffer = std::make_shared(bufsToSend, sent, nullptr); diff --git a/libi2pd_client/I2PTunnel.cpp b/libi2pd_client/I2PTunnel.cpp index 2fecea64..27f7a6d8 100644 --- a/libi2pd_client/I2PTunnel.cpp +++ b/libi2pd_client/I2PTunnel.cpp @@ -255,7 +255,7 @@ namespace client if (m_Stream) { m_Stream->AsyncSend (buf, len, - [s = shared_from_this ()](const boost::system::error_code& ecode) + [s = shared_from_this ()](const boost::system::error_code& ecode, size_t bytes_transferred) { if (!ecode) s->Receive (); diff --git a/libi2pd_client/Torrents.cpp b/libi2pd_client/Torrents.cpp index a9e6cdb6..978c3171 100644 --- a/libi2pd_client/Torrents.cpp +++ b/libi2pd_client/Torrents.cpp @@ -398,7 +398,7 @@ namespace torrents void PeerConnection::WriteToStream (const uint8_t * buf, size_t len) { m_Stream->AsyncSend (buf, len, - [s = shared_from_this ()](const boost::system::error_code& ecode) + [s = shared_from_this ()](const boost::system::error_code& ecode, size_t bytes_transferred) { if (ecode) s->Terminate (); });