event/SocketEvent: allow Cancel() without socket

This commit is contained in:
Max Kellermann 2020-10-14 16:19:08 +02:00
parent 653eea5840
commit 7901b04c78
3 changed files with 6 additions and 11 deletions

View File

@ -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);

View File

@ -91,7 +91,9 @@ public:
callback(_callback),
fd(_fd) {}
~SocketEvent() noexcept;
~SocketEvent() noexcept {
Cancel();
}
auto &GetEventLoop() const noexcept {
return loop;

View File

@ -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)));