public IAsyncDisposable Start()
        {
            var previousStatus = Interlocked.Exchange(ref _status, Started);

            if (previousStatus == Started)
            {
                return(this);
            }

            var task = Task.Run(
                async() =>
            {
                while (_cancellationTokenSource.IsCancellationRequested == false)
                {
                    try
                    {
                        var client = await _networkServer
                                     .WaitForConnectedClientAsync(_cancellationTokenSource.Token)
                                     .ConfigureAwait(false);
                        ReceiveMessagesFor(client);
                    }
                    catch when(_cancellationTokenSource.IsCancellationRequested)
                    {
                        return;
                    }
                }
            });

            _backgroundTasks.Add(task);
            return(this);
        }
예제 #2
0
        internal async Task <SpdySession> ConnectAsync(
            CancellationToken cancellationToken = default)
        {
            _server =
                _testFramework.NetworkServerFactory.CreateAndStart(
                    IPAddress.Any, 1,
                    ProtocolType.Tcp);
            _client = await _testFramework.ConnectAsync(
                new FrameClientFactory(),
                IPAddress.Any, 1,
                ProtocolType.Tcp,
                cancellationToken)
                      .ConfigureAwait(false);

            return(SpdySession.CreateClient(
                       await _server.WaitForConnectedClientAsync(cancellationToken)
                       .ConfigureAwait(false)));
        }
예제 #3
0
        private async Task StartReceivingLocalClientsAsync()
        {
            while (CancellationToken.IsCancellationRequested ==
                   false)
            {
                try
                {
                    var client = await _networkServer
                                 .WaitForConnectedClientAsync(CancellationToken)
                                 .ConfigureAwait(false);

                    _logger.Trace("Local socket connected");
                    _backgroundTasks.Add(StartPortForwardingAsync(client));
                }
                catch when(CancellationToken
                           .IsCancellationRequested)
                {
                    return;
                }
예제 #4
0
        private async Task StartReceivingLocalClients()
        {
            while (_cancellationTokenSource.IsCancellationRequested ==
                   false)
            {
                try
                {
                    var client = await _networkServer
                                 .WaitForConnectedClientAsync(CancellationToken)
                                 .ConfigureAwait(false);

                    _logger.Trace("Local socket connected");
                    await _activeLocalSockets.SendAsync(
                        client, CancellationToken)
                    .ConfigureAwait(false);
                }
                catch when(_cancellationTokenSource
                           .IsCancellationRequested)
                {
                    return;
                }