Debugging in cByteBuffer::Write(); added the ReadAgain() method to allow ProtoProxy re-send the data it has parsed.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@833 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
e3d5da2409
commit
5e5b87a187
@ -48,6 +48,11 @@ cByteBuffer::~cByteBuffer()
|
||||
|
||||
bool cByteBuffer::Write(const char * a_Bytes, int a_Count)
|
||||
{
|
||||
// DEBUG: Store the current free space for a check after writing
|
||||
int CurFreeSpace = GetFreeSpace();
|
||||
int CurReadableSpace = GetReadableSpace();
|
||||
int WrittenBytes = 0;
|
||||
|
||||
if (GetFreeSpace() < a_Count)
|
||||
{
|
||||
return false;
|
||||
@ -60,11 +65,16 @@ bool cByteBuffer::Write(const char * a_Bytes, int a_Count)
|
||||
m_WritePos = 0;
|
||||
a_Bytes += TillEnd;
|
||||
a_Count -= TillEnd;
|
||||
WrittenBytes = TillEnd;
|
||||
}
|
||||
|
||||
// We're guaranteed that we'll fit in a single write op
|
||||
memcpy(m_Buffer + m_WritePos, a_Bytes, a_Count);
|
||||
m_WritePos += a_Count;
|
||||
WrittenBytes += a_Count;
|
||||
|
||||
ASSERT(GetFreeSpace() == CurFreeSpace - WrittenBytes);
|
||||
ASSERT(GetReadableSpace() == CurReadableSpace + WrittenBytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -467,6 +477,24 @@ void cByteBuffer::ResetRead(void)
|
||||
|
||||
|
||||
|
||||
void cByteBuffer::ReadAgain(AString & a_Out)
|
||||
{
|
||||
// Return the data between m_DataStart and m_ReadPos (the data that has been read but not committed)
|
||||
// Used by ProtoProxy to repeat communication twice, once for parsing and the other time for the remote party
|
||||
int DataStart = m_DataStart;
|
||||
if (m_ReadPos < m_DataStart)
|
||||
{
|
||||
// Across the ringbuffer end, read the first part and adjust next part's start:
|
||||
a_Out.append(m_Buffer + m_DataStart, m_BufferSize - m_DataStart);
|
||||
DataStart = 0;
|
||||
}
|
||||
a_Out.append(m_Buffer + DataStart, m_ReadPos - DataStart);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cByteBuffer::AdvanceReadPos(int a_Count)
|
||||
{
|
||||
m_ReadPos += a_Count;
|
||||
|
@ -94,6 +94,9 @@ public:
|
||||
/// Restarts next reading operation at the start of the ringbuffer
|
||||
void ResetRead(void);
|
||||
|
||||
/// Re-reads the data that has been read since the last commit to the current readpos. Used by ProtoProxy to duplicate communication
|
||||
void ReadAgain(AString & a_Out);
|
||||
|
||||
protected:
|
||||
char * m_Buffer;
|
||||
int m_BufferSize; // Total size of the ringbuffer
|
||||
|
Loading…
Reference in New Issue
Block a user