From 4ca0669d1e732b1697a7944a7899b2250bb81cf1 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sun, 6 Feb 2022 17:13:04 +0000 Subject: LookupServer: Convert to Core::Stream::UDPSocket --- Userland/Services/LookupServer/DNSServer.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'Userland/Services/LookupServer/DNSServer.cpp') diff --git a/Userland/Services/LookupServer/DNSServer.cpp b/Userland/Services/LookupServer/DNSServer.cpp index 5c664f36a8..7d3846f0d0 100644 --- a/Userland/Services/LookupServer/DNSServer.cpp +++ b/Userland/Services/LookupServer/DNSServer.cpp @@ -16,24 +16,27 @@ DNSServer::DNSServer(Object* parent) { bind(IPv4Address(), 53); on_ready_to_receive = [this]() { - handle_client(); + auto result = handle_client(); + if (result.is_error()) { + dbgln("DNSServer: Failed to handle client: {}", result.error()); + } }; } -void DNSServer::handle_client() +ErrorOr DNSServer::handle_client() { sockaddr_in client_address; auto buffer = receive(1024, client_address); auto optional_request = DNSPacket::from_raw_packet(buffer.data(), buffer.size()); if (!optional_request.has_value()) { dbgln("Got an invalid DNS packet"); - return; + return {}; } auto& request = optional_request.value(); if (!request.is_query()) { dbgln("It's not a request"); - return; + return {}; } LookupServer& lookup_server = LookupServer::the(); @@ -46,7 +49,7 @@ void DNSServer::handle_client() if (question.class_code() != DNSRecordClass::IN) continue; response.add_question(question); - auto answers = lookup_server.lookup(question.name(), question.record_type()); + auto answers = TRY(lookup_server.lookup(question.name(), question.record_type())); for (auto& answer : answers) { response.add_answer(answer); } @@ -59,8 +62,8 @@ void DNSServer::handle_client() buffer = response.to_byte_buffer(); - // FIXME: We should be handling errors here. - [[maybe_unused]] auto result = send(buffer, client_address); + TRY(send(buffer, client_address)); + return {}; } } -- cgit debian/1.2.3+git2.25.1-1-2-gaceb0