using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HPSocketCS
{
public class SSLPullAgent : SSLAgent
{
protected new TcpPullAgentEvent.OnReceiveEventHandler OnReceive;
public SSLPullAgent()
: base()
{
}
///
///
///
/// 验证模式
/// 证书文件(客户端可选)
/// 私钥文件(客户端可选)
/// 私钥密码(没有密码则为空)
/// CA 证书文件或目录(单向验证或客户端可选)
public SSLPullAgent(SSLVerifyMode verifyModel, string pemCertFile, string pemKeyFile, string keyPasswod, string caPemCertFileOrPath)
: base(verifyModel, pemCertFile, pemKeyFile, keyPasswod, caPemCertFileOrPath)
{
}
///
/// 创建socket监听&服务组件
///
///
protected override bool CreateListener()
{
if (IsCreate == true || pListener != IntPtr.Zero || pAgent != IntPtr.Zero)
{
return false;
}
pListener = Sdk.Create_HP_TcpPullAgentListener();
if (pListener == IntPtr.Zero)
{
return false;
}
pAgent = SSLSdk.Create_HP_SSLPullAgent(pListener);
if (pAgent == IntPtr.Zero)
{
return false;
}
IsCreate = true;
return true;
}
///
/// 抓取数据
/// 用户通过该方法从 Socket 组件中抓取数据
///
///
///
///
///
public FetchResult Fetch(IntPtr connId, IntPtr pBuffer, int size)
{
return Sdk.HP_TcpPullAgent_Fetch(pAgent, connId, pBuffer, size);
}
///
/// 抓取数据
/// 用户通过该方法从 Socket 组件中抓取数据
///
///
///
///
///
public FetchResult Peek(IntPtr connId, IntPtr pBuffer, int size)
{
return Sdk.HP_TcpPullAgent_Peek(pAgent, connId, pBuffer, size);
}
new Sdk.OnPullReceive _OnReceive = null;
///
/// 设置回调函数
///
///
///
///
///
///
///
///
protected override void SetCallback()
{
_OnReceive = new Sdk.OnPullReceive(SDK_OnReceive);
// 设置 Socket 监听器回调函数
Sdk.HP_Set_FN_Agent_OnPullReceive(pListener, _OnReceive);
base.SetCallback();
}
protected virtual HandleResult SDK_OnReceive(IntPtr pSender, IntPtr connId, int length)
{
if (OnReceive != null)
{
return OnReceive(connId, length);
}
return HandleResult.Ignore;
}
///
/// 终止服务并释放资源
///
public override void Destroy()
{
Stop();
if (pAgent != IntPtr.Zero)
{
SSLSdk.Destroy_HP_SSLPullAgent(pAgent);
pAgent = IntPtr.Zero;
}
if (pListener != IntPtr.Zero)
{
Sdk.Destroy_HP_TcpPullAgentListener(pListener);
pListener = IntPtr.Zero;
}
IsCreate = false;
}
}
}