예제 #1
0
 public void RemoveConnection(TcpClientConnection conn)
 {
     lock (_syncRoot)
     {
         _pool.Remove(conn);
     }
 }
예제 #2
0
 public void AddConnection(TcpClientConnection conn)
 {
     lock (_syncRoot)
     {
         _pool.Add(conn);
     }
 }
예제 #3
0
        public async Task <TcpClientConnection> GetNewConnection(bool addToPool)
        {
            var exceptions = new List <Exception>();

            foreach (var tcpRemote in _remotes)
            {
                try
                {
                    var conn = await TcpClientConnection.ConnectAsync(tcpRemote.Host, tcpRemote.Port);

                    if (addToPool)
                    {
                        _pool.Add(conn);
                    }
                    return(conn);
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                }
            }
            throw new AggregateException("Unable to connect to any of the specified hosts", exceptions);
        }