Skip to content

Commit

Permalink
20210824
Browse files Browse the repository at this point in the history
  • Loading branch information
ldcsaa committed Aug 24, 2021
1 parent 6aef9f5 commit 0c4b4c8
Show file tree
Hide file tree
Showing 22 changed files with 449 additions and 172 deletions.
10 changes: 10 additions & 0 deletions Linux/Change-APIs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# ======================================== #
HP-Socket v5.8.5 API Update List:
# ======================================== #
--------------------
1、Thread Pool:
--------------------
Create_HP_ThreadPoolListener (ADD)
Destroy_HP_ThreadPoolListener (ADD)
Create_HP_ThreadPool (UPDATE: add parameter 'HP_ThreadPoolListener pListener')

# ======================================== #
HP-Socket v5.8.4 API Update List:
# ======================================== #
--------------------
Expand Down
30 changes: 15 additions & 15 deletions Linux/include/hpsocket/HPSocket-SSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,23 @@ struct SSLPackClient_Creator
};

// SSL ITcpServer 对象智能指针
typedef CHPSocketPtr<ITcpServer, ITcpServerListener, SSLServer_Creator> CSSLServerPtr;
typedef CHPObjectPtr<ITcpServer, ITcpServerListener, SSLServer_Creator> CSSLServerPtr;
// SSL ITcpAgent 对象智能指针
typedef CHPSocketPtr<ITcpAgent, ITcpAgentListener, SSLAgent_Creator> CSSLAgentPtr;
typedef CHPObjectPtr<ITcpAgent, ITcpAgentListener, SSLAgent_Creator> CSSLAgentPtr;
// SSL ITcpClient 对象智能指针
typedef CHPSocketPtr<ITcpClient, ITcpClientListener, SSLClient_Creator> CSSLClientPtr;
typedef CHPObjectPtr<ITcpClient, ITcpClientListener, SSLClient_Creator> CSSLClientPtr;
// SSL ITcpPullServer 对象智能指针
typedef CHPSocketPtr<ITcpPullServer, ITcpServerListener, SSLPullServer_Creator> CSSLPullServerPtr;
typedef CHPObjectPtr<ITcpPullServer, ITcpServerListener, SSLPullServer_Creator> CSSLPullServerPtr;
// SSL ITcpPullAgent 对象智能指针
typedef CHPSocketPtr<ITcpPullAgent, ITcpAgentListener, SSLPullAgent_Creator> CSSLPullAgentPtr;
typedef CHPObjectPtr<ITcpPullAgent, ITcpAgentListener, SSLPullAgent_Creator> CSSLPullAgentPtr;
// SSL ITcpPullClient 对象智能指针
typedef CHPSocketPtr<ITcpPullClient, ITcpClientListener, SSLPullClient_Creator> CSSLPullClientPtr;
typedef CHPObjectPtr<ITcpPullClient, ITcpClientListener, SSLPullClient_Creator> CSSLPullClientPtr;
// SSL ITcpPackServer 对象智能指针
typedef CHPSocketPtr<ITcpPackServer, ITcpServerListener, SSLPackServer_Creator> CSSLPackServerPtr;
typedef CHPObjectPtr<ITcpPackServer, ITcpServerListener, SSLPackServer_Creator> CSSLPackServerPtr;
// SSL ITcpPackAgent 对象智能指针
typedef CHPSocketPtr<ITcpPackAgent, ITcpAgentListener, SSLPackAgent_Creator> CSSLPackAgentPtr;
typedef CHPObjectPtr<ITcpPackAgent, ITcpAgentListener, SSLPackAgent_Creator> CSSLPackAgentPtr;
// SSL ITcpPackClient 对象智能指针
typedef CHPSocketPtr<ITcpPackClient, ITcpClientListener, SSLPackClient_Creator> CSSLPackClientPtr;
typedef CHPObjectPtr<ITcpPackClient, ITcpClientListener, SSLPackClient_Creator> CSSLPackClientPtr;

/*****************************************************************************************************************************************************/
/*************************************************************** Global Function Exports *************************************************************/
Expand Down Expand Up @@ -257,7 +257,7 @@ HPSOCKET_API IHttpAgent* HP_Create_HttpsAgent(IHttpAgentListener* pListener);
// 创建 IHttpsClient 对象
HPSOCKET_API IHttpClient* HP_Create_HttpsClient(IHttpClientListener* pListener);
// 创建 IHttpsSyncClient 对象
HPSOCKET_API IHttpSyncClient* HP_Create_HttpsSyncClient(IHttpClientListener* pListener);
HPSOCKET_API IHttpSyncClient* HP_Create_HttpsSyncClient(IHttpClientListener* pListener = nullptr);

