From e60b3a6feb7637b9591e0a34ce1f6121c9f331af Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Fri, 15 May 2015 15:04:16 +0100 Subject: [PATCH] Added truncating to IPC log buffer queue #4651 When the IPC log buffer is too large, the oldest log line is removed when a new log line is added. --- src/lib/ipc/IpcLogOutputter.cpp | 9 +++++++-- src/lib/ipc/IpcLogOutputter.h | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/ipc/IpcLogOutputter.cpp b/src/lib/ipc/IpcLogOutputter.cpp index 3f60e215..c718340c 100644 --- a/src/lib/ipc/IpcLogOutputter.cpp +++ b/src/lib/ipc/IpcLogOutputter.cpp @@ -116,7 +116,12 @@ void IpcLogOutputter::appendBuffer(const String& text) { ArchMutexLock lock(m_bufferMutex); - m_buffer.push(text); + if (m_buffer.size() >= m_bufferMaxSize) { + // if the queue is exceeds size limit, + // throw away the oldest item + m_buffer.pop_front(); + } + m_buffer.push_back(text); } void @@ -182,7 +187,7 @@ IpcLogOutputter::getChunk(size_t count) for (size_t i = 0; i < count; i++) { chunk.append(m_buffer.front()); chunk.append("\n"); - m_buffer.pop(); + m_buffer.pop_front(); } return chunk; } diff --git a/src/lib/ipc/IpcLogOutputter.h b/src/lib/ipc/IpcLogOutputter.h index b585b254..463e19c8 100644 --- a/src/lib/ipc/IpcLogOutputter.h +++ b/src/lib/ipc/IpcLogOutputter.h @@ -22,7 +22,7 @@ #include "arch/IArchMultithread.h" #include "base/ILogOutputter.h" -#include +#include class IpcServer; class Event; @@ -87,7 +87,7 @@ private: void appendBuffer(const String& text); private: - typedef std::queue Buffer; + typedef std::deque Buffer; IpcServer& m_ipcServer; Buffer m_buffer;