Skip to content
代码片段 群组 项目
EchoConnectionHandler.cs 1005 字节
更新 更旧
  • 了解如何忽略特定修订
  • // Licensed to the .NET Foundation under one or more agreements.
    // The .NET Foundation licenses this file to you under the MIT license.
    
    moozzyk's avatar
    moozzyk 已提交
    
    
    using System.Buffers;
    
    moozzyk's avatar
    moozzyk 已提交
    using System.Threading.Tasks;
    
    using Microsoft.AspNetCore.Connections;
    
    moozzyk's avatar
    moozzyk 已提交
    
    
    namespace FunctionalTests
    
    moozzyk's avatar
    moozzyk 已提交
    {
    
        public class EchoConnectionHandler : ConnectionHandler
    
    moozzyk's avatar
    moozzyk 已提交
        {
    
                    var result = await connection.Transport.Input.ReadAsync();
                    var buffer = result.Buffer;
    
                        if (!buffer.IsEmpty)
                        {
                            await connection.Transport.Output.WriteAsync(buffer.ToArray());
                        }
                        else if (result.IsCompleted)
                        {
                            break;
                        }
    
                        connection.Transport.Input.AdvanceTo(result.Buffer.End);
    
    moozzyk's avatar
    moozzyk 已提交
            }
        }
    }