// 销毁 IHttpsServer 对象
HPSOCKET_API void HP_Destroy_HttpsServer(IHttpServer* pServer);
Expand Down Expand Up @@ -313,7 +313,7 @@ struct HttpsClient_Creator
// IHttpsSyncClient 对象创建器
struct HttpsSyncClient_Creator
{
static IHttpSyncClient* Create(IHttpClientListener* pListener)
static IHttpSyncClient* Create(IHttpClientListener* pListener = nullptr)
{
return HP_Create_HttpsSyncClient(pListener);
}
Expand All @@ -325,13 +325,13 @@ struct HttpsSyncClient_Creator
};

// IHttpsServer 对象智能指针
typedef CHPSocketPtr<IHttpServer, IHttpServerListener, HttpsServer_Creator> CHttpsServerPtr;
typedef CHPObjectPtr<IHttpServer, IHttpServerListener, HttpsServer_Creator> CHttpsServerPtr;
// IHttpsAgent 对象智能指针
typedef CHPSocketPtr<IHttpAgent, IHttpAgentListener, HttpsAgent_Creator> CHttpsAgentPtr;
typedef CHPObjectPtr<IHttpAgent, IHttpAgentListener, HttpsAgent_Creator> CHttpsAgentPtr;
// IHttpsClient 对象智能指针
typedef CHPSocketPtr<IHttpClient, IHttpClientListener, HttpsClient_Creator> CHttpsClientPtr;
typedef CHPObjectPtr<IHttpClient, IHttpClientListener, HttpsClient_Creator> CHttpsClientPtr;
// IHttpsSyncClient 对象智能指针
typedef CHPSocketPtr<IHttpSyncClient, IHttpClientListener, HttpsSyncClient_Creator> CHttpsSyncClientPtr;
typedef CHPObjectPtr<IHttpSyncClient, IHttpClientListener, HttpsSyncClient_Creator> CHttpsSyncClientPtr;

#endif

Expand Down
101 changes: 38 additions & 63 deletions Linux/include/hpsocket/HPSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ Module: HPSocket
/**************************************************/
/************** HPSocket 对象智能指针 **************/

template<class T, class _Creator> class CHPBasePtr
template<class T, class _Listener, class _Creator> class CHPObjectPtr
{
public:
CHPBasePtr& Reset(T* pObj = nullptr)
CHPObjectPtr& Reset(T* pObj = nullptr)
{
if(pObj != m_pObj)
{
Expand All @@ -78,7 +78,7 @@ template<class T, class _Creator> class CHPBasePtr
return *this;
}

CHPBasePtr& Attach(T* pObj)
CHPObjectPtr& Attach(T* pObj)
{
return Reset(pObj);
}
Expand All @@ -96,57 +96,32 @@ template<class T, class _Creator> class CHPBasePtr
T* operator -> () const {return m_pObj ;}
operator T* () const {return m_pObj ;}

CHPBasePtr& operator = (T* pObj) {return Reset(pObj) ;}
CHPObjectPtr& operator = (T* pObj) {return Reset(pObj) ;}

public:
CHPBasePtr() : m_pObj(nullptr)
CHPObjectPtr(_Listener* pListener = nullptr)
{
m_pObj = _Creator::Create(pListener);
}

CHPObjectPtr(BOOL bCreate, _Listener* pListener = nullptr)
{
m_pObj = bCreate ? _Creator::Create(pListener) : nullptr;
}

virtual ~CHPBasePtr()
virtual ~CHPObjectPtr()
{
Reset();
}

private:
CHPBasePtr(const CHPBasePtr&);
CHPBasePtr& operator = (const CHPBasePtr&);
CHPObjectPtr(const CHPObjectPtr&);
CHPObjectPtr& operator = (const CHPObjectPtr&);

protected:
T* m_pObj;
};

template<class T, class _Listener, class _Creator> class CHPSocketPtr : public CHPBasePtr<T, _Creator>
{
using __super = CHPBasePtr<T, _Creator>;

public:
CHPSocketPtr(_Listener* pListener)
{
__super::m_pObj = _Creator::Create(pListener);
}

CHPSocketPtr()
{

}

};

template<class T, class _Creator> class CHPObjectPtr : public CHPBasePtr<T, _Creator>
{
using __super = CHPBasePtr<T, _Creator>;

public:
CHPObjectPtr(BOOL bCreate = FALSE)
{
if(bCreate)
__super::m_pObj = _Creator::Create();
}

};

/**************************************************/
/**************** HPSocket 导出函数 ****************/

Expand Down Expand Up @@ -345,23 +320,23 @@ struct TcpPackClient_Creator
};

