Truly independent web browser
LibCore+Tests: Take the truncated-UDP test’s port from UDP, not TCP
sideshowbarker88234e8f3244
diff --git a/Libraries/LibCore/UDPServerWindows.cpp b/Libraries/LibCore/UDPServerWindows.cppindex 891275baaf8..ad9481c8fb3 100644--- a/Libraries/LibCore/UDPServerWindows.cpp+++ b/Libraries/LibCore/UDPServerWindows.cpp@@ -4,6 +4,7 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <AK/Format.h>#include <AK/IPv4Address.h>#include <AK/Types.h>#include <LibCore/Notifier.h>@@ -37,7 +38,7 @@ bool UDPServer::bind(IPv4Address const& address, u16 port)auto in = socket_address.to_sockaddr_in();auto bind_result = Core::System::bind(m_fd, (sockaddr const*)&in, sizeof(in));if (bind_result.is_error()) {- perror("UDPServer::bind");+ warnln("UDPServer::bind: {}", bind_result.error());return false;}diff --git a/Tests/LibDNS/TestDNSResolver.cpp b/Tests/LibDNS/TestDNSResolver.cppindex 07f4c475b3f..71c23f919ce 100644--- a/Tests/LibDNS/TestDNSResolver.cpp+++ b/Tests/LibDNS/TestDNSResolver.cpp@@ -763,22 +763,29 @@ TEST_CASE(test_truncated_udp_response_is_retried_over_tcp){Core::EventLoop loop;- // The server answers on one port over both UDP and TCP. The port the system picks for TCP isn't reserved for UDP,- // though, so another socket can already hold it for UDP — in which case, try again with a fresh port.+ // The server answers on one port over both UDP and TCP. A port the system picks for TCP may be one it won't let+ // UDP bind to, so take the port it picks for UDP, and listen for TCP on that one — trying again with a fresh port+ // if another socket already holds it for TCP.RefPtr<Core::TCPServer> tcp_server;RefPtr<Core::UDPServer> udp_server;u16 server_port = 0;- for (size_t attempt = 0; attempt < 10 && !udp_server; ++attempt) {- tcp_server = MUST(Core::TCPServer::try_create());- MUST(tcp_server->listen(IPv4Address { 127, 0, 0, 1 }, 0, Core::TCPServer::AllowAddressReuse::Yes));- server_port = tcp_server->local_port().value();-- auto candidate = Core::UDPServer::construct();- if (candidate->bind(IPv4Address { 127, 0, 0, 1 }, server_port))- udp_server = move(candidate);+ Optional<Error> listen_error;+ for (size_t attempt = 0; attempt < 10 && !tcp_server; ++attempt) {+ udp_server = Core::UDPServer::construct();+ if (!udp_server->bind(IPv4Address { 127, 0, 0, 1 }, 0)) {+ FAIL("Couldn't bind UDP to a port the system picks");+ return;+ }+ server_port = udp_server->local_port().value();++ auto candidate = MUST(Core::TCPServer::try_create());+ if (auto result = candidate->listen(IPv4Address { 127, 0, 0, 1 }, server_port); result.is_error())+ listen_error = result.release_error();+ else+ tcp_server = move(candidate);}- if (!udp_server) {- FAIL("Couldn't bind UDP to the port of a TCP server");+ if (!tcp_server) {+ FAIL(ByteString::formatted("Couldn't listen for TCP on the port of a UDP server: {}", listen_error.value()));return;}