ClickHouse/src/Server/KeeperTCPHandlerFactory.h

49 lines
1.3 KiB
C++
Raw Normal View History

#pragma once
2021-02-01 13:18:17 +00:00
2021-03-29 08:24:56 +00:00
#include <Server/KeeperTCPHandler.h>
#include <Server/TCPServerConnectionFactory.h>
#include <Poco/Net/NetException.h>
2021-10-02 07:13:14 +00:00
#include <base/logger_useful.h>
#include <Server/IServer.h>
#include <string>
namespace DB
{
class KeeperTCPHandlerFactory : public TCPServerConnectionFactory
{
private:
IServer & server;
Poco::Logger * log;
class DummyTCPHandler : public Poco::Net::TCPServerConnection
{
public:
using Poco::Net::TCPServerConnection::TCPServerConnection;
void run() override {}
};
2021-11-18 20:17:22 +00:00
public:
KeeperTCPHandlerFactory(IServer & server_, bool secure)
: server(server_)
, log(&Poco::Logger::get(std::string{"KeeperTCP"} + (secure ? "S" : "") + "HandlerFactory"))
{
}
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket, TCPServer &) override
{
try
{
2021-03-29 08:24:56 +00:00
LOG_TRACE(log, "Keeper request. Address: {}", socket.peerAddress().toString());
return new KeeperTCPHandler(server, socket);
}
catch (const Poco::Net::NetException &)
{
LOG_TRACE(log, "TCP Request. Client is not connected (most likely RST packet was sent).");
return new DummyTCPHandler(socket);
}
}
2021-11-18 20:17:22 +00:00
};
}