ClickHouse/src/Server/TCPServer.cpp
Kevin Michel ffc1fca296
Start/stop servers when listen_host/*_port changes
This allows starting and stopping separately each protocol server
without restarting ClickHouse.

This also allows adding or removing `listen_host` entries, which
start and stops servers for all enabled ports.

When stopping a server, the listening socket is immediately closed
(and available for another server).

Protocols with persistent connections try to wait for any currently
running query to finish before closing the connection, but idle
connection are closed quickly (depending on how often the protocol
is polled).

An extra ProfileEvent is added, `MainConfigLoads`, it is
incremented every time the configuration is reloaded. This helps
when trying to assess whether the new configuration was applied.
2021-12-24 08:26:02 +01:00

37 lines
1.0 KiB
C++

#include <Poco/Net/TCPServerConnectionFactory.h>
#include <Server/TCPServer.h>
namespace DB
{
class TCPServerConnectionFactoryImpl : public Poco::Net::TCPServerConnectionFactory
{
public:
TCPServerConnectionFactoryImpl(TCPServer & tcp_server_, DB::TCPServerConnectionFactory::Ptr factory_)
: tcp_server(tcp_server_)
, factory(factory_)
{}
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket) override
{
return factory->createConnection(socket, tcp_server);
}
private:
TCPServer & tcp_server;
DB::TCPServerConnectionFactory::Ptr factory;
};
TCPServer::TCPServer(
TCPServerConnectionFactory::Ptr factory_,
Poco::ThreadPool & thread_pool,
Poco::Net::ServerSocket & socket_,
Poco::Net::TCPServerParams::Ptr params)
: Poco::Net::TCPServer(new TCPServerConnectionFactoryImpl(*this, factory_), thread_pool, socket_, params)
, factory(factory_)
, socket(socket_)
, is_open(true)
, port_number(socket.address().port())
{}
}