ReadBufferFromPocoSocket.h 999 字节
Newer Older
1 2
#pragma once

3
#include <IO/BufferWithOwnMemory.h>
4 5 6
#include <IO/ReadBuffer.h>

#include <Poco/Net/Socket.h>
7 8 9 10

namespace DB
{

11
/// Works with the ready Poco::Net::Socket. Blocking operations.
12 13 14
class ReadBufferFromPocoSocket : public BufferWithOwnMemory<ReadBuffer>
{
protected:
15
    Poco::Net::Socket & socket;
16

F
f1yegor 已提交
17 18 19
    /** 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).
20 21
      */
    Poco::Net::SocketAddress peer_address;
22

23
    bool nextImpl() override;
24 25

public:
26
    explicit ReadBufferFromPocoSocket(Poco::Net::Socket & socket_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE);
27

28
    bool poll(size_t timeout_microseconds) const;
29

30
    void setAsyncCallback(std::function<void(Poco::Net::Socket &)> async_callback_) { async_callback = std::move(async_callback_); }
31 32

private:
33
    std::function<void(Poco::Net::Socket &)> async_callback;
34 35 36
};

}