Documentation for module: Network

Former-commit-id: d36042138d0883eb118cc9a70f94f3522214dd46
This commit is contained in:
Gawaboumga
2016-05-30 14:22:31 +02:00
parent 96b958d655
commit 0a99058c4d
25 changed files with 1368 additions and 25 deletions

View File

@@ -9,11 +9,36 @@
namespace Nz
{
/*!
* \ingroup network
* \class Nz::NetPacket
* \brief Network class that represents a packet
*/
/*!
* \brief Operation to do when receiving data
*
* \param netCode Packet number
* \param data Raw memory
* \param size Size of the memory
*/
void NetPacket::OnReceive(UInt16 netCode, const void* data, std::size_t size)
{
Reset(netCode, data, size);
}
/*!
* \brief Operation to do when sending data
* \return Beggining of the raw memory
*
* \param newSize Size of the memory to send
*
* \remark Produces a NazaraAssert if newSize is invalid
* \remark Produces a NazaraAssert if net code is invalid
* \remark Produces a NazaraError if header could not be encoded
*/
const void* NetPacket::OnSend(std::size_t* newSize) const
{
NazaraAssert(newSize, "Invalid size pointer");
@@ -30,6 +55,15 @@ namespace Nz
return m_buffer->GetBuffer();
}
/*!
* \brief Decodes the header of the packet
* \return true If successful
*
* \param data Raw memory
* \param packetSize Size of the packet
* \param netCode Packet number
*/
bool NetPacket::DecodeHeader(const void* data, UInt16* packetSize, UInt16* netCode)
{
MemoryView stream(data, HeaderSize);
@@ -40,6 +74,15 @@ namespace Nz
return Unserialize(context, packetSize) && Unserialize(context, netCode);
}
/*!
* \brief Encodes the header of the packet
* \return true If successful
*
* \param data Raw memory
* \param packetSize Size of the packet
* \param netCode Packet number
*/
bool NetPacket::EncodeHeader(void* data, UInt16 packetSize, UInt16 netCode)
{
MemoryView stream(data, HeaderSize);
@@ -50,11 +93,19 @@ namespace Nz
return Serialize(context, packetSize) && Serialize(context, netCode);
}
/*!
* \brief Operation to do when stream is empty
*/
void NetPacket::OnEmptyStream()
{
Reset(0);
}
/*!
* \brief Frees the stream
*/
void NetPacket::FreeStream()
{
if (!m_buffer)
@@ -66,6 +117,16 @@ namespace Nz
s_availableBuffers.emplace_back(std::make_pair(size, std::move(m_buffer)));
}
/*!
* \brief Inits the internal stream
*
* \param minCapacity Minimal capacity of the stream
* \param cursorPos Position of the cursor in the stream
* \param openMode Flag of the stream
*
* \remark Produces a NazaraAssert if cursor position is greather than the capacity
*/
void NetPacket::InitStream(std::size_t minCapacity, UInt64 cursorPos, UInt32 openMode)
{
NazaraAssert(minCapacity >= cursorPos, "Cannot init stream with a smaller capacity than wanted cursor pos");
@@ -92,12 +153,21 @@ namespace Nz
SetStream(&m_memoryStream);
}
/*!
* \brief Initializes the NetPacket class
* \return true If initialization is successful
*/
bool NetPacket::Initialize()
{
s_availableBuffersMutex = std::make_unique<Mutex>();
return true;
}
/*!
* \brief Uninitializes the NetPacket class
*/
void NetPacket::Uninitialize()
{
s_availableBuffers.clear();