mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-17 20:02:05 +00:00
b79ead9c84
* Replicate poco into base/poco/ * De-register poco submodule * Build poco from ClickHouse * Exclude poco from stylecheck * Exclude poco from whitespace check * Exclude poco from typo check * Remove x bit from sources/headers (the style check complained) * Exclude poco from duplicate include check * Fix fasttest * Remove contrib/poco-cmake/* * Simplify poco build descriptions * Remove poco stuff not used by ClickHouse * Glob poco sources * Exclude poco from clang-tidy
187 lines
3.3 KiB
C++
187 lines
3.3 KiB
C++
//
|
|
// FIFOBufferStream.cpp
|
|
//
|
|
// Library: Foundation
|
|
// Package: Streams
|
|
// Module: FIFOBufferStream
|
|
//
|
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
|
// and Contributors.
|
|
//
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
//
|
|
|
|
|
|
#include "Poco/FIFOBufferStream.h"
|
|
|
|
|
|
namespace Poco {
|
|
|
|
|
|
//
|
|
// FIFOBufferStreamBuf
|
|
//
|
|
|
|
|
|
FIFOBufferStreamBuf::FIFOBufferStreamBuf():
|
|
BufferedBidirectionalStreamBuf(STREAM_BUFFER_SIZE + 4, std::ios::in | std::ios::out),
|
|
_pFIFOBuffer(new FIFOBuffer(STREAM_BUFFER_SIZE, true)),
|
|
_fifoBuffer(*_pFIFOBuffer)
|
|
{
|
|
}
|
|
|
|
|
|
FIFOBufferStreamBuf::FIFOBufferStreamBuf(FIFOBuffer& fifoBuffer):
|
|
BufferedBidirectionalStreamBuf(fifoBuffer.size() + 4, std::ios::in | std::ios::out),
|
|
_pFIFOBuffer(0),
|
|
_fifoBuffer(fifoBuffer)
|
|
{
|
|
fifoBuffer.setNotify(true);
|
|
}
|
|
|
|
|
|
FIFOBufferStreamBuf::FIFOBufferStreamBuf(char* pBuffer, std::size_t length):
|
|
BufferedBidirectionalStreamBuf(length + 4, std::ios::in | std::ios::out),
|
|
_pFIFOBuffer(new FIFOBuffer(pBuffer, length, true)),
|
|
_fifoBuffer(*_pFIFOBuffer)
|
|
{
|
|
}
|
|
|
|
|
|
FIFOBufferStreamBuf::FIFOBufferStreamBuf(const char* pBuffer, std::size_t length):
|
|
BufferedBidirectionalStreamBuf(length + 4, std::ios::in | std::ios::out),
|
|
_pFIFOBuffer(new FIFOBuffer(pBuffer, length, true)),
|
|
_fifoBuffer(*_pFIFOBuffer)
|
|
{
|
|
}
|
|
|
|
|
|
FIFOBufferStreamBuf::FIFOBufferStreamBuf(std::size_t length):
|
|
BufferedBidirectionalStreamBuf(length + 4, std::ios::in | std::ios::out),
|
|
_pFIFOBuffer(new FIFOBuffer(length, true)),
|
|
_fifoBuffer(*_pFIFOBuffer)
|
|
{
|
|
}
|
|
|
|
|
|
FIFOBufferStreamBuf::~FIFOBufferStreamBuf()
|
|
{
|
|
delete _pFIFOBuffer;
|
|
}
|
|
|
|
|
|
int FIFOBufferStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
|
{
|
|
poco_assert (length > 0);
|
|
return static_cast<int>(_fifoBuffer.read(buffer, static_cast<std::size_t>(length)));
|
|
}
|
|
|
|
|
|
int FIFOBufferStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
|
{
|
|
poco_assert (length > 0);
|
|
return static_cast<int>(_fifoBuffer.write(buffer, static_cast<std::size_t>(length)));
|
|
}
|
|
|
|
|
|
//
|
|
// FIFOIOS
|
|
//
|
|
|
|
|
|
FIFOIOS::FIFOIOS(FIFOBuffer& fifoBuffer): _buf(fifoBuffer)
|
|
{
|
|
poco_ios_init(&_buf);
|
|
}
|
|
|
|
|
|
FIFOIOS::FIFOIOS(char* pBuffer, std::size_t length): _buf(pBuffer, length)
|
|
{
|
|
poco_ios_init(&_buf);
|
|
}
|
|
|
|
|
|
FIFOIOS::FIFOIOS(const char* pBuffer, std::size_t length): _buf(pBuffer, length)
|
|
{
|
|
poco_ios_init(&_buf);
|
|
}
|
|
|
|
|
|
FIFOIOS::FIFOIOS(std::size_t length): _buf(length)
|
|
{
|
|
poco_ios_init(&_buf);
|
|
}
|
|
|
|
|
|
FIFOIOS::~FIFOIOS()
|
|
{
|
|
try
|
|
{
|
|
_buf.sync();
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
FIFOBufferStreamBuf* FIFOIOS::rdbuf()
|
|
{
|
|
return &_buf;
|
|
}
|
|
|
|
|
|
void FIFOIOS::close()
|
|
{
|
|
_buf.sync();
|
|
}
|
|
|
|
|
|
//
|
|
// FIFOBufferStream
|
|
//
|
|
|
|
|
|
FIFOBufferStream::FIFOBufferStream(FIFOBuffer& fifoBuffer):
|
|
FIFOIOS(fifoBuffer),
|
|
std::iostream(&_buf),
|
|
readable(_buf.fifoBuffer().readable),
|
|
writable(_buf.fifoBuffer().writable)
|
|
{
|
|
}
|
|
|
|
|
|
FIFOBufferStream::FIFOBufferStream(char* pBuffer, std::size_t length):
|
|
FIFOIOS(pBuffer, length),
|
|
std::iostream(&_buf),
|
|
readable(_buf.fifoBuffer().readable),
|
|
writable(_buf.fifoBuffer().writable)
|
|
{
|
|
}
|
|
|
|
|
|
FIFOBufferStream::FIFOBufferStream(const char* pBuffer, std::size_t length):
|
|
FIFOIOS(pBuffer, length),
|
|
std::iostream(&_buf),
|
|
readable(_buf.fifoBuffer().readable),
|
|
writable(_buf.fifoBuffer().writable)
|
|
{
|
|
}
|
|
|
|
|
|
FIFOBufferStream::FIFOBufferStream(std::size_t length):
|
|
FIFOIOS(length),
|
|
std::iostream(&_buf),
|
|
readable(_buf.fifoBuffer().readable),
|
|
writable(_buf.fifoBuffer().writable)
|
|
{
|
|
}
|
|
|
|
|
|
FIFOBufferStream::~FIFOBufferStream()
|
|
{
|
|
}
|
|
|
|
|
|
} // namespace Poco
|