ClickHouse/programs/server/TCPHandlerFactory.h

50 lines
1.2 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>
2017-08-09 14:33:07 +00:00
#include "IServer.h"
#include "TCPHandler.h"
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_)
2018-03-13 19:58:26 +00:00
, log(&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
{
LOG_TRACE(log, "TCP Request. Address: " << socket.peerAddress().toString());
return new TCPHandler(server, socket);
}
catch (const Poco::Net::NetException & e)
{
LOG_TRACE(log, "TCP Request. Client is not connected (most likely RST packet was sent).");
return new DummyTCPHandler(socket);
}
2017-08-09 14:33:07 +00:00
}
};
}