protected virtual void ProcessAccepted(Socket socket) { socket.Blocking = false; var connection = new ProxyConnection(socket, Context, Connections); Connections.Register(connection); }
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; }
public void RemoveConnection(ProxyConnection connection) { lock (Connections) { Connections.Remove(connection); if (Connections.Count == 0) { Stop(); } } }
public void AddConnection(ProxyConnection connection) { lock (Connections) { Connections.Add(connection); if (Connections.Count == 1) { Start(); } } }
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; }
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 void AddConnection(ProxyConnection connection) { lock (Connections) { Connections.Add(connection); if (Connections.Count == 1) { Start(); } } connection.Socket.ReceiveTimeout = ReceiveTimeout; }
private void DisposeConnection(ProxyConnection connection) { try { connection.Socket.Close(); connection.Socket.Dispose(); } catch { } if (connection is IDisposable disposable) { using (disposable) { } } }
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); } }
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); } } }
public long GetId(ProxyConnection connection) { return(ConnectionIndecies.GetValueOrDefault(connection, -1)); }