1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 04:37:40 +00:00

LibCore: Make CSocket's notifiers into children of the CSocket

The Inspector app quickly exposes crappy flat object hiearchies without
parent/child relationships. This is one of many commits that improves
the situation by making parent/child CObject relationships explicit.
This commit is contained in:
Andreas Kling 2019-08-18 11:54:39 +02:00
parent 9d57e7ed68
commit 1b3599fbbc
3 changed files with 6 additions and 5 deletions

View file

@ -2,8 +2,9 @@
#include <LibCore/CEventLoop.h> #include <LibCore/CEventLoop.h>
#include <LibCore/CNotifier.h> #include <LibCore/CNotifier.h>
CNotifier::CNotifier(int fd, unsigned event_mask) CNotifier::CNotifier(int fd, unsigned event_mask, CObject* parent)
: m_fd(fd) : CObject(parent)
, m_fd(fd)
, m_event_mask(event_mask) , m_event_mask(event_mask)
{ {
set_enabled(true); set_enabled(true);

View file

@ -12,7 +12,7 @@ public:
Write = 2, Write = 2,
Exceptional = 4, Exceptional = 4,
}; };
CNotifier(int fd, unsigned event_mask); CNotifier(int fd, unsigned event_mask, CObject* parent = nullptr);
virtual ~CNotifier() override; virtual ~CNotifier() override;
void set_enabled(bool); void set_enabled(bool);

View file

@ -68,7 +68,7 @@ bool CSocket::connect(const CSocketAddress& address, int port)
if (rc < 0) { if (rc < 0) {
if (errno == EINPROGRESS) { if (errno == EINPROGRESS) {
dbg() << *this << " connection in progress (EINPROGRESS)"; dbg() << *this << " connection in progress (EINPROGRESS)";
m_notifier = make<CNotifier>(fd(), CNotifier::Event::Write); m_notifier = make<CNotifier>(fd(), CNotifier::Event::Write, this);
m_notifier->on_ready_to_write = [this] { m_notifier->on_ready_to_write = [this] {
dbg() << *this << " connected!"; dbg() << *this << " connected!";
m_connected = true; m_connected = true;
@ -138,7 +138,7 @@ void CSocket::did_update_fd(int fd)
m_read_notifier = nullptr; m_read_notifier = nullptr;
return; return;
} }
m_read_notifier = make<CNotifier>(fd, CNotifier::Event::Read); m_read_notifier = make<CNotifier>(fd, CNotifier::Event::Read, this);
m_read_notifier->on_ready_to_read = [this] { m_read_notifier->on_ready_to_read = [this] {
if (on_ready_to_read) if (on_ready_to_read)
on_ready_to_read(); on_ready_to_read();