SSLPackAgent.CS 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace HPSocketCS
  6. {
  7. public class SSLPackAgent : SSLAgent
  8. {
  9. public SSLPackAgent()
  10. : base()
  11. {
  12. }
  13. /// <summary>
  14. ///
  15. /// </summary>
  16. /// <param name="verifyModel">验证模式</param>
  17. /// <param name="pemCertFile">证书文件(客户端可选)</param>
  18. /// <param name="pemKeyFile">私钥文件(客户端可选)</param>
  19. /// <param name="keyPasswod">私钥密码(没有密码则为空)</param>
  20. /// <param name="caPemCertFileOrPath">CA 证书文件或目录(单向验证或客户端可选)</param>
  21. public SSLPackAgent(SSLVerifyMode verifyModel, string pemCertFile, string pemKeyFile, string keyPasswod, string caPemCertFileOrPath)
  22. : base(verifyModel, pemCertFile, pemKeyFile, keyPasswod, caPemCertFileOrPath)
  23. {
  24. }
  25. /// <summary>
  26. /// 创建socket监听&服务组件
  27. /// </summary>
  28. /// <returns></returns>
  29. protected override bool CreateListener()
  30. {
  31. if (IsCreate == true || pListener != IntPtr.Zero || pAgent != IntPtr.Zero)
  32. {
  33. return false;
  34. }
  35. pListener = Sdk.Create_HP_TcpPackAgentListener();
  36. if (pListener == IntPtr.Zero)
  37. {
  38. return false;
  39. }
  40. pAgent = SSLSdk.Create_HP_SSLPackAgent(pListener);
  41. if (pAgent == IntPtr.Zero)
  42. {
  43. return false;
  44. }
  45. IsCreate = true;
  46. return true;
  47. }
  48. /// <summary>
  49. /// 终止服务并释放资源
  50. /// </summary>
  51. public override void Destroy()
  52. {
  53. Stop();
  54. if (pAgent != IntPtr.Zero)
  55. {
  56. SSLSdk.Destroy_HP_SSLPackAgent(pAgent);
  57. pAgent = IntPtr.Zero;
  58. }
  59. if (pListener != IntPtr.Zero)
  60. {
  61. Sdk.Destroy_HP_TcpPackAgentListener(pListener);
  62. pListener = IntPtr.Zero;
  63. }
  64. IsCreate = false;
  65. }
  66. /// <summary>
  67. /// 读取或设置数据包最大长度
  68. /// 有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000
  69. /// </summary>
  70. public uint MaxPackSize
  71. {
  72. get
  73. {
  74. return Sdk.HP_TcpPackAgent_GetMaxPackSize(pAgent);
  75. }
  76. set
  77. {
  78. Sdk.HP_TcpPackAgent_SetMaxPackSize(pAgent, value);
  79. }
  80. }
  81. /// <summary>
  82. /// 读取或设置包头标识
  83. /// 有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0
  84. /// </summary>
  85. public ushort PackHeaderFlag
  86. {
  87. get
  88. {
  89. return Sdk.HP_TcpPackAgent_GetPackHeaderFlag(pAgent);
  90. }
  91. set
  92. {
  93. Sdk.HP_TcpPackAgent_SetPackHeaderFlag(pAgent, value);
  94. }
  95. }
  96. }
  97. }