mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-16 21:04:20 +00:00
LibIPC: Move waiting for synchronous responses to ConnectionBase
This commit is contained in:
parent
8728d36dd0
commit
9a8bdf84c8
|
@ -181,4 +181,27 @@ bool ConnectionBase::drain_messages_from_peer(u32 local_endpoint_magic)
|
|||
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 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();
|
||||
Result<Vector<u8>, bool> read_as_much_as_possible_from_socket_without_blocking();
|
||||
bool drain_messages_from_peer(u32 local_endpoint_magic);
|
||||
|
@ -104,25 +105,8 @@ protected:
|
|||
template<typename MessageType, typename Endpoint>
|
||||
OwnPtr<MessageType> wait_for_specific_endpoint_message()
|
||||
{
|
||||
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::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;
|
||||
}
|
||||
if (auto message = wait_for_specific_endpoint_message_impl(Endpoint::static_magic(), MessageType::static_message_id(), LocalEndpoint::static_magic()))
|
||||
return message.template release_nonnull<MessageType>();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue