summaryrefslogtreecommitdiff
path: root/gcsdk/netpacket.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /gcsdk/netpacket.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'gcsdk/netpacket.cpp')
-rw-r--r--gcsdk/netpacket.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/gcsdk/netpacket.cpp b/gcsdk/netpacket.cpp
new file mode 100644
index 0000000..13c3818
--- /dev/null
+++ b/gcsdk/netpacket.cpp
@@ -0,0 +1,106 @@
+//====== Copyright (c), Valve Corporation, All rights reserved. =======
+//
+// Purpose: Holds the CNetPacket class
+//
+//=============================================================================
+
+
+#include "stdafx.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+
+namespace GCSDK
+{
+
+//-----------------------------------------------------------------------------
+// Purpose: Constructor
+//-----------------------------------------------------------------------------
+CNetPacket::CNetPacket()
+{
+ m_cRef = 0;
+ m_pubData = NULL;
+ m_cubData = 0;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Destructor, validates refcount
+//-----------------------------------------------------------------------------
+CNetPacket::~CNetPacket()
+{
+ Assert( m_cRef == 0 );
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Inits all members
+// Input : hConnection - connection we're from
+// pubData - message data
+// cubData - message size
+// *pubNetworkBuffer - network buffer that contains the message
+// assumes control of this memory
+//-----------------------------------------------------------------------------
+void CNetPacket::Init( uint32 cubData, const void* pCopyData )
+{
+ Assert( cubData );
+
+ m_pubData = (uint8 *)g_MemPoolMsg.Alloc( cubData );
+ m_cubData = cubData;
+
+ if( pCopyData )
+ {
+ Q_memcpy( m_pubData, pCopyData, cubData );
+ }
+
+ AddRef();
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: adds to refcount
+//-----------------------------------------------------------------------------
+void CNetPacket::AddRef()
+{
+ ++m_cRef;
+}
+
+//-----------------------------------------------------------------------------
+void CNetPacket::InitAdoptBuffer( uint32 cubData, uint8* pubData )
+{
+ Assert( !m_pubData );
+
+ m_pubData = pubData;
+ m_cubData = cubData;
+
+ AddRef();
+}
+
+//-----------------------------------------------------------------------------
+void CNetPacket::OrphanBuffer()
+{
+ m_pubData = NULL;
+ m_cubData = 0;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: decrements refcount
+//-----------------------------------------------------------------------------
+void CNetPacket::Release()
+{
+ Assert( m_cRef > 0 );
+ if ( --m_cRef == 0 )
+ {
+ // delete the network buffer we're associated with, if we have one
+ if ( m_pubData )
+ {
+ g_MemPoolMsg.Free( m_pubData );
+ }
+ // delete ourselves
+ g_cNetPacket--;
+ CNetPacketPool::sm_MemPoolNetPacket.Free( this );
+ }
+}
+
+} // namespace GCSDK