1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:07:44 +00:00

LibCore: Convert CLocalServer to ObjectPtr

This commit is contained in:
Andreas Kling 2019-09-21 10:46:55 +02:00
parent c83da29a9d
commit 953cb4e436
8 changed files with 26 additions and 21 deletions

View file

@ -29,7 +29,7 @@ HashMap<int, NonnullOwnPtr<CEventLoop::EventLoopTimer>>* CEventLoop::s_timers;
HashTable<CNotifier*>* CEventLoop::s_notifiers;
int CEventLoop::s_next_timer_id = 1;
int CEventLoop::s_wake_pipe_fds[2];
CLocalServer CEventLoop::s_rpc_server;
ObjectPtr<CLocalServer> CEventLoop::s_rpc_server;
class RPCClient : public CObject {
C_OBJECT(RPCClient)
@ -140,11 +140,13 @@ CEventLoop::CEventLoop()
perror("unlink");
ASSERT_NOT_REACHED();
}
bool listening = s_rpc_server.listen(rpc_path);
s_rpc_server = CLocalServer::construct();
s_rpc_server->set_name("CEventLoop_RPC_server");
bool listening = s_rpc_server->listen(rpc_path);
ASSERT(listening);
s_rpc_server.on_ready_to_accept = [&] {
auto client_socket = s_rpc_server.accept();
s_rpc_server->on_ready_to_accept = [&] {
auto client_socket = s_rpc_server->accept();
ASSERT(client_socket);
new RPCClient(move(client_socket));
};

View file

@ -87,5 +87,5 @@ private:
static HashTable<CNotifier*>* s_notifiers;
static CLocalServer s_rpc_server;
static ObjectPtr<CLocalServer> s_rpc_server;
};

View file

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