mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-09 00:22:36 +02:00
Previously, `create_paired()` returned two full Transport objects, and
callers would immediately call `from_transport()` on the remote side to
extract its underlying fd. This wasted resources: the remote
Transport's IO thread, wakeup pipes, and send queue were initialized
only to be torn down without ever sending or receiving a message.
Now `create_paired()` returns `{Transport, TransportHandle}` — the
remote side is born as a lightweight handle containing just the raw fd,
skipping all unnecessary initialization.
Also replace `release_underlying_transport_for_transfer()` (which
returned a raw int fd) with `release_for_transfer()` (which returns a
TransportHandle directly), hiding the socket implementation detail
from callers including MessagePort.
42 lines
907 B
C++
42 lines
907 B
C++
/*
|
|
* Copyright (c) 2026, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibCore/Socket.h>
|
|
#include <LibIPC/Decoder.h>
|
|
#include <LibIPC/Encoder.h>
|
|
#include <LibIPC/File.h>
|
|
#include <LibIPC/Transport.h>
|
|
#include <LibIPC/TransportHandle.h>
|
|
|
|
namespace IPC {
|
|
|
|
TransportHandle::TransportHandle(File file)
|
|
: m_file(move(file))
|
|
{
|
|
}
|
|
|
|
ErrorOr<NonnullOwnPtr<Transport>> TransportHandle::create_transport() const
|
|
{
|
|
auto socket = TRY(Core::LocalSocket::adopt_fd(m_file.take_fd()));
|
|
TRY(socket->set_blocking(false));
|
|
return make<Transport>(move(socket));
|
|
}
|
|
|
|
template<>
|
|
ErrorOr<void> encode(Encoder& encoder, TransportHandle const& handle)
|
|
{
|
|
return encoder.encode(handle.m_file);
|
|
}
|
|
|
|
template<>
|
|
ErrorOr<TransportHandle> decode(Decoder& decoder)
|
|
{
|
|
auto file = TRY(decoder.decode<File>());
|
|
return TransportHandle { move(file) };
|
|
}
|
|
|
|
}
|