// ITcpServer 对象智能指针
typedef CHPSocketPtr<ITcpServer, ITcpServerListener, TcpServer_Creator> CTcpServerPtr;
typedef CHPObjectPtr<ITcpServer, ITcpServerListener, TcpServer_Creator> CTcpServerPtr;
// ITcpAgent 对象智能指针
typedef CHPSocketPtr<ITcpAgent, ITcpAgentListener, TcpAgent_Creator> CTcpAgentPtr;
typedef CHPObjectPtr<ITcpAgent, ITcpAgentListener, TcpAgent_Creator> CTcpAgentPtr;
// ITcpClient 对象智能指针
typedef CHPSocketPtr<ITcpClient, ITcpClientListener, TcpClient_Creator> CTcpClientPtr;
typedef CHPObjectPtr<ITcpClient, ITcpClientListener, TcpClient_Creator> CTcpClientPtr;
// ITcpPullServer 对象智能指针
typedef CHPSocketPtr<ITcpPullServer, ITcpServerListener, TcpPullServer_Creator> CTcpPullServerPtr;
typedef CHPObjectPtr<ITcpPullServer, ITcpServerListener, TcpPullServer_Creator> CTcpPullServerPtr;
// ITcpPullAgent 对象智能指针
typedef CHPSocketPtr<ITcpPullAgent, ITcpAgentListener, TcpPullAgent_Creator> CTcpPullAgentPtr;
typedef CHPObjectPtr<ITcpPullAgent, ITcpAgentListener, TcpPullAgent_Creator> CTcpPullAgentPtr;
// ITcpPullClient 对象智能指针
typedef CHPSocketPtr<ITcpPullClient, ITcpClientListener, TcpPullClient_Creator> CTcpPullClientPtr;
typedef CHPObjectPtr<ITcpPullClient, ITcpClientListener, TcpPullClient_Creator> CTcpPullClientPtr;
// ITcpPackServer 对象智能指针
typedef CHPSocketPtr<ITcpPackServer, ITcpServerListener, TcpPackServer_Creator> CTcpPackServerPtr;
typedef CHPObjectPtr<ITcpPackServer, ITcpServerListener, TcpPackServer_Creator> CTcpPackServerPtr;
// ITcpPackAgent 对象智能指针
typedef CHPSocketPtr<ITcpPackAgent, ITcpAgentListener, TcpPackAgent_Creator> CTcpPackAgentPtr;
typedef CHPObjectPtr<ITcpPackAgent, ITcpAgentListener, TcpPackAgent_Creator> CTcpPackAgentPtr;
// ITcpPackClient 对象智能指针
typedef CHPSocketPtr<ITcpPackClient, ITcpClientListener, TcpPackClient_Creator> CTcpPackClientPtr;
typedef CHPObjectPtr<ITcpPackClient, ITcpClientListener, TcpPackClient_Creator> CTcpPackClientPtr;

#ifdef _UDP_SUPPORT

Expand Down Expand Up @@ -450,17 +425,17 @@ struct UdpArqClient_Creator
};

// IUdpServer 对象智能指针
typedef CHPSocketPtr<IUdpServer, IUdpServerListener, UdpServer_Creator> CUdpServerPtr;
typedef CHPObjectPtr<IUdpServer, IUdpServerListener, UdpServer_Creator> CUdpServerPtr;
// IUdpClient 对象智能指针
typedef CHPSocketPtr<IUdpClient, IUdpClientListener, UdpClient_Creator> CUdpClientPtr;
typedef CHPObjectPtr<IUdpClient, IUdpClientListener, UdpClient_Creator> CUdpClientPtr;
// IUdpCast 对象智能指针
typedef CHPSocketPtr<IUdpCast, IUdpCastListener, UdpCast_Creator> CUdpCastPtr;
typedef CHPObjectPtr<IUdpCast, IUdpCastListener, UdpCast_Creator> CUdpCastPtr;
// IUdpNode 对象智能指针
typedef CHPSocketPtr<IUdpNode, IUdpNodeListener, UdpNode_Creator> CUdpNodePtr;
typedef CHPObjectPtr<IUdpNode, IUdpNodeListener, UdpNode_Creator> CUdpNodePtr;
// IUdpArqServer 对象智能指针
typedef CHPSocketPtr<IUdpArqServer, IUdpServerListener, UdpArqServer_Creator> CUdpArqServerPtr;
typedef CHPObjectPtr<IUdpArqServer, IUdpServerListener, UdpArqServer_Creator> CUdpArqServerPtr;
// IUdpArqClient 对象智能指针
typedef CHPSocketPtr<IUdpArqClient, IUdpClientListener, UdpArqClient_Creator> CUdpArqClientPtr;
typedef CHPObjectPtr<IUdpArqClient, IUdpClientListener, UdpArqClient_Creator> CUdpArqClientPtr;

