1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +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:
Alexander Narsudinov 2022-12-18 00:52:12 +03:00 committed by Andreas Kling
parent e279a1723b
commit ce2ed7615a
2 changed files with 8 additions and 6 deletions

View file

@ -44,26 +44,28 @@ MulticastDNS::MulticastDNS(Object* parent)
bind(IPv4Address(), 5353); bind(IPv4Address(), 5353);
on_ready_to_receive = [this]() { 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, // TODO: Announce on startup. We cannot just call announce() here,
// because it races with the network interfaces getting configured. // 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 = TRY(receive(1024));
auto buffer = MUST(receive(1024));
auto optional_packet = Packet::from_raw_packet(buffer.data(), buffer.size()); auto optional_packet = Packet::from_raw_packet(buffer.data(), buffer.size());
if (!optional_packet.has_value()) { if (!optional_packet.has_value()) {
dbgln("Got an invalid mDNS packet"); dbgln("Got an invalid mDNS packet");
return; return {};
} }
auto& packet = optional_packet.value(); auto& packet = optional_packet.value();
if (packet.is_query()) if (packet.is_query())
handle_query(packet); handle_query(packet);
return {};
} }
void MulticastDNS::handle_query(Packet const& packet) void MulticastDNS::handle_query(Packet const& packet)

View file

@ -29,7 +29,7 @@ private:
void announce(); void announce();
ErrorOr<size_t> emit_packet(Packet const&, sockaddr_in const* destination = nullptr); ErrorOr<size_t> emit_packet(Packet const&, sockaddr_in const* destination = nullptr);
void handle_packet(); ErrorOr<void> handle_packet();
void handle_query(Packet const&); void handle_query(Packet const&);
Vector<IPv4Address> local_addresses() const; Vector<IPv4Address> local_addresses() const;