fix: Client receiving big package failed
This commit is contained in:
@@ -30,103 +30,101 @@ CBuffer::~CBuffer(void)
|
||||
|
||||
ULONG CBuffer::ReadBuffer(PBYTE Buffer, ULONG ulLength)
|
||||
{
|
||||
if (ulLength > GetBufferMaxLength())
|
||||
if (ulLength > m_ulMaxLength)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (ulLength > GetBufferLength())
|
||||
ULONG len = (ULONG)m_Ptr - (ULONG)m_Base;
|
||||
if (ulLength > len)
|
||||
{
|
||||
ulLength = GetBufferLength();
|
||||
ulLength = len;
|
||||
}
|
||||
|
||||
if (ulLength)
|
||||
{
|
||||
CopyMemory(Buffer,m_Base,ulLength);
|
||||
|
||||
MoveMemory(m_Base,m_Base+ulLength,GetBufferMaxLength() - ulLength);
|
||||
MoveMemory(m_Base,m_Base+ulLength, m_ulMaxLength - ulLength);
|
||||
m_Ptr -= ulLength;
|
||||
}
|
||||
|
||||
DeAllocateBuffer(GetBufferLength());
|
||||
DeAllocateBuffer((ULONG)m_Ptr - (ULONG)m_Base);
|
||||
|
||||
return ulLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ULONG CBuffer::DeAllocateBuffer(ULONG ulLength)
|
||||
// <20><><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>С
|
||||
VOID CBuffer::DeAllocateBuffer(ULONG ulLength)
|
||||
{
|
||||
if (ulLength < GetBufferLength())
|
||||
return 0;
|
||||
int len = (ULONG)m_Ptr - (ULONG)m_Base;
|
||||
if (ulLength < len)
|
||||
return;
|
||||
|
||||
ULONG ulNewMaxLength = (ULONG)ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
|
||||
|
||||
if (GetBufferMaxLength() <= ulNewMaxLength)
|
||||
if (m_ulMaxLength <= ulNewMaxLength)
|
||||
{
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
PBYTE NewBase = (PBYTE) VirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||
if (NewBase == NULL)
|
||||
return 0;
|
||||
ULONG ulv1 = GetBufferLength(); //<2F><>ԭ<EFBFBD><D4AD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
|
||||
CopyMemory(NewBase,m_Base,ulv1);
|
||||
return;
|
||||
|
||||
CopyMemory(NewBase,m_Base,len);
|
||||
|
||||
VirtualFree(m_Base,0,MEM_RELEASE);
|
||||
|
||||
m_Base = NewBase;
|
||||
|
||||
m_Ptr = m_Base + ulv1;
|
||||
m_Ptr = m_Base + len;
|
||||
|
||||
m_ulMaxLength = ulNewMaxLength;
|
||||
|
||||
return m_ulMaxLength;
|
||||
}
|
||||
|
||||
|
||||
BOOL CBuffer::WriteBuffer(PBYTE Buffer, ULONG ulLength)
|
||||
{
|
||||
if (ReAllocateBuffer(ulLength + GetBufferLength()) == -1)//10 +1 1024
|
||||
if (ReAllocateBuffer(ulLength + ((ULONG)m_Ptr - (ULONG)m_Base)) == FALSE)
|
||||
{
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CopyMemory(m_Ptr,Buffer,ulLength);//Hello 5
|
||||
|
||||
CopyMemory(m_Ptr, Buffer, ulLength);
|
||||
m_Ptr+=ulLength;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ULONG CBuffer::ReAllocateBuffer(ULONG ulLength)
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>泤<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>·<EFBFBD><C2B7><EFBFBD>
|
||||
BOOL CBuffer::ReAllocateBuffer(ULONG ulLength)
|
||||
{
|
||||
if (ulLength < GetBufferMaxLength())
|
||||
return 0;
|
||||
if (ulLength < m_ulMaxLength)
|
||||
return TRUE;
|
||||
|
||||
ULONG ulNewMaxLength = (ULONG)ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
|
||||
PBYTE NewBase = (PBYTE) VirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||
if (NewBase == NULL)
|
||||
{
|
||||
return -1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ULONG ulv1 = GetBufferLength(); //ԭ<>ȵ<EFBFBD><C8B5><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
CopyMemory(NewBase,m_Base,ulv1);
|
||||
ULONG len = (ULONG)m_Ptr - (ULONG)m_Base;
|
||||
CopyMemory(NewBase, m_Base, len);
|
||||
|
||||
if (m_Base)
|
||||
{
|
||||
VirtualFree(m_Base,0,MEM_RELEASE);
|
||||
}
|
||||
m_Base = NewBase;
|
||||
m_Ptr = m_Base + ulv1; //1024
|
||||
m_Ptr = m_Base + len;
|
||||
m_ulMaxLength = ulNewMaxLength;
|
||||
|
||||
m_ulMaxLength = ulNewMaxLength; //2048
|
||||
|
||||
return m_ulMaxLength;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
VOID CBuffer::ClearBuffer()
|
||||
{
|
||||
m_Ptr = m_Base;
|
||||
@@ -136,27 +134,15 @@ VOID CBuffer::ClearBuffer()
|
||||
|
||||
|
||||
|
||||
ULONG CBuffer::GetBufferLength() const //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
ULONG CBuffer::GetBufferLength() const
|
||||
{
|
||||
if (m_Base == NULL)
|
||||
return 0;
|
||||
|
||||
return (ULONG)m_Ptr - (ULONG)m_Base;
|
||||
}
|
||||
|
||||
|
||||
ULONG CBuffer::GetBufferMaxLength() const
|
||||
{
|
||||
return m_ulMaxLength;
|
||||
}
|
||||
|
||||
PBYTE CBuffer::GetBuffer(ULONG ulPos) const
|
||||
{
|
||||
if (m_Base==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (ulPos>=GetBufferLength())
|
||||
if (m_Base==NULL || ulPos>=((ULONG)m_Ptr - (ULONG)m_Base))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user