Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorSimon Hartmann <shartmann@bigpoint.net>2015-09-07 17:54:20 +0300
committerSimon Hartmann <shartmann@bigpoint.net>2015-09-08 12:08:50 +0300
commit932359f3d627da13408350b1172ceb63c30f6327 (patch)
treed5b3eb98a6bf88393dc8c92d725ce5f5f77f49b2 /mcs
parente97227a53dc1a598f4e38de0fbd401dbe9ca7ca5 (diff)
implemented DnsRefreshTimeout to ServicePointManager and adjusted behavior of ServicePoint.HostEntry property.
simplified some calls as requested
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/System/System.Net/ServicePoint.cs40
-rw-r--r--mcs/class/System/System.Net/ServicePointManager.cs6
-rw-r--r--mcs/class/System/Test/System.Net/ServicePointTest.cs31
3 files changed, 51 insertions, 26 deletions
diff --git a/mcs/class/System/System.Net/ServicePoint.cs b/mcs/class/System/System.Net/ServicePoint.cs
index d3a3dd507be..ebac3e9cf1d 100644
--- a/mcs/class/System/System.Net/ServicePoint.cs
+++ b/mcs/class/System/System.Net/ServicePoint.cs
@@ -47,6 +47,7 @@ namespace System.Net
int maxIdleTime;
int currentConnections;
DateTime idleSince;
+ DateTime lastDnsResolve;
Version protocolVersion;
X509Certificate certificate;
X509Certificate clientCertificate;
@@ -339,37 +340,30 @@ namespace System.Net
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;
}
}
diff --git a/mcs/class/System/System.Net/ServicePointManager.cs b/mcs/class/System/System.Net/ServicePointManager.cs
index dc7412d725a..9f0ae0b1d9f 100644
--- a/mcs/class/System/System.Net/ServicePointManager.cs
+++ b/mcs/class/System/System.Net/ServicePointManager.cs
@@ -134,6 +134,7 @@ namespace System.Net
private static int defaultConnectionLimit = DefaultPersistentConnectionLimit;
private static int maxServicePointIdleTime = 100000; // 100 seconds
private static int maxServicePoints = 0;
+ private static int dnsRefreshTimeout = 2 * 60 * 1000;
private static bool _checkCRL = false;
private static SecurityProtocolType _securityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
@@ -218,14 +219,13 @@ namespace System.Net
return new NotImplementedException ();
}
- [MonoTODO]
public static int DnsRefreshTimeout
{
get {
- throw GetMustImplement ();
+ return dnsRefreshTimeout;
}
set {
- throw GetMustImplement ();
+ dnsRefreshTimeout = Math.Max (-1, value);
}
}
diff --git a/mcs/class/System/Test/System.Net/ServicePointTest.cs b/mcs/class/System/Test/System.Net/ServicePointTest.cs
index 8c564e24658..cb6a705905a 100644
--- a/mcs/class/System/Test/System.Net/ServicePointTest.cs
+++ b/mcs/class/System/Test/System.Net/ServicePointTest.cs
@@ -13,6 +13,7 @@ using System;
using System.Collections;
using System.IO;
using System.Net;
+using System.Reflection;
using System.Threading;
namespace MonoTests.System.Net
@@ -205,6 +206,36 @@ public class ServicePointTest
}
}
+
+ [Test]
+ public void DnsRefreshTimeout ()
+ {
+ const int dnsRefreshTimeout = 2;
+
+ ServicePoint sp;
+ IPHostEntry host0, host1, host2;
+ Uri uri;
+ PropertyInfo hostEntryProperty;
+
+ ServicePointManager.DnsRefreshTimeout = dnsRefreshTimeout;
+
+ uri = new Uri ("http://ww.google.com/");
+ sp = ServicePointManager.FindServicePoint (uri);
+
+ hostEntryProperty = typeof (ServicePoint).GetProperty ("HostEntry", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ host0 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
+ host1 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
+
+ Assert.AreEqual (host0, host1, "HostEntry should result in the same IPHostEntry object.");
+
+ Thread.Sleep (dnsRefreshTimeout);
+ host2 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
+
+ Assert.AreNotEqual(host0, host2, "HostEntry should result in a new IPHostEntry " +
+ "object when DnsRefreshTimeout is reached.");
+ }
+
// Debug code not used now, but could be useful later
/*
private void WriteServicePoint (string label, ServicePoint sp)