summaryrefslogtreecommitdiffstats
path: root/source/ByteBuffer.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-04 21:06:46 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-04 21:06:46 +0200
commit5e5b87a18797967345d4933981c8500176de3870 (patch)
treedd0e84b9b709c760fe845a5f61580b94eebce4d9 /source/ByteBuffer.cpp
parentFixed a possible race condition in cClientHandle's packet sending code; prepared for moving cSocket out of cClientHandle's ownership. (diff)
downloadcuberite-5e5b87a18797967345d4933981c8500176de3870.tar
cuberite-5e5b87a18797967345d4933981c8500176de3870.tar.gz
cuberite-5e5b87a18797967345d4933981c8500176de3870.tar.bz2
cuberite-5e5b87a18797967345d4933981c8500176de3870.tar.lz
cuberite-5e5b87a18797967345d4933981c8500176de3870.tar.xz
cuberite-5e5b87a18797967345d4933981c8500176de3870.tar.zst
cuberite-5e5b87a18797967345d4933981c8500176de3870.zip
Diffstat (limited to '')
-rw-r--r--source/ByteBuffer.cpp28
1 files changed, 28 insertions, 0 deletions
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;