mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
SharedBuffer: Split the creation and share steps
This allows us to seal a buffer *before* anyone else has access to it (well, ok, the creating process still does, but you can't win them all). It also means that a SharedBuffer can be shared with multiple clients: all you need is to have access to it to share it on again.
This commit is contained in:
parent
f60d7e5d1f
commit
b907608e46
12 changed files with 58 additions and 22 deletions
|
@ -3,10 +3,10 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
RefPtr<SharedBuffer> SharedBuffer::create(pid_t peer, int size)
|
||||
RefPtr<SharedBuffer> SharedBuffer::create_with_size(int size)
|
||||
{
|
||||
void* data;
|
||||
int shared_buffer_id = create_shared_buffer(peer, size, &data);
|
||||
int shared_buffer_id = create_shared_buffer(size, &data);
|
||||
if (shared_buffer_id < 0) {
|
||||
perror("create_shared_buffer");
|
||||
return nullptr;
|
||||
|
@ -14,6 +14,16 @@ RefPtr<SharedBuffer> SharedBuffer::create(pid_t peer, int size)
|
|||
return adopt(*new SharedBuffer(shared_buffer_id, size, data));
|
||||
}
|
||||
|
||||
bool SharedBuffer::share_with(pid_t peer)
|
||||
{
|
||||
int ret = share_buffer_with(shared_buffer_id(), peer);
|
||||
if (ret < 0) {
|
||||
perror("share_buffer_with");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RefPtr<SharedBuffer> SharedBuffer::create_from_shared_buffer_id(int shared_buffer_id)
|
||||
{
|
||||
void* data = get_shared_buffer(shared_buffer_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue