mirror of
https://github.com/oatpp/oatpp.git
synced 2025-04-18 19:00:23 +08:00
ConnectionMonitor: introduce ConnectionInactivityChecker
This commit is contained in:
parent
d47ae5c20a
commit
eb1296cbb5
@ -138,6 +138,8 @@ add_library(oatpp
|
||||
oatpp/encoding/Hex.hpp
|
||||
oatpp/encoding/Unicode.cpp
|
||||
oatpp/encoding/Unicode.hpp
|
||||
oatpp/network/monitor/ConnectionInactivityChecker.cpp
|
||||
oatpp/network/monitor/ConnectionInactivityChecker.hpp
|
||||
oatpp/network/monitor/ConnectionMaxAgeChecker.cpp
|
||||
oatpp/network/monitor/ConnectionMaxAgeChecker.hpp
|
||||
oatpp/network/monitor/ConnectionMonitor.cpp
|
||||
|
49
src/oatpp/network/monitor/ConnectionInactivityChecker.cpp
Normal file
49
src/oatpp/network/monitor/ConnectionInactivityChecker.cpp
Normal 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "ConnectionInactivityChecker.hpp"
|
||||
|
||||
namespace oatpp { namespace network { namespace monitor {
|
||||
|
||||
ConnectionInactivityChecker::ConnectionInactivityChecker(const std::chrono::duration<v_int64, std::micro>& lastReadTimeout,
|
||||
const std::chrono::duration<v_int64, std::micro>& lastWriteTimeout)
|
||||
: m_lastReadTimeout(lastReadTimeout)
|
||||
, m_lastWriteTimeout(lastWriteTimeout)
|
||||
{}
|
||||
|
||||
std::vector<oatpp::String> ConnectionInactivityChecker::getMetricsList() {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<StatCollector> ConnectionInactivityChecker::createStatCollector(const oatpp::String& metricName) {
|
||||
throw std::runtime_error("[oatpp::network::monitor::ConnectionInactivityChecker::createStatCollector()]: "
|
||||
"Error. ConnectionInactivityChecker doesn't use any stat collectors.");
|
||||
}
|
||||
|
||||
bool ConnectionInactivityChecker::check(const ConnectionStats& stats, v_int64 currMicroTime) {
|
||||
return currMicroTime - stats.timestampLastRead < m_lastReadTimeout.count() &&
|
||||
currMicroTime - stats.timestampLastWrite < m_lastWriteTimeout.count();
|
||||
}
|
||||
|
||||
}}}
|
51
src/oatpp/network/monitor/ConnectionInactivityChecker.hpp
Normal file
51
src/oatpp/network/monitor/ConnectionInactivityChecker.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* 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_monitor_ConnectionInactivityChecker_hpp
|
||||
#define oatpp_network_monitor_ConnectionInactivityChecker_hpp
|
||||
|
||||
#include "MetricsChecker.hpp"
|
||||
|
||||
namespace oatpp { namespace network { namespace monitor {
|
||||
|
||||
class ConnectionInactivityChecker : public MetricsChecker {
|
||||
private:
|
||||
std::chrono::duration<v_int64, std::micro> m_lastReadTimeout;
|
||||
std::chrono::duration<v_int64, std::micro> m_lastWriteTimeout;
|
||||
public:
|
||||
|
||||
ConnectionInactivityChecker(const std::chrono::duration<v_int64, std::micro>& lastReadTimeout,
|
||||
const std::chrono::duration<v_int64, std::micro>& lastWriteTimeout);
|
||||
|
||||
std::vector<oatpp::String> getMetricsList();
|
||||
|
||||
std::shared_ptr<StatCollector> createStatCollector(const oatpp::String& metricName);
|
||||
|
||||
bool check(const ConnectionStats& stats, v_int64 currMicroTime);
|
||||
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif //oatpp_network_monitor_ConnectionInactivityChecker_hpp
|
Loading…
x
Reference in New Issue
Block a user