mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02: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.
64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
|
* Copyright (c) 2025, stasoid <stasoid@yahoo.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Queue.h>
|
|
#include <LibCore/Socket.h>
|
|
#include <LibIPC/Attachment.h>
|
|
#include <LibIPC/TransportHandle.h>
|
|
|
|
namespace IPC {
|
|
|
|
class TransportSocketWindows {
|
|
AK_MAKE_NONCOPYABLE(TransportSocketWindows);
|
|
AK_MAKE_DEFAULT_MOVABLE(TransportSocketWindows);
|
|
|
|
public:
|
|
struct Paired {
|
|
NonnullOwnPtr<TransportSocketWindows> local;
|
|
TransportHandle remote_handle;
|
|
};
|
|
static ErrorOr<Paired> create_paired();
|
|
static ErrorOr<NonnullOwnPtr<TransportSocketWindows>> from_socket(NonnullOwnPtr<Core::LocalSocket> socket);
|
|
|
|
explicit TransportSocketWindows(NonnullOwnPtr<Core::LocalSocket> socket);
|
|
|
|
void set_peer_pid(int pid);
|
|
void set_up_read_hook(Function<void()>);
|
|
bool is_open() const;
|
|
void close();
|
|
void close_after_sending_all_pending_messages();
|
|
|
|
void wait_until_readable();
|
|
|
|
ErrorOr<void> transfer_message(ReadonlyBytes, Vector<size_t> const& handle_offsets);
|
|
|
|
enum class ShouldShutdown {
|
|
No,
|
|
Yes,
|
|
};
|
|
struct Message {
|
|
Vector<u8> bytes;
|
|
Queue<Attachment> attachments; // always empty, present to avoid OS #ifdefs in Connection.cpp
|
|
};
|
|
ShouldShutdown read_as_many_messages_as_possible_without_blocking(Function<void(Message&&)>&&);
|
|
|
|
ErrorOr<TransportHandle> release_for_transfer();
|
|
|
|
private:
|
|
ErrorOr<void> duplicate_handles(Bytes, Vector<size_t> const& handle_offsets);
|
|
ErrorOr<void> transfer(ReadonlyBytes);
|
|
|
|
private:
|
|
NonnullOwnPtr<Core::LocalSocket> m_socket;
|
|
ByteBuffer m_unprocessed_bytes;
|
|
int m_peer_pid = -1;
|
|
};
|
|
|
|
}
|