don't exceed stream max send buffer size

This commit is contained in:
orignal 2025-05-03 08:47:49 -04:00
parent 539cd5a656
commit aece5bb16c
2 changed files with 17 additions and 5 deletions

View file

@ -151,15 +151,21 @@ namespace client
void I2PTunnelConnection::Receive ()
{
if (m_IsReceiving) return; // already receiving
size_t bufSize = I2P_TUNNEL_CONNECTION_BUFFER_SIZE;
size_t unsentSize = m_Stream ? m_Stream->GetSendBufferSize () : 0;
if (unsentSize >= I2P_TUNNEL_CONNECTION_STREAM_MAX_SEND_BUFFER_SIZE) return; // buffer is full
if (unsentSize)
{
if (unsentSize >= I2P_TUNNEL_CONNECTION_STREAM_MAX_SEND_BUFFER_SIZE) return; // buffer is full
if (unsentSize > I2P_TUNNEL_CONNECTION_STREAM_MAX_SEND_BUFFER_SIZE - I2P_TUNNEL_CONNECTION_BUFFER_SIZE)
bufSize = I2P_TUNNEL_CONNECTION_STREAM_MAX_SEND_BUFFER_SIZE - unsentSize;
}
m_IsReceiving = true;
if (m_SSL)
m_SSL->async_read_some (boost::asio::buffer(m_Buffer, I2P_TUNNEL_CONNECTION_BUFFER_SIZE),
m_SSL->async_read_some (boost::asio::buffer(m_Buffer, bufSize),
std::bind(&I2PTunnelConnection::HandleReceive, shared_from_this (),
std::placeholders::_1, std::placeholders::_2));
else
m_Socket->async_read_some (boost::asio::buffer(m_Buffer, I2P_TUNNEL_CONNECTION_BUFFER_SIZE),
m_Socket->async_read_some (boost::asio::buffer(m_Buffer, bufSize),
std::bind(&I2PTunnelConnection::HandleReceive, shared_from_this (),
std::placeholders::_1, std::placeholders::_2));
}

View file

@ -947,10 +947,16 @@ namespace client
if (m_SocketType == eSAMSocketTypeStream)
{
if (m_IsReceiving) return;
size_t bufSize = SAM_SOCKET_BUFFER_SIZE;
size_t unsentSize = m_Stream ? m_Stream->GetSendBufferSize () : 0;
if (unsentSize >= SAM_STREAM_MAX_SEND_BUFFER_SIZE) return; // buffer is full
if (unsentSize)
{
if (unsentSize >= SAM_STREAM_MAX_SEND_BUFFER_SIZE) return; // buffer is full
if (unsentSize > SAM_STREAM_MAX_SEND_BUFFER_SIZE - SAM_SOCKET_BUFFER_SIZE)
bufSize = SAM_STREAM_MAX_SEND_BUFFER_SIZE - unsentSize;
}
m_IsReceiving = true;
m_Socket.async_read_some (boost::asio::buffer(m_Buffer, SAM_SOCKET_BUFFER_SIZE),
m_Socket.async_read_some (boost::asio::buffer(m_Buffer, bufSize),
std::bind(&SAMSocket::HandleReceived, shared_from_this (), std::placeholders::_1, std::placeholders::_2));
}
else