MessageBuffer::transfer_message() handed a MessageDataType to transport APIs that accepted Vector<u8> const&. That forced the inline-capacity vector to be materialized as a plain Vector<u8>, and the Mach transport then copied the same payload again into its pending-send queue. Make the transport API take MessageDataType by value and pass the encoded buffer with take_data(). The Mach pending queue now stores the same type so the payload can move directly to the IO thread. The socket transport keeps queued messages as owned headers plus moved payloads instead of copying the payload into an AllocatingMemoryStream, while preserving the existing chunked send and fd acknowledgement behavior.
56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibIPC/Limits.h>
|
|
#include <LibIPC/Message.h>
|
|
|
|
namespace IPC {
|
|
|
|
MessageBuffer::MessageBuffer()
|
|
{
|
|
}
|
|
|
|
ErrorOr<void> MessageBuffer::extend_data_capacity(size_t capacity)
|
|
{
|
|
TRY(m_data.try_ensure_capacity(m_data.size() + capacity));
|
|
return {};
|
|
}
|
|
|
|
ErrorOr<void> MessageBuffer::append_data(u8 const* values, size_t count)
|
|
{
|
|
TRY(m_data.try_append(values, count));
|
|
return {};
|
|
}
|
|
|
|
ErrorOr<void> MessageBuffer::append_file_descriptor(int fd)
|
|
{
|
|
TRY(m_attachments.try_append(Attachment::from_fd(fd)));
|
|
return {};
|
|
}
|
|
|
|
ErrorOr<void> MessageBuffer::append_attachment(Attachment attachment)
|
|
{
|
|
TRY(m_attachments.try_append(move(attachment)));
|
|
return {};
|
|
}
|
|
|
|
ErrorOr<void> MessageBuffer::extend(MessageBuffer&& buffer)
|
|
{
|
|
TRY(m_data.try_extend(move(buffer.m_data)));
|
|
TRY(m_attachments.try_extend(move(buffer.m_attachments)));
|
|
return {};
|
|
}
|
|
|
|
ErrorOr<void> MessageBuffer::transfer_message(Transport& transport)
|
|
{
|
|
VERIFY(m_data.size() <= MAX_MESSAGE_PAYLOAD_SIZE);
|
|
VERIFY(m_attachments.size() <= MAX_MESSAGE_FD_COUNT);
|
|
|
|
transport.post_message(take_data(), m_attachments);
|
|
return {};
|
|
}
|
|
|
|
}
|