From 6ef5d2deba355460312f3181b7f2af43b269f2c9 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 8 Apr 2013 09:44:12 +0200 Subject: [PATCH] Fix FIFO bug. --- lib/base/fifo.cpp | 12 ++++++++---- lib/base/fifo.h | 2 +- lib/remoting/endpoint.cpp | 2 -- lib/remoting/endpointmanager.cpp | 4 +--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/base/fifo.cpp b/lib/base/fifo.cpp index cc12f422f..b908c7843 100644 --- a/lib/base/fifo.cpp +++ b/lib/base/fifo.cpp @@ -42,13 +42,16 @@ FIFO::~FIFO(void) * * @param newSize The minimum new size of the FIFO buffer. */ -void FIFO::ResizeBuffer(size_t newSize) +void FIFO::ResizeBuffer(size_t newSize, bool decrease) { - if (m_AllocSize >= newSize) + if (m_AllocSize >= newSize && !decrease) return; newSize = (newSize / FIFO::BlockSize + 1) * FIFO::BlockSize; + if (newSize == m_AllocSize) + return; + char *newBuffer = static_cast(realloc(m_Buffer, newSize)); if (newBuffer == NULL) @@ -69,7 +72,8 @@ void FIFO::Optimize(void) memcpy(m_Buffer, m_Buffer + m_Offset, m_DataSize); m_Offset = 0; - ResizeBuffer(m_DataSize); + if (m_DataSize > 0) + ResizeBuffer(m_DataSize, true); return; } @@ -99,7 +103,7 @@ size_t FIFO::Read(void *buffer, size_t count) */ void FIFO::Write(const void *buffer, size_t count) { - ResizeBuffer(m_Offset + m_DataSize + count); + ResizeBuffer(m_Offset + m_DataSize + count, false); memcpy(m_Buffer + m_Offset + m_DataSize, buffer, count); m_DataSize += count; } diff --git a/lib/base/fifo.h b/lib/base/fifo.h index 4c41a9c89..97c81e1a1 100644 --- a/lib/base/fifo.h +++ b/lib/base/fifo.h @@ -54,7 +54,7 @@ private: size_t m_AllocSize; size_t m_Offset; - void ResizeBuffer(size_t newSize); + void ResizeBuffer(size_t newSize, bool decrease); void Optimize(void); }; diff --git a/lib/remoting/endpoint.cpp b/lib/remoting/endpoint.cpp index 713aad064..151e3c3ef 100644 --- a/lib/remoting/endpoint.cpp +++ b/lib/remoting/endpoint.cpp @@ -292,8 +292,6 @@ void Endpoint::MessageThreadProc(const Stream::Ptr& stream) } catch (const std::exception& ex) { Log(LogWarning, "jsonrpc", "Error while reading JSON-RPC message for endpoint '" + GetName() + "': " + boost::diagnostic_information(ex)); - GetClient()->Close(); - m_Client.reset(); } diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp index ff5759f37..af517bfd9 100644 --- a/lib/remoting/endpointmanager.cpp +++ b/lib/remoting/endpointmanager.cpp @@ -203,9 +203,7 @@ void EndpointManager::NewClientHandler(const Socket::Ptr& client, TlsRole role) if (!endpoint) endpoint = Endpoint::MakeEndpoint(identity, true); - BufferedStream::Ptr bufferedStream = boost::make_shared(tlsStream); - - endpoint->SetClient(bufferedStream); + endpoint->SetClient(tlsStream); } /** -- 2.40.0