示例#1
0
        async Task Connect(string host, int port)
        {
            await ConnectAsync(host, port);

            _pump             = new FramePump(_client.GetStream());
            _outboundEndpoint = new OutboundTcpEndpoint(this, _pump);
            _inboundEndpoint  = _rpcEngine.AddEndpoint(_outboundEndpoint);
            _pumpThread       = new Thread(() =>
            {
                try
                {
                    Thread.CurrentThread.Name = $"TCP RPC Client Thread {Thread.CurrentThread.ManagedThreadId}";

                    _pump.Run();
                }
                finally
                {
                    _outboundEndpoint.Dismiss();
                    _inboundEndpoint.Dismiss();
                    _pump.Dispose();
                }
            });

            _pump.FrameReceived += _inboundEndpoint.Forward;
            _pumpThread.Start();
        }
        async Task ConnectAndRunAsync(string host, int port)
        {
            await ConnectAsync(host, port);

            State = ConnectionState.Active;

            var stream = _createLayers(_client.GetStream());

            _pump = new FramePump(stream);
            _attachTracerAction?.Invoke();
            _outboundEndpoint = new OutboundTcpEndpoint(this, _pump);
            _inboundEndpoint  = _rpcEngine.AddEndpoint(_outboundEndpoint);
            _pumpThread       = new Thread(() =>
            {
                try
                {
                    Thread.CurrentThread.Name = $"TCP RPC Client Thread {Thread.CurrentThread.ManagedThreadId}";

                    _pump.Run();
                }
                finally
                {
                    State = ConnectionState.Down;
                    _outboundEndpoint.Dismiss();
                    _inboundEndpoint.Dismiss();
                    _pump.Dispose();
                }
            });

            _pump.FrameReceived += _inboundEndpoint.Forward;
            _pumpThread.Start();
        }
 public EnginePair()
 {
     Engine1   = new RpcEngine();
     Engine2   = new RpcEngine();
     _channel1 = new EngineChannel();
     Endpoint1 = Engine1.AddEndpoint(_channel1);
     _channel2 = new EngineChannel();
     Endpoint2 = Engine2.AddEndpoint(_channel2);
     _channel1.OtherEndpoint = Endpoint2;
     _channel2.OtherEndpoint = Endpoint1;
 }
示例#4
0
 public EnginePair(DecisionTree decisionTree)
 {
     _decisionTree           = decisionTree;
     Engine1                 = new RpcEngine();
     Engine2                 = new RpcEngine();
     _channel1               = new EngineChannel(decisionTree.MakeDecision);
     Endpoint1               = Engine1.AddEndpoint(_channel1);
     _channel2               = new EngineChannel(() => false);
     Endpoint2               = Engine2.AddEndpoint(_channel2);
     _channel1.OtherEndpoint = Endpoint2;
     _channel2.OtherEndpoint = Endpoint1;
 }
示例#5
0
        void AcceptClients()
        {
            try
            {
                if (Thread.CurrentThread.Name == null)
                {
                    Thread.CurrentThread.Name = $"TCP RPC Acceptor Thread {Thread.CurrentThread.ManagedThreadId}";
                }

                while (true)
                {
                    var client           = _listener.AcceptTcpClient();
                    var pump             = new FramePump(client.GetStream());
                    var outboundEndpoint = new OutboundTcpEndpoint(this, pump);
                    var inboundEndpoint  = _rpcEngine.AddEndpoint(outboundEndpoint);
                    pump.FrameReceived += inboundEndpoint.Forward;

                    var connection = new Connection(this, client, pump, outboundEndpoint, inboundEndpoint);

                    lock (_reentrancyBlocker)
                    {
                        ++ConnectionCount;
                        _connections.Add(connection);

                        OnConnectionChanged?.Invoke(this, new ConnectionEventArgs(connection));
                        connection.Start();
                    }

                    connection.PumpRunner.Start();
                }
            }
            catch (SocketException)
            {
                // Listener was stopped. Maybe a little bit rude, but this is
                // our way of shutting down the acceptor thread.
            }
            catch (System.Exception exception)
            {
                // Any other exception might be due to some other problem.
                Logger.LogError(exception.Message);
            }
        }