mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 01:40:33 +00:00
On macOS, use Mach port messaging instead of Unix domain sockets for all IPC transport. This makes the transport capable of carrying Mach port rights as message attachments, which is a prerequisite for sending IOSurface handles over the main IPC channel (currently sent via a separate out-of-band path). It also avoids the need for the FD acknowledgement protocol that TransportSocket requires, since Mach port right transfers are atomic in the kernel. Three connection establishment patterns: - Spawned helper processes (WebContent, RequestServer, etc.) use the existing MachPortServer: the child sends its task port with a reply port, and the parent responds with a pre-created port pair. - Socket-bootstrapped connections (WebDriver, BrowserProcess) exchange Mach port names over the socket, then drop the socket. - Pre-created pairs for IPC tests and in-message transport transfer. Attachment on macOS now wraps a MachPort instead of a file descriptor, converting between the two via fileport_makeport()/fileport_makefd(). The LibIPC socket transport tests are disabled on macOS since they are socket-specific.
35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Platform.h>
|
|
#include <LibIPC/ConnectionFromClient.h>
|
|
#include <LibIPC/Transport.h>
|
|
|
|
#if defined(AK_OS_MACOS)
|
|
# include <LibIPC/TransportBootstrapMach.h>
|
|
#else
|
|
# include <LibCore/SystemServerTakeover.h>
|
|
#endif
|
|
|
|
namespace IPC {
|
|
|
|
template<typename ConnectionFromClientType, typename... Args>
|
|
ErrorOr<NonnullRefPtr<ConnectionFromClientType>> take_over_accepted_client_from_system_server([[maybe_unused]] StringView mach_server_name, Args&&... args)
|
|
{
|
|
#if defined(AK_OS_MACOS)
|
|
auto ports = TRY(bootstrap_transport_from_mach_server(mach_server_name));
|
|
return IPC::new_client_connection<ConnectionFromClientType>(
|
|
make<IPC::Transport>(move(ports.receive_right), move(ports.send_right)),
|
|
forward<Args>(args)...);
|
|
#else
|
|
auto socket = TRY(Core::take_over_socket_from_system_server());
|
|
return IPC::new_client_connection<ConnectionFromClientType>(make<IPC::Transport>(move(socket)), forward<Args>(args)...);
|
|
#endif
|
|
}
|
|
|
|
}
|