Skip to content

Commit 6b78cf5

Browse files
committed
Replace EndPoint with DnsEndPoint
1 parent 6d41f90 commit 6b78cf5

File tree

8 files changed

+21
-82
lines changed

8 files changed

+21
-82
lines changed

Enyim.Caching/Configuration/ConfigurationHelper.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void CheckForInterface(Type type, Type interfaceType)
7373
// throw new System.Configuration.ConfigurationErrorsException("The type " + type.AssemblyQualifiedName + " must implement " + interfaceType.AssemblyQualifiedName);
7474
}
7575

76-
public static EndPoint ResolveToEndPoint(string value)
76+
public static DnsEndPoint ResolveToEndPoint(string value)
7777
{
7878
if (String.IsNullOrEmpty(value))
7979
throw new ArgumentNullException("value");
@@ -86,25 +86,8 @@ public static EndPoint ResolveToEndPoint(string value)
8686
if (!Int32.TryParse(parts[1], out port))
8787
throw new ArgumentException("Cannot parse port: " + parts[1], "value");
8888

89-
return ResolveToEndPoint(parts[0], port);
90-
}
91-
92-
public static EndPoint ResolveToEndPoint(string host, int port)
93-
{
94-
if (String.IsNullOrEmpty(host))
95-
throw new ArgumentNullException("host");
96-
97-
IPAddress address;
98-
// parse as an IP address
99-
if (!IPAddress.TryParse(host, out address))
100-
{
101-
var addresses = Dns.GetHostAddresses(host);
102-
address = addresses.FirstOrDefault(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
103-
if (address == null)
104-
throw new ArgumentException(String.Format("Could not resolve host '{0}'.", host));
105-
}
106-
return new IPEndPoint(address, port);
107-
}
89+
return new DnsEndPoint(parts[0], port);
90+
}
10891
}
10992
}
11093

Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IMemcachedClientConfiguration
1313
/// <summary>
1414
/// Gets a list of <see cref="T:IPEndPoint"/> each representing a Memcached server in the pool.
1515
/// </summary>
16-
IList<EndPoint> Servers { get; }
16+
IList<DnsEndPoint> Servers { get; }
1717

1818
/// <summary>
1919
/// Gets the configuration of the socket pool.

Enyim.Caching/Configuration/MemcachedClientConfiguration.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,10 @@ public MemcachedClientConfiguration(
4444
configuration.GetSection("enyimMemcached").Bind(options);
4545
}
4646

47-
Servers = new List<EndPoint>();
47+
Servers = new List<DnsEndPoint>();
4848
foreach (var server in options.Servers)
4949
{
50-
IPAddress address;
51-
if (IPAddress.TryParse(server.Address, out address))
52-
{
53-
Servers.Add(new IPEndPoint(address, server.Port));
54-
}
55-
else
56-
{
57-
Servers.Add(new DnsEndPoint(server.Address, server.Port));
58-
}
50+
Servers.Add(new DnsEndPoint(server.Address, server.Port));
5951
}
6052

6153
SocketPool = new SocketPoolConfiguration();
@@ -187,13 +179,13 @@ public void AddServer(string address)
187179
/// <param name="port">The port number of the memcached instance.</param>
188180
public void AddServer(string host, int port)
189181
{
190-
this.Servers.Add(ConfigurationHelper.ResolveToEndPoint(host, port));
182+
this.Servers.Add(new DnsEndPoint(host, port));
191183
}
192184

193185
/// <summary>
194186
/// Gets a list of <see cref="T:IPEndPoint"/> each representing a Memcached server in the pool.
195187
/// </summary>
196-
public IList<EndPoint> Servers { get; private set; }
188+
public IList<DnsEndPoint> Servers { get; private set; }
197189

198190
/// <summary>
199191
/// Gets the configuration of the socket pool.
@@ -250,7 +242,7 @@ public ITranscoder Transcoder
250242

251243
#region [ interface ]
252244

253-
IList<System.Net.EndPoint> IMemcachedClientConfiguration.Servers
245+
IList<System.Net.DnsEndPoint> IMemcachedClientConfiguration.Servers
254246
{
255247
get { return this.Servers; }
256248
}

Enyim.Caching/Memcached/DefaultServerPool.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public DefaultServerPool(
4848
catch { }
4949
}
5050

