mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +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
|
@ -8,14 +8,14 @@
|
|||
#include "Launcher.h"
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/LocalServer.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibIPC/MultiServer.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments)
|
||||
{
|
||||
Core::EventLoop event_loop;
|
||||
auto server = TRY(Core::LocalServer::try_create());
|
||||
auto server = TRY(IPC::MultiServer<LaunchServer::ClientConnection>::try_create());
|
||||
|
||||
auto launcher = LaunchServer::Launcher();
|
||||
launcher.load_handlers();
|
||||
|
@ -23,12 +23,5 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
|||
|
||||
TRY(Core::System::pledge("stdio accept rpath proc exec"));
|
||||
|
||||
TRY(server->take_over_from_system_server());
|
||||
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<LaunchServer::ClientConnection>(move(client_socket), client_id);
|
||||
};
|
||||
|
||||
return event_loop.exec();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue