2012-03-09 15:46:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Poco/Net/Socket.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
|
|
|
#include <IO/BufferWithOwnMemory.h>
|
2012-03-09 15:46:52 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/** Works with the ready Poco::Net::Socket. Blocking operations.
|
2012-03-09 15:46:52 +00:00
|
|
|
*/
|
|
|
|
class ReadBufferFromPocoSocket : public BufferWithOwnMemory<ReadBuffer>
|
|
|
|
{
|
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Net::Socket & socket;
|
2013-11-20 00:49:47 +00:00
|
|
|
|
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).
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
Poco::Net::SocketAddress peer_address;
|
2013-11-20 00:49:47 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool nextImpl() override;
|
2012-03-09 15:46:52 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBufferFromPocoSocket(Poco::Net::Socket & socket_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE);
|
2012-05-09 08:16:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool poll(size_t timeout_microseconds);
|
2020-12-02 17:02:14 +00:00
|
|
|
|
2020-12-18 14:24:44 +00:00
|
|
|
void setAsyncCallback(std::function<void(Poco::Net::Socket &)> async_callback_) { async_callback = std::move(async_callback_); }
|
2020-12-02 17:02:14 +00:00
|
|
|
|
|
|
|
private:
|
2020-12-18 14:24:44 +00:00
|
|
|
std::function<void(Poco::Net::Socket &)> async_callback;
|
2012-03-09 15:46:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|