mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:47:35 +00:00
LookupServer: Propagate the errors from MulticastDNS::handle_packet()
This is a bit awkward, but I think it is better to make the caller deal with possible errors.
This commit is contained in:
parent
e279a1723b
commit
ce2ed7615a
2 changed files with 8 additions and 6 deletions
|
@ -44,26 +44,28 @@ MulticastDNS::MulticastDNS(Object* parent)
|
|||
bind(IPv4Address(), 5353);
|
||||
|
||||
on_ready_to_receive = [this]() {
|
||||
handle_packet();
|
||||
if (auto result = handle_packet(); result.is_error()) {
|
||||
dbgln("Failed to handle packet: {}", result.error());
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: Announce on startup. We cannot just call announce() here,
|
||||
// because it races with the network interfaces getting configured.
|
||||
}
|
||||
|
||||
void MulticastDNS::handle_packet()
|
||||
ErrorOr<void> MulticastDNS::handle_packet()
|
||||
{
|
||||
// TODO: propagate the error somehow
|
||||
auto buffer = MUST(receive(1024));
|
||||
auto buffer = TRY(receive(1024));
|
||||
auto optional_packet = Packet::from_raw_packet(buffer.data(), buffer.size());
|
||||
if (!optional_packet.has_value()) {
|
||||
dbgln("Got an invalid mDNS packet");
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
auto& packet = optional_packet.value();
|
||||
|
||||
if (packet.is_query())
|
||||
handle_query(packet);
|
||||
return {};
|
||||
}
|
||||
|
||||
void MulticastDNS::handle_query(Packet const& packet)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue