mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
Fix FIFO bug.
This commit is contained in:
parent
06839ba4b0
commit
6ef5d2deba
@ -42,13 +42,16 @@ FIFO::~FIFO(void)
|
|||||||
*
|
*
|
||||||
* @param newSize The minimum new size of the FIFO buffer.
|
* @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;
|
return;
|
||||||
|
|
||||||
newSize = (newSize / FIFO::BlockSize + 1) * FIFO::BlockSize;
|
newSize = (newSize / FIFO::BlockSize + 1) * FIFO::BlockSize;
|
||||||
|
|
||||||
|
if (newSize == m_AllocSize)
|
||||||
|
return;
|
||||||
|
|
||||||
char *newBuffer = static_cast<char *>(realloc(m_Buffer, newSize));
|
char *newBuffer = static_cast<char *>(realloc(m_Buffer, newSize));
|
||||||
|
|
||||||
if (newBuffer == NULL)
|
if (newBuffer == NULL)
|
||||||
@ -69,7 +72,8 @@ void FIFO::Optimize(void)
|
|||||||
memcpy(m_Buffer, m_Buffer + m_Offset, m_DataSize);
|
memcpy(m_Buffer, m_Buffer + m_Offset, m_DataSize);
|
||||||
m_Offset = 0;
|
m_Offset = 0;
|
||||||
|
|
||||||
ResizeBuffer(m_DataSize);
|
if (m_DataSize > 0)
|
||||||
|
ResizeBuffer(m_DataSize, true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -99,7 +103,7 @@ size_t FIFO::Read(void *buffer, size_t count)
|
|||||||
*/
|
*/
|
||||||
void FIFO::Write(const 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);
|
memcpy(m_Buffer + m_Offset + m_DataSize, buffer, count);
|
||||||
m_DataSize += count;
|
m_DataSize += count;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ private:
|
|||||||
size_t m_AllocSize;
|
size_t m_AllocSize;
|
||||||
size_t m_Offset;
|
size_t m_Offset;
|
||||||
|
|
||||||
void ResizeBuffer(size_t newSize);
|
void ResizeBuffer(size_t newSize, bool decrease);
|
||||||
void Optimize(void);
|
void Optimize(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -292,8 +292,6 @@ void Endpoint::MessageThreadProc(const Stream::Ptr& stream)
|
|||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
Log(LogWarning, "jsonrpc", "Error while reading JSON-RPC message for endpoint '" + GetName() + "': " + boost::diagnostic_information(ex));
|
Log(LogWarning, "jsonrpc", "Error while reading JSON-RPC message for endpoint '" + GetName() + "': " + boost::diagnostic_information(ex));
|
||||||
|
|
||||||
GetClient()->Close();
|
|
||||||
|
|
||||||
m_Client.reset();
|
m_Client.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,9 +203,7 @@ void EndpointManager::NewClientHandler(const Socket::Ptr& client, TlsRole role)
|
|||||||
if (!endpoint)
|
if (!endpoint)
|
||||||
endpoint = Endpoint::MakeEndpoint(identity, true);
|
endpoint = Endpoint::MakeEndpoint(identity, true);
|
||||||
|
|
||||||
BufferedStream::Ptr bufferedStream = boost::make_shared<BufferedStream>(tlsStream);
|
endpoint->SetClient(tlsStream);
|
||||||
|
|
||||||
endpoint->SetClient(bufferedStream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user