mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
LimitReadBuffer fix [#CLICKHOUSE-2].
This commit is contained in:
parent
eca1b39dee
commit
2e6eb504dc
@ -16,18 +16,44 @@ private:
|
||||
|
||||
bool nextImpl() override
|
||||
{
|
||||
if (count() >= limit || !in.next())
|
||||
/// Let underlying buffer calculate read bytes in `next()` call.
|
||||
in.position() = position();
|
||||
|
||||
if (bytes >= limit || !in.next())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
position() = in.position();
|
||||
|
||||
working_buffer = in.buffer();
|
||||
|
||||
if (limit - count() < working_buffer.size())
|
||||
{
|
||||
working_buffer.resize(limit - count());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
LimitReadBuffer(ReadBuffer & in_, size_t limit_) : ReadBuffer(nullptr, 0), in(in_), limit(limit_) {}
|
||||
LimitReadBuffer(ReadBuffer & in_, size_t limit_) : ReadBuffer(in_.position(), 0), in(in_), limit(limit_)
|
||||
{
|
||||
working_buffer = in.buffer();
|
||||
|
||||
size_t bytes_in_buffer = working_buffer.end() - position();
|
||||
|
||||
working_buffer = Buffer(position(), working_buffer.end());
|
||||
|
||||
if (limit < bytes_in_buffer)
|
||||
working_buffer.resize(limit);
|
||||
}
|
||||
virtual ~LimitReadBuffer() override
|
||||
{
|
||||
/// Update underlying buffer's position in case when limit wasn't reached.
|
||||
if (working_buffer.size() != 0)
|
||||
in.position() = position();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user