1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +00:00

LibCore: Convert CTCPServer to ObjectPtr

Also get rid of the custom CNotifier::create() in favor of construct().
This commit is contained in:
Andreas Kling 2019-09-21 15:18:12 +02:00
parent bce58bbbca
commit 4ea229accd
12 changed files with 23 additions and 27 deletions

View file

@ -31,7 +31,7 @@ bool CLocalServer::listen(const String& address)
ASSERT(rc == 0);
m_listening = true;
m_notifier = CNotifier::create(m_fd, CNotifier::Event::Read, this);
m_notifier = CNotifier::construct(m_fd, CNotifier::Event::Read, this);
m_notifier->on_ready_to_read = [this] {
if (on_ready_to_accept)
on_ready_to_accept();

View file

@ -14,11 +14,6 @@ public:
Exceptional = 4,
};
static ObjectPtr<CNotifier> create(int fd, unsigned event_mask, CObject* parent = nullptr)
{
return new CNotifier(fd, event_mask, parent);
}
virtual ~CNotifier() override;
void set_enabled(bool);
@ -33,7 +28,7 @@ public:
void event(CEvent&) override;
private:
CNotifier(int fd, unsigned event_mask, CObject* parent);
CNotifier(int fd, unsigned event_mask, CObject* parent = nullptr);
int m_fd { -1 };
unsigned m_event_mask { 0 };

View file

@ -85,7 +85,7 @@ bool CSocket::common_connect(const struct sockaddr* addr, socklen_t addrlen)
if (rc < 0) {
if (errno == EINPROGRESS) {
dbg() << *this << " connection in progress (EINPROGRESS)";
m_notifier = CNotifier::create(fd(), CNotifier::Event::Write, this);
m_notifier = CNotifier::construct(fd(), CNotifier::Event::Write, this);
m_notifier->on_ready_to_write = [this] {
dbg() << *this << " connected!";
m_connected = true;
@ -132,7 +132,7 @@ void CSocket::did_update_fd(int fd)
m_read_notifier = nullptr;
return;
}
m_read_notifier = CNotifier::create(fd, CNotifier::Event::Read, this);
m_read_notifier = CNotifier::construct(fd, CNotifier::Event::Read, this);
m_read_notifier->on_ready_to_read = [this] {
if (on_ready_to_read)
on_ready_to_read();

View file

@ -32,7 +32,7 @@ bool CTCPServer::listen(const IPv4Address& address, u16 port)
ASSERT(rc == 0);
m_listening = true;
m_notifier = CNotifier::create(m_fd, CNotifier::Event::Read);
m_notifier = CNotifier::construct(m_fd, CNotifier::Event::Read);
m_notifier->on_ready_to_read = [this] {
if (on_ready_to_accept)
on_ready_to_accept();

View file

@ -9,7 +9,6 @@ class CTCPSocket;
class CTCPServer : public CObject {
C_OBJECT(CTCPServer)
public:
explicit CTCPServer(CObject* parent = nullptr);
virtual ~CTCPServer() override;
bool is_listening() const { return m_listening; }
@ -20,7 +19,9 @@ public:
Function<void()> on_ready_to_accept;
private:
explicit CTCPServer(CObject* parent = nullptr);
int m_fd { -1 };
bool m_listening { false };
OwnPtr<CNotifier> m_notifier;
ObjectPtr<CNotifier> m_notifier;
};

View file

@ -51,7 +51,7 @@ namespace Client {
public:
Connection(const StringView& address)
: m_connection(CLocalSocket::construct(this))
, m_notifier(CNotifier::create(m_connection->fd(), CNotifier::Read, this))
, m_notifier(CNotifier::construct(m_connection->fd(), CNotifier::Read, this))
{
// We want to rate-limit our clients
m_connection->set_blocking(true);
@ -241,7 +241,7 @@ namespace Client {
public:
ConnectionNG(const StringView& address)
: m_connection(CLocalSocket::construct(this))
, m_notifier(CNotifier::create(m_connection->fd(), CNotifier::Read, this))
, m_notifier(CNotifier::construct(m_connection->fd(), CNotifier::Read, this))
{
// We want to rate-limit our clients
m_connection->set_blocking(true);