#endif

Expand Down Expand Up @@ -630,7 +605,7 @@ HPSOCKET_API IHttpAgent* HP_Create_HttpAgent(IHttpAgentListener* pListener);
// 创建 IHttpClient 对象
HPSOCKET_API IHttpClient* HP_Create_HttpClient(IHttpClientListener* pListener);
// 创建 IHttpSyncClient 对象
HPSOCKET_API IHttpSyncClient* HP_Create_HttpSyncClient(IHttpClientListener* pListener);
HPSOCKET_API IHttpSyncClient* HP_Create_HttpSyncClient(IHttpClientListener* pListener = nullptr);

// 销毁 IHttpServer 对象
HPSOCKET_API void HP_Destroy_HttpServer(IHttpServer* pServer);
Expand Down Expand Up @@ -686,7 +661,7 @@ struct HttpClient_Creator
// IHttpSyncClient 对象创建器
struct HttpSyncClient_Creator
{
static IHttpSyncClient* Create(IHttpClientListener* pListener)
static IHttpSyncClient* Create(IHttpClientListener* pListener = nullptr)
{
return HP_Create_HttpSyncClient(pListener);
}
Expand All @@ -698,13 +673,13 @@ struct HttpSyncClient_Creator
};

// IHttpServer 对象智能指针
typedef CHPSocketPtr<IHttpServer, IHttpServerListener, HttpServer_Creator> CHttpServerPtr;
typedef CHPObjectPtr<IHttpServer, IHttpServerListener, HttpServer_Creator> CHttpServerPtr;
// IHttpAgent 对象智能指针
typedef CHPSocketPtr<IHttpAgent, IHttpAgentListener, HttpAgent_Creator> CHttpAgentPtr;
typedef CHPObjectPtr<IHttpAgent, IHttpAgentListener, HttpAgent_Creator> CHttpAgentPtr;
// IHttpClient 对象智能指针
typedef CHPSocketPtr<IHttpClient, IHttpClientListener, HttpClient_Creator> CHttpClientPtr;
typedef CHPObjectPtr<IHttpClient, IHttpClientListener, HttpClient_Creator> CHttpClientPtr;
// IHttpSyncClient 对象智能指针
typedef CHPSocketPtr<IHttpSyncClient, IHttpClientListener, HttpSyncClient_Creator> CHttpSyncClientPtr;
typedef CHPObjectPtr<IHttpSyncClient, IHttpClientListener, HttpSyncClient_Creator> CHttpSyncClientPtr;

/**************************************************************************/
/*************************** HTTP Cookie 管理方法 **************************/
Expand Down Expand Up @@ -750,7 +725,7 @@ HPSOCKET_API int HP_HttpCookie_HLP_ExpiresToMaxAge(__time64_t tmExpires);
/*****************************************************************************************************************************************************/

// 创建 IHPThreadPool 对象
HPSOCKET_API IHPThreadPool* HP_Create_ThreadPool();
HPSOCKET_API IHPThreadPool* HP_Create_ThreadPool(IHPThreadPoolListener* pListener = nullptr);
// 销毁 IHPThreadPool 对象
HPSOCKET_API void HP_Destroy_ThreadPool(IHPThreadPool* pThreadPool);

Expand Down Expand Up @@ -782,9 +757,9 @@ HPSOCKET_API void HP_Destroy_SocketTaskObj(LPTSocketTask pTask);
// IHPThreadPool 对象创建器
struct HPThreadPool_Creator
{
static IHPThreadPool* Create()
static IHPThreadPool* Create(IHPThreadPoolListener* pListener = nullptr)
{
return HP_Create_ThreadPool();
return HP_Create_ThreadPool(pListener);
}

static void Destroy(IHPThreadPool* pThreadPool)
Expand All @@ -794,4 +769,4 @@ struct HPThreadPool_Creator
};

// IHPThreadPool 对象智能指针
typedef CHPObjectPtr<IHPThreadPool, HPThreadPool_Creator> CHPThreadPoolPtr;
typedef CHPObjectPtr<IHPThreadPool, IHPThreadPoolListener, HPThreadPool_Creator> CHPThreadPoolPtr;
15 changes: 14 additions & 1 deletion Linux/include/hpsocket/HPSocket4C.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ typedef HP_Object HP_HttpClientListener;

typedef HP_Object HP_ThreadPool;

