Avoid error message on RST

This commit is contained in:
Alexey Milovidov 2020-04-15 06:56:42 +03:00
parent 747bb16677
commit ddd840a81b

View File

@ -1,6 +1,7 @@
#pragma once
#include <Poco/Net/TCPServerConnectionFactory.h>
#include <Poco/Net/NetException.h>
#include <common/logger_useful.h>
#include "IServer.h"
#include "TCPHandler.h"
@ -16,6 +17,13 @@ private:
IServer & server;
Poco::Logger * log;
class DummyTCPHandler : public Poco::Net::TCPServerConnection
{
public:
using Poco::Net::TCPServerConnection::TCPServerConnection;
void run() override {}
};
public:
explicit TCPHandlerFactory(IServer & server_, bool secure_ = false)
: server(server_)
@ -25,12 +33,16 @@ public:
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket) override
{
LOG_TRACE(log,
"TCP Request. "
<< "Address: "
<< socket.peerAddress().toString());
return new TCPHandler(server, socket);
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);
}
}
};