/// <summary> /// Creates a new instance of the network connection from the existing /// instance. The inner socket and direction will copied, but the caller /// can decide how the encryption and decryption will work. /// </summary> /// <param name="connection">The existing instance of the connection.</param> /// <param name="configurer">The new configuration.</param> public NetworkPoolConnection(NetworkPoolConnection connection, NetworkConfiguration configurer) { listener = connection.listener; socket = connection.socket; remote = connection.remote; direction = connection.direction; identifier = connection.identifier; incoming = new NetworkIncomingBuffer(connection.incoming, configurer.Decryptor); outgoing = new NetworkOutgoingBuffer(connection.outgoing, configurer.Encryptor); }
public NetworkConnection Create(TcpSocket socket, NetworkDirection direction, IPEndPoint remote) { long identifier = Interlocked.Increment(ref sequence); NetworkPoolListener listener = new NetworkPoolListener(items, queue, hooks, configuration, dependencies); NetworkPoolConnection connection = new NetworkPoolConnection(listener, socket, direction, identifier, remote); lock (items) { items.Add(identifier, new NetworkPoolEntry { Connection = connection, IsAvailable = true }); } hooks.CallConnectionAttached(connection); return(connection); }
public NetworkConnection Change(NetworkConnection connection, NetworkConfiguration configurer) { NetworkPoolEntry entry; long identifier = connection.Identifier; lock (items) { items.TryGetValue(identifier, out entry); } if (entry?.Connection != null) { connection = new NetworkPoolConnection(entry.Connection, configurer); hooks.CallConnectionEncrypted(connection); return(connection); } return(connection); }