typedef HP_Object HP_ThreadPoolListener;

/*****************************************************************************************************************************************************/
/****************************************************************** TCP/UDP Exports ******************************************************************/
/*****************************************************************************************************************************************************/
Expand Down Expand Up @@ -2540,11 +2542,22 @@ HPSOCKET_API int __HP_CALL HP_HttpCookie_HLP_ExpiresToMaxAge(__time64_t tmExpire
/**************************************************************** Thread Pool Exports ****************************************************************/
/*****************************************************************************************************************************************************/

/* Thread Pool 回调函数 */
typedef void (__HP_CALL *HP_FN_ThreadPool_OnStartup) (HP_ThreadPool pThreadPool);
typedef void (__HP_CALL *HP_FN_ThreadPool_OnShutdown) (HP_ThreadPool pThreadPool);
typedef void (__HP_CALL *HP_FN_ThreadPool_OnWorkerThreadStart) (HP_ThreadPool pThreadPool, THR_ID dwThreadID);
typedef void (__HP_CALL *HP_FN_ThreadPool_OnWorkerThreadEnd) (HP_ThreadPool pThreadPool, THR_ID dwThreadID);

/****************************************************/
/******************* 对象创建函数 ********************/

// 创建 IHPThreadPoolListener 对象
HPSOCKET_API HP_ThreadPoolListener __HP_CALL Create_HP_ThreadPoolListener();
// 销毁 IHPThreadPoolListener 对象
HPSOCKET_API void __HP_CALL Destroy_HP_ThreadPoolListener(HP_ThreadPoolListener pListener);

// 创建 IHPThreadPool 对象
HPSOCKET_API HP_ThreadPool __HP_CALL Create_HP_ThreadPool();
HPSOCKET_API HP_ThreadPool __HP_CALL Create_HP_ThreadPool(HP_ThreadPoolListener pListener);
// 销毁 IHPThreadPool 对象
HPSOCKET_API void __HP_CALL Destroy_HP_ThreadPool(HP_ThreadPool pThreadPool);

Expand Down
63 changes: 63 additions & 0 deletions Linux/include/hpsocket/SocketInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2949,3 +2949,66 @@ class IHPThreadPool
public:
virtual ~IHPThreadPool() = default;
};

/************************************************************************
名称:线程池监听器接口
描述:定义线程池监听器的所有事件
************************************************************************/
class IHPThreadPoolListener
{
public:

/*
* 名称:线程池启动通知
* 描述:线程池启动时监听器将收到该通知,监听器可以在通知处理方法中执行预处理工作
*
* 参数: pThreadPool -- 线程池对象
* 返回值: 无
*/
virtual void OnStartup(IHPThreadPool* pThreadPool) = 0;

/*
* 名称:线程池启动关闭通知
* 描述:线程池关闭时监听器将收到该通知,监听器可以在通知处理方法中执行后处理工作
*
* 参数: pThreadPool -- 线程池对象
* 返回值: 无
*/
virtual void OnShutdown(IHPThreadPool* pThreadPool) = 0;

/*
* 名称:工作线程启动通知
* 描述:工作线程启动时监听器将收到该通知,监听器可以在通知处理方法中执行线程级别预处理工作
*
* 参数: pThreadPool -- 线程池对象
* dwThreadID -- 工作线程 ID
* 返回值: 无
*/
virtual void OnWorkerThreadStart(IHPThreadPool* pThreadPool, THR_ID dwThreadID) = 0;

/*
* 名称:工作线程退出通知
* 描述:工作线程退出时监听器将收到该通知,监听器可以在通知处理方法中执行线程级别后处理工作
*
* 参数: pThreadPool -- 线程池对象
* dwThreadID -- 工作线程 ID
* 返回值: 无
*/
virtual void OnWorkerThreadEnd(IHPThreadPool* pThreadPool, THR_ID dwThreadID) = 0;

public:
virtual ~IHPThreadPoolListener() {};
};

/************************************************************************
名称:线程池监听器抽象基类
描述:定义某些事件的默认处理方法(忽略事件)
************************************************************************/
class CHPThreadPoolListener : public IHPThreadPoolListener
{
public:
virtual void OnStartup(IHPThreadPool* pThreadPool) override {}
virtual void OnShutdown(IHPThreadPool* pThreadPool) override {}
virtual void OnWorkerThreadStart(IHPThreadPool* pThreadPool, THR_ID dwThreadID) override {}
virtual void OnWorkerThreadEnd(IHPThreadPool* pThreadPool, THR_ID dwThreadID) override {}
};
Loading

0 comments on commit 0c4b4c8

Please sign in to comment.