mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LibCore: Fix crash on RPC client disconnect
The RPC client management was not updated for the changes that made CObject reference-counted it seems. :^)
This commit is contained in:
parent
e76e533a69
commit
70a41420a9
1 changed files with 10 additions and 6 deletions
|
@ -23,6 +23,8 @@
|
||||||
//#define CEVENTLOOP_DEBUG
|
//#define CEVENTLOOP_DEBUG
|
||||||
//#define DEFERRED_INVOKE_DEBUG
|
//#define DEFERRED_INVOKE_DEBUG
|
||||||
|
|
||||||
|
class RPCClient;
|
||||||
|
|
||||||
static CEventLoop* s_main_event_loop;
|
static CEventLoop* s_main_event_loop;
|
||||||
static Vector<CEventLoop*>* s_event_loop_stack;
|
static Vector<CEventLoop*>* s_event_loop_stack;
|
||||||
HashMap<int, NonnullOwnPtr<CEventLoop::EventLoopTimer>>* CEventLoop::s_timers;
|
HashMap<int, NonnullOwnPtr<CEventLoop::EventLoopTimer>>* CEventLoop::s_timers;
|
||||||
|
@ -30,13 +32,18 @@ HashTable<CNotifier*>* CEventLoop::s_notifiers;
|
||||||
int CEventLoop::s_next_timer_id = 1;
|
int CEventLoop::s_next_timer_id = 1;
|
||||||
int CEventLoop::s_wake_pipe_fds[2];
|
int CEventLoop::s_wake_pipe_fds[2];
|
||||||
RefPtr<CLocalServer> CEventLoop::s_rpc_server;
|
RefPtr<CLocalServer> CEventLoop::s_rpc_server;
|
||||||
|
HashMap<int, RefPtr<RPCClient>> s_rpc_clients;
|
||||||
|
// FIXME: It's not great if this wraps around.
|
||||||
|
static int s_next_client_id = 0;
|
||||||
|
|
||||||
class RPCClient : public CObject {
|
class RPCClient : public CObject {
|
||||||
C_OBJECT(RPCClient)
|
C_OBJECT(RPCClient)
|
||||||
public:
|
public:
|
||||||
explicit RPCClient(RefPtr<CLocalSocket> socket)
|
explicit RPCClient(RefPtr<CLocalSocket> socket)
|
||||||
: m_socket(move(socket))
|
: m_socket(move(socket))
|
||||||
|
, m_client_id(s_next_client_id++)
|
||||||
{
|
{
|
||||||
|
s_rpc_clients.set(m_client_id, this);
|
||||||
add_child(*m_socket);
|
add_child(*m_socket);
|
||||||
m_socket->on_ready_to_read = [this] {
|
m_socket->on_ready_to_read = [this] {
|
||||||
i32 length;
|
i32 length;
|
||||||
|
@ -118,12 +125,12 @@ public:
|
||||||
|
|
||||||
void shutdown()
|
void shutdown()
|
||||||
{
|
{
|
||||||
// FIXME: This is quite a hackish way to clean ourselves up.
|
s_rpc_clients.remove(m_client_id);
|
||||||
delete this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RefPtr<CLocalSocket> m_socket;
|
RefPtr<CLocalSocket> m_socket;
|
||||||
|
int m_client_id { -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
CEventLoop::CEventLoop()
|
CEventLoop::CEventLoop()
|
||||||
|
@ -159,10 +166,7 @@ CEventLoop::CEventLoop()
|
||||||
ASSERT(listening);
|
ASSERT(listening);
|
||||||
|
|
||||||
s_rpc_server->on_ready_to_accept = [&] {
|
s_rpc_server->on_ready_to_accept = [&] {
|
||||||
auto client_socket = s_rpc_server->accept();
|
RPCClient::construct(s_rpc_server->accept());
|
||||||
ASSERT(client_socket);
|
|
||||||
// NOTE: RPCClient will delete itself in RPCClient::shutdown().
|
|
||||||
(void)RPCClient::construct(move(client_socket)).leak_ref();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue