shut down socket and don't allocate buffer for each write in WriteI2PData

This commit is contained in:
Jeff Becker 2018-04-24 11:11:48 -04:00
parent b7a67b4b03
commit 60463fdafa
No known key found for this signature in database
GPG key ID: F357B3B42F6F9B05

View file

@ -26,7 +26,6 @@ namespace client
SAMSocket::~SAMSocket () SAMSocket::~SAMSocket ()
{ {
m_Stream.reset (); m_Stream.reset ();
if (m_Socket.is_open()) m_Socket.close ();
} }
void SAMSocket::Terminate (const char* reason) void SAMSocket::Terminate (const char* reason)
@ -59,7 +58,11 @@ namespace client
; ;
} }
m_SocketType = eSAMSocketTypeTerminated; 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); m_Owner.RemoveSocket(this);
} }
@ -742,9 +745,11 @@ namespace client
void SAMSocket::WriteI2PData(size_t sz) void SAMSocket::WriteI2PData(size_t sz)
{ {
uint8_t * sendbuff = new uint8_t[sz]; boost::asio::async_write (
memcpy(sendbuff, m_StreamBuffer, sz); m_Socket,
WriteI2PDataImmediate(sendbuff, sz); 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) void SAMSocket::HandleI2PReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred)
@ -778,6 +783,7 @@ namespace client
{ {
WriteI2PData(bytes_transferred); WriteI2PData(bytes_transferred);
} }
else
I2PReceive(); I2PReceive();
} }
} }
@ -897,7 +903,6 @@ namespace client
SAMSession::~SAMSession () SAMSession::~SAMSession ()
{ {
CloseStreams();
i2p::client::context.DeleteLocalDestination (localDestination); i2p::client::context.DeleteLocalDestination (localDestination);
} }