diff --git a/Libraries/LibCore/Notifier.cpp b/Libraries/LibCore/Notifier.cpp index 7d39ae0e89..655a73ed1b 100644 --- a/Libraries/LibCore/Notifier.cpp +++ b/Libraries/LibCore/Notifier.cpp @@ -46,12 +46,22 @@ Notifier::~Notifier() void Notifier::set_enabled(bool enabled) { + if (m_fd < 0) + return; if (enabled) Core::EventLoop::register_notifier({}, *this); else Core::EventLoop::unregister_notifier({}, *this); } +void Notifier::close() +{ + if (m_fd < 0) + return; + set_enabled(false); + m_fd = -1; +} + void Notifier::event(Core::Event& event) { if (event.type() == Core::Event::NotifierRead && on_ready_to_read) { diff --git a/Libraries/LibCore/Notifier.h b/Libraries/LibCore/Notifier.h index fd40053284..b197b55204 100644 --- a/Libraries/LibCore/Notifier.h +++ b/Libraries/LibCore/Notifier.h @@ -48,6 +48,8 @@ public: Function on_ready_to_read; Function on_ready_to_write; + void close(); + int fd() const { return m_fd; } unsigned event_mask() const { return m_event_mask; } void set_event_mask(unsigned event_mask) { m_event_mask = event_mask; }