add ConnectionConfigurer

This commit is contained in:
linhaojun857 2023-09-16 13:32:39 +08:00
parent 7e14e48a98
commit 55971cf099
4 changed files with 68 additions and 2 deletions

View File

@ -171,6 +171,7 @@ add_library(oatpp
oatpp/network/monitor/StatCollector.hpp
oatpp/network/tcp/Connection.cpp
oatpp/network/tcp/Connection.hpp
oatpp/network/tcp/ConnectionConfigurer.hpp
oatpp/network/tcp/client/ConnectionProvider.cpp
oatpp/network/tcp/client/ConnectionProvider.hpp
oatpp/network/tcp/server/ConnectionProvider.cpp

View File

@ -0,0 +1,49 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_network_tcp_ConnectionConfigurer_hpp
#define oatpp_network_tcp_ConnectionConfigurer_hpp
namespace oatpp { namespace network { namespace tcp {
/**
* Connection configurer
*/
class ConnectionConfigurer {
public:
/**
* Constructor.
*/
virtual ~ConnectionConfigurer() = default;
/**
* Configure connection options.
* @param connection
*/
virtual void configure(oatpp::v_io_handle handle) = 0;
};
}}}
#endif

View File

@ -133,6 +133,10 @@ ConnectionProvider::ConnectionProvider(const network::Address& address, bool use
m_serverHandle = instantiateServer();
}
void ConnectionProvider::setConnectionConfigurer(const std::shared_ptr<ConnectionConfigurer> &connectionConfigurer) {
m_connectionConfigurer = connectionConfigurer;
}
ConnectionProvider::~ConnectionProvider() {
stop();
}
@ -329,6 +333,10 @@ void ConnectionProvider::prepareConnectionHandle(oatpp::v_io_handle handle) {
}
#endif
if(m_connectionConfigurer) {
m_connectionConfigurer->configure(handle);
}
}
provider::ResourceHandle<data::stream::IOStream> ConnectionProvider::getDefaultConnection() {

View File

@ -22,12 +22,13 @@
*
***************************************************************************/
#ifndef oatpp_netword_tcp_server_ConnectionProvider_hpp
#define oatpp_netword_tcp_server_ConnectionProvider_hpp
#ifndef oatpp_network_tcp_server_ConnectionProvider_hpp
#define oatpp_network_tcp_server_ConnectionProvider_hpp
#include "oatpp/network/Address.hpp"
#include "oatpp/network/ConnectionProvider.hpp"
#include "oatpp/network/tcp/Connection.hpp"
#include "oatpp/network/tcp/ConnectionConfigurer.hpp"
#include "oatpp/core/Types.hpp"
@ -89,6 +90,7 @@ private:
std::atomic<bool> m_closed;
oatpp::v_io_handle m_serverHandle;
bool m_useExtendedConnections;
std::shared_ptr<ConnectionConfigurer> m_connectionConfigurer;
private:
oatpp::v_io_handle instantiateServer();
private:
@ -118,6 +120,12 @@ public:
return std::make_shared<ConnectionProvider>(address, useExtendedConnections);
}
/**
* Set connection configurer.
* @param connectionConfigurer
*/
void setConnectionConfigurer(const std::shared_ptr<ConnectionConfigurer>& connectionConfigurer);
/**
* Virtual destructor.
*/