mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibIPC+Meta: Keep message buffer alive until acknowledged by peer
This change ensures that instead of immediately deallocating the message buffer after sending, we retain it in an acknowledgement wait queue until an acknowledgement is received from the peer. This is necessary to handle a behavior of the macOS kernel, which may prematurely garbage-collect file descriptors contained within the message buffer before the peer receives them. The acknowledgement mechanism assumes messages are received in the same order they were sent so, each acknowledgement message simply indicates the count of successfully received messages, specifying how many entries can safely be removed from the acknowledgement wait queue.
This commit is contained in:
parent
15e2c78e9a
commit
c3121c9d8a
Notes:
github-actions[bot]
2025-04-05 21:15:26 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: c3121c9d8a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4230
5 changed files with 121 additions and 16 deletions
|
@ -111,4 +111,32 @@ ErrorOr<NonnullOwnPtr<LargeMessageWrapper>> LargeMessageWrapper::decode(u32 endp
|
|||
return make<LargeMessageWrapper>(endpoint_magic, wrapped_message_data, move(wrapped_fds));
|
||||
}
|
||||
|
||||
Acknowledgement::Acknowledgement(u32 endpoint_magic, u32 ack_count)
|
||||
: m_endpoint_magic(endpoint_magic)
|
||||
, m_ack_count(ack_count)
|
||||
{
|
||||
}
|
||||
|
||||
NonnullOwnPtr<Acknowledgement> Acknowledgement::create(u32 endpoint_magic, u32 ack_count)
|
||||
{
|
||||
return make<Acknowledgement>(endpoint_magic, ack_count);
|
||||
}
|
||||
|
||||
ErrorOr<MessageBuffer> Acknowledgement::encode() const
|
||||
{
|
||||
MessageBuffer buffer;
|
||||
Encoder stream { buffer };
|
||||
TRY(stream.encode(m_endpoint_magic));
|
||||
TRY(stream.encode(MESSAGE_ID));
|
||||
TRY(stream.encode(m_ack_count));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Acknowledgement>> Acknowledgement::decode(u32 endpoint_magic, Stream& stream, UnprocessedFileDescriptors& files)
|
||||
{
|
||||
Decoder decoder { stream, files };
|
||||
auto ack_count = TRY(decoder.decode<u32>());
|
||||
return make<Acknowledgement>(endpoint_magic, ack_count);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue