mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:07:44 +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
2 changed files with 18 additions and 14 deletions
|
@ -20,6 +20,16 @@ namespace Core {
|
||||||
/// classes. Sockets are non-seekable streams which can be read byte-wise.
|
/// classes. Sockets are non-seekable streams which can be read byte-wise.
|
||||||
class Socket : public Stream {
|
class Socket : public Stream {
|
||||||
public:
|
public:
|
||||||
|
enum class PreventSIGPIPE {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class SocketType {
|
||||||
|
Stream,
|
||||||
|
Datagram,
|
||||||
|
};
|
||||||
|
|
||||||
Socket(Socket&&) = default;
|
Socket(Socket&&) = default;
|
||||||
Socket& operator=(Socket&&) = default;
|
Socket& operator=(Socket&&) = default;
|
||||||
|
|
||||||
|
@ -46,12 +56,11 @@ public:
|
||||||
/// Conversely, set_notifications_enabled(true) will re-enable notifications.
|
/// Conversely, set_notifications_enabled(true) will re-enable notifications.
|
||||||
virtual void set_notifications_enabled(bool) { }
|
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 {
|
Function<void()> on_ready_to_read;
|
||||||
No,
|
|
||||||
Yes,
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum class SocketDomain {
|
enum class SocketDomain {
|
||||||
|
@ -59,20 +68,12 @@ protected:
|
||||||
Inet,
|
Inet,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SocketType {
|
|
||||||
Stream,
|
|
||||||
Datagram,
|
|
||||||
};
|
|
||||||
|
|
||||||
Socket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::No)
|
Socket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::No)
|
||||||
: m_prevent_sigpipe(prevent_sigpipe == PreventSIGPIPE::Yes)
|
: m_prevent_sigpipe(prevent_sigpipe == PreventSIGPIPE::Yes)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<int> create_fd(SocketDomain, SocketType);
|
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_local(int fd, ByteString const& path);
|
||||||
static ErrorOr<void> connect_inet(int fd, SocketAddress const&);
|
static ErrorOr<void> connect_inet(int fd, SocketAddress const&);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
#include <LibCore/Proxy.h>
|
#include <LibCore/Proxy.h>
|
||||||
|
#include <LibCore/Socket.h>
|
||||||
#include <RequestServer/ConnectionFromClient.h>
|
#include <RequestServer/ConnectionFromClient.h>
|
||||||
#include <RequestServer/Protocol.h>
|
#include <RequestServer/Protocol.h>
|
||||||
#include <RequestServer/Request.h>
|
#include <RequestServer/Request.h>
|
||||||
|
@ -159,7 +160,9 @@ void ConnectionFromClient::ensure_connection(URL const& url, ::RequestServer::Ca
|
||||||
if (cache_level == CacheLevel::ResolveOnly) {
|
if (cache_level == CacheLevel::ResolveOnly) {
|
||||||
return Core::deferred_invoke([host = url.serialized_host().release_value_but_fixme_should_propagate_errors().to_byte_string()] {
|
return Core::deferred_invoke([host = url.serialized_host().release_value_but_fixme_should_propagate_errors().to_byte_string()] {
|
||||||
dbgln("EnsureConnection: DNS-preload for {}", host);
|
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…
Add table
Add a link
Reference in a new issue