1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

LibCore+LibIPC: Add Core::AnonymousBuffer, an IPC-friendly buffer class

This will be used to migrate remaining clients off of shbufs.
This commit is contained in:
Andreas Kling 2021-01-16 17:18:58 +01:00
parent a7f63eab84
commit 9c6c18d9b6
6 changed files with 243 additions and 0 deletions

View file

@ -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();
}
}