mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 10:17:34 +00:00
LibIPC: Add IPC::MultiServer convenience class
This encapsulates what our multi-client IPC servers typically do on startup: 1. Create a Core::LocalServer 2. Take over a listening socket file descriptor from SystemServer 3. Set up an accept handler for incoming connections IPC::MultiServer does all this for you! All you have to do is provide the relevant client connection type as a template argument.
This commit is contained in:
parent
81047d8f9c
commit
6d0f504822
11 changed files with 62 additions and 81 deletions
|
@ -19,26 +19,12 @@
|
|||
namespace WindowServer {
|
||||
|
||||
EventLoop::EventLoop()
|
||||
: m_window_server(Core::LocalServer::construct())
|
||||
, m_wm_server(Core::LocalServer::construct())
|
||||
{
|
||||
m_keyboard_fd = open("/dev/keyboard0", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
m_mouse_fd = open("/dev/mouse0", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
|
||||
MUST(m_window_server->take_over_from_system_server("/tmp/portal/window"));
|
||||
MUST(m_wm_server->take_over_from_system_server("/tmp/portal/wm"));
|
||||
|
||||
m_window_server->on_accept = [&](auto client_socket) {
|
||||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
(void)IPC::new_client_connection<ClientConnection>(move(client_socket), client_id);
|
||||
};
|
||||
|
||||
m_wm_server->on_accept = [&](auto client_socket) {
|
||||
static int s_next_wm_id = 0;
|
||||
int wm_id = ++s_next_wm_id;
|
||||
(void)IPC::new_client_connection<WMClientConnection>(move(client_socket), wm_id);
|
||||
};
|
||||
m_window_server = MUST(IPC::MultiServer<ClientConnection>::try_create("/tmp/portal/window"));
|
||||
m_wm_server = MUST(IPC::MultiServer<WMClientConnection>::try_create("/tmp/portal/wm"));
|
||||
|
||||
if (m_keyboard_fd >= 0) {
|
||||
m_keyboard_notifier = Core::Notifier::construct(m_keyboard_fd, Core::Notifier::Read);
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "ClientConnection.h"
|
||||
#include "WMClientConnection.h"
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/LocalServer.h>
|
||||
#include <LibCore/Notifier.h>
|
||||
#include <LibIPC/MultiServer.h>
|
||||
|
||||
namespace WindowServer {
|
||||
|
||||
|
@ -31,8 +33,8 @@ private:
|
|||
RefPtr<Core::Notifier> m_keyboard_notifier;
|
||||
int m_mouse_fd { -1 };
|
||||
RefPtr<Core::Notifier> m_mouse_notifier;
|
||||
RefPtr<Core::LocalServer> m_window_server;
|
||||
RefPtr<Core::LocalServer> m_wm_server;
|
||||
OwnPtr<IPC::MultiServer<ClientConnection>> m_window_server;
|
||||
OwnPtr<IPC::MultiServer<WMClientConnection>> m_wm_server;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue