mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
LibIPC: Move AutoCloseFileDescriptor to its own header
This commit is contained in:
parent
1893f89799
commit
ccf303eefc
Notes:
github-actions[bot]
2025-06-17 21:38:15 +00:00
Author: https://github.com/stasoid
Commit: ccf303eefc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5010
Reviewed-by: https://github.com/ADKaster ✅
4 changed files with 42 additions and 29 deletions
40
Libraries/LibIPC/AutoCloseFileDescriptor.h
Normal file
40
Libraries/LibIPC/AutoCloseFileDescriptor.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, the Ladybird developers.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/RefCounted.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
|
|
||||||
|
namespace IPC {
|
||||||
|
|
||||||
|
class AutoCloseFileDescriptor : public RefCounted<AutoCloseFileDescriptor> {
|
||||||
|
public:
|
||||||
|
AutoCloseFileDescriptor(int fd)
|
||||||
|
: m_fd(fd)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~AutoCloseFileDescriptor()
|
||||||
|
{
|
||||||
|
if (m_fd != -1)
|
||||||
|
(void)Core::System::close(m_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int value() const { return m_fd; }
|
||||||
|
|
||||||
|
int take_fd()
|
||||||
|
{
|
||||||
|
int fd = m_fd;
|
||||||
|
m_fd = -1;
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibIPC/AutoCloseFileDescriptor.h>
|
||||||
#include <LibIPC/Transport.h>
|
#include <LibIPC/Transport.h>
|
||||||
|
|
||||||
namespace IPC {
|
namespace IPC {
|
||||||
|
|
|
@ -12,17 +12,6 @@
|
||||||
|
|
||||||
namespace IPC {
|
namespace IPC {
|
||||||
|
|
||||||
AutoCloseFileDescriptor::AutoCloseFileDescriptor(int fd)
|
|
||||||
: m_fd(fd)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoCloseFileDescriptor::~AutoCloseFileDescriptor()
|
|
||||||
{
|
|
||||||
if (m_fd != -1)
|
|
||||||
(void)Core::System::close(m_fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SendQueue::enqueue_message(Vector<u8>&& bytes, Vector<int>&& fds)
|
void SendQueue::enqueue_message(Vector<u8>&& bytes, Vector<int>&& fds)
|
||||||
{
|
{
|
||||||
Threading::MutexLocker locker(m_mutex);
|
Threading::MutexLocker locker(m_mutex);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/MemoryStream.h>
|
#include <AK/MemoryStream.h>
|
||||||
#include <AK/Queue.h>
|
#include <AK/Queue.h>
|
||||||
#include <LibCore/Socket.h>
|
#include <LibCore/Socket.h>
|
||||||
|
#include <LibIPC/AutoCloseFileDescriptor.h>
|
||||||
#include <LibIPC/File.h>
|
#include <LibIPC/File.h>
|
||||||
#include <LibThreading/ConditionVariable.h>
|
#include <LibThreading/ConditionVariable.h>
|
||||||
#include <LibThreading/MutexProtected.h>
|
#include <LibThreading/MutexProtected.h>
|
||||||
|
@ -18,24 +19,6 @@
|
||||||
|
|
||||||
namespace IPC {
|
namespace IPC {
|
||||||
|
|
||||||
class AutoCloseFileDescriptor : public RefCounted<AutoCloseFileDescriptor> {
|
|
||||||
public:
|
|
||||||
AutoCloseFileDescriptor(int fd);
|
|
||||||
~AutoCloseFileDescriptor();
|
|
||||||
|
|
||||||
int value() const { return m_fd; }
|
|
||||||
|
|
||||||
int take_fd()
|
|
||||||
{
|
|
||||||
int fd = m_fd;
|
|
||||||
m_fd = -1;
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_fd;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SendQueue : public AtomicRefCounted<SendQueue> {
|
class SendQueue : public AtomicRefCounted<SendQueue> {
|
||||||
public:
|
public:
|
||||||
enum class Running {
|
enum class Running {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue