mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
8a48246ed1
This class had slightly confusing semantics and the added weirdness doesn't seem worth it just so we can say "." instead of "->" when iterating over a vector of NNRPs. This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
62 lines
1.1 KiB
C++
62 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/RefCounted.h>
|
|
#include <AK/RefPtr.h>
|
|
#include <unistd.h>
|
|
|
|
namespace IPC {
|
|
|
|
class AutoCloseFileDescriptor : public RefCounted<AutoCloseFileDescriptor> {
|
|
public:
|
|
AutoCloseFileDescriptor(int fd)
|
|
: m_fd(fd)
|
|
{
|
|
}
|
|
|
|
~AutoCloseFileDescriptor()
|
|
{
|
|
if (m_fd != -1)
|
|
close(m_fd);
|
|
}
|
|
|
|
int value() const { return m_fd; }
|
|
|
|
private:
|
|
int m_fd;
|
|
};
|
|
|
|
struct MessageBuffer {
|
|
Vector<u8, 1024> data;
|
|
Vector<NonnullRefPtr<AutoCloseFileDescriptor>, 1> fds;
|
|
};
|
|
|
|
enum class ErrorCode : u32 {
|
|
PeerDisconnected
|
|
};
|
|
|
|
template<typename Value>
|
|
using IPCErrorOr = ErrorOr<Value, ErrorCode>;
|
|
|
|
class Message {
|
|
public:
|
|
virtual ~Message() = default;
|
|
|
|
virtual u32 endpoint_magic() const = 0;
|
|
virtual int message_id() const = 0;
|
|
virtual char const* message_name() const = 0;
|
|
virtual bool valid() const = 0;
|
|
virtual ErrorOr<MessageBuffer> encode() const = 0;
|
|
|
|
protected:
|
|
Message() = default;
|
|
};
|
|
|
|
}
|