ClickHouse/src/Server/TCPHandlerFactory.h

50 lines
1.3 KiB
C++
Raw Normal View History

2017-08-09 14:33:07 +00:00
#pragma once
#include <Poco/Net/TCPServerConnectionFactory.h>
2020-04-15 03:56:42 +00:00
#include <Poco/Net/NetException.h>
2017-09-01 19:04:46 +00:00
#include <common/logger_useful.h>
#include <Server/IServer.h>
#include <Server/TCPHandler.h>
2017-08-09 14:33:07 +00:00
2017-09-01 19:04:46 +00:00
namespace Poco { class Logger; }
2017-08-09 14:33:07 +00:00
namespace DB
{
class TCPHandlerFactory : public Poco::Net::TCPServerConnectionFactory
{
private:
IServer & server;
2017-09-01 19:04:46 +00:00
Poco::Logger * log;
2017-08-09 14:33:07 +00:00
2020-04-15 03:56:42 +00:00
class DummyTCPHandler : public Poco::Net::TCPServerConnection
{
public:
using Poco::Net::TCPServerConnection::TCPServerConnection;
void run() override {}
};
2017-08-09 14:33:07 +00:00
public:
2018-03-13 19:49:21 +00:00
explicit TCPHandlerFactory(IServer & server_, bool secure_ = false)
2017-08-09 14:33:07 +00:00
: server(server_)
2020-05-30 21:57:37 +00:00
, log(&Poco::Logger::get(std::string("TCP") + (secure_ ? "S" : "") + "HandlerFactory"))
2017-08-09 14:33:07 +00:00
{
}
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket) override
{
2020-04-15 03:56:42 +00:00
try
{
2020-05-23 22:24:01 +00:00
LOG_TRACE(log, "TCP Request. Address: {}", socket.peerAddress().toString());
2020-04-15 03:56:42 +00:00
return new TCPHandler(server, socket);
}
catch (const Poco::Net::NetException &)
2020-04-15 03:56:42 +00:00
{
2020-05-23 22:24:01 +00:00
LOG_TRACE(log, "TCP Request. Client is not connected (most likely RST packet was sent).");
2020-04-15 03:56:42 +00:00
return new DummyTCPHandler(socket);
}
2017-08-09 14:33:07 +00:00
}
};
}