Ejemplo n.º 1
0
        private async Task ConnectSocketAsync(Uri uri)
        {
            var innerErrors = new List <Exception>();
            var addresses   = await _resolver.ResolveAsync(uri.Host).ConfigureAwait(false);

            foreach (var address in addresses)
            {
                try
                {
                    await ConnectSocketAsync(address, uri.Port).ConfigureAwait(false);

                    return;
                }
                catch (Exception e)
                {
                    var actualException = e;
                    if (actualException is AggregateException)
                    {
                        actualException = ((AggregateException)actualException).GetBaseException();
                    }

                    innerErrors.Add(new IOException(
                                        $"Failed to connect to server '{uri}' via IP address '{address}': {actualException.Message}",
                                        actualException));
                }
            }

            // all failed
            throw new IOException(
                      $"Failed to connect to server '{uri}' via IP addresses'{addresses.ToContentString()}' at port '{uri.Port}'.",
                      new AggregateException(innerErrors));
        }
        public Task <IPAddress[]> ResolveAsync(string hostname)
        {
            if (_getHostByNameMethod != null)
            {
                return(Task.FromResult(Resolve(hostname)));
            }

            return(_fallBackResolver.ResolveAsync(hostname));
        }
Ejemplo n.º 3
0
 public Task <IPAddress[]> ResolveAsync(string hostname)
 {
     return(_original.ResolveAsync(_target.Host));
 }