You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DuplexPipe.cs 1.3 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.IO.Pipelines;
  2. namespace MQTTnet.AspNetCore.Client.Tcp
  3. {
  4. public class DuplexPipe : IDuplexPipe
  5. {
  6. public DuplexPipe(PipeReader reader, PipeWriter writer)
  7. {
  8. Input = reader;
  9. Output = writer;
  10. }
  11. public PipeReader Input { get; }
  12. public PipeWriter Output { get; }
  13. public static DuplexPipePair CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions)
  14. {
  15. var input = new Pipe(inputOptions);
  16. var output = new Pipe(outputOptions);
  17. var transportToApplication = new DuplexPipe(output.Reader, input.Writer);
  18. var applicationToTransport = new DuplexPipe(input.Reader, output.Writer);
  19. return new DuplexPipePair(applicationToTransport, transportToApplication);
  20. }
  21. // This class exists to work around issues with value tuple on .NET Framework
  22. public readonly struct DuplexPipePair
  23. {
  24. public IDuplexPipe Transport { get; }
  25. public IDuplexPipe Application { get; }
  26. public DuplexPipePair(IDuplexPipe transport, IDuplexPipe application)
  27. {
  28. Transport = transport;
  29. Application = application;
  30. }
  31. }
  32. }
  33. }