Esempio n. 1
0
        internal static ConnectionPair Pair(SimpleInMemConnection client, SimpleInMemConnection server)
        {
            ConnectionPair pair = new ConnectionPair(client, server);

            server.pairedReadQueue = client.writeQueue;
            client.pairedReadQueue = server.writeQueue;

            server.Start();
            client.Start();
            return(pair);
        }
        private void Stop(ConnectionPair pair)
        {
            if (pair.Client.State == CnxState.Connected)
            {
                pair.Client.StopAsync();
            }

            if (pair.Server.State == CnxState.Connected)
            {
                pair.Server.StopAsync();
            }
        }
        private void Add(ConnectionPair connectionPair)
        {
            var   client             = connectionPair.Client;
            var   connectedEventArgs = new ConnectedEventArgs(client);
            Error error = OnConnected(connectedEventArgs);

            if (error != null)
            {
                logger.Site().Information("{0}: Rejecting connection {1} because {2}:{3}.",
                                          logname, client.Id, error.error_code, error.message);
                throw new SimpleInMemProtocolErrorException(
                          "Connection rejected",
                          details: error,
                          innerException: null);
            }

            lock (connectionsLock)
            {
                connectionPairs.Add(connectionPair.Id, connectionPair);
            }
        }