From f2c6cea07153eec7587ede0dacc13783416c81f7 Mon Sep 17 00:00:00 2001 From: Andrej Mitrovic Date: Tue, 18 Aug 2020 17:49:58 +0900 Subject: [PATCH] Add optional timeout parameter to resolveHost This will be useful in e.g. the client, which uses connection timeouts but does not use any timeout for resolving the host as of yet. --- source/vibe/core/net.d | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index 08be6e8..c8b2727 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -27,12 +27,12 @@ import core.time : Duration; Setting use_dns to false will only allow IP address strings but also guarantees that the call will not block. */ -NetworkAddress resolveHost(string host, AddressFamily address_family = AddressFamily.UNSPEC, bool use_dns = true) +NetworkAddress resolveHost(string host, AddressFamily address_family = AddressFamily.UNSPEC, bool use_dns = true, Duration timeout = Duration.max) { - return resolveHost(host, cast(ushort)address_family, use_dns); + return resolveHost(host, cast(ushort)address_family, use_dns, timeout); } /// ditto -NetworkAddress resolveHost(string host, ushort address_family, bool use_dns = true) +NetworkAddress resolveHost(string host, ushort address_family, bool use_dns = true, Duration timeout = Duration.max) { import std.socket : parseAddress; version (Windows) import core.sys.windows.winsock2 : sockaddr_in, sockaddr_in6; @@ -66,7 +66,7 @@ NetworkAddress resolveHost(string host, ushort address_family, bool use_dns = tr } ); - asyncAwaitAny!(true, waitable); + asyncAwaitAny!(true, waitable)(timeout); enforce(success, "Failed to lookup host '"~host~"'."); return res;