ClickHouse/src/IO/ReadBufferFromIStream.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.1 KiB
C++
Raw Normal View History

2018-07-09 20:36:58 +00:00
#include <IO/ReadBufferFromIStream.h>
#include <Common/Exception.h>
namespace DB
{
bool ReadBufferFromIStream::nextImpl()
{
2024-01-17 13:38:06 +00:00
if (eof)
return false;
2024-03-03 13:22:40 +00:00
chassert(internal_buffer.begin() != nullptr);
chassert(!internal_buffer.empty());
2023-11-18 22:59:09 +00:00
size_t bytes_read = 0;
2024-01-17 13:38:06 +00:00
char * read_to = internal_buffer.begin();
2018-07-09 20:36:58 +00:00
2024-01-17 13:38:06 +00:00
/// It is necessary to read in a loop, since socket usually returns only data available at the moment.
while (bytes_read < internal_buffer.size())
2023-11-18 22:59:09 +00:00
{
2024-03-03 13:22:40 +00:00
const auto bytes_read_last_time = stream_buf.readFromDevice(read_to, internal_buffer.size() - bytes_read);
if (bytes_read_last_time <= 0)
2023-11-18 22:59:09 +00:00
{
2024-03-03 13:22:40 +00:00
eof = true;
break;
2023-11-18 22:59:09 +00:00
}
2024-03-03 13:22:40 +00:00
bytes_read += bytes_read_last_time;
read_to += bytes_read_last_time;
2023-11-18 22:59:09 +00:00
}
2024-01-17 13:38:06 +00:00
if (bytes_read)
2024-03-03 13:22:40 +00:00
{
working_buffer = internal_buffer;
2023-11-18 22:59:09 +00:00
working_buffer.resize(bytes_read);
2024-03-03 13:22:40 +00:00
}
2018-07-09 20:36:58 +00:00
2024-01-17 13:38:06 +00:00
return bytes_read;
2018-07-09 20:36:58 +00:00
}
ReadBufferFromIStream::ReadBufferFromIStream(std::istream & istr_, size_t size)
2024-03-03 13:22:40 +00:00
: BufferWithOwnMemory<ReadBuffer>(size)
, istr(istr_)
, stream_buf(dynamic_cast<Poco::Net::HTTPBasicStreamBuf &>(*istr.rdbuf()))
2018-07-09 20:36:58 +00:00
{
}
}