ClickHouse/src/Server/TCPProtocolStackHandler.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 KiB
C++
Raw Normal View History

2022-09-11 19:00:40 +00:00
#pragma once
#include <Server/TCPServerConnectionFactory.h>
#include <Server/TCPServer.h>
#include <Poco/Util/LayeredConfiguration.h>
#include <Server/IServer.h>
#include <Server/TCPProtocolStackData.h>
2022-09-11 19:00:40 +00:00
namespace DB
{
class TCPProtocolStackHandler : public Poco::Net::TCPServerConnection
{
using StreamSocket = Poco::Net::StreamSocket;
using TCPServerConnection = Poco::Net::TCPServerConnection;
private:
IServer & server;
2022-09-11 19:00:40 +00:00
TCPServer & tcp_server;
2022-09-29 00:13:40 +00:00
std::vector<TCPServerConnectionFactory::Ptr> stack;
2022-09-11 19:00:40 +00:00
std::string conf_name;
public:
2022-09-29 00:13:40 +00:00
TCPProtocolStackHandler(IServer & server_, TCPServer & tcp_server_, const StreamSocket & socket, const std::vector<TCPServerConnectionFactory::Ptr> & stack_, const std::string & conf_name_)
: TCPServerConnection(socket), server(server_), tcp_server(tcp_server_), stack(stack_), conf_name(conf_name_)
2022-09-11 19:00:40 +00:00
{}
void run() override
{
const auto & conf = server.config();
2022-09-11 19:00:40 +00:00
TCPProtocolStackData stack_data;
stack_data.socket = socket();
stack_data.default_database = conf.getString(conf_name + ".default_database", "");
2022-09-11 19:00:40 +00:00
for (auto & factory : stack)
{
std::unique_ptr<TCPServerConnection> connection(factory->createConnection(socket(), tcp_server, stack_data));
connection->run();
if (stack_data.socket != socket())
socket() = stack_data.socket;
}
}
};
}