summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-08-18 11:54:39 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-08-18 11:54:39 +0200
commit1b3599fbbcdd6da0ad53d293d6f19c63721b257f (patch)
tree2824b982cf5bfaaf967beb87f7eef9fbf7e363a9
parent9d57e7ed68cb7a2cdf67a36633a9122b80735269 (diff)
downloadserenity-1b3599fbbcdd6da0ad53d293d6f19c63721b257f.zip
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.
-rw-r--r--Libraries/LibCore/CNotifier.cpp5
-rw-r--r--Libraries/LibCore/CNotifier.h2
-rw-r--r--Libraries/LibCore/CSocket.cpp4
3 files changed, 6 insertions, 5 deletions
diff --git a/Libraries/LibCore/CNotifier.cpp b/Libraries/LibCore/CNotifier.cpp
index 31870d5b34..6aee87bbea 100644
--- a/Libraries/LibCore/CNotifier.cpp
+++ b/Libraries/LibCore/CNotifier.cpp
@@ -2,8 +2,9 @@
#include <LibCore/CEventLoop.h>
#include <LibCore/CNotifier.h>
-CNotifier::CNotifier(int fd, unsigned event_mask)
- : m_fd(fd)
+CNotifier::CNotifier(int fd, unsigned event_mask, CObject* parent)
+ : CObject(parent)
+ , m_fd(fd)
, m_event_mask(event_mask)
{
set_enabled(true);
diff --git a/Libraries/LibCore/CNotifier.h b/Libraries/LibCore/CNotifier.h
index 5d9a185c5f..ffe20e129a 100644
--- a/Libraries/LibCore/CNotifier.h
+++ b/Libraries/LibCore/CNotifier.h
@@ -12,7 +12,7 @@ public:
Write = 2,
Exceptional = 4,
};
- CNotifier(int fd, unsigned event_mask);
+ CNotifier(int fd, unsigned event_mask, CObject* parent = nullptr);
virtual ~CNotifier() override;
void set_enabled(bool);
diff --git a/Libraries/LibCore/CSocket.cpp b/Libraries/LibCore/CSocket.cpp
index a6339bedb1..e477315822 100644
--- a/Libraries/LibCore/CSocket.cpp
+++ b/Libraries/LibCore/CSocket.cpp
@@ -68,7 +68,7 @@ bool CSocket::connect(const CSocketAddress& address, int port)
if (rc < 0) {
if (errno == 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] {
dbg() << *this << " connected!";
m_connected = true;
@@ -138,7 +138,7 @@ void CSocket::did_update_fd(int fd)
m_read_notifier = nullptr;
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] {
if (on_ready_to_read)
on_ready_to_read();