IWaitingClient.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //------------------------------------------------------------------------------
  2. // 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
  3. // 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
  4. // CSDN博客:https://blog.csdn.net/qq_40374647
  5. // 哔哩哔哩视频:https://space.bilibili.com/94253567
  6. // Gitee源代码仓库:https://gitee.com/RRQM_Home
  7. // Github源代码仓库:https://github.com/RRQM
  8. // API首页:https://www.yuque.com/rrqm/touchsocket/index
  9. // 交流QQ群:234762506
  10. // 感谢您的下载和使用
  11. //------------------------------------------------------------------------------
  12. //------------------------------------------------------------------------------
  13. using System;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using TouchSocket.Core;
  17. namespace TouchSocket.Sockets
  18. {
  19. /// <summary>
  20. /// 等待型客户端。
  21. /// </summary>
  22. public interface IWaitingClient<TClient> : IWaitSender,IDisposable where TClient : IClient, IDefaultSender, ISender
  23. {
  24. /// <summary>
  25. /// 等待设置。
  26. /// </summary>
  27. public WaitingOptions WaitingOptions { get;}
  28. /// <summary>
  29. /// 客户端终端
  30. /// </summary>
  31. TClient Client { get; }
  32. /// <summary>
  33. /// 发送字节流
  34. /// </summary>
  35. /// <param name="buffer">数据缓存区</param>
  36. /// <param name="offset">偏移</param>
  37. /// <param name="length">长度</param>
  38. /// <param name="timeout">超时时间</param>
  39. /// <param name="token">取消令箭</param>
  40. /// <exception cref="NotConnectedException">客户端没有连接</exception>
  41. /// <exception cref="OverlengthException">发送数据超长</exception>
  42. /// <exception cref="Exception">其他异常</exception>
  43. /// <returns>返回的数据</returns>
  44. ResponsedData SendThenResponse(byte[] buffer, int offset, int length, int timeout = 1000 * 5, CancellationToken token = default);
  45. /// <summary>
  46. /// 发送字节流
  47. /// </summary>
  48. /// <param name="buffer">数据缓存区</param>
  49. /// <param name="timeout">超时时间</param>
  50. /// <param name="token">取消令箭</param>
  51. /// <exception cref="NotConnectedException">客户端没有连接</exception>
  52. /// <exception cref="OverlengthException">发送数据超长</exception>
  53. /// <exception cref="Exception">其他异常</exception>
  54. /// <returns>返回的数据</returns>
  55. ResponsedData SendThenResponse(byte[] buffer, int timeout = 1000 * 5, CancellationToken token = default);
  56. /// <summary>
  57. /// 发送流中的有效数据
  58. /// </summary>
  59. /// <param name="byteBlock">数据块载体</param>
  60. /// <param name="timeout">超时时间</param>
  61. /// <param name="token">取消令箭</param>
  62. /// <exception cref="NotConnectedException">客户端没有连接</exception>
  63. /// <exception cref="OverlengthException">发送数据超长</exception>
  64. /// <exception cref="Exception">其他异常</exception>
  65. /// <returns>返回的数据</returns>
  66. ResponsedData SendThenResponse(ByteBlock byteBlock, int timeout = 1000 * 5, CancellationToken token = default);
  67. /// <summary>
  68. /// 异步发送
  69. /// </summary>
  70. /// <param name="buffer">数据缓存区</param>
  71. /// <param name="offset">偏移</param>
  72. /// <param name="length">长度</param>
  73. /// <param name="timeout">超时时间</param>
  74. /// <param name="token">取消令箭</param>
  75. /// <exception cref="NotConnectedException">客户端没有连接</exception>
  76. /// <exception cref="OverlengthException">发送数据超长</exception>
  77. /// <exception cref="Exception">其他异常</exception>
  78. /// <returns>返回的数据</returns>
  79. Task<ResponsedData> SendThenResponseAsync(byte[] buffer, int offset, int length, int timeout = 1000 * 5, CancellationToken token = default);
  80. /// <summary>
  81. /// 异步发送
  82. /// </summary>
  83. /// <param name="buffer">数据缓存区</param>
  84. /// <param name="timeout">超时时间</param>
  85. /// <param name="token">取消令箭</param>
  86. /// <exception cref="NotConnectedException">客户端没有连接</exception>
  87. /// <exception cref="OverlengthException">发送数据超长</exception>
  88. /// <exception cref="Exception">其他异常</exception>
  89. /// <returns>返回的数据</returns>
  90. Task<ResponsedData> SendThenResponseAsync(byte[] buffer, int timeout = 1000 * 5, CancellationToken token = default);
  91. /// <summary>
  92. /// 异步发送
  93. /// </summary>
  94. /// <param name="byteBlock">数据块载体</param>
  95. /// <param name="timeout">超时时间</param>
  96. /// <param name="token">取消令箭</param>
  97. /// <exception cref="NotConnectedException">客户端没有连接</exception>
  98. /// <exception cref="OverlengthException">发送数据超长</exception>
  99. /// <exception cref="Exception">其他异常</exception>
  100. /// <returns>返回的数据</returns>
  101. Task<ResponsedData> SendThenResponseAsync(ByteBlock byteBlock, int timeout = 1000 * 5, CancellationToken token = default);
  102. }
  103. }