From 7901b04c78b4d235b20053b4c3e2deea8780f825 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 14 Oct 2020 16:19:08 +0200 Subject: [PATCH] event/SocketEvent: allow Cancel() without socket --- src/event/SocketEvent.cxx | 10 ++-------- src/event/SocketEvent.hxx | 4 +++- src/lib/dbus/Watch.cxx | 3 +-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/event/SocketEvent.cxx b/src/event/SocketEvent.cxx index acea03d53..96e2f4580 100644 --- a/src/event/SocketEvent.cxx +++ b/src/event/SocketEvent.cxx @@ -38,12 +38,6 @@ SocketEvent::Dispatch() noexcept callback(flags); } -SocketEvent::~SocketEvent() noexcept -{ - if (IsDefined()) - Cancel(); -} - void SocketEvent::Open(SocketDescriptor _fd) noexcept { @@ -72,11 +66,11 @@ SocketEvent::Close() noexcept bool SocketEvent::Schedule(unsigned flags) noexcept { - assert(IsDefined()); - if (flags == GetScheduledFlags()) return true; + assert(IsDefined()); + bool success; if (scheduled_flags == 0) success = loop.AddFD(fd.Get(), flags, *this); diff --git a/src/event/SocketEvent.hxx b/src/event/SocketEvent.hxx index 83f67dac4..96525ed41 100644 --- a/src/event/SocketEvent.hxx +++ b/src/event/SocketEvent.hxx @@ -91,7 +91,9 @@ public: callback(_callback), fd(_fd) {} - ~SocketEvent() noexcept; + ~SocketEvent() noexcept { + Cancel(); + } auto &GetEventLoop() const noexcept { return loop; diff --git a/src/lib/dbus/Watch.cxx b/src/lib/dbus/Watch.cxx index 2e6892a48..e711b438a 100644 --- a/src/lib/dbus/Watch.cxx +++ b/src/lib/dbus/Watch.cxx @@ -52,8 +52,7 @@ DbusToLibevent(unsigned flags) noexcept void WatchManager::Watch::Toggled() noexcept { - if (event.IsDefined()) - event.Cancel(); + event.Cancel(); if (dbus_watch_get_enabled(&watch)) { event.Open(SocketDescriptor(dbus_watch_get_unix_fd(&watch)));