mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 07:04:37 +02:00
Timeout#Timeout(): drop unnecessary template parameters
This commit is contained in:
parent
d2285bcf0e
commit
cb51649363
@ -3,6 +3,7 @@
|
|||||||
#ifndef IO_ENGINE_H
|
#ifndef IO_ENGINE_H
|
||||||
#define IO_ENGINE_H
|
#define IO_ENGINE_H
|
||||||
|
|
||||||
|
#include "base/debug.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/lazy-init.hpp"
|
#include "base/lazy-init.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
@ -169,12 +170,15 @@ class Timeout : public SharedObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(Timeout);
|
DECLARE_PTR_TYPEDEFS(Timeout);
|
||||||
|
using Timer = boost::asio::deadline_timer;
|
||||||
|
|
||||||
template<class Executor, class TimeoutFromNow, class OnTimeout>
|
template<class OnTimeout>
|
||||||
Timeout(boost::asio::io_context& io, Executor& executor, TimeoutFromNow timeoutFromNow, OnTimeout onTimeout)
|
Timeout(boost::asio::io_context::strand& strand, const Timer::duration_type& timeoutFromNow, OnTimeout onTimeout)
|
||||||
: m_Timer(io, timeoutFromNow)
|
: m_Timer(strand.context(), timeoutFromNow)
|
||||||
{
|
{
|
||||||
m_Timer.async_wait(boost::asio::bind_executor(executor, [onTimeout = std::move(onTimeout)](boost::system::error_code ec) {
|
VERIFY(strand.running_in_this_thread());
|
||||||
|
|
||||||
|
m_Timer.async_wait(boost::asio::bind_executor(strand, [onTimeout = std::move(onTimeout)](boost::system::error_code ec) {
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
onTimeout();
|
onTimeout();
|
||||||
}
|
}
|
||||||
@ -184,7 +188,7 @@ public:
|
|||||||
void Cancel();
|
void Cancel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::asio::deadline_timer m_Timer;
|
Timer m_Timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ void AsioTlsStream::GracefulDisconnect(boost::asio::io_context::strand& strand,
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Timeout::Ptr shutdownTimeout(new Timeout(strand.context(), strand, boost::posix_time::seconds(10),
|
Timeout::Ptr shutdownTimeout(new Timeout(strand, boost::posix_time::seconds(10),
|
||||||
[this] {
|
[this] {
|
||||||
// Forcefully terminate the connection if async_shutdown() blocked more than 10 seconds.
|
// Forcefully terminate the connection if async_shutdown() blocked more than 10 seconds.
|
||||||
ForceDisconnect();
|
ForceDisconnect();
|
||||||
|
@ -515,7 +515,6 @@ template<class StreamPtr>
|
|||||||
Timeout::Ptr RedisConnection::MakeTimeout(StreamPtr& stream)
|
Timeout::Ptr RedisConnection::MakeTimeout(StreamPtr& stream)
|
||||||
{
|
{
|
||||||
return new Timeout(
|
return new Timeout(
|
||||||
m_Strand.context(),
|
|
||||||
m_Strand,
|
m_Strand,
|
||||||
boost::posix_time::microseconds(intmax_t(m_ConnectTimeout * 1000000)),
|
boost::posix_time::microseconds(intmax_t(m_ConnectTimeout * 1000000)),
|
||||||
[stream] {
|
[stream] {
|
||||||
|
@ -456,7 +456,7 @@ void IfwApiCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
|||||||
IoEngine::SpawnCoroutine(
|
IoEngine::SpawnCoroutine(
|
||||||
*strand,
|
*strand,
|
||||||
[strand, checkable, cr, psCommand, psHost, expectedSan, psPort, conn, req, checkTimeout, reportResult = std::move(reportResult)](asio::yield_context yc) {
|
[strand, checkable, cr, psCommand, psHost, expectedSan, psPort, conn, req, checkTimeout, reportResult = std::move(reportResult)](asio::yield_context yc) {
|
||||||
Timeout::Ptr timeout = new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(checkTimeout * 1e6)),
|
Timeout::Ptr timeout = new Timeout(*strand, boost::posix_time::microseconds(int64_t(checkTimeout * 1e6)),
|
||||||
[&conn, &checkable] {
|
[&conn, &checkable] {
|
||||||
Log(LogNotice, "IfwApiCheckTask")
|
Log(LogNotice, "IfwApiCheckTask")
|
||||||
<< "Timeout while checking " << checkable->GetReflectionType()->GetName()
|
<< "Timeout while checking " << checkable->GetReflectionType()->GetName()
|
||||||
|
@ -534,7 +534,7 @@ void ApiListener::ListenerCoroutineProc(boost::asio::yield_context yc, const Sha
|
|||||||
auto strand (Shared<asio::io_context::strand>::Make(io));
|
auto strand (Shared<asio::io_context::strand>::Make(io));
|
||||||
|
|
||||||
IoEngine::SpawnCoroutine(*strand, [this, strand, sslConn, remoteEndpoint](asio::yield_context yc) {
|
IoEngine::SpawnCoroutine(*strand, [this, strand, sslConn, remoteEndpoint](asio::yield_context yc) {
|
||||||
Timeout::Ptr timeout(new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)),
|
Timeout::Ptr timeout (new Timeout(*strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)),
|
||||||
[sslConn, remoteEndpoint] {
|
[sslConn, remoteEndpoint] {
|
||||||
Log(LogWarning, "ApiListener")
|
Log(LogWarning, "ApiListener")
|
||||||
<< "Timeout while processing incoming connection from " << remoteEndpoint;
|
<< "Timeout while processing incoming connection from " << remoteEndpoint;
|
||||||
@ -585,7 +585,7 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
|
|||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
Timeout::Ptr timeout(new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)),
|
Timeout::Ptr timeout (new Timeout(*strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)),
|
||||||
[sslConn, endpoint, host, port] {
|
[sslConn, endpoint, host, port] {
|
||||||
Log(LogCritical, "ApiListener")
|
Log(LogCritical, "ApiListener")
|
||||||
<< "Timeout while reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host
|
<< "Timeout while reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host
|
||||||
@ -684,7 +684,6 @@ void ApiListener::NewClientHandlerInternal(
|
|||||||
|
|
||||||
{
|
{
|
||||||
Timeout::Ptr handshakeTimeout (new Timeout(
|
Timeout::Ptr handshakeTimeout (new Timeout(
|
||||||
strand->context(),
|
|
||||||
*strand,
|
*strand,
|
||||||
boost::posix_time::microseconds(intmax_t(Configuration::TlsHandshakeTimeout * 1000000)),
|
boost::posix_time::microseconds(intmax_t(Configuration::TlsHandshakeTimeout * 1000000)),
|
||||||
[client] {
|
[client] {
|
||||||
|
@ -19,7 +19,7 @@ BOOST_AUTO_TEST_CASE(timeout_run)
|
|||||||
boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
|
boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
|
||||||
boost::asio::deadline_timer timer (io);
|
boost::asio::deadline_timer timer (io);
|
||||||
|
|
||||||
Timeout::Ptr timeout = new Timeout(io, strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
Timeout::Ptr timeout = new Timeout(strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
||||||
BOOST_CHECK_EQUAL(called, 0);
|
BOOST_CHECK_EQUAL(called, 0);
|
||||||
|
|
||||||
timer.expires_from_now(boost::posix_time::millisec(200));
|
timer.expires_from_now(boost::posix_time::millisec(200));
|
||||||
@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(timeout_cancelled)
|
|||||||
|
|
||||||
boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
|
boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
|
||||||
boost::asio::deadline_timer timer (io);
|
boost::asio::deadline_timer timer (io);
|
||||||
Timeout::Ptr timeout = new Timeout(io, strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
Timeout::Ptr timeout = new Timeout(strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
||||||
|
|
||||||
timer.expires_from_now(boost::posix_time::millisec(200));
|
timer.expires_from_now(boost::posix_time::millisec(200));
|
||||||
timer.async_wait(yc);
|
timer.async_wait(yc);
|
||||||
@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(timeout_scope)
|
|||||||
boost::asio::deadline_timer timer (io);
|
boost::asio::deadline_timer timer (io);
|
||||||
|
|
||||||
{
|
{
|
||||||
Timeout::Ptr timeout = new Timeout(io, strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
Timeout::Ptr timeout = new Timeout(strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
||||||
|
|
||||||
timer.expires_from_now(boost::posix_time::millisec(200));
|
timer.expires_from_now(boost::posix_time::millisec(200));
|
||||||
timer.async_wait(yc);
|
timer.async_wait(yc);
|
||||||
@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_cancelled)
|
|||||||
|
|
||||||
boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
|
boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
|
||||||
boost::asio::deadline_timer timer (io);
|
boost::asio::deadline_timer timer (io);
|
||||||
Timeout::Ptr timeout = new Timeout(io, strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
Timeout::Ptr timeout = new Timeout(strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
||||||
|
|
||||||
// Give the timeout enough time to become due while blocking its strand to prevent it from actually running...
|
// Give the timeout enough time to become due while blocking its strand to prevent it from actually running...
|
||||||
Utility::Sleep(0.4);
|
Utility::Sleep(0.4);
|
||||||
@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_scope)
|
|||||||
boost::asio::deadline_timer timer (io);
|
boost::asio::deadline_timer timer (io);
|
||||||
|
|
||||||
{
|
{
|
||||||
Timeout::Ptr timeout = new Timeout(io, strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
Timeout::Ptr timeout = new Timeout(strand, boost::posix_time::millisec(300), [&called] { ++called; });
|
||||||
|
|
||||||
// Give the timeout enough time to become due while blocking its strand to prevent it from actually running...
|
// Give the timeout enough time to become due while blocking its strand to prevent it from actually running...
|
||||||
Utility::Sleep(0.4);
|
Utility::Sleep(0.4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user