Пример #1
0
 public void Close(ProxyConnection connection)
 {
     if (ConnectionIndecies.TryRemove(connection, out var id))
     {
         IndexConnections.TryRemove(id, out connection);
         OnConnectionRemoved?.Invoke(this, connection);
         DisposeConnection(connection);
     }
 }
Пример #2
0
 public void Close(long id)
 {
     if (IndexConnections.TryRemove(id, out var connection))
     {
         if (ConnectionIndecies.TryRemove(connection, out id))
         {
             OnConnectionRemoved?.Invoke(this, connection);
             DisposeConnection(connection);
         }
     }
 }
Пример #3
0
        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);
        }
Пример #4
0
 public long GetId(ProxyConnection connection)
 {
     return(ConnectionIndecies.GetValueOrDefault(connection, -1));
 }