From 5e5b87a18797967345d4933981c8500176de3870 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 4 Sep 2012 19:06:46 +0000 Subject: 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 --- source/ByteBuffer.cpp | 28 ++++++++++++++++++++++++++++ source/ByteBuffer.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/source/ByteBuffer.cpp b/source/ByteBuffer.cpp index 0f360a104..4f74ca19f 100644 --- a/source/ByteBuffer.cpp +++ b/source/ByteBuffer.cpp @@ -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; diff --git a/source/ByteBuffer.h b/source/ByteBuffer.h index c0ffed43c..3981ab066 100644 --- a/source/ByteBuffer.h +++ b/source/ByteBuffer.h @@ -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 -- cgit v1.2.3