summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-21 10:46:55 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-21 15:25:08 +0200
commit953cb4e43621a62272620bcc24bab2b036f25c49 (patch)
treef067c4996ba60152e2ede7f52e081b532fecb481
parentc83da29a9d332236ea67ac88f5ab5839657f958f (diff)
downloadserenity-953cb4e43621a62272620bcc24bab2b036f25c49.zip
LibCore: Convert CLocalServer to ObjectPtr
-rw-r--r--Lagom/SimpleIPCServer.cpp8
-rw-r--r--Libraries/LibCore/CEventLoop.cpp10
-rw-r--r--Libraries/LibCore/CEventLoop.h2
-rw-r--r--Libraries/LibCore/CLocalServer.h3
-rw-r--r--Servers/AudioServer/ASEventLoop.cpp7
-rw-r--r--Servers/AudioServer/ASEventLoop.h8
-rw-r--r--Servers/WindowServer/WSEventLoop.cpp7
-rw-r--r--Servers/WindowServer/WSEventLoop.h2
8 files changed, 26 insertions, 21 deletions
diff --git a/Lagom/SimpleIPCServer.cpp b/Lagom/SimpleIPCServer.cpp
index 3d4b5b69f1..290c95300c 100644
--- a/Lagom/SimpleIPCServer.cpp
+++ b/Lagom/SimpleIPCServer.cpp
@@ -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);
diff --git a/Libraries/LibCore/CEventLoop.cpp b/Libraries/LibCore/CEventLoop.cpp
index adeeabb4cc..e0eeda332b 100644
--- a/Libraries/LibCore/CEventLoop.cpp
+++ b/Libraries/LibCore/CEventLoop.cpp
@@ -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));
};
diff --git a/Libraries/LibCore/CEventLoop.h b/Libraries/LibCore/CEventLoop.h
index bf8700d779..6ec33fd715 100644
--- a/Libraries/LibCore/CEventLoop.h
+++ b/Libraries/LibCore/CEventLoop.h
@@ -87,5 +87,5 @@ private:
static HashTable<CNotifier*>* s_notifiers;
- static CLocalServer s_rpc_server;
+ static ObjectPtr<CLocalServer> s_rpc_server;
};
diff --git a/Libraries/LibCore/CLocalServer.h b/Libraries/LibCore/CLocalServer.h
index 0af430c66a..ca2b1099da 100644
--- a/Libraries/LibCore/CLocalServer.h
+++ b/Libraries/LibCore/CLocalServer.h
@@ -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;
diff --git a/Servers/AudioServer/ASEventLoop.cpp b/Servers/AudioServer/ASEventLoop.cpp
index 2c59b4f4d7..4df03e522d 100644
--- a/Servers/AudioServer/ASEventLoop.cpp
+++ b/Servers/AudioServer/ASEventLoop.cpp
@@ -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;
diff --git a/Servers/AudioServer/ASEventLoop.h b/Servers/AudioServer/ASEventLoop.h
index 72e0a31758..a9126353c7 100644
--- a/Servers/AudioServer/ASEventLoop.h
+++ b/Servers/AudioServer/ASEventLoop.h
@@ -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;
};
diff --git a/Servers/WindowServer/WSEventLoop.cpp b/Servers/WindowServer/WSEventLoop.cpp
index 6634e4ba5e..cd8b2a8e80 100644
--- a/Servers/WindowServer/WSEventLoop.cpp
+++ b/Servers/WindowServer/WSEventLoop.cpp
@@ -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;
diff --git a/Servers/WindowServer/WSEventLoop.h b/Servers/WindowServer/WSEventLoop.h
index 93313ee2df..9bc0bd0e65 100644
--- a/Servers/WindowServer/WSEventLoop.h
+++ b/Servers/WindowServer/WSEventLoop.h
@@ -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;
};