mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
LibIPC: Move waiting for synchronous responses to ConnectionBase
This commit is contained in:
parent
8728d36dd0
commit
9a8bdf84c8
2 changed files with 26 additions and 19 deletions
|
@ -181,4 +181,27 @@ bool ConnectionBase::drain_messages_from_peer(u32 local_endpoint_magic)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OwnPtr<IPC::Message> ConnectionBase::wait_for_specific_endpoint_message_impl(u32 endpoint_magic, int message_id, u32 local_endpoint_magic)
|
||||||
|
{
|
||||||
|
for (;;) {
|
||||||
|
// Double check we don't already have the event waiting for us.
|
||||||
|
// Otherwise we might end up blocked for a while for no reason.
|
||||||
|
for (size_t i = 0; i < m_unprocessed_messages.size(); ++i) {
|
||||||
|
auto& message = m_unprocessed_messages[i];
|
||||||
|
if (message.endpoint_magic() != endpoint_magic)
|
||||||
|
continue;
|
||||||
|
if (message.message_id() == message_id)
|
||||||
|
return m_unprocessed_messages.take(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_socket->is_open())
|
||||||
|
break;
|
||||||
|
|
||||||
|
wait_for_socket_to_become_readable();
|
||||||
|
if (!drain_messages_from_peer(local_endpoint_magic))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ protected:
|
||||||
virtual void did_become_responsive() { }
|
virtual void did_become_responsive() { }
|
||||||
virtual void try_parse_messages(Vector<u8> const& bytes, size_t& index) = 0;
|
virtual void try_parse_messages(Vector<u8> const& bytes, size_t& index) = 0;
|
||||||
|
|
||||||
|
OwnPtr<IPC::Message> wait_for_specific_endpoint_message_impl(u32 endpoint_magic, int message_id, u32 local_endpoint_magic);
|
||||||
void wait_for_socket_to_become_readable();
|
void wait_for_socket_to_become_readable();
|
||||||
Result<Vector<u8>, bool> read_as_much_as_possible_from_socket_without_blocking();
|
Result<Vector<u8>, bool> read_as_much_as_possible_from_socket_without_blocking();
|
||||||
bool drain_messages_from_peer(u32 local_endpoint_magic);
|
bool drain_messages_from_peer(u32 local_endpoint_magic);
|
||||||
|
@ -104,25 +105,8 @@ protected:
|
||||||
template<typename MessageType, typename Endpoint>
|
template<typename MessageType, typename Endpoint>
|
||||||
OwnPtr<MessageType> wait_for_specific_endpoint_message()
|
OwnPtr<MessageType> wait_for_specific_endpoint_message()
|
||||||
{
|
{
|
||||||
for (;;) {
|
if (auto message = wait_for_specific_endpoint_message_impl(Endpoint::static_magic(), MessageType::static_message_id(), LocalEndpoint::static_magic()))
|
||||||
// Double check we don't already have the event waiting for us.
|
return message.template release_nonnull<MessageType>();
|
||||||
// Otherwise we might end up blocked for a while for no reason.
|
|
||||||
for (size_t i = 0; i < m_unprocessed_messages.size(); ++i) {
|
|
||||||
auto& message = m_unprocessed_messages[i];
|
|
||||||
if (message.endpoint_magic() != Endpoint::static_magic())
|
|
||||||
continue;
|
|
||||||
if (message.message_id() == MessageType::static_message_id())
|
|
||||||
return m_unprocessed_messages.take(i).template release_nonnull<MessageType>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_socket->is_open())
|
|
||||||
break;
|
|
||||||
|
|
||||||
wait_for_socket_to_become_readable();
|
|
||||||
|
|
||||||
if (!drain_messages_from_peer(LocalEndpoint::static_magic()))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue