ladybird/Libraries/LibIPC/Attachment.cpp
Aliaksandr Kalenik da6b928909 LibIPC+LibWeb: Introduce IPC::Attachment abstraction
Replace IPC::File / AutoCloseFileDescriptor / MessageFileType in
the IPC message pipeline with a new IPC::Attachment class. This
wraps a file descriptor transferred alongside IPC messages, and
provides a clean extension point for platform-specific transport
mechanisms (e.g., Mach ports on macOS) that will be introduced later.
2026-03-13 20:22:50 +01:00

45 lines
780 B
C++

/*
* Copyright (c) 2026, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/System.h>
#include <LibIPC/Attachment.h>
namespace IPC {
Attachment::Attachment(Attachment&& other)
: m_fd(exchange(other.m_fd, -1))
{
}
Attachment& Attachment::operator=(Attachment&& other)
{
if (this != &other) {
if (m_fd != -1)
(void)Core::System::close(m_fd);
m_fd = exchange(other.m_fd, -1);
}
return *this;
}
Attachment::~Attachment()
{
if (m_fd != -1)
(void)Core::System::close(m_fd);
}
Attachment Attachment::from_fd(int fd)
{
Attachment attachment;
attachment.m_fd = fd;
return attachment;
}
int Attachment::to_fd()
{
return exchange(m_fd, -1);
}
}