mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
RequestServer: Avoid using gethostbyname
Replace gethostbyname with Core::Socket::resolve_host in RequestServer::ConnectionFromClient::ensure_connection. Resolved #22199.
This commit is contained in:
parent
38164411f0
commit
7326d00baa
Notes:
sideshowbarker
2024-07-17 14:36:19 +09:00
Author: https://github.com/mobounya 🔰 Commit: https://github.com/SerenityOS/serenity/commit/7326d00baa Pull-request: https://github.com/SerenityOS/serenity/pull/22982 Issue: https://github.com/SerenityOS/serenity/issues/22199 Reviewed-by: https://github.com/alimpfard
|
@ -20,6 +20,16 @@ namespace Core {
|
|||
/// classes. Sockets are non-seekable streams which can be read byte-wise.
|
||||
class Socket : public Stream {
|
||||
public:
|
||||
enum class PreventSIGPIPE {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class SocketType {
|
||||
Stream,
|
||||
Datagram,
|
||||
};
|
||||
|
||||
Socket(Socket&&) = default;
|
||||
Socket& operator=(Socket&&) = default;
|
||||
|
||||
|
@ -46,12 +56,11 @@ public:
|
|||
/// Conversely, set_notifications_enabled(true) will re-enable notifications.
|
||||
virtual void set_notifications_enabled(bool) { }
|
||||
|
||||
Function<void()> on_ready_to_read;
|
||||
// FIXME: This will need to be updated when IPv6 socket arrives. Perhaps a
|
||||
// base class for all address types is appropriate.
|
||||
static ErrorOr<IPv4Address> resolve_host(ByteString const&, SocketType);
|
||||
|
||||
enum class PreventSIGPIPE {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
Function<void()> on_ready_to_read;
|
||||
|
||||
protected:
|
||||
enum class SocketDomain {
|
||||
|
@ -59,20 +68,12 @@ protected:
|
|||
Inet,
|
||||
};
|
||||
|
||||
enum class SocketType {
|
||||
Stream,
|
||||
Datagram,
|
||||
};
|
||||
|
||||
Socket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::No)
|
||||
: m_prevent_sigpipe(prevent_sigpipe == PreventSIGPIPE::Yes)
|
||||
{
|
||||
}
|
||||
|
||||
static ErrorOr<int> create_fd(SocketDomain, SocketType);
|
||||
// FIXME: This will need to be updated when IPv6 socket arrives. Perhaps a
|
||||
// base class for all address types is appropriate.
|
||||
static ErrorOr<IPv4Address> resolve_host(ByteString const&, SocketType);
|
||||
|
||||
static ErrorOr<void> connect_local(int fd, ByteString const& path);
|
||||
static ErrorOr<void> connect_inet(int fd, SocketAddress const&);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <LibCore/Proxy.h>
|
||||
#include <LibCore/Socket.h>
|
||||
#include <RequestServer/ConnectionFromClient.h>
|
||||
#include <RequestServer/Protocol.h>
|
||||
#include <RequestServer/Request.h>
|
||||
|
@ -159,7 +160,9 @@ void ConnectionFromClient::ensure_connection(URL const& url, ::RequestServer::Ca
|
|||
if (cache_level == CacheLevel::ResolveOnly) {
|
||||
return Core::deferred_invoke([host = url.serialized_host().release_value_but_fixme_should_propagate_errors().to_byte_string()] {
|
||||
dbgln("EnsureConnection: DNS-preload for {}", host);
|
||||
(void)gethostbyname(host.characters());
|
||||
auto resolved_host = Core::Socket::resolve_host(host, Core::Socket::SocketType::Stream);
|
||||
if (resolved_host.is_error())
|
||||
dbgln("EnsureConnection: DNS-preload failed for {}", host);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue