style: Format source code and support grouping client
This commit is contained in:
@@ -11,151 +11,143 @@
|
||||
|
||||
CBuffer::CBuffer()
|
||||
{
|
||||
m_ulMaxLength = 0;
|
||||
m_ulMaxLength = 0;
|
||||
|
||||
m_Ptr = m_Base = NULL;
|
||||
m_Ptr = m_Base = NULL;
|
||||
}
|
||||
|
||||
|
||||
CBuffer::~CBuffer(void)
|
||||
{
|
||||
if (m_Base)
|
||||
{
|
||||
MVirtualFree(m_Base, 0, MEM_RELEASE);
|
||||
m_Base = NULL;
|
||||
}
|
||||
if (m_Base) {
|
||||
MVirtualFree(m_Base, 0, MEM_RELEASE);
|
||||
m_Base = NULL;
|
||||
}
|
||||
|
||||
m_Base = m_Ptr = NULL;
|
||||
m_ulMaxLength = 0;
|
||||
m_Base = m_Ptr = NULL;
|
||||
m_ulMaxLength = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ULONG CBuffer::ReadBuffer(PBYTE Buffer, ULONG ulLength)
|
||||
{
|
||||
if (ulLength > m_ulMaxLength)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ULONG len = m_Ptr - m_Base;
|
||||
if (ulLength > len)
|
||||
{
|
||||
ulLength = len;
|
||||
}
|
||||
if (ulLength > m_ulMaxLength) {
|
||||
return 0;
|
||||
}
|
||||
ULONG len = m_Ptr - m_Base;
|
||||
if (ulLength > len) {
|
||||
ulLength = len;
|
||||
}
|
||||
|
||||
if (ulLength)
|
||||
{
|
||||
CopyMemory(Buffer,m_Base,ulLength);
|
||||
if (ulLength) {
|
||||
CopyMemory(Buffer,m_Base,ulLength);
|
||||
|
||||
MoveMemory(m_Base,m_Base+ulLength, m_ulMaxLength - ulLength);
|
||||
m_Ptr -= ulLength;
|
||||
}
|
||||
MoveMemory(m_Base,m_Base+ulLength, m_ulMaxLength - ulLength);
|
||||
m_Ptr -= ulLength;
|
||||
}
|
||||
|
||||
DeAllocateBuffer(m_Ptr - m_Base);
|
||||
DeAllocateBuffer(m_Ptr - m_Base);
|
||||
|
||||
return ulLength;
|
||||
return ulLength;
|
||||
}
|
||||
|
||||
|
||||
// <20><><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>С
|
||||
VOID CBuffer::DeAllocateBuffer(ULONG ulLength)
|
||||
VOID CBuffer::DeAllocateBuffer(ULONG ulLength)
|
||||
{
|
||||
int len = m_Ptr - m_Base;
|
||||
if (ulLength < len)
|
||||
return;
|
||||
int len = m_Ptr - m_Base;
|
||||
if (ulLength < len)
|
||||
return;
|
||||
|
||||
ULONG ulNewMaxLength = ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
|
||||
ULONG ulNewMaxLength = ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
|
||||
|
||||
if (m_ulMaxLength <= ulNewMaxLength)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PBYTE NewBase = (PBYTE) MVirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||
if (NewBase == NULL)
|
||||
return;
|
||||
if (m_ulMaxLength <= ulNewMaxLength) {
|
||||
return;
|
||||
}
|
||||
PBYTE NewBase = (PBYTE) MVirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||
if (NewBase == NULL)
|
||||
return;
|
||||
|
||||
CopyMemory(NewBase,m_Base,len);
|
||||
CopyMemory(NewBase,m_Base,len);
|
||||
|
||||
MVirtualFree(m_Base,0,MEM_RELEASE);
|
||||
MVirtualFree(m_Base,0,MEM_RELEASE);
|
||||
|
||||
m_Base = NewBase;
|
||||
m_Base = NewBase;
|
||||
|
||||
m_Ptr = m_Base + len;
|
||||
m_Ptr = m_Base + len;
|
||||
|
||||
m_ulMaxLength = ulNewMaxLength;
|
||||
m_ulMaxLength = ulNewMaxLength;
|
||||
}
|
||||
|
||||
|
||||
BOOL CBuffer::WriteBuffer(PBYTE Buffer, ULONG ulLength)
|
||||
{
|
||||
if (ReAllocateBuffer(ulLength + (m_Ptr - m_Base)) == FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (ReAllocateBuffer(ulLength + (m_Ptr - m_Base)) == FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CopyMemory(m_Ptr, Buffer, ulLength);
|
||||
m_Ptr+=ulLength;
|
||||
CopyMemory(m_Ptr, Buffer, ulLength);
|
||||
m_Ptr+=ulLength;
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>泤<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>·<EFBFBD><C2B7><EFBFBD>
|
||||
BOOL CBuffer::ReAllocateBuffer(ULONG ulLength)
|
||||
{
|
||||
if (ulLength < m_ulMaxLength)
|
||||
return TRUE;
|
||||
if (ulLength < m_ulMaxLength)
|
||||
return TRUE;
|
||||
|
||||
ULONG ulNewMaxLength = ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
|
||||
PBYTE NewBase = (PBYTE) MVirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||
if (NewBase == NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
ULONG ulNewMaxLength = ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
|
||||
PBYTE NewBase = (PBYTE) MVirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||
if (NewBase == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ULONG len = m_Ptr - m_Base;
|
||||
CopyMemory(NewBase, m_Base, len);
|
||||
ULONG len = m_Ptr - m_Base;
|
||||
CopyMemory(NewBase, m_Base, len);
|
||||
|
||||
if (m_Base)
|
||||
{
|
||||
MVirtualFree(m_Base,0,MEM_RELEASE);
|
||||
}
|
||||
m_Base = NewBase;
|
||||
m_Ptr = m_Base + len;
|
||||
m_ulMaxLength = ulNewMaxLength;
|
||||
if (m_Base) {
|
||||
MVirtualFree(m_Base,0,MEM_RELEASE);
|
||||
}
|
||||
m_Base = NewBase;
|
||||
m_Ptr = m_Base + len;
|
||||
m_ulMaxLength = ulNewMaxLength;
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
VOID CBuffer::ClearBuffer()
|
||||
{
|
||||
m_Ptr = m_Base;
|
||||
m_Ptr = m_Base;
|
||||
|
||||
DeAllocateBuffer(1024);
|
||||
DeAllocateBuffer(1024);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ULONG CBuffer::GetBufferLength() const
|
||||
ULONG CBuffer::GetBufferLength() const
|
||||
{
|
||||
return m_Ptr - m_Base;
|
||||
return m_Ptr - m_Base;
|
||||
}
|
||||
|
||||
|
||||
void CBuffer::Skip(ULONG ulPos) {
|
||||
if (ulPos == 0)
|
||||
return;
|
||||
MoveMemory(m_Base, m_Base + ulPos, m_ulMaxLength - ulPos);
|
||||
m_Ptr -= ulPos;
|
||||
void CBuffer::Skip(ULONG ulPos)
|
||||
{
|
||||
if (ulPos == 0)
|
||||
return;
|
||||
MoveMemory(m_Base, m_Base + ulPos, m_ulMaxLength - ulPos);
|
||||
m_Ptr -= ulPos;
|
||||
}
|
||||
|
||||
|
||||
PBYTE CBuffer::GetBuffer(ULONG ulPos) const
|
||||
{
|
||||
if (m_Base==NULL || ulPos>=(m_Ptr - m_Base))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return m_Base+ulPos;
|
||||
if (m_Base==NULL || ulPos>=(m_Ptr - m_Base)) {
|
||||
return NULL;
|
||||
}
|
||||
return m_Base+ulPos;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user