forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetpacket.cpp
106 lines (85 loc) · 2.58 KB
/
netpacket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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