Network/TcpClient|UdpSocket: Add SendMultiple method

To efficiently merge multiples buffers into a reduced number of network
packets
This commit is contained in:
Lynix
2017-01-27 14:51:01 +01:00
parent 1d6f22cd8a
commit ab3b730d21
10 changed files with 201 additions and 11 deletions

View File

@@ -353,6 +353,45 @@ namespace Nz
return true;
}
/*!
* \brief Sends multiple buffers at once
* \return true If data were sent
*
* \param buffers A pointer to an array of NetBuffer containing buffers and size data
* \param size Number of NetBuffer to send
* \param sent Optional argument to get the number of bytes sent
*/
bool TcpClient::SendMultiple(const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent)
{
NazaraAssert(buffers && bufferCount > 0, "Invalid buffer");
int byteSent;
if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, m_peerAddress, &byteSent, &m_lastError))
{
switch (m_lastError)
{
case SocketError_ConnectionClosed:
case SocketError_ConnectionRefused:
UpdateState(SocketState_NotConnected);
break;
default:
break;
}
if (sent)
*sent = byteSent;
return false;
}
if (sent)
*sent = byteSent;
UpdateState(SocketState_Connected);
return true;
}
/*!
* \brief Sends the packet available
* \return true If packet sent