mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
shut down socket and don't allocate buffer for each write in WriteI2PData
This commit is contained in:
parent
b7a67b4b03
commit
60463fdafa
@ -26,7 +26,6 @@ namespace client
|
||||
SAMSocket::~SAMSocket ()
|
||||
{
|
||||
m_Stream.reset ();
|
||||
if (m_Socket.is_open()) m_Socket.close ();
|
||||
}
|
||||
|
||||
void SAMSocket::Terminate (const char* reason)
|
||||
@ -59,7 +58,11 @@ namespace client
|
||||
;
|
||||
}
|
||||
m_SocketType = eSAMSocketTypeTerminated;
|
||||
if (m_Socket.is_open()) m_Socket.close ();
|
||||
if (m_Socket.is_open ())
|
||||
{
|
||||
m_Socket.shutdown ();
|
||||
m_Socket.close ();
|
||||
}
|
||||
m_Owner.RemoveSocket(this);
|
||||
}
|
||||
|
||||
@ -742,9 +745,11 @@ namespace client
|
||||
|
||||
void SAMSocket::WriteI2PData(size_t sz)
|
||||
{
|
||||
uint8_t * sendbuff = new uint8_t[sz];
|
||||
memcpy(sendbuff, m_StreamBuffer, sz);
|
||||
WriteI2PDataImmediate(sendbuff, sz);
|
||||
boost::asio::async_write (
|
||||
m_Socket,
|
||||
boost::asio::buffer (m_StreamBuffer, sz),
|
||||
boost::asio::transfer_all(),
|
||||
std::bind(&SAMSocket::HandleWriteI2PData, shared_from_this(), std::placeholders::_1));
|
||||
}
|
||||
|
||||
void SAMSocket::HandleI2PReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
||||
@ -778,6 +783,7 @@ namespace client
|
||||
{
|
||||
WriteI2PData(bytes_transferred);
|
||||
}
|
||||
else
|
||||
I2PReceive();
|
||||
}
|
||||
}
|
||||
@ -897,7 +903,6 @@ namespace client
|
||||
|
||||
SAMSession::~SAMSession ()
|
||||
{
|
||||
CloseStreams();
|
||||
i2p::client::context.DeleteLocalDestination (localDestination);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user