mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-25 18:52:22 -05:00
6d0f504822
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.
33 lines
1 KiB
C++
33 lines
1 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "InspectableProcess.h"
|
|
#include <InspectorServer/ClientConnection.h>
|
|
#include <LibCore/EventLoop.h>
|
|
#include <LibCore/LocalServer.h>
|
|
#include <LibCore/System.h>
|
|
#include <LibIPC/ClientConnection.h>
|
|
#include <LibIPC/MultiServer.h>
|
|
#include <LibMain/Main.h>
|
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
|
{
|
|
Core::EventLoop event_loop;
|
|
|
|
TRY(Core::System::pledge("stdio unix accept"));
|
|
|
|
auto server = TRY(IPC::MultiServer<InspectorServer::ClientConnection>::try_create("/tmp/portal/inspector"));
|
|
|
|
auto inspectables_server = TRY(Core::LocalServer::try_create());
|
|
TRY(inspectables_server->take_over_from_system_server("/tmp/portal/inspectables"));
|
|
|
|
inspectables_server->on_accept = [&](auto client_socket) {
|
|
auto pid = client_socket->peer_pid();
|
|
InspectorServer::g_processes.set(pid, make<InspectorServer::InspectableProcess>(pid, move(client_socket)));
|
|
};
|
|
|
|
return event_loop.exec();
|
|
}
|