[icinga-checkins] icinga.org: icinga2/mfriedrich/config: Fix FIFO bug.
git at icinga.org
git at icinga.org
Mon Apr 8 11:20:14 CEST 2013
Module: icinga2
Branch: mfriedrich/config
Commit: 6ef5d2deba355460312f3181b7f2af43b269f2c9
URL: https://git.icinga.org/?p=icinga2.git;a=commit;h=6ef5d2deba355460312f3181b7f2af43b269f2c9
Author: Gunnar Beutner <gunnar at beutner.name>
Date: Mon Apr 8 09:44:12 2013 +0200
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 cc12f42..b908c78 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<char *>(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 4c41a9c..97c81e1 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 713aad0..151e3c3 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 ff5759f..af517bf 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<BufferedStream>(tlsStream);
-
- endpoint->SetClient(bufferedStream);
+ endpoint->SetClient(tlsStream);
}
/**
More information about the icinga-checkins
mailing list