1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 20:27:46 +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:
Andreas Kling 2021-12-06 17:54:11 +01:00
parent 81047d8f9c
commit 6d0f504822
11 changed files with 62 additions and 81 deletions

View file

@ -72,13 +72,7 @@ LookupServer::LookupServer()
}
m_mdns = MulticastDNS::construct(this);
m_local_server = Core::LocalServer::construct(this);
m_local_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);
};
MUST(m_local_server->take_over_from_system_server());
m_server = MUST(IPC::MultiServer<ClientConnection>::try_create());
}
void LookupServer::load_etc_hosts()

View file

@ -6,12 +6,14 @@
#pragma once
#include "ClientConnection.h"
#include "DNSName.h"
#include "DNSPacket.h"
#include "DNSServer.h"
#include "MulticastDNS.h"
#include <LibCore/FileWatcher.h>
#include <LibCore/Object.h>
#include <LibIPC/MultiServer.h>
namespace LookupServer {
@ -32,7 +34,7 @@ private:
Vector<DNSAnswer> lookup(const DNSName& hostname, const String& nameserver, bool& did_get_response, DNSRecordType record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes);
RefPtr<Core::LocalServer> m_local_server;
OwnPtr<IPC::MultiServer<ClientConnection>> m_server;
RefPtr<DNSServer> m_dns_server;
RefPtr<MulticastDNS> m_mdns;
Vector<String> m_nameservers;