UdpArqServer.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace HPSocketCS
  5. {
  6. public class UdpArqServer<T> : UdpArqServer
  7. {
  8. public new T GetExtra(IntPtr connId)
  9. {
  10. return base.GetExtra<T>(connId);
  11. }
  12. public bool SetExtra(IntPtr connId, T obj)
  13. {
  14. return base.SetExtra(connId, obj);
  15. }
  16. }
  17. public class UdpArqServer : UdpServer
  18. {
  19. /// <summary>
  20. /// 创建socket监听&服务组件
  21. /// </summary>
  22. /// <returns></returns>
  23. protected override bool CreateListener()
  24. {
  25. if (IsCreate == true || pListener != IntPtr.Zero || pServer != IntPtr.Zero)
  26. {
  27. return false;
  28. }
  29. pListener = Sdk.Create_HP_UdpArqServerListener();
  30. if (pListener == IntPtr.Zero)
  31. {
  32. return false;
  33. }
  34. pServer = Sdk.Create_HP_UdpArqServer(pListener);
  35. if (pServer == IntPtr.Zero)
  36. {
  37. return false;
  38. }
  39. IsCreate = true;
  40. return true;
  41. }
  42. /// <summary>
  43. /// 终止服务并释放资源
  44. /// </summary>
  45. public override void Destroy()
  46. {
  47. Stop();
  48. if (pServer != IntPtr.Zero)
  49. {
  50. Sdk.Destroy_HP_UdpArqServer(pServer);
  51. pServer = IntPtr.Zero;
  52. }
  53. if (pListener != IntPtr.Zero)
  54. {
  55. Sdk.Destroy_HP_UdpArqServerListener(pListener);
  56. pListener = IntPtr.Zero;
  57. }
  58. IsCreate = false;
  59. }
  60. /// <summary>
  61. /// 获取或设置是否开启 NoDelay 模式
  62. /// </summary>
  63. public bool NoDelay
  64. {
  65. get
  66. {
  67. return Sdk.HP_UdpArqServer_IsNoDelay(pServer);
  68. }
  69. set
  70. {
  71. Sdk.HP_UdpArqServer_SetNoDelay(pServer, value);
  72. }
  73. }
  74. /// <summary>
  75. /// 获取或设置是否关闭拥塞控制
  76. /// </summary>
  77. public bool TurnoffCongestCtrl
  78. {
  79. get
  80. {
  81. return Sdk.HP_UdpArqServer_IsTurnoffCongestCtrl(pServer);
  82. }
  83. set
  84. {
  85. Sdk.HP_UdpArqServer_SetTurnoffCongestCtrl(pServer, value);
  86. }
  87. }
  88. /// <summary>
  89. /// 获取或设置数据刷新间隔
  90. /// </summary>
  91. public uint FlushInterval
  92. {
  93. get
  94. {
  95. return Sdk.HP_UdpArqServer_GetFlushInterval(pServer);
  96. }
  97. set
  98. {
  99. Sdk.HP_UdpArqServer_SetFlushInterval(pServer, value);
  100. }
  101. }
  102. /// <summary>
  103. /// 获取或设置快速重传 ACK 跨越次数
  104. /// </summary>
  105. public uint ResendByAcks
  106. {
  107. get
  108. {
  109. return Sdk.HP_UdpArqServer_GetResendByAcks(pServer);
  110. }
  111. set
  112. {
  113. Sdk.HP_UdpArqServer_SetResendByAcks(pServer, value);
  114. }
  115. }
  116. /// <summary>
  117. /// 获取或设置发送窗口大小
  118. /// </summary>
  119. public uint SendWndSize
  120. {
  121. get
  122. {
  123. return Sdk.HP_UdpArqServer_GetSendWndSize(pServer);
  124. }
  125. set
  126. {
  127. Sdk.HP_UdpArqServer_SetSendWndSize(pServer, value);
  128. }
  129. }
  130. /// <summary>
  131. /// 获取或设置接收窗口大小
  132. /// </summary>
  133. public uint RecvWndSize
  134. {
  135. get
  136. {
  137. return Sdk.HP_UdpArqServer_GetRecvWndSize(pServer);
  138. }
  139. set
  140. {
  141. Sdk.HP_UdpArqServer_SetRecvWndSize(pServer, value);
  142. }
  143. }
  144. /// <summary>
  145. /// 获取或设置最小重传超时时间
  146. /// </summary>
  147. public uint MinRto
  148. {
  149. get
  150. {
  151. return Sdk.HP_UdpArqServer_GetMinRto(pServer);
  152. }
  153. set
  154. {
  155. Sdk.HP_UdpArqServer_SetMinRto(pServer, value);
  156. }
  157. }
  158. /// <summary>
  159. /// 获取或设置最大传输单元
  160. /// </summary>
  161. public uint MaxTransUnit
  162. {
  163. get
  164. {
  165. return Sdk.HP_UdpArqServer_GetMaxTransUnit(pServer);
  166. }
  167. set
  168. {
  169. Sdk.HP_UdpArqServer_SetMaxTransUnit(pServer, value);
  170. }
  171. }
  172. /// <summary>
  173. /// 获取或设置最大数据包大小
  174. /// </summary>
  175. public uint MaxMessageSize
  176. {
  177. get
  178. {
  179. return Sdk.HP_UdpArqServer_GetMaxMessageSize(pServer);
  180. }
  181. set
  182. {
  183. Sdk.HP_UdpArqServer_SetMaxMessageSize(pServer, value);
  184. }
  185. }
  186. /// <summary>
  187. /// 获取或设置握手超时时间
  188. /// </summary>
  189. public uint HandShakeTimeout
  190. {
  191. get
  192. {
  193. return Sdk.HP_UdpArqServer_GetHandShakeTimeout(pServer);
  194. }
  195. set
  196. {
  197. Sdk.HP_UdpArqServer_SetHandShakeTimeout(pServer, value);
  198. }
  199. }
  200. /// <summary>
  201. /// 获取等待发送包数量
  202. /// </summary>
  203. /// <param name="dwConnId"></param>
  204. /// <returns></returns>
  205. public int GetWaitingSendMessageCount(IntPtr dwConnId)
  206. {
  207. var count = 0;
  208. if (Sdk.HP_UdpArqServer_GetWaitingSendMessageCount(pServer, dwConnId, ref count))
  209. {
  210. return count;
  211. }
  212. return 0;
  213. }
  214. }
  215. }