public void Close(ProxyConnection connection)
 {
     if (ConnectionIndecies.TryRemove(connection, out var id))
     {
         IndexConnections.TryRemove(id, out connection);
         OnConnectionRemoved?.Invoke(this, connection);
         DisposeConnection(connection);
     }
 }
 public void Close(long id)
 {
     if (IndexConnections.TryRemove(id, out var connection))
     {
         if (ConnectionIndecies.TryRemove(connection, out id))
         {
             OnConnectionRemoved?.Invoke(this, connection);
             DisposeConnection(connection);
         }
     }
 }
        public long Register(ProxyConnection connection)
        {
            var id = Interlocked.Increment(ref NextConnectionIndex);

            if (!ConnectionIndecies.TryAdd(connection, id) || !IndexConnections.TryAdd(id, connection))
            {
                throw new Exception("Connection register failed");
            }
            OnConnectionRegistered?.Invoke(this, connection);
            return(id);
        }
 public long GetId(ProxyConnection connection)
 {
     return(ConnectionIndecies.GetValueOrDefault(connection, -1));
 }