Skip to content

Commit 509c86d

Browse files
kalenikaliaksandrgmta
authored andcommitted
LibIPC: Simplify IPC read hook
- Return `PeerEOF` enum instead of `Error` containing string from `drain_messages_from_peer()`. There are no other error types to return from this function, so boolean-like enum is sufficient. - Don't override read hook in `ConnectionFromClient` constructor. It was previously redefined only to suppress EOF error returned by `drain_messages_from_peer()`.
1 parent edb60e3 commit 509c86d

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

Libraries/LibIPC/Connection.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ ConnectionBase::ConnectionBase(IPC::Stub& local_stub, NonnullOwnPtr<Transport> t
2121
{
2222
m_transport->set_up_read_hook([this] {
2323
NonnullRefPtr protect = *this;
24-
25-
if (auto result = drain_messages_from_peer(); result.is_error())
26-
dbgln("Read hook error while draining messages: {}", result.error());
27-
24+
drain_messages_from_peer();
2825
handle_messages();
2926
});
3027
}
@@ -96,7 +93,7 @@ void ConnectionBase::wait_for_transport_to_become_readable()
9693
m_transport->wait_until_readable();
9794
}
9895

99-
ErrorOr<void> ConnectionBase::drain_messages_from_peer()
96+
ConnectionBase::PeerEOF ConnectionBase::drain_messages_from_peer()
10097
{
10198
auto schedule_shutdown = m_transport->read_as_many_messages_as_possible_without_blocking([&](auto&& raw_message) {
10299
if (auto message = try_parse_message(raw_message.bytes, raw_message.fds)) {
@@ -117,10 +114,10 @@ ErrorOr<void> ConnectionBase::drain_messages_from_peer()
117114
deferred_invoke([this] {
118115
shutdown();
119116
});
120-
return Error::from_string_literal("IPC connection EOF");
117+
return PeerEOF::Yes;
121118
}
122119

123-
return {};
120+
return PeerEOF::No;
124121
}
125122

126123
OwnPtr<IPC::Message> ConnectionBase::wait_for_specific_endpoint_message_impl(u32 endpoint_magic, int message_id)
@@ -140,7 +137,7 @@ OwnPtr<IPC::Message> ConnectionBase::wait_for_specific_endpoint_message_impl(u32
140137
break;
141138

142139
wait_for_transport_to_become_readable();
143-
if (drain_messages_from_peer().is_error())
140+
if (drain_messages_from_peer() == PeerEOF::Yes)
144141
break;
145142
}
146143

Libraries/LibIPC/Connection.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class ConnectionBase : public Core::EventReceiver {
4141

4242
OwnPtr<IPC::Message> wait_for_specific_endpoint_message_impl(u32 endpoint_magic, int message_id);
4343
void wait_for_transport_to_become_readable();
44-
ErrorOr<void> drain_messages_from_peer();
44+
enum class PeerEOF {
45+
No,
46+
Yes
47+
};
48+
PeerEOF drain_messages_from_peer();
4549

4650
void handle_messages();
4751

Libraries/LibIPC/ConnectionFromClient.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ class ConnectionFromClient : public Connection<ServerEndpoint, ClientEndpoint>
3131
, ClientEndpoint::template Proxy<ServerEndpoint>(*this, {})
3232
, m_client_id(client_id)
3333
{
34-
this->transport().set_up_read_hook([this] {
35-
NonnullRefPtr protect = *this;
36-
// FIXME: Do something about errors.
37-
(void)this->drain_messages_from_peer();
38-
});
3934
}
4035

4136
virtual ~ConnectionFromClient() override = default;

0 commit comments

Comments
 (0)