51-
protected virtual IMemcachedNode CreateNode(EndPoint endpoint)
51+
protected virtual IMemcachedNode CreateNode(DnsEndPoint endpoint)
5252
{
5353
return new MemcachedNode(endpoint, this.configuration.SocketPool, _logger);
5454
}
@@ -207,9 +207,9 @@ IEnumerable<IMemcachedNode> IServerPool.GetWorkingNodes()
207207
void IServerPool.Start()
208208
{
209209
this.allNodes = this.configuration.Servers.
210-
Select(ip =>
210+
Select(ep =>
211211
{
212-
var node = this.CreateNode(ip);
212+
var node = this.CreateNode(ep);
213213
node.Failed += this.NodeFail;
214214

215215
return node;

Enyim.Caching/Memcached/MemcachedNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public class MemcachedNode : IMemcachedNode
2727

2828
private bool isDisposed;
2929

30-
private EndPoint endPoint;
30+
private DnsEndPoint endPoint;
3131
private ISocketPoolConfiguration config;
3232
private InternalPoolImpl internalPoolImpl;
3333
private bool isInitialized;
3434

3535
public MemcachedNode(
36-
EndPoint endpoint,
36+
DnsEndPoint endpoint,
3737
ISocketPoolConfiguration socketPoolConfig,
3838
ILogger logger
3939
)

Enyim.Caching/Memcached/PooledSocket.cs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public partial class PooledSocket : IDisposable
2828
private Stream inputStream;
2929
private AsyncSocketHelper helper;
3030

31-
public PooledSocket(EndPoint endpoint, TimeSpan connectionTimeout, TimeSpan receiveTimeout, ILogger logger)
31+
public PooledSocket(DnsEndPoint endpoint, TimeSpan connectionTimeout, TimeSpan receiveTimeout, ILogger logger)
3232
{
3333
_logger = logger;
3434

@@ -59,59 +59,23 @@ public PooledSocket(EndPoint endpoint, TimeSpan connectionTimeout, TimeSpan rece
5959
this.inputStream = new BasicNetworkStream(socket);
6060
}
6161

62-
private void ConnectWithTimeout(Socket socket, EndPoint endpoint, int timeout)
62+
private void ConnectWithTimeout(Socket socket, DnsEndPoint endpoint, int timeout)
6363
{
64-
//var task = socket.ConnectAsync(endpoint);
65-
//if(!task.Wait(timeout))
66-
//{
67-
// using (socket)
68-
// {
69-
// throw new TimeoutException("Could not connect to " + endpoint);
70-
// }
71-
//}
72-
73-
if (endpoint is DnsEndPoint && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
74-
{
75-
var dnsEndPoint = ((DnsEndPoint)endpoint);
76-
var host = dnsEndPoint.Host;
77-
var addresses = Dns.GetHostAddresses(dnsEndPoint.Host);
78-
var address = addresses.FirstOrDefault(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
79-
if (address == null)
80-
{
81-
throw new ArgumentException(String.Format("Could not resolve host '{0}'.", host));
82-
}
83-
_logger.LogDebug($"Resolved '{host}' to '{address}'");
84-
endpoint = new IPEndPoint(address, dnsEndPoint.Port);
85-
}
86-
8764
var completed = new AutoResetEvent(false);
65+
8866
var args = new SocketAsyncEventArgs();
8967
args.RemoteEndPoint = endpoint;
9068
args.Completed += OnConnectCompleted;
9169
args.UserToken = completed;
9270
socket.ConnectAsync(args);
71+
9372
if (!completed.WaitOne(timeout) || !socket.Connected)
9473
{
9574
using (socket)
9675
{
9776
throw new TimeoutException("Could not connect to " + endpoint);
9877
}
99-
}
100-
101-
/*
102-
var mre = new ManualResetEvent(false);
103-
socket.Connect(endpoint, iar =>
104-
{
105-
try { using (iar.AsyncWaitHandle) socket.EndConnect(iar); }
106-
catch { }
107-
108-
mre.Set();
109-
}, null);
110-
111-
if (!mre.WaitOne(timeout) || !socket.Connected)
112-
using (socket)
113-
throw new TimeoutException("Could not connect to " + endpoint);
114-
*/
78+
}
11579
}
11680

11781
private void OnConnectCompleted(object sender, SocketAsyncEventArgs args)

Enyim.Caching/Memcached/Protocol/Binary/BinaryNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class BinaryNode : MemcachedNode
2020
ISaslAuthenticationProvider authenticationProvider;
2121

2222
public BinaryNode(
23-
EndPoint endpoint,
23+
DnsEndPoint endpoint,
2424
ISocketPoolConfiguration config,
2525
ISaslAuthenticationProvider authenticationProvider,
2626
ILogger logger)

Enyim.Caching/Memcached/Protocol/Binary/BinaryPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public BinaryPool(IMemcachedClientConfiguration configuration, ILogger logger)
2727
_logger = logger;
2828
}
2929

30-
protected override IMemcachedNode CreateNode(EndPoint endpoint)
30+
protected override IMemcachedNode CreateNode(DnsEndPoint endpoint)
3131
{
3232
return new BinaryNode(endpoint, this.configuration.SocketPool, this.authenticationProvider, _logger);
3333
}

0 commit comments

Comments
 (0)