Esempio n. 1
0
        protected virtual void ProcessAccepted(Socket socket)
        {
            socket.Blocking = false;
            var connection = new ProxyConnection(socket, Context, Connections);

            Connections.Register(connection);
        }
Esempio n. 2
0
 public void Close(ProxyConnection connection)
 {
     if (ConnectionIndecies.TryRemove(connection, out var id))
     {
         IndexConnections.TryRemove(id, out connection);
         OnConnectionRemoved?.Invoke(this, connection);
         DisposeConnection(connection);
     }
 }
 public ProxyConnection(Socket socket, ProxyConnection reverseConnection)
 {
     Socket            = socket;
     Context           = reverseConnection.Context;
     ReverseConnection = reverseConnection;
     IsClient          = false;
     DataHandler       = new ProxyHandler(this);
     AssignedTabled    = reverseConnection.AssignedTabled;
 }
Esempio n. 4
0
 public void RemoveConnection(ProxyConnection connection)
 {
     lock (Connections)
     {
         Connections.Remove(connection);
         if (Connections.Count == 0)
         {
             Stop();
         }
     }
 }
Esempio n. 5
0
 public void AddConnection(ProxyConnection connection)
 {
     lock (Connections)
     {
         Connections.Add(connection);
         if (Connections.Count == 1)
         {
             Start();
         }
     }
 }
Esempio n. 6
0
        public ProxyConnection(Socket socket, ProxyConnection reverseConnection)
        {
            ActivityTime = AcceptedTime = DateTime.Now;

            Socket            = socket;
            Context           = reverseConnection.Context;
            ReverseConnection = reverseConnection;
            IsClient          = false;
            DataHandler       = new ProxyHandler(this);
            AssignedTabled    = reverseConnection.AssignedTabled;
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
 public void AddConnection(ProxyConnection connection)
 {
     lock (Connections)
     {
         Connections.Add(connection);
         if (Connections.Count == 1)
         {
             Start();
         }
     }
     connection.Socket.ReceiveTimeout = ReceiveTimeout;
 }
Esempio n. 9
0
 private void DisposeConnection(ProxyConnection connection)
 {
     try
     {
         connection.Socket.Close();
         connection.Socket.Dispose();
     }
     catch
     {
     }
     if (connection is IDisposable disposable)
     {
         using (disposable) { }
     }
 }
Esempio n. 10
0
 private void ConnectionTable_OnConnectionRegistered(ConnectionTable connectionTable, ProxyConnection connection)
 {
     lock (ConnectionLock)
     {
         if (IncompleteReceivers.Count == 0)
         {
             IncompleteReceivers.Push(new SocketSelectReceiverThread(SelectTimeout, ReceiveBufferSize));
         }
         SocketSelectReceiverThread receiver = IncompleteReceivers.Peek();
         if (receiver.Count + 1 >= ConnectionsPerThread)
         {
             IncompleteReceivers.Pop();
         }
         ConnectionReceiver[connection] = receiver;
         receiver.AddConnection(connection);
     }
 }
Esempio n. 11
0
 private void ConnectionTable_OnConnectionRemoved(ConnectionTable connectionTable, ProxyConnection connection)
 {
     lock (ConnectionLock)
     {
         if (ConnectionReceiver.TryGetValue(connection, out var receiver))
         {
             if (receiver.Count == ConnectionsPerThread)
             {
                 IncompleteReceivers.Push(receiver);
             }
             receiver.RemoveConnection(connection);
             ConnectionReceiver.Remove(connection);
         }
     }
 }
Esempio n. 12
0
 public long GetId(ProxyConnection connection)
 {
     return(ConnectionIndecies.GetValueOrDefault(connection, -1));
 }