-
Notifications
You must be signed in to change notification settings - Fork 14
/
IOCPBuffer.h
98 lines (86 loc) · 2.56 KB
/
IOCPBuffer.h
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
#pragma once
typedef struct IOCPBufferData
{
ULONG m_nRefs;
BYTE* m_pData;
DWORD m_dwAllocLength;
DWORD m_dwDataLength;
IOCPBufferData( DWORD dwAllocLength );
IOCPBufferData( );
~IOCPBufferData( );
VOID AddRef( );
VOID Release( );
}IOCPBufferData, *PIOCPBufferData;
class CIOCPBuffer
{
public:
IOCPBufferData* m_pData;
public:
CIOCPBuffer(void);
CIOCPBuffer(DWORD dwAllocLength);
CIOCPBuffer(CIOCPBuffer& rhs);
CIOCPBuffer(CIOCPBuffer* rhs);
~CIOCPBuffer(void);
CIOCPBuffer& operator = (const CIOCPBuffer& rhs);
CIOCPBuffer& operator += (const CIOCPBuffer& rhs);
CIOCPBuffer operator + (const CIOCPBuffer& rhs);
void AddBytesAndReallocate(ULONG dwDataLength);
void Reallocate(ULONG dwAllocLength);
void Append(CONST BYTE* lpData,ULONG dwLength);
BYTE* GetBytes();
ULONG GetLength();
};
class IOCPBufferMngr
{
private:
IOCPMutex m_MutexLock;
IOCPMemPool <IOCPBufferData> m_BufferMemPool;
static IOCPBufferMngr* m_Instance;
private:
IOCPBufferMngr();
virtual ~IOCPBufferMngr();
public:
static IOCPBufferMngr* getInstance();
static void ReleasePool( );
static IOCPBufferData* Allocate(DWORD dwAllocLength);
static VOID Free(IOCPBufferData* pData);
static IOCPBufferData* Reallocate(IOCPBufferData* pData,DWORD dwAllocLength);
};
//
//template <class templateType>
//void __inline CIOCPBuffer::Write(const templateType &inTemplateVar)
//{
// AddBytesAndReallocate(sizeof(templateType));
//
// memcpy(&m_pData->m_pData[m_dwWriterPosition],&inTemplateVar,sizeof(templateType));
//
// m_dwWriterPosition += sizeof(templateType);
//}
//template <class templateType>
//void __inline CIOCPBuffer::WritePtr(templateType *inTemplateVar)
//{
// AddBytesAndReallocate(sizeof(templateType));
//
// memcpy(&m_pData->m_pData[m_dwWriterPosition],inTemplateVar,sizeof(templateType));
//
// m_dwWriterPosition += sizeof(templateType);
//}
//template <class templateType>
//void __inline CIOCPBuffer::Read(templateType &outTemplateVar) throw (...)
//{
// if(m_dwReaderPosition + sizeof(templateType) > m_pData->m_dwDataLength)
// throw std::exception("Read data length exceeds the buffer length.");
//
// memcpy(&outTemplateVar,&m_pData->m_pData[m_dwReaderPosition],sizeof(templateType));
//
// m_dwReaderPosition += sizeof(templateType);
//}
//
//template <class templateType>
//void __inline CIOCPBuffer::Peek(templateType &outTemplateVar) throw (...)
//{
// if(m_dwReaderPosition + sizeof(templateType) > m_pData->m_dwDataLength)
// throw std::exception("Read data length exceeds the buffer length.");
//
// memcpy(&outTemplateVar,&m_pData->m_pData[m_dwReaderPosition],sizeof(templateType));
//}