From 5132161e30d44295ddfd66803a4f8134fa718610 Mon Sep 17 00:00:00 2001 From: crs Date: Thu, 2 May 2002 11:43:52 +0000 Subject: [PATCH] Fixed bug in stream buffer that could cause data to be inserted out of order. Also removed unnecessary limit on writes to the TCP socket. --- io/CStreamBuffer.cpp | 18 +++--------------- net/CTCPSocket.cpp | 4 ---- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/io/CStreamBuffer.cpp b/io/CStreamBuffer.cpp index 2f78e6dc..d468847d 100644 --- a/io/CStreamBuffer.cpp +++ b/io/CStreamBuffer.cpp @@ -56,13 +56,13 @@ void CStreamBuffer::pop(UInt32 n) scan = m_chunks.erase(scan); assert(scan != m_chunks.end()); } - assert(n > 0); // remove left over bytes from the head chunk - scan->erase(scan->begin(), scan->begin() + n); + if (n > 0) { + scan->erase(scan->begin(), scan->begin() + n); + } } -#include "CLog.h" void CStreamBuffer::write( const void* vdata, UInt32 n) { @@ -72,28 +72,19 @@ void CStreamBuffer::write( if (n == 0) { return; } -log((CLOG_DEBUG "### %p buffering %d bytes onto %d bytes", this, n, m_size)); m_size += n; // cast data to bytes const UInt8* data = reinterpret_cast(vdata); -if (n > 1000) -log((CLOG_DEBUG "### %p src: %u %u %u %u %u %u %u %u", this, -data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7])); // point to last chunk if it has space, otherwise append an empty chunk ChunkList::iterator scan = m_chunks.end(); if (scan != m_chunks.begin()) { -log((CLOG_DEBUG "### %p at least one chunk", this)); --scan; if (scan->size() >= kChunkSize) -{ -log((CLOG_DEBUG "### %p last chunk full", this)); ++scan; -} } if (scan == m_chunks.end()) { -log((CLOG_DEBUG "### %p append chunk", this)); scan = m_chunks.insert(scan, Chunk()); } @@ -106,7 +97,6 @@ log((CLOG_DEBUG "### %p append chunk", this)); count = n; // transfer data -log((CLOG_DEBUG "### %p append %d bytes onto last chunk", this, count)); scan->insert(scan->end(), data, data + count); n -= count; data += count; @@ -115,7 +105,6 @@ log((CLOG_DEBUG "### %p append %d bytes onto last chunk", this, count)); if (n > 0) { ++scan; scan = m_chunks.insert(scan, Chunk()); -log((CLOG_DEBUG "### %p append chunk2", this)); } } } @@ -124,4 +113,3 @@ UInt32 CStreamBuffer::getSize() const { return m_size; } - diff --git a/net/CTCPSocket.cpp b/net/CTCPSocket.cpp index f5f4f3a5..dc631862 100644 --- a/net/CTCPSocket.cpp +++ b/net/CTCPSocket.cpp @@ -211,10 +211,6 @@ void CTCPSocket::ioService() // get amount of data to write UInt32 n = m_output->getSize(); - if (n > 4096) { - // limit write size - n = 4096; - } // write data const void* buffer = m_output->peek(n);