1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

LibIPC: Make TransportSocket responsible for reading entire messages

With this change, the responsibility for prepending messages with their
size and ensuring the entire message is received before returning it to
the caller is moved to TransportSocket. This removes the need to
duplicate this logic in both LibIPC and MessagePort.

Another advantage of reducing message granularity at IPC::Transport
layer is that it will make it easier to support alternative transport
implementations (like Mach ports, which unlike Unix domain sockets are
not stream oriented).
This commit is contained in:
Aliaksandr Kalenik 2025-04-07 04:17:36 +02:00 committed by Alexander Kalenik
parent 0a58497ab9
commit a371f849e3
Notes: github-actions[bot] 2025-04-07 15:00:45 +00:00
7 changed files with 130 additions and 204 deletions

View file

@ -15,7 +15,6 @@ using MessageSizeType = u32;
MessageBuffer::MessageBuffer()
{
m_data.resize(sizeof(MessageSizeType));
}
ErrorOr<void> MessageBuffer::extend_data_capacity(size_t capacity)
@ -40,13 +39,9 @@ ErrorOr<void> MessageBuffer::append_file_descriptor(int fd)
ErrorOr<void> MessageBuffer::transfer_message(Transport& transport)
{
Checked<MessageSizeType> checked_message_size { m_data.size() };
checked_message_size -= sizeof(MessageSizeType);
if (checked_message_size.has_overflow())
if (checked_message_size.has_overflow()) {
return Error::from_string_literal("Message is too large for IPC encoding");
MessageSizeType const message_size = checked_message_size.value();
m_data.span().overwrite(0, reinterpret_cast<u8 const*>(&message_size), sizeof(message_size));
}
auto raw_fds = Vector<int, 1> {};
auto num_fds_to_transfer = m_fds.size();
@ -57,16 +52,15 @@ ErrorOr<void> MessageBuffer::transfer_message(Transport& transport)
}
}
TRY(transport.transfer(m_data.span(), raw_fds));
TRY(transport.transfer_message(m_data.span(), raw_fds));
return {};
}
NonnullOwnPtr<LargeMessageWrapper> LargeMessageWrapper::create(u32 endpoint_magic, MessageBuffer& buffer_to_wrap)
{
auto size = buffer_to_wrap.data().size() - sizeof(MessageSizeType);
u8 const* data = buffer_to_wrap.data().data() + sizeof(MessageSizeType);
auto size = buffer_to_wrap.data().size();
auto wrapped_message_data = MUST(Core::AnonymousBuffer::create_with_size(size));
memcpy(wrapped_message_data.data<void>(), data, size);
memcpy(wrapped_message_data.data<void>(), buffer_to_wrap.data().data(), size);
Vector<File> files;
for (auto& owned_fd : buffer_to_wrap.take_fds()) {
files.append(File::adopt_fd(owned_fd->take_fd()));