2024-01-02 20:14:18 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2026-01-21 22:07:21 +01:00
|
|
|
#include <LibIPC/Limits.h>
|
2024-01-02 20:14:18 -05:00
|
|
|
#include <LibIPC/Message.h>
|
|
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
2024-01-02 20:27:29 -05:00
|
|
|
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)
|
|
|
|
|
{
|
2026-03-13 17:11:22 +01:00
|
|
|
TRY(m_attachments.try_append(Attachment::from_fd(fd)));
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorOr<void> MessageBuffer::append_attachment(Attachment attachment)
|
|
|
|
|
{
|
|
|
|
|
TRY(m_attachments.try_append(move(attachment)));
|
2024-01-02 20:27:29 -05:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-17 09:47:15 -04:00
|
|
|
ErrorOr<void> MessageBuffer::extend(MessageBuffer&& buffer)
|
|
|
|
|
{
|
|
|
|
|
TRY(m_data.try_extend(move(buffer.m_data)));
|
2026-03-13 17:11:22 +01:00
|
|
|
TRY(m_attachments.try_extend(move(buffer.m_attachments)));
|
2025-07-17 09:47:15 -04:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-22 15:47:33 -06:00
|
|
|
ErrorOr<void> MessageBuffer::transfer_message(Transport& transport)
|
2024-01-02 20:14:18 -05:00
|
|
|
{
|
2026-01-21 22:07:21 +01:00
|
|
|
VERIFY(m_data.size() <= MAX_MESSAGE_PAYLOAD_SIZE);
|
2026-03-13 17:11:22 +01:00
|
|
|
VERIFY(m_attachments.size() <= MAX_MESSAGE_FD_COUNT);
|
2024-01-02 20:14:18 -05:00
|
|
|
|
2026-03-13 17:11:22 +01:00
|
|
|
transport.post_message(m_data, m_attachments);
|
2024-01-02 20:14:18 -05:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|