diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-02-01 20:49:29 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-04-21 13:55:00 +0200 |
commit | fc7d231b004e6d141caf880dc837b701dd1898f5 (patch) | |
tree | 5b37f9a73c5be26a6e870b7f3be3cfb4e8981262 /Userland/Libraries | |
parent | 6b13436ef64b8ae91f71b3fed2e8555f733d7998 (diff) | |
download | serenity-fc7d231b004e6d141caf880dc837b701dd1898f5.zip |
LibIPC: Allow transporting a SharedCircularQueue over IPC
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibIPC/Decoder.h | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Encoder.h | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibIPC/Decoder.h b/Userland/Libraries/LibIPC/Decoder.h index 57d4014c73..fc5ea6e117 100644 --- a/Userland/Libraries/LibIPC/Decoder.h +++ b/Userland/Libraries/LibIPC/Decoder.h @@ -11,7 +11,10 @@ #include <AK/NumericLimits.h> #include <AK/StdLibExtras.h> #include <AK/String.h> +#include <AK/Try.h> +#include <LibCore/SharedCircularQueue.h> #include <LibCore/Stream.h> +#include <LibIPC/File.h> #include <LibIPC/Forward.h> #include <LibIPC/Message.h> @@ -117,6 +120,18 @@ public: return {}; } + template<typename T, size_t Size> + ErrorOr<void> decode(Core::SharedSingleProducerCircularQueue<T, Size>& queue) + { + // FIXME: We don't support decoding into valid queues. + VERIFY(!queue.is_valid()); + + IPC::File anon_file; + TRY(decode(anon_file)); + queue = TRY((Core::SharedSingleProducerCircularQueue<T, Size>::try_create(anon_file.take_fd()))); + return {}; + } + template<typename T> ErrorOr<void> decode(Optional<T>& optional) { diff --git a/Userland/Libraries/LibIPC/Encoder.h b/Userland/Libraries/LibIPC/Encoder.h index b207e73ccd..4c39ebd64b 100644 --- a/Userland/Libraries/LibIPC/Encoder.h +++ b/Userland/Libraries/LibIPC/Encoder.h @@ -8,6 +8,7 @@ #include <AK/Concepts.h> #include <AK/StdLibExtras.h> +#include <LibCore/SharedCircularQueue.h> #include <LibIPC/Forward.h> #include <LibIPC/Message.h> @@ -77,6 +78,13 @@ public: return *this; } + template<typename T, size_t Size> + Encoder& operator<<(Core::SharedSingleProducerCircularQueue<T, Size> const& queue) + { + *this << IPC::File(queue.fd()); + return *this; + } + template<Enum T> Encoder& operator<<(T const& enum_value) { |