ClickHouse/src/IO/ReadBufferFromPocoSocket.h

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

56 lines
1.8 KiB
C++
Raw Normal View History

2012-03-09 15:46:52 +00:00
#pragma once
#include <IO/BufferWithOwnMemory.h>
#include <IO/ReadBuffer.h>
2023-03-03 19:30:43 +00:00
#include <Common/AsyncTaskExecutor.h>
#include <Poco/Net/Socket.h>
2012-03-09 15:46:52 +00:00
namespace DB
{
/// Works with the ready Poco::Net::Socket. Blocking operations.
2024-05-31 04:18:36 +00:00
class ReadBufferFromPocoSocketBase : public BufferWithOwnMemory<ReadBuffer>
2012-03-09 15:46:52 +00:00
{
protected:
Poco::Net::Socket & socket;
2017-05-28 14:29:40 +00:00
/** For error messages. It is necessary to receive this address in advance, because,
* for example, if the connection is broken, the address will not be received anymore
* (getpeername will return an error).
*/
Poco::Net::SocketAddress peer_address;
ProfileEvents::Event read_event;
bool nextImpl() override;
2012-03-09 15:46:52 +00:00
public:
2024-05-31 04:18:36 +00:00
explicit ReadBufferFromPocoSocketBase(Poco::Net::Socket & socket_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE);
explicit ReadBufferFromPocoSocketBase(Poco::Net::Socket & socket_, const ProfileEvents::Event & read_event_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE);
2012-05-09 08:16:09 +00:00
bool poll(size_t timeout_microseconds) const;
2020-12-02 17:02:14 +00:00
2021-01-19 19:21:06 +00:00
void setAsyncCallback(AsyncCallback async_callback_) { async_callback = std::move(async_callback_); }
2020-12-02 17:02:14 +00:00
2024-05-31 04:18:36 +00:00
ssize_t socketReceiveBytesImpl(char * ptr, size_t size);
2024-05-14 15:37:20 +00:00
2024-10-26 18:59:45 +00:00
void setReceiveTimeout(size_t receive_timeout_microseconds);
2020-12-02 17:02:14 +00:00
private:
2021-01-19 19:21:06 +00:00
AsyncCallback async_callback;
2021-02-06 00:54:27 +00:00
std::string socket_description;
2012-03-09 15:46:52 +00:00
};
2024-05-31 04:18:36 +00:00
class ReadBufferFromPocoSocket : public ReadBufferFromPocoSocketBase
{
public:
explicit ReadBufferFromPocoSocket(Poco::Net::Socket & socket_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE)
2024-06-03 09:55:51 +00:00
: ReadBufferFromPocoSocketBase(socket_, buf_size)
2024-05-31 04:18:36 +00:00
{}
explicit ReadBufferFromPocoSocket(Poco::Net::Socket & socket_, const ProfileEvents::Event & read_event_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE)
: ReadBufferFromPocoSocketBase(socket_, read_event_, buf_size)
{}
};
2012-03-09 15:46:52 +00:00
}