int maxIdleTime;
int currentConnections;
DateTime idleSince;
+ DateTime lastDnsResolve;
Version protocolVersion;
X509Certificate certificate;
X509Certificate clientCertificate;
CheckAvailableForRecycling (out dummy);
}
+ private bool HasTimedOut
+ {
+ get {
+ int timeout = ServicePointManager.DnsRefreshTimeout;
+ return timeout != Timeout.Infinite &&
+ (lastDnsResolve + TimeSpan.FromMilliseconds (timeout)) < DateTime.UtcNow;
+ }
+ }
+
internal IPHostEntry HostEntry
{
get {
lock (hostE) {
- if (host != null)
- return host;
-
string uriHost = uri.Host;
- // There is no need to do DNS resolution on literal IP addresses
- if (uri.HostNameType == UriHostNameType.IPv6 ||
- uri.HostNameType == UriHostNameType.IPv4) {
+ if (host == null || HasTimedOut) {
+ lastDnsResolve = DateTime.UtcNow;
- if (uri.HostNameType == UriHostNameType.IPv6) {
- // Remove square brackets
- uriHost = uriHost.Substring(1,uriHost.Length-2);
+ try {
+ host = Dns.GetHostEntry (uriHost);
+ }
+ catch (Exception) {
+ return null;
}
-
- // Creates IPHostEntry
- host = new IPHostEntry();
- host.AddressList = new IPAddress[] { IPAddress.Parse(uriHost) };
-
- return host;
- }
-
- // Try DNS resolution on host names
- try {
- host = Dns.GetHostByName (uriHost);
- }
- catch {
- return null;
}
}