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.
 
 
 

29 lines
851 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Threading.Channels;
  6. using System.Threading.Tasks;
  7. namespace JT808.Gateway.NormalHosting.Services
  8. {
  9. public class JT808MsgReplyDataService
  10. {
  11. private readonly Channel<(string TerminalNo, byte[] Data)> _channel;
  12. public JT808MsgReplyDataService()
  13. {
  14. _channel = Channel.CreateUnbounded<(string TerminalNo, byte[] Data)>();
  15. }
  16. public async ValueTask WriteAsync(string terminalNo, byte[] Data)
  17. {
  18. await _channel.Writer.WriteAsync((terminalNo, Data));
  19. }
  20. public async ValueTask<(string TerminalNo, byte[] Data)> ReadAsync(CancellationToken cancellationToken)
  21. {
  22. return await _channel.Reader.ReadAsync(cancellationToken);
  23. }
  24. }
  25. }