#pragma once #include #include #include #include #include namespace DB { /** Работает с готовым Poco::Net::Socket. Операции блокирующие. */ class ReadBufferFromPocoSocket : public BufferWithOwnMemory { protected: Poco::Net::Socket & socket; bool nextImpl() { ssize_t bytes_read = socket.impl()->receiveBytes(internal_buffer.begin(), internal_buffer.size()); if (bytes_read < 0) throw Exception("Cannot read from socket", ErrorCodes::CANNOT_READ_FROM_SOCKET); if (bytes_read) working_buffer.resize(bytes_read); else return false; return true; } public: ReadBufferFromPocoSocket(Poco::Net::Socket & socket_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE) : BufferWithOwnMemory(buf_size), socket(socket_) {} bool poll(size_t timeout_microseconds) { return offset() != buffer().size() || socket.poll(timeout_microseconds, Poco::Net::Socket::SELECT_READ | Poco::Net::Socket::SELECT_ERROR); } }; }