Skip to content

Commit

Permalink
event/net/PingClient: remove the timeout feature
Browse files Browse the repository at this point in the history
Anybody using this class shall implement their own timeout.
  • Loading branch information
MaxKellermann committed Aug 20, 2024
1 parent b0dc7c7 commit a905e31
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 22 deletions.
4 changes: 0 additions & 4 deletions demo/net/RunPing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 0 additions & 13 deletions src/event/net/PingClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand All @@ -35,7 +34,6 @@ inline void
PingClient::ScheduleRead() noexcept
{
event.ScheduleRead();
timeout_event.Schedule(std::chrono::seconds(10));
}

static bool
Expand Down Expand Up @@ -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")));
}
}
Expand All @@ -97,15 +93,6 @@ PingClient::EventCallback(unsigned) noexcept
Read();
}

inline void
PingClient::OnTimeout() noexcept
{
assert(event.IsDefined());

event.Close();
handler.PingTimeout();
}

/*
* constructor
*
Expand Down
5 changes: 0 additions & 5 deletions src/event/net/PingClient.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
#pragma once

#include "event/SocketEvent.hxx"
#include "event/CoarseTimerEvent.hxx"

#include <exception>

class PingClientHandler {
public:
virtual void PingResponse() noexcept = 0;
virtual void PingTimeout() noexcept = 0;
virtual void PingError(std::exception_ptr ep) noexcept = 0;
};

Expand All @@ -22,7 +20,6 @@ public:
*/
class PingClient final {
SocketEvent event;
CoarseTimerEvent timeout_event;

PingClientHandler &handler;

Expand All @@ -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;
};

0 comments on commit a905e31

Please sign in to comment.