diff --git a/Dache.Client/CacheClient.cs b/Dache.Client/CacheClient.cs index 612f3a8..6bd19b0 100644 --- a/Dache.Client/CacheClient.cs +++ b/Dache.Client/CacheClient.cs @@ -80,6 +80,13 @@ public CacheClient() clientContainer.Disconnected += OnClientDisconnected; clientContainer.Reconnected += OnClientReconnected; + // Attempt to connect + if (!clientContainer.Connect()) + { + // Skip it for now + continue; + } + // Add to the client list - constructor so no lock needed over the add here _cacheHostLoadBalancingDistribution.Add(new CacheHostBucket { @@ -89,16 +96,6 @@ public CacheClient() // Now calculate the load balancing distribution CalculateCacheHostLoadBalancingDistribution(); - - // Now connect to each cache host - for (int i = 0; i < _cacheHostLoadBalancingDistribution.Count; i++) - { - var cacheHostBucket = _cacheHostLoadBalancingDistribution[i]; - if (!cacheHostBucket.CacheHost.Connect()) - { - i--; - } - } } /// diff --git a/Dache.Client/CommunicationClient.cs b/Dache.Client/CommunicationClient.cs index d5d4f68..d098a50 100644 --- a/Dache.Client/CommunicationClient.cs +++ b/Dache.Client/CommunicationClient.cs @@ -81,7 +81,13 @@ public CommunicationClient(string address, int port, int hostReconnectIntervalMi public bool Connect() { - return _client.Connect(_remoteEndPoint); + var result = _client.Connect(_remoteEndPoint); + if (!result) + { + // Disconnect the client + DisconnectFromServer(); + } + return result; } /// @@ -708,14 +714,6 @@ public override string ToString() /// public event EventHandler Reconnected; - private void HandleError(object state, SocketErrorArgs e) - { - // Enter the disconnected state - DisconnectFromServer(); - - throw new Exception(e.ErrorMessage); - } - /// /// Makes the client enter the disconnected state. /// diff --git a/Dache.PerformanceTests/InfiniteAdd/InfiniteAddTest.cs b/Dache.PerformanceTests/InfiniteAdd/InfiniteAddTest.cs index 15c433a..f43a835 100644 --- a/Dache.PerformanceTests/InfiniteAdd/InfiniteAddTest.cs +++ b/Dache.PerformanceTests/InfiniteAdd/InfiniteAddTest.cs @@ -15,6 +15,9 @@ public static void Run() Console.WriteLine("***** BEGIN INFINITE ADD TEST (WILL NEVER END) *****"); Console.WriteLine(); + cacheClient.HostDisconnected += (sender, e) => { Console.WriteLine("*** Host disconnected"); }; + cacheClient.HostReconnected += (sender, e) => { Console.WriteLine("*** Host reconnected"); }; + int i = 1; while (true) {