From a905e3124a84357830a5ff8304e2d3c3dce0799e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 20 Aug 2024 15:06:14 +0200 Subject: [PATCH] event/net/PingClient: remove the timeout feature Anybody using this class shall implement their own timeout. --- demo/net/RunPing.cxx | 4 ---- src/event/net/PingClient.cxx | 13 ------------- src/event/net/PingClient.hxx | 5 ----- 3 files changed, 22 deletions(-) diff --git a/demo/net/RunPing.cxx b/demo/net/RunPing.cxx index 47478ef07..04cd519e1 100644 --- a/demo/net/RunPing.cxx +++ b/demo/net/RunPing.cxx @@ -20,10 +20,6 @@ class MyPingClientHandler final : public PingClientHandler { printf("ok\n"); } - void PingTimeout() noexcept override { - fprintf(stderr, "timeout\n"); - } - void PingError(std::exception_ptr ep) noexcept override { PrintException(ep); } diff --git a/src/event/net/PingClient.cxx b/src/event/net/PingClient.cxx index cbcc6e238..8a962898c 100644 --- a/src/event/net/PingClient.cxx +++ b/src/event/net/PingClient.cxx @@ -26,7 +26,6 @@ PingClient::PingClient(EventLoop &event_loop, PingClientHandler &_handler) noexcept :event(event_loop, BIND_THIS_METHOD(EventCallback)), - timeout_event(event_loop, BIND_THIS_METHOD(OnTimeout)), handler(_handler) { } @@ -35,7 +34,6 @@ inline void PingClient::ScheduleRead() noexcept { event.ScheduleRead(); - timeout_event.Schedule(std::chrono::seconds(10)); } static bool @@ -73,12 +71,10 @@ PingClient::Read() noexcept if (cc >= 0) { if (parse_reply(header, payload, cc, ident)) { event.Close(); - timeout_event.Cancel(); handler.PingResponse(); } } else if (const auto e = GetSocketError(); !IsSocketErrorReceiveWouldBlock(e)) { event.Close(); - timeout_event.Cancel(); handler.PingError(std::make_exception_ptr(MakeSocketError(e, "Failed to receive ping reply"))); } } @@ -97,15 +93,6 @@ PingClient::EventCallback(unsigned) noexcept Read(); } -inline void -PingClient::OnTimeout() noexcept -{ - assert(event.IsDefined()); - - event.Close(); - handler.PingTimeout(); -} - /* * constructor * diff --git a/src/event/net/PingClient.hxx b/src/event/net/PingClient.hxx index 681e280b4..16a1bc71a 100644 --- a/src/event/net/PingClient.hxx +++ b/src/event/net/PingClient.hxx @@ -5,14 +5,12 @@ #pragma once #include "event/SocketEvent.hxx" -#include "event/CoarseTimerEvent.hxx" #include class PingClientHandler { public: virtual void PingResponse() noexcept = 0; - virtual void PingTimeout() noexcept = 0; virtual void PingError(std::exception_ptr ep) noexcept = 0; }; @@ -22,7 +20,6 @@ public: */ class PingClient final { SocketEvent event; - CoarseTimerEvent timeout_event; PingClientHandler &handler; @@ -49,14 +46,12 @@ public: void Start(SocketAddress address) noexcept; void Cancel() noexcept { - timeout_event.Cancel(); event.Close(); } private: void ScheduleRead() noexcept; void EventCallback(unsigned events) noexcept; - void OnTimeout() noexcept; void Read() noexcept; };