LibCore: Convert CLocalServer to ObjectPtr

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

View file

@ -27,10 +27,10 @@ int main(int, char**)
CEventLoop event_loop;
unlink("/tmp/simple-ipc");
CLocalServer server_sock;
server_sock.listen("/tmp/simple-ipc");
server_sock.on_ready_to_accept = [&] {
auto* client_socket = server_sock.accept();
auto server = CLocalServer::construct();
server->listen("/tmp/simple-ipc");
server->on_ready_to_accept = [&] {
auto client_socket = server->accept();
ASSERT(client_socket);
static int next_client_id = 0;
IPC::Server::new_connection_ng_for_client<SimpleIPCServer>(*client_socket, ++next_client_id);

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;

View file

@ -5,11 +5,12 @@
#include <unistd.h>
ASEventLoop::ASEventLoop()
: m_server(CLocalServer::construct())
{
unlink("/tmp/asportal");
m_server_sock.listen("/tmp/asportal");
m_server_sock.on_ready_to_accept = [this] {
auto client_socket = m_server_sock.accept();
m_server->listen("/tmp/asportal");
m_server->on_ready_to_accept = [this] {
auto client_socket = m_server->accept();
if (!client_socket) {
dbg() << "AudioServer: accept failed.";
return;

View file

@ -1,17 +1,17 @@
#pragma once
#include "ASMixer.h"
#include <LibCore/CEventLoop.h>
#include <LibCore/CLocalServer.h>
#include <LibCore/CNotifier.h>
#include "ASMixer.h"
class ASEventLoop
{
class ASEventLoop {
public:
ASEventLoop();
int exec() { return m_event_loop.exec(); }
private:
CEventLoop m_event_loop;
CLocalServer m_server_sock;
ObjectPtr<CLocalServer> m_server;
ASMixer m_mixer;
};

View file

@ -22,15 +22,16 @@
//#define WSMESSAGELOOP_DEBUG
WSEventLoop::WSEventLoop()
: m_server(CLocalServer::construct())
{
m_keyboard_fd = open("/dev/keyboard", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
m_mouse_fd = open("/dev/psaux", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
unlink("/tmp/wsportal");
m_server_sock.listen("/tmp/wsportal");
m_server->listen("/tmp/wsportal");
m_server_sock.on_ready_to_accept = [this] {
auto client_socket = m_server_sock.accept();
m_server->on_ready_to_accept = [this] {
auto client_socket = m_server->accept();
if (!client_socket) {
dbg() << "WindowServer: accept failed.";
return;

View file

@ -24,5 +24,5 @@ private:
ObjectPtr<CNotifier> m_keyboard_notifier;
int m_mouse_fd { -1 };
ObjectPtr<CNotifier> m_mouse_notifier;
CLocalServer m_server_sock;
ObjectPtr<CLocalServer> m_server;
};