mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibCore: Add Notifier::close
If a file descriptor is being closed, we need to permanently disable any Notifier and remove it from the event loop. This method removes the notifier and disables it so that the EventLoop does not use a invalid file descriptor.
This commit is contained in:
parent
0579a2db34
commit
d67553e128
Notes:
sideshowbarker
2024-07-19 02:23:04 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/d67553e1282 Pull-request: https://github.com/SerenityOS/serenity/pull/3509 Issue: https://github.com/SerenityOS/serenity/issues/3508
2 changed files with 12 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
Function<void()> on_ready_to_read;
|
||||
Function<void()> 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; }
|
||||
|
|
Loading…
Add table
Reference in a new issue