summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibIPC
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-16 17:18:58 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-16 17:20:24 +0100
commit9c6c18d9b69f09b9e29fac6d5a66b6d4e56ad9e5 (patch)
treeff897053260e2fc75db2d07aeee2b2cc3e9dfc2a /Userland/Libraries/LibIPC
parenta7f63eab84aa577c90b7dc95f85a951d04859a36 (diff)
downloadserenity-9c6c18d9b69f09b9e29fac6d5a66b6d4e56ad9e5.zip
LibCore+LibIPC: Add Core::AnonymousBuffer, an IPC-friendly buffer class
This will be used to migrate remaining clients off of shbufs.
Diffstat (limited to 'Userland/Libraries/LibIPC')
-rw-r--r--Userland/Libraries/LibIPC/Decoder.cpp21
-rw-r--r--Userland/Libraries/LibIPC/Encoder.cpp10
2 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibIPC/Decoder.cpp b/Userland/Libraries/LibIPC/Decoder.cpp
index 96871f0b5b..5176d6ab12 100644
--- a/Userland/Libraries/LibIPC/Decoder.cpp
+++ b/Userland/Libraries/LibIPC/Decoder.cpp
@@ -26,6 +26,7 @@
#include <AK/MemoryStream.h>
#include <AK/URL.h>
+#include <LibCore/AnonymousBuffer.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Dictionary.h>
#include <LibIPC/File.h>
@@ -183,4 +184,24 @@ bool Decoder::decode([[maybe_unused]] File& file)
#endif
}
+bool decode(Decoder& decoder, Core::AnonymousBuffer& buffer)
+{
+ bool valid = false;
+ if (!decoder.decode(valid))
+ return false;
+ if (!valid) {
+ buffer = {};
+ return true;
+ }
+ u32 size;
+ if (!decoder.decode(size))
+ return false;
+ IPC::File anon_file;
+ if (!decoder.decode(anon_file))
+ return false;
+
+ buffer = Core::AnonymousBuffer::create_from_anon_fd(anon_file.take_fd(), size);
+ return buffer.is_valid();
+}
+
}
diff --git a/Userland/Libraries/LibIPC/Encoder.cpp b/Userland/Libraries/LibIPC/Encoder.cpp
index 240c3d927f..42aa60a675 100644
--- a/Userland/Libraries/LibIPC/Encoder.cpp
+++ b/Userland/Libraries/LibIPC/Encoder.cpp
@@ -27,6 +27,7 @@
#include <AK/ByteBuffer.h>
#include <AK/String.h>
#include <AK/URL.h>
+#include <LibCore/AnonymousBuffer.h>
#include <LibIPC/Dictionary.h>
#include <LibIPC/Encoder.h>
#include <LibIPC/File.h>
@@ -170,4 +171,13 @@ Encoder& Encoder::operator<<(const File& file)
return *this;
}
+bool encode(Encoder& encoder, const Core::AnonymousBuffer& buffer)
+{
+ encoder << buffer.is_valid();
+ if (buffer.is_valid()) {
+ encoder << (u32)buffer.size();
+ encoder << IPC::File(buffer.fd());
+ }
+ return true;
+}
}