Fix FIFO bug.

This commit is contained in:
Gunnar Beutner 2013-04-08 09:44:12 +02:00
parent 06839ba4b0
commit 6ef5d2deba
4 changed files with 10 additions and 10 deletions

View File

@ -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;
}

View File

@ -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);
};

View File

@ -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();
}

View File

@ -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);
}
/**