diff --git a/.gitignore b/.gitignore index 620d3dc8a..14f84d1ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# Compiled Object files +# Compiled Object files *.slo *.lo *.o diff --git a/ChangeLog.txt b/ChangeLog.txt new file mode 100644 index 000000000..d84b64855 --- /dev/null +++ b/ChangeLog.txt @@ -0,0 +1,605 @@ +========================================================================================== +v3.4.3 £ +========================================================================================== + +> Bug ޸ +----------------- +1޸ vc-common-src CCASQueue ܵѭ Bug + +> ˵ +----------------- +1HP-Socket v3.4.3 ȫ HP-Socket v3.4.2 汾ֱ滻 + +========================================================================================== +v3.4.2 £ +========================================================================================== + +> Bug ޸ +----------------- +1޸ TcpPackServer TcpPackAgent ijЩòЧ Bug + +> ˵ +----------------- +1HP-Socket v3.4.2 ȫ HP-Socket v3.4.1 汾ֱ滻 + +========================================================================================== +v3.4.1 £ +========================================================================================== + +> Tcp Pack ϵͨ +----------------- +1Tcp Pack ϵ֤ÿ OnReceive ¼Ӧóṩһݰ +2Tcp Pack ϵ PUSH/PULL ģʽĽ壬Ӧó򲻱شְ磺PUSHץȡ磺PULL +3Tcp Pack ϵṩ Get/SetMaxPackSize() Get/SetPackHeaderFlag() Ͱͷʶ +2CTcpPackServer ʵ ITcpServer ӿڣCTcpPackAgent ʵ ITcpAgent ӿڣCTcpPackClient ʵ ITcpClient ӿ + +> ӿڵ +----------------- +1OnClose/OnError ϲΪһͨ¼ OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +2ö EnSocketOperation һöֵ SO_CLOSE = 5ʶر Socket +3IServer IAgent ӿɾӿڷ Get/SetRecvPolicy() +4IServer IAgent ӿɾӿڷ Get/SetMaxShutdownWaitTime() + +> ˵ +----------------- +1HP-Socket v3.3.2 ֮ǰ汾 HP-Socket v3.4.1 汾Ҫ޸ OnClose/OnError ¼Ĵ + +========================================================================================== +v3.3.2 £ +========================================================================================== + +> +----------------- +1ǿ +2޸ C#E SDK ֪ Bug + +> ˵ +----------------- +1HP-Socket v3.3.2 ȫ HP-Socket v3.3.1 汾ֱ滻 + +========================================================================================== +v3.3.1 £ +========================================================================================== + +> ӿڵ +----------------- +1IClientListener ӿ IClient* ȡ CONNID ʶ Client +2 IPullClient ӿڣ PULL Client Ļӿ +3IPullSocket IPullClient ӿ Peek() ڿ̽ݣƳݣ +4 IComplexSocketListener ӿڣ Server/Agent ļӿ +5IComplexSocketListener ṩ OnShutdown ֪ͨȡ Server/Agent ԭ OnServerShutdown/OnAgentShutdown +6IClient Get/SetExtra() ڱԶ帽 +7IServer IAgent ӡĬӴط + 1) DisconnectSilenceConnections()ϿָʱľĬ + 2) GetSilencePeriod()ȡijӾĬʱ䣨룩 + 3) SetMarkSilence()ǷǾĬʱ䣨Ϊ TRUE ʱ DisconnectSilenceConnections() GetSilencePeriod() ЧĬϣFALSE + 4) IsMarkSilence()ǷǾĬʱ + +> UdpCast ͨ +----------------- +1UdpClient / UdpServer C/S ģʽĵԵ㵥ͨţijЩӦó£Ҫõ鲥㲥ͨ +2UdpCast ʵ鲥㲥ͨţUdpCast ṩ IUdpCast ӿڣýӿڼ̳ IClient½ӿڷ + + 1) ֪ͨӿڷ + OnPrepareConnect(IClient* pClient, SOCKET socket) + OnConnect(IClient* pClient) + OnSend(IClient* pClient, const BYTE* pData, int iLength) + OnReceive(IClient* pClient, const BYTE* pData, int iLength) + OnClose(IClient* pClient) + OnError(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) + + 2) Ҫ + Start(LPCTSTR pszBindAddress = nullptr, BOOL bAsyncConnect = TRUE /*ò*/) + Stop() + Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID = nullptr) + Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0) + SendPackets(const WSABUF pBuffers[], int iCount) + +3 UdpCast ʹʾTestUDPCast + +> ˵ +----------------- +1HP-Socket v3.3.1 ڹϼ HP-Socket v3.2.3 汾뼶ȫ +2HP-Socket v3.2.3 HP-Socket v3.3.1 Ҫעµ + + 1) Client + a) IClientListener ӿڵ֪ͨIJе + b) PULL Client IPullClient ΪӿڣFetch()/Peek()е + 2) Agent/Server + a) OnShutdown ȡ OnServerShutdown/OnAgentShutdown + +========================================================================================== +v3.2.3 £ +========================================================================================== + +> common-src Ż +----------------- +1Żͨͬ +2Լ 10% + +> ˵ +----------------- +1ʹ HP-Socket v3.2.2 ǰ汾Ӧó԰ȫ HP-Socket v3.2.3 + +========================================================================================== +v3.2.2 £ +========================================================================================== + +> ɰ +----------------- +1ͷ SendPackets() + 1) IClient / IServer / IAgent ͷ SendPackets(dwConnID, pBuffers[], iBufferCount) + 2) TCP - ˳ݰ + 3) UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ +2Сļͷ SendSmallFile() + 1) ITcpClient / ITcpServer / ITcpAgent Сļͷ SendSmallFile(dwConnID, lpszFileName, pHead, pTail) + 2) ͨ pHead pTail ԷֱļݵͷβԶ + 3) SendSmallFile() ֻܷ 4096 KB ڴСļ +3HPSocket.dll HPSocket4C.dll µ + 1) SYS_WSAGetLastError()ϵͳ WSAGetLastError() + 2) SYS_SetSocketOption()ϵͳ setsockopt() + 3) SYS_GetSocketOption()ϵͳ getsockopt() + 4) SYS_IoctlSocket() ϵͳ ioctlsocket() + 5) SYS_WSAIoctl() ϵͳ WSAIoctl() + +> ˵ +----------------- +1ʹ HP-Socket v3.2.1 ǰ汾Ӧó԰ȫ HP-Socket v3.2.2 + +========================================================================================== +v3.2.1 £ +========================================================================================== + +> TcpAgent / TcpPullAgent ͨ +----------------- +1ڴתӦóҲΪͻģ +2TcpClient / TcpPullClient Event Select ͨģͣÿһ Socketһ̣߳ʺӦó +3TcpAgent / TcpPullAgent IOCP ͨģͣһ SocketʺתĿͻͨ +4TcpAgent / TcpPullAgent ʹ÷ʽȻ򵥣ṩ½ӿڷ + + 1) ֪ͨӿڷ + OnPrepareConnect(CONNID dwConnID, SOCKET socket) + OnConnect(CONNID dwConnID) + OnSend(CONNID dwConnID, const BYTE* pData, int iLength) + OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) //Push ģͣ + OnReceive(CONNID dwConnID, int iLength) //Pull ģͣ + OnClose(CONNID dwConnID) + OnError(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) + OnAgentShutdown() + + 2) Ҫ + Start(LPCTSTR pszBindAddress = nullptr, BOOL bAsyncConnect = TRUE) + Stop() + Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID = nullptr) + Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0) + Disconnect(CONNID dwConnID, BOOL bForce = TRUE) + Fetch(CONNID dwConnID, BYTE* pData, int iLength) //Pull ģͣ + +5 TcpAgent / TcpPullAgent ʹʾ + 1) Agent-PFM + 2) Agent-Pull + 3) Agent-4C + +6 TcpAgent + TcpServer ʵֵ HTTP ʾHttpProxy + +> HPSocket for Java SDK +----------------- +1ṩ Java hpsocket-3.2.1.jarͨ JNA ʵ֣Ŀǰֻ֧ Windows ƽ̨ +2лJDK 1.6+JVM server ģʽ"java -server" client ģʽӰ죩 +3ʾ TestEcho-4Jչʾ HPSocket4J ʹ÷ PULL ģʾܲʾ +4MBCS Unicode 汾ֲλڰ org.jessma.hpsocket.mbcs org.jessma.hpsocket.unicode +5HPSocket for Java SDK ṩͨ + + 1) TcpServerTCP ͨŷ֧ PUSH/PULL ģ + 2) TcpClientTCP ͨſͻ֧ PUSH/PULL ģ + 3) TcpAgent TCP ͨ Agent ֧ PUSH/PULL ģ + 4) UdpServerUDP ͨŷ֧ PUSH ģ + 5) UdpClientUDP ͨſͻ֧ PUSH ģ + +6HPSocket4J ʹ÷ TcpAgent Ϊ + + /* 0: Ӧó hpsocket-3.2.1.jar jna-4.1.0.jar */ + + /* 1: ͨ */ + TcpAgent agent = TcpAgent.create(Mode.PUSH); + + /* 2: ûص */ + // ѡ + agent.setCallBackOnPrepareConnect(new OnPrepareConnectImpl()); + // ѡ + agent.setCallBackOnConnect(new OnConnectImpl()); + // 룩PUSH ģҪ OnReceive ص + agent.setCallBackOnReceive(new OnReceiveImpl()); + // 룩PULL ģҪ OnPullReceive ص + // agent.setCallBackOnPullReceive(new OnPullReceiveImpl()); + // ѡ + agent.setCallBackOnSend(new OnSendImpl()); + // 룩 + agent.setCallBackOnClose(new OnCloseImpl()); + // 룩 + agent.setCallBackOnError(new OnErrorImpl()); + // ѡ + agent.setCallBackOnAgentShutdown(new OnAgentShutdownImpl()); + + /* 3ͨ */ + agent.start("127.0.0.1", false); + + /* 4ӷ */ + agent.connect("localhost", (short)5555, pdwConnID); + + /* 5ͨ */ + // Ӧ OnReceive / OnPullReceive ¼ + // ʹ agent.send(dwConnID, data, data.length) + + /* 6رͨ */ + agent.stop(); + + /* 7ͨ */ + TcpAgent.destroy(agent); + +> Żݷ/ղԣ +----------------- +1Server Agent ṩݷͲԣ + 1PACK - ģʽĬϣ ѶͲһͣӴЧ + 2SAFE - ȫģʽ ѶͲһͣƴٶȣ⻺ + 3DIRECT - ֱģʽ ÿһͲֱͶݣڸزߵҪʵʱԽϸߵij +2Server Agent ṩݽղԣ + 1SERIAL - ģʽĬϣ˳򴥷ͬһӵ OnReceive OnClose/OnError ¼ + 2PARALLEL - ģʽ ڲͬͨ߳ͬʱͬһӵ OnReceive OnClose/OnError ¼ + +> £ +----------------- +1IServer GetClientAddress() Ϊ GetRemoteAddress() +2IClient Send() ɾ CONNID dwConnID +3IClient/IServer/IAgent Send() ӷݻָƫ int iOffset +4 EnSendPolicy öͣIServer/IAgent ӷģʽ÷ SetSendPolicy() +5 EnRecvPolicy öͣIServer/IAgent ӽģʽ÷ SetRecvPolicy() +6IServer/IAgent ӷBOOL GetAllConnectionIDs()ȡӵ CONNID +7IUdpServer ӷSetPostReceiveCount() Receive ԤͶ +8EnServerError / EnClientError öͺϲΪ EnSocketError +9EnSocketError / EnHandleResult / EnFetchResult öʹԭƵⲿ +10IClient/IServer/IAgent ӷBOOL GetPendingDataLength()ȡδݵij +11HPSocket4C.dll ӷ SendPart()ָָ֧ƫ +12 HPSocket for C# SDK int 2e ṩ +13 HPSocket ֿ֧⣨ Yecate ṩ +14 vc-common-src Ϊ v2.3.5οvc-common-src v2.3.5 Change Log + +> ˵ +----------------- +1HP-Socket v3.2.1 ڹϼ HP-Socket v3.1.3 ǰ汾 +2ӿб仯Ҫʾ޸ij룻ע⣺гֱ滻 v3.1.3 DLL +3EnServerError / EnClientError öͺϲΪ EnSocketErrorעһЩöֵ˱仯 + +========================================================================================== +v3.1.3 £ +========================================================================================== + +> Demo +----------------- +1C# +2Delphi +3E + +> Bug Fix +----------------- +1޸ IP ַжϴ Bug + 1) ͻӷʱ IP ַλ12֣AAA.BBB.CCC.DDD򱻴жΪ + 2) Ӱ TCP/UDP ͻ + 3) Ӱ汾v3.1.2 ֮ǰа汾 + +2޸ IP ַ Bug + 1) ͻͨӷʱܻ IP ַ + 2) Ӱ TCP/UDP ͻ + 3) Ӱ汾v3.1.2 ֮ǰа汾 + +> ˵ +----------------- +1ʹ HP-Socket v3.1.2 ǰ汾Ӧó԰ȫ HP-Socket v3.1.3 + +========================================================================================== +v3.1.2 £ +========================================================================================== + +> ޸ Server OnClose() / OnError() ¼Ĵ +----------------- +1ǰ汾 TCP/UDP Server Уرһʱܻͬʱһ OnClose() ¼ɸ OnError() ¼ +2. ڴԣӦóҪ OnClose() / OnError() Ĵ¼νͬ +3 v3.1.2 ʼ OnClose() / OnError() ¼ͬʱʱֻӦó֪ͨһ¼¼ +4. ˣӦóڴ OnClose() / OnError() ¼ʱشͬ˳Ŀܺͱдͬĸ + + ʾһ + -------------------------------------------------------------------------------------- + ISocketListener::EnHandleResult CServerDlg::OnClose(CONNID dwConnID) + { + // ǰ汾пܴڲ OnClose()/OnError()ҪѴٽвֵⷵ + + CCriSecLock locallock(m_csPkgInfo); // <-- ٽ + + PVOID pInfo = nullptr; + + if(m_Server->GetConnectionExtra(dwConnID, &pInfo) && pInfo != nullptr) // <-- ֵⷵ + { + m_Server->SetConnectionExtra(dwConnID, nullptr); + delete pInfo; + } + } + + ʾ + -------------------------------------------------------------------------------------- + ISocketListener::EnHandleResult CServerDlg::OnClose(CONNID dwConnID) + { + // v3.1.2 汾ֻյһ OnClose()/OnError() ¼ܰȫƳٽͼ + + PVOID pInfo = nullptr; + m_Server->GetConnectionExtra(dwConnID, &pInfo); + ASSERT(pInfo != nullptr); + + delete pInfo; + } + +> £ +----------------- +1 TCP Server Ĭϲ + 1) DEFAULT_SOCKET_LISTEN_QUEUE : 300 + 2) DEFAULT_ACCEPT_SOCKET_COUNT : 300 + 3) DEFAULT_FREE_SOCKETOBJ_POOL : 150 + 4) DEFAULT_FREE_SOCKETOBJ_HOLD : 450 + 5) DEFAULT_FREE_BUFFEROBJ_POOL : 300 + 6) DEFAULT_FREE_BUFFEROBJ_HOLD : 900 + +2 UDP Server Ĭϲ + 1) DEFAULT_FREE_SOCKETOBJ_POOL : 150 + 2) DEFAULT_FREE_SOCKETOBJ_HOLD : 450 + 3) DEFAULT_FREE_BUFFEROBJ_POOL : 300 + 4) DEFAULT_FREE_BUFFEROBJ_HOLD : 900 + +> ˵ +----------------- +1ʹ HP-Socket v3.1.1 ǰ汾Ӧó԰ȫ HP-Socket v3.1.2 + +========================================================================================== +v3.1.1 £ +========================================================================================== + +> ӵ C Ķ̬ӿ HPSocket4C.dll +----------------- +1Ӵļ HPSocket4C.h HPSocket4C.cppڴ HPSocket4C.dll +2 C ԣ磺C/C#/Delphi ȣܷʹ HPSocket +3HPSocket4C.dll ʹ÷ + + һ + -------------------------------------------------------------------------------------- + (0) C/C++ 򣩰 HPSocket4C.h ͷļ + (1) ::Create_HP_XxxListener() + (2) ::Create_HP_Xxx(pListener) HPSocket + (3) ::HP_Set_FN_Xxx_OnYyy(pListener, ...) üĻص + (4) ص HPSocket + (5) ...... ...... + (6) ::Destroy_HP_Xxx(pSocket) HPSocket + (7) ::Destroy_HP_XxxListener(pListener) ټ + + + -------------------------------------------------------------------------------------- + (1) ӦóҪõĵװضԵİװ + (2) ͨװװķʽʹ HPSocket + +4HPSocket4C.dll ̬ӿⷢа汾 + + (1) x86/HPSocket4C.dll - (32λ/MBCS/Release) + (2) x86/HPSocket4C_D.dll - (32λ/MBCS/DeBug) + (3) x86/HPSocket4C_U.dll - (32λ/UNICODE/Release) + (4) x86/HPSocket4C_UD.dll - (32λ/UNICODE/DeBug) + (5) x64/HPSocket4C.dll - (64λ/MBCS/Release) + (6) x64/HPSocket4C_D.dll - (64λ/MBCS/DeBug) + (7) x64/HPSocket4C_U.dll - (64λ/UNICODE/Release) + (8) x64/HPSocket4C_UD.dll - (64λ/UNICODE/DeBug) + +> ȫ Buffer Pool ƣ +----------------- +1Common/Src Ӵļ bufferpool.h bufferpool.cppʵ Buffer Pool +2ͨ Buffer Pool ڴʹЧʣٶ̬ڴͷŲڴն +3CTcpClient CItemPool TItemList ʵַͻ +4CUdpClient CItemPool TItemList ʵַͻ +5CTcpPullClient CItemPool TItemList ʵַͻ PULL +6CTcpPullServer CBufferPool TBuffer ʵ PULL + +> £ +----------------- +1IServer ӽӿڷ DisconnectLongConnections() ڶϿг +2IServer ɾӿڷ GetConnectionCriSec() +3IClient ӷ Get/SetFreeBufferPoolSize()Get/SetFreeBufferPoolHold() Buffer Pool Сͷֵ +4IPullServer ɾ Get/SetFreePullBufferPool()Get/SetFreePullBufferHold() +5HPSocket.dll HPSocket4C.dll ʹ /MT(d) ѡ±룬ʱ +6ʾ TestEcho-4Cչʾ HPSocket4C.dll ʹ÷ + +> ˵ +----------------- +1ʹ HP-Socket v3.0.2 ǰ汾Ӧó԰ȫ HP-Socket v3.1.1 +2ͨ HPSocket4C.dll ķʽʹ HP-Socketο TestEcho-4C ʾ + +========================================================================================== +v3.0.2 £ +========================================================================================== + +> HP-Socket Ϊ̬ӿ⣺ +----------------- +1ӦóͨԴ̬ӿⷽʽʹ HP-Socket +2̬ӿʹ÷ + + һ + ----------------------------------------------------------------------- + (0) Ӧó SocketInterface.h HPSocket.h ͷļ + (1) HP_Create_Xxx() HPSocket + (2) ʹϺ HP_Destroy_Xxx() HPSocket + + + ----------------------------------------------------------------------- + (0) Ӧó SocketInterface.h HPSocket.h ͷļ + (1) CXxxWrapper װͨװָʹ HPSocket + +3̬ӿⷢа汾 + + (1) x86/HPSocket.dll - (32λ/MBCS/Release) + (2) x86/HPSocket_D.dll - (32λ/MBCS/DeBug) + (3) x86/HPSocket_U.dll - (32λ/UNICODE/Release) + (4) x86/HPSocket_UD.dll - (32λ/UNICODE/DeBug) + (5) x64/HPSocket.dll - (64λ/MBCS/Release) + (6) x64/HPSocket_D.dll - (64λ/MBCS/DeBug) + (7) x64/HPSocket_U.dll - (64λ/UNICODE/Release) + (8) x64/HPSocket_UD.dll - (64λ/UNICODE/DeBug) + +> £ +----------------- +1ӿԼӿڵƵ SocketInterface.h +2IServer ӽӿڷ GetConnectionCount()/GetConnectPeriod() ֱȡǰijӵʱ +3IServer ӿڷ GetListenAddress()/GetClientAddress() CString& Ϊ LPTSTR +4IClient ӿڷ GetLocalAddress() CString& Ϊ LPTSTR +5SocketHelper.h ȫֺ CString& Ϊ LPTSTR +6ʾ TestEcho-Pull TestEcho-PFM Ϊö̬ӿⷽʽʹ HP-Socket + +> ˵ +----------------- +1ʹ HP-Socket v3.0.1 Ӧó԰ȫ HP-Socket v3.0.2 +2ijЩӿڷIJ˵οԹӦ޸ +3̬ͨӿⷽʽʹ HP-Socketο TestEcho-Pull TestEcho-PFM ʾ + +========================================================================================== +v3.0.1 £ +========================================================================================== + +> UDP ͨ +----------------- +1 UDP ͨCUdpServer ΪCUdpClient Ϊͻ +2 CUdpServer IOCP ͨģ +3ͻ CUdpClient Event Select ͨģ +4UDP ͨĽӿԭ TCP ͨһ£ʵ +5UDP ͨͨ·Զ +6 UDP ͨʾ TestEcho-UDP + +> عŻ +----------------- +1淶нӿڡԼļ +2عŻ˴ +3дƣЧƽ⴦밲ȫ +4 Socket 󻺴бʱ䣬߷ʵİȫ + +> ˵ +----------------- +1ʹ HP-Socket v2.2.3 Ӧó԰ȫ HP-Socket v3.0.1 +2˴ӿڡԼļʱҪӦ + +========================================================================================== +v2.2.3 £ +========================================================================================== + +> ID ͸ΪCONNID +----------------- +1SocketHelper.h ж CONNID ͣĬϣtypedef ULONG_PTR CONNID +2Ӧó԰ CONNID Ϊϣͣ磺ULONG / ULONGLONG ȣ +3Ϊ˱ֲάӦóκεطӦáCONNID ID + +> Socket ֧ΪÿӰ󶨸ݣ +----------------- +1IServerSocket CIocpServer ӷ Get/SetConnectionExtra() +2ͨӦóΪÿӰ⸽ݲݻȡ + +> £ +----------------- +1ſ CIocpServer IOCP ߳Ŀƣ64 Ϊ 500 +2 Socket Disconnect() һʶbForceָʾǷǿƶϿ +3 ID ɹ򣬱ֵΪ 0 ID + +========================================================================================== +v2.2.2 £ +========================================================================================== + +> Żعܣ +----------------- +1IServerSocket IClientSocket Get/SetKeepAliveTimes() Ϊ Get/SetKeepAliveTime() +2CIocpServer CClientSocket Ĭ KeepAliveTime ԸΪ 5000 +3CIocpServer CClientSocket Ĭ KeepAliveInterval ԸΪ 3000 + +========================================================================================== +v2.2.1 £ +========================================================================================== + +> PULL ģ֧֣ +----------------- +1ISocketListener PULL ģݽ֪ͨ OnReceive(dwConnID, int) +2 PULL Socket ӿ IPullSocketýӿڵ Fetch(dwConnID, pBuffer, iLength) ץȡͨ + +> Server +----------------- +1 Socket ӿ ISocketServer Ϊ IServerSocket +2 PULL Server Socket CPullServerSocketListener +3 PULL Server Socket ӿ IPullServerSocket +4 PULL Server Socket ʵ CIocpPullServer + +> Client +----------------- +1ͻ Socket ӿ ISocketClient Ϊ IClientSocket +2ͻ Socket ʵ CSocketClient Ϊ CClientSocket +3 PULL Client Socket CPullClientSocketListener +4 PULL Client Socket ӿ IPullClientSocket +5 PULL Client Socket ʵ CPullClientSocket + +> £ +----------------- +1 PULL Socket Գ TestEcho-Pull +2 SocketHelper.h (.cpp) ɰṹ + +> ˵ +----------------- +1ʹ HP-Socket v2.1.1 Ӧó԰ȫ v2.2.1 +2 ISocketServerISocketClient CSocketClient ޸ģˣӦóҪõƺͰͷļӦ޸ + +========================================================================================== +v2.1.1 £ +========================================================================================== + +> Server +----------------- +1IServerSocketListener ȡ OnPrepareSocket(connID, socket) ֪ͨ +2IServerSocketListener ޸ OnAccept((connID, soClient) ֪ͨӲsoClientʵԭ OnPrepareSocket(connID, socket) ֪ͨĹ +3IServerSocketListener OnPrepareListen(soListen) ֪ͨü socket SOCKET ѡ +4ISocketServer ӷ GetListenAddress(strAddress, usPort)ڻȡ Socket ĵַϢ +5ISocketServer ӷ GetClientAddress(connID, strAddress, usPort)ijͻӵĵַϢ +6Ż Socket غڴ黺ع +7һЩԷʷķ +8޸BUG¿ܳ + +> Client +----------------- +1ISocketServer ӷ GetLocalAddress(strAddress, usPort)ڻȡ Client Socket ĵַϢ +2ŻݷͷʽݷЧ + +> £ +----------------- +1Ż TestEcho TestEcho-PFM Գ +3 SocketHelper.h (.cpp) ɰ +4Ϊ SocketHelper.h жнӿڡͷע + +========================================================================================== +v2.0.1 £ +========================================================================================== + +> Server +----------------- +1IServerSocketListener OnPrepareSocket(connID, socket) ֪ͨʹ socket ǰ SOCKET ѡ˿ͻ +2ISocketServer ӷ Disconnect(connID) Ͽͻ +3 IServerSocketListener CServerSocketListenerṩĬϣյģ֪ͨ + +> Client +----------------- +1IClientSocketListener OnPrepareSocket(connID, socket) ֪ͨʹ socket ǰ SOCKET ѡ +2֧첽 ConnectISocketServer Start() һ BOOL bAsyncConnect Ƿ첽 Connect +3 IClientSocketListener CClientSocketListenerṩĬϣյģ֪ͨ +4޸BUG߸³ֶ + + +> £ +----------------- +1֧ Windows x64 ƽ̨ +2Ż TestEcho TestEcho-PFM Գ +3TestEcho ͻ˳롰첽ӡʾ +4TestEcho ˳롰ӹˡ͡Ͽӡʾ \ No newline at end of file diff --git a/Common/ChangeLog.txt b/Common/ChangeLog.txt new file mode 100644 index 000000000..18a290b04 --- /dev/null +++ b/Common/ChangeLog.txt @@ -0,0 +1,103 @@ + +Module : vc-common-src +Desc : HP-Socket VC-Logger Ĺ +Usage : ҪĴļ뵽Ŀ + +========================================================================================== +v2.3.11 £ +========================================================================================== + +1޸ RingBuffer.h޸ CCASQueue ܵѭ Bug + +========================================================================================== +v2.3.10 £ +========================================================================================== + +1޸ RWLock.h/.cpp Slim Lock ʵд CSlimRWLock + +========================================================================================== +v2.3.9 £ +========================================================================================== + +1޸ GeneralHelper.h߱ +2޸ Thread.hֲ߳̾洢 CTlsObj + +========================================================================================== +v2.3.8 £ +========================================================================================== + +1޸ bufferpool.h(.cpp) + 1) TItem Peek() + 2) TItemList Peek() + 3) TBuffer Peek() +2޸ CriticalSection.h + 1) CReentrantSpinLockCReentrantSpinGuard + +========================================================================================== +v2.3.7 £ +========================================================================================== + +1޸ CriticalSection.h + 1) CSpinLockCSpinGuard + 2) CInterCriSec Ĭ Spin Count Ϊ 4096 +2޸ RWLock.h + 1) CSpinLock ȡ CInterCriSec Ϊ CRWLock CSWMR ͬ + 2) ICVCondition/CCVGuardCS/CCVGuardSRW ࣬ʵ-ģ +3 RingBuffer.h/.cppܶд +4 Thread.h/.cpp̷߳װ + +========================================================================================== +v2.3.6 £ +========================================================================================== + +1޸ RWLock.h VS 2005/2008 +2޸ bufferpool.cppmemmove() 滻Ϊ memcpy() + +========================================================================================== +v2.3.5 £ +========================================================================================== + +1޸ STLHelper.h unordered_set / unordered_map +2޸ bufferpool.hTBufferPtrMap Ϊ unordered_map + +========================================================================================== +v2.3.4 £ +========================================================================================== + +1޸ RWLock.hӷд CSlimLock +2޸ bufferpool.h/bufferpool.cpp TItemListEx +3 SysHelper.h/SysHelper.cppṩȡϵͳϢİ + +========================================================================================== +v2.3.3 £ +========================================================================================== + +1޸ bufferpool.cppŻ CBufferPoolTItemList +2޸ STLHelper.h stackqueuedeque Ļ typedef +3޸ FuncHelper.hFuncHelper.cpp VS 2013 +4޸ GeneralHelper.h + 1) 32 λϵͳ _WIN32_WINNT Ĭֵ_WIN32_WINNT_WINXP + 2) 64 λϵͳ _WIN32_WINNT Ĭֵ_WIN32_WINNT_WIN7 + +========================================================================================== +v2.3.2 £ +========================================================================================== + +1 bufferpool.h +2 bufferpool.cpp + +========================================================================================== +v2.3.1 £ +========================================================================================== + +1 RWLock.h +2 RWLock.cpp +3ɾ CMTX/CSEM/CEvent ġoperator HANDLE* &() +4޸ WaitFor.cppŻGetTimeGap32() + +========================================================================================== +v2.2.2 £ +========================================================================================== + +1޸ GeneralHelper.h +2޸ FuncHelper.cpp diff --git a/Common/License.txt b/Common/License.txt new file mode 100644 index 000000000..c643115bd --- /dev/null +++ b/Common/License.txt @@ -0,0 +1,23 @@ +/* + * Copyright JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/Common/Src/CriticalSection.cpp b/Common/Src/CriticalSection.cpp new file mode 100644 index 000000000..01df2e8b0 --- /dev/null +++ b/Common/Src/CriticalSection.cpp @@ -0,0 +1,26 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "CriticalSection.h" \ No newline at end of file diff --git a/Common/Src/CriticalSection.h b/Common/Src/CriticalSection.h new file mode 100644 index 000000000..4eb88d1c0 --- /dev/null +++ b/Common/Src/CriticalSection.h @@ -0,0 +1,316 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#pragma intrinsic(_ReadBarrier) +#pragma intrinsic(_WriteBarrier) +#pragma intrinsic(_ReadWriteBarrier) + +#define DEFAULT_CRISEC_SPIN_COUNT 4096 + +#if defined (_WIN64) + #define DEFAULT_PAUSE_YIELD 32 + #define DEFAULT_PAUSE_CYCLE 8192 +#else + #define DEFAULT_PAUSE_YIELD 8 + #define DEFAULT_PAUSE_CYCLE 4096 +#endif + +#ifndef YieldProcessor + #pragma intrinsic(_mm_pause) + #define YieldProcessor _mm_pause +#endif + +class CInterCriSec +{ +public: + CInterCriSec(DWORD dwSpinCount = DEFAULT_CRISEC_SPIN_COUNT) + {VERIFY(::InitializeCriticalSectionAndSpinCount(&m_crisec, dwSpinCount));} + ~CInterCriSec() + {::DeleteCriticalSection(&m_crisec);} + + void Lock() {::EnterCriticalSection(&m_crisec);} + void Unlock() {::LeaveCriticalSection(&m_crisec);} + BOOL TryLock() {return ::TryEnterCriticalSection(&m_crisec);} + DWORD SetSpinCount(DWORD dwSpinCount) {return ::SetCriticalSectionSpinCount(&m_crisec, dwSpinCount);} + + CRITICAL_SECTION* GetObject() {return &m_crisec;} + +private: + CInterCriSec(const CInterCriSec& cs); + CInterCriSec operator = (const CInterCriSec& cs); + +private: + CRITICAL_SECTION m_crisec; +}; + +class CInterCriSec2 +{ +public: + CInterCriSec2(DWORD dwSpinCount = DEFAULT_CRISEC_SPIN_COUNT, BOOL bInitialize = TRUE) + { + if(bInitialize) + { + m_pcrisec = new CRITICAL_SECTION; + VERIFY(::InitializeCriticalSectionAndSpinCount(m_pcrisec, dwSpinCount)); + } + else + m_pcrisec = nullptr; + } + + ~CInterCriSec2() {Reset();} + + void Attach(CRITICAL_SECTION* pcrisec) + { + Reset(); + m_pcrisec = pcrisec; + } + + CRITICAL_SECTION* Detach() + { + CRITICAL_SECTION* pcrisec = m_pcrisec; + m_pcrisec = nullptr; + return pcrisec; + } + + void Lock() {::EnterCriticalSection(m_pcrisec);} + void Unlock() {::LeaveCriticalSection(m_pcrisec);} + BOOL TryLock() {return ::TryEnterCriticalSection(m_pcrisec);} + DWORD SetSpinCount(DWORD dwSpinCount) {return ::SetCriticalSectionSpinCount(m_pcrisec, dwSpinCount);} + + CRITICAL_SECTION* GetObject() {return m_pcrisec;} + +private: + CInterCriSec2(const CInterCriSec2& cs); + CInterCriSec2 operator = (const CInterCriSec2& cs); + + void Reset() + { + if(m_pcrisec) + { + ::DeleteCriticalSection(m_pcrisec); + delete m_pcrisec; + m_pcrisec = nullptr; + } + } + +private: + CRITICAL_SECTION* m_pcrisec; +}; + +class CMTX +{ +public: + CMTX(BOOL bInitialOwner = FALSE, LPCTSTR pszName = nullptr, LPSECURITY_ATTRIBUTES pSecurity = nullptr) + { + m_hMutex = ::CreateMutex(pSecurity, bInitialOwner, pszName); + ASSERT(IsValid()); + } + + ~CMTX() + { + if(IsValid()) + ::CloseHandle(m_hMutex); + } + + BOOL Open(DWORD dwAccess, BOOL bInheritHandle, LPCTSTR pszName) + { + if(IsValid()) + VERIFY(::CloseHandle(m_hMutex)); + + m_hMutex = ::OpenMutex(dwAccess, bInheritHandle, pszName); + return(IsValid()); + } + + void Lock(DWORD dwMilliseconds = INFINITE) {::WaitForSingleObject(m_hMutex, dwMilliseconds);} + void Unlock() {::ReleaseMutex(m_hMutex);} + + HANDLE& GetHandle () {return m_hMutex;} + operator HANDLE () {return m_hMutex;} + BOOL IsValid () {return m_hMutex != nullptr;} + +private: + CMTX(const CMTX& mtx); + CMTX operator = (const CMTX& mtx); + +private: + HANDLE m_hMutex; +}; + +class CSpinGuard +{ +public: + CSpinGuard() : m_lFlag(0) + { + + } + + ~CSpinGuard() + { + ASSERT(m_lFlag == 0); + } + + void Lock() + { + for(UINT i = 0; !TryLock(); ++i) + Pause(i); + } + + BOOL TryLock() + { + if(::InterlockedCompareExchange(&m_lFlag, 1, 0) == 0) + { + ::_ReadWriteBarrier(); + return TRUE; + } + + return FALSE; + } + + void Unlock() + { + ASSERT(m_lFlag == 1); + m_lFlag = 0; + } + + static void Pause(UINT i) + { + if (i < DEFAULT_PAUSE_YIELD) YieldProcessor(); + else if (i < DEFAULT_PAUSE_CYCLE - 1) SwitchToThread(); + else if (i < DEFAULT_PAUSE_CYCLE) Sleep(1); + else Pause(i & (DEFAULT_PAUSE_CYCLE - 1)); + } + +private: + CSpinGuard(const CSpinGuard& cs); + CSpinGuard operator = (const CSpinGuard& cs); + +private: + volatile LONG m_lFlag; +}; + +class CReentrantSpinGuard +{ +public: + CReentrantSpinGuard() + : m_dwThreadID (0) + , m_iCount (0) + { + + } + + ~CReentrantSpinGuard() + { + ASSERT(m_dwThreadID == 0); + ASSERT(m_iCount == 0); + } + + void Lock() + { + for(UINT i = 0; !_TryLock(i == 0); ++i) + Pause(i); + } + + BOOL TryLock() + { + return _TryLock(TRUE); + } + + void Unlock() + { + ASSERT(m_dwThreadID == ::GetCurrentThreadId()); + + if((--m_iCount) == 0) + m_dwThreadID = 0; + } + + static void Pause(UINT i) + { + if (i < DEFAULT_PAUSE_YIELD) YieldProcessor(); + else if (i < DEFAULT_PAUSE_CYCLE - 1) SwitchToThread(); + else if (i < DEFAULT_PAUSE_CYCLE) Sleep(1); + else Pause(i & (DEFAULT_PAUSE_CYCLE - 1)); + } + +private: + CReentrantSpinGuard(const CReentrantSpinGuard& cs); + CReentrantSpinGuard operator = (const CReentrantSpinGuard& cs); + + BOOL _TryLock(BOOL bFirst) + { + DWORD dwCurrentThreadID = ::GetCurrentThreadId(); + + if(bFirst && m_dwThreadID == dwCurrentThreadID) + { + ++m_iCount; + return TRUE; + } + + if(::InterlockedCompareExchange(&m_dwThreadID, dwCurrentThreadID, 0) == 0) + { + ::_ReadWriteBarrier(); + ASSERT(m_iCount == 0); + + m_iCount = 1; + + return TRUE; + } + + return FALSE; + } + +private: + volatile DWORD m_dwThreadID; + int m_iCount; +}; + +class CFakeGuard +{ +public: + void Lock() {} + void Unlock() {} + BOOL TryLock() {return TRUE;} +}; + +template class CLocalLock +{ +public: + CLocalLock(CLockObj& obj) : m_lock(obj) {m_lock.Lock();} + ~CLocalLock() {m_lock.Unlock();} +private: + CLockObj& m_lock; +}; + +typedef CInterCriSec CCriSec; + +typedef CLocalLock CCriSecLock; +typedef CLocalLock CInterCriSecLock; +typedef CLocalLock CInterCriSecLock2; +typedef CLocalLock CMutexLock; +typedef CLocalLock CSpinLock; +typedef CLocalLock CReentrantSpinLock; +typedef CLocalLock CFakeLock; diff --git a/Common/Src/Event.cpp b/Common/Src/Event.cpp new file mode 100644 index 000000000..61a492b1a --- /dev/null +++ b/Common/Src/Event.cpp @@ -0,0 +1,26 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "Event.h" diff --git a/Common/Src/Event.h b/Common/Src/Event.h new file mode 100644 index 000000000..1cec83b11 --- /dev/null +++ b/Common/Src/Event.h @@ -0,0 +1,66 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +class CEvt +{ +public: + CEvt(BOOL bManualReset = FALSE, BOOL bInitialState = FALSE, LPCTSTR pszName = nullptr, LPSECURITY_ATTRIBUTES pSecurity = nullptr) + { + m_hEvent = ::CreateEvent(pSecurity, bManualReset, bInitialState, pszName); + ASSERT(IsValid()); + } + + ~CEvt() + { + if(IsValid()) + VERIFY(::CloseHandle(m_hEvent)); + } + + BOOL Open(DWORD dwAccess, BOOL bInheritHandle, LPCTSTR pszName) + { + if(IsValid()) + VERIFY(::CloseHandle(m_hEvent)); + + m_hEvent = ::OpenEvent(dwAccess, bInheritHandle, pszName); + return(IsValid()); + } + + BOOL Pulse() {return(::PulseEvent(m_hEvent));} + BOOL Reset() {return(::ResetEvent(m_hEvent));} + BOOL Set() {return(::SetEvent(m_hEvent));} + + HANDLE& GetHandle () {return m_hEvent;} + operator HANDLE () {return m_hEvent;} + BOOL IsValid () {return m_hEvent != nullptr;} + +private: + CEvt(const CEvt&); + CEvt operator = (const CEvt&); + +private: + HANDLE m_hEvent; +}; + diff --git a/Common/Src/FuncHelper.cpp b/Common/Src/FuncHelper.cpp new file mode 100644 index 000000000..433cea2f0 --- /dev/null +++ b/Common/Src/FuncHelper.cpp @@ -0,0 +1,986 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "FuncHelper.h" +#include "WaitFor.h" + +#ifndef _WIN32_WCE + #define CloseToolhelp32Snapshot(h) CloseHandle(h) + + #include + #include + + #pragma comment(lib, "Psapi") +#else + #pragma comment(lib, "Toolhelp") +#endif + +BYTE DoubleCharToByte(LPCTSTR psValue) +{ + return (BYTE)DOUBLECHARTOVALUE(psValue); +} + +LPTSTR ByteToDoubleChar(BYTE b, LPTSTR des) +{ + VALUETODOUBLECHAR(des, b); + return des; +} + +UINT HexStrToInt(LPCTSTR pHexText, int len) +{ + LPTSTR pTemp = (LPTSTR)pHexText; + int Val = 0; + int iLen = lstrlen(pHexText); + if(len > 0 && len < iLen) + iLen = len; + if(iLen % 2) + { + pTemp = (TCHAR*)_alloca(sizeof(TCHAR) * ((++iLen) + 1)); + lstrcpyn(pTemp+1, pHexText, iLen); + pTemp[0] = '0'; + } + + for(int i = 0; i < iLen; i+=2) + Val += (DOUBLECHARTOVALUE(&pTemp[i]) << ((iLen - i)/2 - 1) * 8); + + return Val; +} + +UINT DecStrToInt(LPCTSTR pDecText, int len) +{ + int Val = 0; + int iLen = lstrlen(pDecText); + if(len > 0 && len < iLen) + { + ++len; + CString text; + LPTSTR ptext = text.GetBuffer(len); + lstrcpyn(ptext, pDecText, len); + Val = _ttol(ptext); + text.ReleaseBuffer(); + } + else + Val = _ttol(pDecText); + return Val; +} + +CString& IntToHexStr(CString& dest, UINT v, int len) +{ + if(len > 0) + { + CString format; + format.Format(_T("%%0%uX"), len); + dest.Format(format, v); + if(dest.GetLength() > len) + dest = dest.Right(len); + } + else + dest.Format(_T("%X"), v); + return dest; +} + +CString& IntToDecStr(CString& dest, UINT v, int len) +{ + if(len > 0) + { + CString format; + format.Format(_T("%%0%uu"), len); + dest.Format(format, v); + if(dest.GetLength() > len) + dest = dest.Right(len); + } + else + dest.Format(_T("%u"), v); + return dest; +} + +CString& HexAddrToDecAddr(CString& dest, LPCTSTR src, int destlen, int srclen) +{ + return IntToDecStr(dest, HexStrToInt(src, srclen), destlen); +} +CString& DecAddrToHexAddr(CString& dest, LPCTSTR src, int destlen, int srclen) +{ + return IntToHexStr(dest, DecStrToInt(src, srclen), destlen); +} + + +//-----------------------------MultiByteַUnicodeַ֮ת-----------------------------// + +EnCodePage GetCodePageByName(LPCTSTR lpszCodePageName) +{ + if(!lpszCodePageName || !*lpszCodePageName) + return XCP_ACP; + else if(_tcsicmp(lpszCodePageName, _T("GB2312")) == 0) + return XCP_GB2312; + else if(_tcsicmp(lpszCodePageName, _T("GBK")) == 0) + return XCP_GBK; + else if(_tcsicmp(lpszCodePageName, _T("UTF-8")) == 0) + return XCP_UTF8; + else if(_tcsicmp(lpszCodePageName, _T("UTF-7")) == 0) + return XCP_UTF7; + else if(_tcsicmp(lpszCodePageName, _T("BIG5")) == 0) + return XCP_BIG5; + + return XCP_ACP; +} + +BOOL MbcsToUnicode(const char* pszInString, WCHAR** ptrOutWStr, int& nSizeCount) +{ + return CPToUni(pszInString, ptrOutWStr, CP_ACP, nSizeCount); +} + +BOOL UnicodeToMbcs(const WCHAR* pwzInString, char** ptrOutStr, int& nSizeCount) +{ + return UniToCP(pwzInString, ptrOutStr, CP_ACP, nSizeCount); +} + +BOOL Utf8ToUnicode(const char* pszInString, WCHAR** ptrOutWStr, int& nSizeCount) +{ + return CPToUni(pszInString, ptrOutWStr, CP_UTF8, nSizeCount); +} + +BOOL UnicodeToUtf8(const WCHAR* pwzInString, char** ptrOutStr, int& nSizeCount) +{ + return UniToCP(pwzInString, ptrOutStr, CP_UTF8, nSizeCount); +} + +BOOL CPToUni(const char* pszInString, WCHAR** ptrOutWStr, unsigned int nCodePage, int& nSizeCount) +{ + nSizeCount = 0 ; + if( pszInString == nullptr || ptrOutWStr == nullptr ) + return FALSE ; + + nSizeCount = MultiByteToWideChar( nCodePage, 0, pszInString, -1, nullptr, 0 ) ; + if( 0 == nSizeCount ) + return FALSE ; + + (*ptrOutWStr) = new WCHAR[nSizeCount] ; + if( nullptr == (*ptrOutWStr) ) + return FALSE ; + + if( 0 == MultiByteToWideChar( nCodePage, 0, pszInString, -1, (*ptrOutWStr), nSizeCount ) ) + { + delete[] (*ptrOutWStr); + return FALSE ; + } + + return TRUE; +} + +BOOL UniToCP(const WCHAR* pwzInString, char** ptrOutStr, unsigned int nCodePage, int& nSizeCount) +{ + nSizeCount = 0 ; + if( pwzInString == nullptr || ptrOutStr == nullptr ) + return FALSE ; + + nSizeCount = WideCharToMultiByte( nCodePage, 0, pwzInString, -1, nullptr, 0, nullptr, nullptr) ; + if( 0 == nSizeCount ) + return FALSE ; + + (*ptrOutStr) = new char[nSizeCount] ; + if( nullptr == (*ptrOutStr) ) + return FALSE ; + + if(0 == WideCharToMultiByte( nCodePage, 0, pwzInString, -1, (*ptrOutStr), nSizeCount, nullptr, nullptr)) + { + delete[] (*ptrOutStr); + return FALSE ; + } + + return TRUE; +} + +int BytesToHex(const BYTE* pBytes, int nLength, LPTSTR* lpszDest) +{ + int des_length = nLength * 2; + + if(des_length > 0) + { + LPTSTR dest = new TCHAR[des_length + 1]; + dest[des_length] = '\0'; + + TCHAR chs[3] = {0}; + for(int i = 0; i < nLength; i++) + { + ByteToDoubleChar(pBytes[i], chs); + dest[2 * i] = chs[0]; + dest[2 * i + 1] = chs[1]; + } + + *lpszDest = dest; + } + else + *lpszDest = nullptr; + + return des_length; +} + +int HexToBytes(LPCTSTR lpszHex, BYTE** ppBytes, int* pnLength) +{ + int src_length = lstrlen(lpszHex); + int des_length = src_length / 2; + + *pnLength = des_length; + + if(des_length > 0) + { + BYTE* pBytes = new BYTE[des_length]; + + for(int i = 0; i < des_length; i++) + pBytes[i] = DoubleCharToByte(&lpszHex[2 * i]); + + *ppBytes = pBytes; + } + else + *ppBytes = nullptr; + + return des_length; +} + +CString& StrToHex(const TCHAR* src, CString& strDec) +{ + BYTE* t = (BYTE*)src; + int src_length = lstrlen(src) * sizeof(TCHAR); + strDec.Empty(); + +#ifdef UNICODE + char* temp = nullptr; + UnicodeToMbcs(src, &temp, src_length); + + src_length -= 1; + t = (BYTE*)temp; +#else + t = (BYTE*)src; + src_length = lstrlen(src); +#endif + + for(int i = 0; i < src_length; ++i, ++t) + { + TCHAR tc[3] = {0, 0, 0}; + VALUETODOUBLECHAR(tc, *t); + strDec += tc; + } + +#ifdef UNICODE + delete[] temp; +#endif + + return strDec; +} + +CString& HexToStr(const TCHAR* src, CString& strDec) +{ + char* temp = nullptr; + int src_length = 0; + + strDec.Empty(); + +#ifdef UNICODE + char* temp1 = new char[(src_length = lstrlen(src)) +1]; + temp = temp1; + while(*(temp1++) = (char)*(src++)); +#else + temp = (char*)src; + src_length = lstrlen(src); + //t = strDec.GetBuffer(src_length/2 + 1); +#endif + int i=0; + for(; i < src_length / 2; ++i) + { + temp[i] = DOUBLECHARTOVALUE(temp + 2 * i); + } + temp[i] = 0; + +#ifdef UNICODE + int iLen = 0; + WCHAR* wh = nullptr; + + MbcsToUnicode(temp, &wh, iLen); + + strDec = wh; + delete[] wh; + delete[] temp; +#else + strDec.ReleaseBuffer(); +#endif + + return strDec; +} + +CString& StrToUtf8Hex(const TCHAR* src, CString& strDec) +{ + char* t = nullptr; + WCHAR* temp = nullptr; + int src_length = 0; + + strDec.Empty(); + +#ifndef UNICODE + MbcsToUnicode(src, &temp, src_length); +#else + temp = (TCHAR*)src; +#endif + + UnicodeToUtf8(temp, &t, src_length); + src_length -= 1; + + for(int i = 0; i < src_length; ++i) + { + TCHAR tc[3] = {0, 0, 0}; + VALUETODOUBLECHAR(tc, t[i]); + strDec += tc; + } + +#ifndef UNICODE + delete[] temp; +#endif + delete[] t; + + return strDec; +} + +CString& HexUtf8ToStr(const TCHAR* src, CString& strDec) +{ + char* temp = nullptr; + WCHAR* pwsz = nullptr; + int iLen = 0; + int src_length = 0; + + strDec.Empty(); + +#ifdef UNICODE + char* temp1 = new char[(src_length = lstrlen(src)) +1]; + temp = temp1; + + while(*(temp1++) = (char)*(src++)); +#else + temp = (char*)src; + src_length = lstrlen(src); +#endif + int i=0; + for(; i < src_length / 2; ++i) + { + temp[i] = DOUBLECHARTOVALUE(temp + 2*i); + } + + temp[i] = 0; + + Utf8ToUnicode(temp, &pwsz, iLen); + +#ifdef UNICODE + strDec = pwsz; + delete[] temp; +#else + char* psz = nullptr; + UnicodeToMbcs(pwsz, &psz, iLen); + + strDec = psz; + delete[] psz; +#endif + delete[] pwsz; + + return strDec; +} + +CString GetSystemErrorDesc(DWORD dwCode) +{ + CString msg; + LPTSTR lpMsgBuf; + + if(::FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + nullptr, + dwCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&lpMsgBuf, + 0, + nullptr + )) + { + msg = lpMsgBuf; + ::LocalFree(lpMsgBuf); + } + + return msg; +} + +BOOL SplitStr(LPCTSTR pszSrc, vector& vtItem, LPCTSTR pszSepectors, LPCTSTR pszQMarks) +{ + vtItem.clear(); + + CString strQMarks = pszQMarks; + CString strSepectors = pszSepectors; + + if(strSepectors.IsEmpty()) + strSepectors = _T(" "); + + if(!strQMarks.IsEmpty()) + if(strQMarks.FindOneOf(strSepectors) != -1) + return FALSE; + + BOOL bRetVal = TRUE; + CString strSrc = pszSrc; + + while(!strSrc.Trim(strSepectors).IsEmpty()) + { + CString strItem; + + int iSrcLen = strSrc.GetLength(); + int iPos1 = strSrc.FindOneOf(strSepectors); + int iPos2 = !strQMarks.IsEmpty() ? strSrc.FindOneOf(strQMarks) : -1; + int iPos3 = -1; + + if(iPos1 == -1 && iPos2 == -1) + strItem = strSrc; + else if(iPos1 != -1 && (iPos1 < iPos2 || iPos2 == -1)) + strItem = strSrc.Left(iPos1); + else // (iPos1 > iPos2 || iPos1 == -1) + { + TCHAR tc = strSrc[iPos2]; + iPos3 = strSrc.Find(tc, iPos2 + 1); + if(iPos3 != -1) + strItem = strSrc.Mid(iPos2 + 1, iPos3 - iPos2 - 1); + else + { + vtItem.clear(); + bRetVal = FALSE; + break; + } + } + + vtItem.push_back(strItem); + + strSrc = strSrc.Right(iPos3 == -1 ? (iSrcLen - (iPos1 == -1 ? strItem.GetLength() : iPos1 + 1)) : (iSrcLen - iPos3 - 1)); + } + + return bRetVal; +} + +CString ExtractFileName(LPCTSTR lpszFullFileName) +{ + CString strPath = lpszFullFileName; + strPath.Trim(); + + if(!strPath.IsEmpty()) + { + int iLen = strPath.GetLength(); + int iLastSep = strPath.ReverseFind(PATH_SEPARATOR_CHAR); + + if(iLastSep != -1) + strPath = strPath.Right(iLen - 1 - iLastSep); + } + + return strPath; +} + +CString ExtractPath(LPCTSTR lpszFullFileName) +{ + CString strPath = lpszFullFileName; + strPath.Trim(); + + if(strPath.IsEmpty()) + return PATH_SEPARATOR; + + int iLen = strPath.GetLength(); + int iLastSep = strPath.ReverseFind(PATH_SEPARATOR_CHAR); + int iLastDot = strPath.ReverseFind(FILE_EXTEND_SEPARATOR_CHAR); + + if(iLastSep == -1 && iLastDot == -1) + strPath.Append(PATH_SEPARATOR); + else if(iLastSep == -1 && iLastDot != -1) + strPath = PATH_SEPARATOR; + else if(iLastSep > iLastDot) + { + if(iLastSep < iLen) + strPath.Append(PATH_SEPARATOR); + } + else + { + strPath = strPath.Left(iLastSep + 1); + } + + return strPath; +} + +CString ExtractModulePath(HMODULE hModule) +{ + CString strCurPath; + LPTSTR lpszCurPath = strCurPath.GetBuffer(MAX_PATH); + + BOOL isOK = ::GetModuleFileName(hModule, lpszCurPath, MAX_PATH); + strCurPath.ReleaseBuffer(); + + if(isOK) + { + strCurPath = ::ExtractPath(strCurPath); + ASSERT(!strCurPath.IsEmpty()); + } + + return strCurPath; +} + +BOOL RunProcess(LPCTSTR szFileName, LPCTSTR cmdline/* = nullptr*/, BOOL bHide /* = TRUE */, LPCTSTR dir /* = nullptr*/, BOOL bWait /* = TRUE */, DWORD dwWaitTime /* = INFINITE */) +{ + LPCTSTR process_dir; + if (dir == nullptr || _tcslen(dir) == 0) + process_dir = nullptr; + else + process_dir = dir; + + LPCTSTR process_name; + if (szFileName == nullptr || _tcslen(szFileName) == 0) + process_name = nullptr; + else + process_name = szFileName; + + STARTUPINFO si; + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + + DWORD dwCreationFlags = 0; + if (bHide) + { + si.wShowWindow = SW_HIDE; +#ifndef _WIN32_WCE + dwCreationFlags = CREATE_NO_WINDOW; +#endif + } + + PROCESS_INFORMATION pi; + ZeroMemory(&pi, sizeof(pi)); + + // Start the child process + CString strCmd(cmdline); + LPTSTR pszcmd = (LPTSTR)(LPCTSTR)strCmd; + + BOOL bRet = CreateProcess( + process_name, + pszcmd, // Command line. + nullptr, // Process handle not inheritable. + nullptr, // Thread handle not inheritable. + FALSE, // Set handle inheritance to FALSE. + dwCreationFlags, // No creation flags. + nullptr, // Use parent's environment block. + (LPTSTR)process_dir, // Use parent's starting directory. + &si, // Pointer to STARTUPINFO structure. + &pi + ); + + if(bRet) + { + if(bWait) + bRet = (::WaitForSingleObject(pi.hProcess, dwWaitTime) != WAIT_FAILED) ? TRUE : FALSE; + + ::CloseHandle(pi.hProcess); + ::CloseHandle(pi.hThread); + } + + return bRet; +} + +BOOL ShellRunExe(LPCTSTR lpszPath, LPCTSTR lpszParams, int iShow, HANDLE* phProcess, BOOL bWait, DWORD dwWaitTime) +{ + CString strPath = lpszPath; + strPath.Trim(); + + ASSERT(strPath.GetLength() > 4 && strPath.Right(4).CompareNoCase(EXE_FILE_EXTEND_NAME) == 0); + +#ifdef _WIN32_WCE + if(strPath.GetAt(0) != PATH_SEPARATOR_CHAR) +#else + if(strPath.GetAt(1) != DISK_SYMBLE_CHAR) +#endif + { + CString strCurPath = ExtractModulePath(); + strPath = strCurPath + strPath; + } + + SHELLEXECUTEINFO info = {0}; + + info.cbSize = sizeof(SHELLEXECUTEINFO); + info.lpFile = strPath; + info.fMask = SEE_MASK_FLAG_NO_UI; + info.nShow = iShow; + info.lpParameters = lpszParams; + + if(phProcess || bWait) + info.fMask |= SEE_MASK_NOCLOSEPROCESS; + + BOOL isOK = FALSE; + + if(::ShellExecuteEx(&info)) + { + if(phProcess) + *phProcess = info.hProcess; + + if(bWait) + { + isOK = (::WaitForSingleObject(info.hProcess, dwWaitTime) != WAIT_FAILED) ? TRUE : FALSE; + ::CloseHandle(info.hProcess); + } + else + isOK = TRUE; + } + + return isOK; +} + +void WriteLog(LPCTSTR pszLogFileName, LPCTSTR pszLog) +{ +#ifdef _UNICODE + USES_CONVERSION; +#endif + + HANDLE hLogFile = ::CreateFile(pszLogFileName, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if(hLogFile != INVALID_HANDLE_VALUE) + ::SetFilePointer(hLogFile, 0, 0, FILE_END); + else + return; + + DWORD dwSize; + SYSTEMTIME st; + GetLocalTime(&st); + CString strLog; + strLog.Format(_T("[%02d-%02d %02d:%02d:%02d.%03d] %s\r\n"), st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, pszLog); + +#ifdef _UNICODE + LPSTR lpszLog = T2A((LPTSTR)(LPCTSTR)strLog); + ::WriteFile(hLogFile, lpszLog, (DWORD)::strlen(lpszLog), &dwSize, nullptr); +#else + ::WriteFile(hLogFile, strLog, strLog.GetLength(), &dwSize, nullptr); +#endif + + ::CloseHandle(hLogFile); +} + +BOOL FindProcess(LPCTSTR pszProcessName) +{ + BOOL isOK = FALSE; + HANDLE hTool = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + + if(hTool != INVALID_HANDLE_VALUE) + { + PROCESSENTRY32 pe32; + pe32.dwSize = sizeof(PROCESSENTRY32); + + if(::Process32First(hTool, &pe32)) + { + do + { + if(_tcsicmp(pszProcessName, pe32.szExeFile) == 0) + { + isOK = TRUE; + break; + } + + } while(::Process32Next(hTool, &pe32)); + } + + VERIFY(::CloseToolhelp32Snapshot(hTool)); + } + + return isOK; +} + +HANDLE FindProcessHandle(LPCTSTR pszProcessName, DWORD dwDesiredAccess, BOOL bInheritHandle) +{ + HANDLE hProc = nullptr; + HANDLE hTool = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + + if(hTool != INVALID_HANDLE_VALUE) + { + PROCESSENTRY32 pe32; + pe32.dwSize = sizeof(PROCESSENTRY32); + + if(::Process32First(hTool, &pe32)) + { + do + { + if(_tcsicmp(pszProcessName, pe32.szExeFile) == 0) + { + hProc = ::OpenProcess(dwDesiredAccess, bInheritHandle, pe32.th32ProcessID); + break; + } + + } while(::Process32Next(hTool, &pe32)); + } + + VERIFY(::CloseToolhelp32Snapshot(hTool)); + } + + return hProc; +} + +BOOL FindRunningProcessesInfo(ProcessInfoMap& infoMap) +{ + infoMap.Clear(); + + HANDLE hProc = nullptr; + HANDLE hTool = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + + if(hTool != INVALID_HANDLE_VALUE) + { + PROCESSENTRY32 pe32; + pe32.dwSize = sizeof(PROCESSENTRY32); + + if(::Process32First(hTool, &pe32)) + { + do + { + PROCESSENTRY32* ppe32 = new PROCESSENTRY32; + memcpy(ppe32, &pe32, sizeof(PROCESSENTRY32)); + infoMap[pe32.th32ProcessID] = ppe32; + } while(::Process32Next(hTool, &pe32)); + } + + VERIFY(::CloseToolhelp32Snapshot(hTool)); + } + else + return FALSE; + + return TRUE; +} + +#ifndef _WIN32_WCE +BOOL FindProcessEx(LPCTSTR pszProcessName) +{ + BOOL bRet = FALSE; + + DWORD aProcesses[1024], cbNeeded, cProcesses; + + if (::EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded)) + { + cProcesses = cbNeeded / sizeof(DWORD); + + for (DWORD i = 0; i < cProcesses; i++) + { + HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i]); + + if (hProcess) + { + HMODULE hMod; + DWORD cbNeeded; + if (::EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded)) + { + TCHAR szProcessName[MAX_PATH] = {0}; + if(::GetModuleBaseName(hProcess, hMod, szProcessName, sizeof(szProcessName))) + { + if(_tcsicmp(szProcessName, pszProcessName) == 0) + { + DWORD dwExitCode = 0; + if(::GetExitCodeProcess(hProcess, &dwExitCode) && dwExitCode == STILL_ACTIVE) + { + bRet = TRUE; + break; + } + } + } + } + ::CloseHandle( hProcess ); + } + } + } + + return bRet; +} + +CString GetIniString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpFileName, DWORD dwSize) +{ + CString strValue; + LPTSTR pszBuffer = strValue.GetBuffer(dwSize); + ::GetPrivateProfileString(lpAppName, lpKeyName, _T(""), pszBuffer, dwSize, lpFileName); + strValue.ReleaseBuffer(); + strValue.Trim(); + return strValue; +} + +BOOL SetCurrentPathToModulePath(HMODULE hModule) +{ + TCHAR szPath[MAX_PATH]; + if(::GetModuleFileName(hModule, szPath, MAX_PATH)) + { + TCHAR drive[MAX_PATH], dir[MAX_PATH], fname[MAX_PATH], ext[MAX_PATH]; + _tsplitpath(szPath, drive, dir, fname, ext); + lstrcpy(szPath, drive); + lstrcat(szPath, dir); + + return ::SetCurrentDirectory(szPath); + } + + return FALSE; +} +#endif + +struct TProcWnd +{ + DWORD dwProcID; + LPCTSTR lpszClassName; + HWND hWnd; +}; + +BOOL CALLBACK ProcessMainWindowEnumFunc(HWND hwnd, LPARAM lParam) +{ + TProcWnd* ppw = (TProcWnd*)lParam; + + DWORD dwProcID; + ::GetWindowThreadProcessId(hwnd, &dwProcID); + + if(dwProcID == ppw->dwProcID) + { + while(TRUE) + { + HWND hwParent = ::GetParent(hwnd); + + if(hwParent == nullptr) + { + if(ppw->lpszClassName == nullptr) + { + ppw->hWnd = hwnd; + return FALSE; + } + else + { + int nMaxCount = MAX_PATH - 1; + TCHAR szName[MAX_PATH] = {0}; + + if(::GetClassName(hwnd, szName, nMaxCount)) + { + if(_tcscmp(szName, ppw->lpszClassName) == 0) + { + ppw->hWnd = hwnd; + return FALSE; + } + } + } + + break; + } + else + hwnd = hwParent; + } + } + + return TRUE; +} + +HWND FindProcessMainWindow(DWORD dwProcID, LPCTSTR lpszWndClassName) +{ + if(dwProcID == 0) + dwProcID = ::GetCurrentProcessId(); + + ASSERT(dwProcID != 0); + + TProcWnd pw; + pw.dwProcID = dwProcID; + pw.lpszClassName = lpszWndClassName; + pw.hWnd = nullptr; + + ::EnumWindows(ProcessMainWindowEnumFunc, (LPARAM)&pw); + + return pw.hWnd; +} + +HWND FindProcessMainWindow(HANDLE hProcess, LPCTSTR lpszWndClassName) +{ + DWORD dwProcID = (hProcess == nullptr) ? ::GetCurrentProcessId() : ::GetProcessId(hProcess); + + if(dwProcID != 0) + return FindProcessMainWindow(dwProcID, lpszWndClassName); + + return nullptr; +} + +BOOL CALLBACK CloseWindowEnumFunc(HWND hwnd, LPARAM lParam) +{ + DWORD dwProcID; + ::GetWindowThreadProcessId(hwnd, &dwProcID); + + if(dwProcID == (DWORD)lParam) + ::PostMessage(hwnd, WM_CLOSE, 0, 0); + + return TRUE; +} + +BOOL TerminateProcessFairily(HANDLE hProcess, DWORD dwWait) +{ + DWORD dwProcID = ::GetProcessId(hProcess); + + if(dwProcID != 0) + { + VERIFY(::EnumWindows(CloseWindowEnumFunc, (LPARAM)dwProcID)); + + if(!::MsgWaitForSingleObject(hProcess, dwWait)) + return ::TerminateProcess(hProcess, -1); + + return TRUE; + } + + return FALSE; +} + +#ifdef _AFX +CString SecondToTimeStr(DWORD dwSeconds, BOOL bDayOnly) +{ + CTime tm(dwSeconds); + LPCTSTR pszFormat = bDayOnly ? _T("%Y-%m-%d") : _T("%Y-%m-%d %H:%M:%S"); + return tm.Format(pszFormat); +} +#endif + +BOOL GetRegistryValue(HKEY hRoot, LPCTSTR wcSubKey, LPCTSTR wcName, LPBYTE pValue, DWORD* pdwSize, DWORD* pdwType) +{ + DWORD result = ERROR_INVALID_DATA; + + CRegKey reg; + + result = reg.Create(hRoot, wcSubKey, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_READ); + if(result == ERROR_SUCCESS) + result = reg.QueryValue(wcName, pdwType, pValue, pdwSize); + + + BOOL isOK = (result == ERROR_SUCCESS); + + if(!isOK) + { + *pValue = 0; + *pdwSize = 0; + *pdwType = REG_NONE; + } + + return isOK; +} + +BOOL SetRegistryValue(HKEY hRoot, LPCTSTR wcSubKey, LPCTSTR wcName, LPBYTE pValue, DWORD dwSize, DWORD dwType) +{ + DWORD result = ERROR_INVALID_DATA; + + CRegKey reg; + + result = reg.Create(hRoot, wcSubKey); + if(result == ERROR_SUCCESS) + result = reg.SetValue(wcName, dwType, pValue, dwSize); + + return (result == ERROR_SUCCESS); +} diff --git a/Common/Src/FuncHelper.h b/Common/Src/FuncHelper.h new file mode 100644 index 000000000..86dc5c45a --- /dev/null +++ b/Common/Src/FuncHelper.h @@ -0,0 +1,171 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "GeneralHelper.h" + +#include +#include + +#define PATH_SEPARATOR _T("\\") +#define PATH_SEPARATOR_CHAR _T('\\') +#define FILE_EXTEND_SEPARATOR _T(".") +#define FILE_EXTEND_SEPARATOR_CHAR _T('.') +#define DISK_SYMBLE _T(":") +#define DISK_SYMBLE_CHAR _T(':') +#define EXE_FILE_EXTEND_NAME _T(".exe") + +enum EnCodePage +{ + XCP_ACP = CP_ACP, + XCP_GB2312 = 936, +#ifdef _WIN32_WCE + XCP_BIG5 = CP_ACP, +#else + XCP_BIG5 = 950, +#endif + XCP_GBK = XCP_GB2312, + XCP_UTF7 = CP_UTF7, + XCP_UTF8 = CP_UTF8, +}; + +/************************************* ַ *************************************/ + +// ַתʾֵ: ַ 'F' ת ֵ 15 +#define CHARTOVALUE(c) (c <= '9' ? c - '0' : (c <= 'F' ? c - 'A' + 0x0A : c - 'a' + 0X0A)) +// ˫ַתʾֵ: ַ '1F' ת ֵ 31 +#define DOUBLECHARTOVALUE(pc) (((CHARTOVALUE(*(pc))) << 4) | (CHARTOVALUE(*(pc + 1)))) + +// ֵתʮַ: ֵ 15 ת ַ 'F' +#define VALUETOCHAR(n) (n <= 9 ? n + '0' : (n <= 'F' ? n + 'A' - 0X0A : n + 'a' - 0X0A)) +// ֵַתʮַ: ֵ 11 ת ַ '0B' +#define VALUETODOUBLECHAR(pc, n) {*(pc) = VALUETOCHAR((n >> 4)); *((pc) + 1) = VALUETOCHAR((n & 0X0F));} + +// ˫ַתʾֵ: ַ '1F' ת ֵ 31 +BYTE DoubleCharToByte(LPCTSTR psValue); +// ֵַתʮַ: ֵ 11 ת ַ '0B' +LPTSTR ByteToDoubleChar(BYTE b, LPTSTR des); +// ʮתʾֵ: ַ '601F' ת ֵ 24607 +UINT HexStrToInt(LPCTSTR pHexText, int len = -1); +// ʮתʾֵ: ַ '0000024607' ת ֵ 24607 +UINT DecStrToInt(LPCTSTR pDecText, int len = -1); +// ֵʮַʾֵ: ֵ 24607 ת ַ '601F' +CString& IntToHexStr(CString& dest, UINT v, int len = -1); +// ֵʮַʾֵ: ֵ 24607 ת ַ '24607' +CString& IntToDecStr(CString& dest, UINT v, int len = -1); +// ʮƱʾĵַΪʮƱʾĵַ: "000C35CE" ת '0000800236' +CString& HexAddrToDecAddr(CString& dest, LPCTSTR src, int destlen = 10, int srclen = -1); +// ʮƱʾĵַΪʮƱʾĵַ: "0000800236" ת '000C35CE' +CString& DecAddrToHexAddr(CString& dest, LPCTSTR src, int destlen = 8, int srclen = -1); + +// Code Page Name -> Code Page Value +EnCodePage GetCodePageByName(LPCTSTR lpszCodePageName); + +// MBCS -> UNICODE +BOOL MbcsToUnicode(const char* pszInString, WCHAR** ptrOutWStr, int& nSizeCount); +// UNICODE -> MBCS +BOOL UnicodeToMbcs(const WCHAR* pwzInString, char** ptrOutStr, int& nSizeCount); +// UTF8 -> UNICODE +BOOL Utf8ToUnicode(const char* pszInString, WCHAR** ptrOutWStr, int& nSizeCount); +// UNICODE -> UTF8 +BOOL UnicodeToUtf8(const WCHAR* pwzInString, char** ptrOutStr, int& nSizeCount); +// CP_XXX -> UNICODE +BOOL CPToUni(const char* pszInString, WCHAR** ptrOutWStr, unsigned int nCodePage, int& nSizeCount); +// UNICODE -> CP_XXX +BOOL UniToCP(const WCHAR* pwzInString, char** ptrOutStr, unsigned int nCodePage, int& nSizeCount); + +// ֽת16ַ +int BytesToHex(const BYTE* pBytes, int nLength, LPTSTR* lpszDest); +// 16ַתֽ +int HexToBytes(LPCTSTR lpszHex, BYTE** ppBytes, int* pnLength); + +// ַͨת16ַ +CString& StrToHex(const TCHAR* src, CString& des); +// 16ַתַͨ +CString& HexToStr(const TCHAR* src, CString& des); +// ַͨתUTF8ַ, ȻٰѸUTF8ַת16ַ +CString& StrToUtf8Hex(const TCHAR* src, CString& strDec); +// 16ַתUTF8ַ, ȻٰѸUTF8ַתַͨ +CString& HexUtf8ToStr(const TCHAR* src, CString& strDec); + +// ȡϵͳϢ +CString GetSystemErrorDesc(DWORD dwCode); + +// ַָ +BOOL SplitStr(LPCTSTR pszSrc, vector& vtItem, LPCTSTR pszSepectors = nullptr, LPCTSTR pszQMarks = nullptr); + +// ȡļ +CString ExtractFileName(LPCTSTR lpszFullFileName); +// ȡļ· +CString ExtractPath(LPCTSTR lpszFullFileName); +// ȡļ· +CString ExtractPath(LPCTSTR lpszFullFileName); +// ȡǰģ· +CString ExtractModulePath(HMODULE hModule = nullptr); + +// +BOOL RunProcess(LPCTSTR sFileName, LPCTSTR cmdline = nullptr, BOOL bHide = TRUE, LPCTSTR dir = nullptr, BOOL bWait = TRUE, DWORD dwWaitTime = INFINITE); +BOOL ShellRunExe(LPCTSTR lpszPath, LPCTSTR lpszParams = nullptr, int iShow = SW_SHOWNORMAL, HANDLE* phProcess = nullptr, BOOL bWait = FALSE, DWORD dwWaitTime = INFINITE); + +// ҽ +BOOL FindProcess(LPCTSTR pszProcessName); + +// ҽ̾ +HANDLE FindProcessHandle(LPCTSTR pszProcessName, DWORD dwDesiredAccess = PROCESS_QUERY_INFORMATION, BOOL bInheritHandle = FALSE); + +typedef map ProcessInfos; +typedef MapWrapper> ProcessInfoMap; + +// ҵǰеϢ +BOOL FindRunningProcessesInfo(ProcessInfoMap& infoMap); + +// ҽ̵ +HWND FindProcessMainWindow(DWORD dwProcID, LPCTSTR lpszClassName = nullptr); +// ҽ̵ +HWND FindProcessMainWindow(HANDLE hProcess, LPCTSTR lpszClassName = nullptr); + +BOOL TerminateProcessFairily(HANDLE hProcess, DWORD dwWait = INFINITE); + +// 򵥼¼־ +void WriteLog(LPCTSTR pszLogFileName, LPCTSTR pszLog); + +#ifndef _WIN32_WCE + // õǰ· + BOOL SetCurrentPathToModulePath(HMODULE hModule = nullptr); + // ҽ + BOOL FindProcessEx(LPCTSTR pszProcessName); + // ȡ INI + CString GetIniString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpFileName, DWORD dwSize); +#endif + +#ifdef _AFX + // תʱַ + CString SecondToTimeStr(DWORD dwSeconds, BOOL bDayOnly = FALSE); +#endif + +// ע +BOOL GetRegistryValue(HKEY hRoot, LPCTSTR wcSubKey, LPCTSTR wcName, LPBYTE pValue, DWORD* pdwSize, DWORD* pdwType); +// ȡע +BOOL SetRegistryValue(HKEY hRoot, LPCTSTR wcSubKey, LPCTSTR wcName, LPBYTE pValue, DWORD dwSize, DWORD dwType); \ No newline at end of file diff --git a/Common/Src/GeneralHelper.cpp b/Common/Src/GeneralHelper.cpp new file mode 100644 index 000000000..6c19d50ff --- /dev/null +++ b/Common/Src/GeneralHelper.cpp @@ -0,0 +1,26 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "GeneralHelper.h" diff --git a/Common/Src/GeneralHelper.h b/Common/Src/GeneralHelper.h new file mode 100644 index 000000000..a5fce2ede --- /dev/null +++ b/Common/Src/GeneralHelper.h @@ -0,0 +1,234 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + +Optional Macros: + +Windows: +++++++++++++++++++++++ +_WIN32_WINNT : Windows NT 汾 Ĭϣ_WIN32_WINNT_WINXP / _WIN32_WINNT_WIN7 +WINVER : Windows 汾 Ĭϣ_WIN32_WINNT +_USE_MFC : ʹ MFC +_WINSOCK_SUPPORT : ֧ Windows Socket +_NO_RIBBONS_SUPPORT : ֧ Ribbons +_DETECT_MEMORY_LEAK : DEBUG ״̬֧ڴй¶ + +Windows CE: +++++++++++++++++++++++ +WINVER : Windows 汾 +_USE_MFC : ʹ MFC +_WINSOCK_SUPPORT : ֧ Windows Socket +_DETECT_MEMORY_LEAK : DEBUG ״̬֧ڴй¶ +_ONLY_DETECT_CONFIRMED_MEMORY_LEAK_ : ֻܹȷϵڴй¶ȷIJ棩 +--------------------------- +VC 2015 + _MSC_VER == 1900 +VC 2013 + _MSC_VER == 1800 +VC 2012 + _MSC_VER == 1700 +VC 2010 + _MSC_VER == 1600 +VC 2008 + _MSC_VER == 1500 +VC 2005 + _MSC_VER == 1400 +VC 7.1 + _MSC_VER == 1310 +VC 7.0 + _MSC_VER == 1300 +VC 6.0 + _MSC_VER == 1200 +--------------------------- +Windows Versions: +_WIN32_WINNT_NT4 x0400 +_WIN32_WINNT_WIN2K 0x0500 +_WIN32_WINNT_WINXP 0x0501 +_WIN32_WINNT_WS03 0x0502 +_WIN32_WINNT_WIN6 0x0600 +_WIN32_WINNT_VISTA 0x0600 +_WIN32_WINNT_WS08 0x0600 +_WIN32_WINNT_LONGHORN 0x0600 +_WIN32_WINNT_WIN7 0x0601 +_WIN32_WINNT_WIN8 0x0602 +_WIN32_WINNT_WINBLUE 0x0603 +_WIN32_WINNT_WIN10 0x0A00 +--------------------------- +*/ + +#pragma once + +#ifndef VC_EXTRALEAN + #define VC_EXTRALEAN +#endif + +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif + +#ifndef _ATL_CSTRING_EXPLICIT_CONSTRUCTORS + #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS +#endif + +#if _MSC_VER >= 1400 + + #if defined _DEBUG && _MSC_VER < 1600 + #ifndef _SECURE_SCL + #define _SECURE_SCL 0 + #endif + #ifndef _HAS_ITERATOR_DEBUGGING + #define _HAS_ITERATOR_DEBUGGING 0 + #endif + #endif + + #ifndef _CRT_SECURE_NO_DEPRECATE + #define _CRT_SECURE_NO_DEPRECATE 1 + #endif + + #ifndef _SCL_SECURE_NO_DEPRECATE + #define _SCL_SECURE_NO_DEPRECATE 1 + #endif + + #ifndef _ATL_SECURE_NO_WARNINGS + #define _ATL_SECURE_NO_WARNINGS 1 + #endif + + #ifndef _CRT_NON_CONFORMING_SWPRINTFS + #define _CRT_NON_CONFORMING_SWPRINTFS 1 + #endif + + #ifndef _SECURE_ATL + #define _SECURE_ATL 1 + #endif + + #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS + #define _WINSOCK_DEPRECATED_NO_WARNINGS 1 + #endif + +#endif + +#ifndef _WIN32_WINNT + #if defined (_WIN64) + #define _WIN32_WINNT _WIN32_WINNT_WIN7 + #else + #define _WIN32_WINNT _WIN32_WINNT_WINXP + #endif +#endif + +#ifndef WINVER + #define WINVER _WIN32_WINNT +#endif + +#if _MSC_VER >= 1600 + #include +#else + #if !defined(nullptr) + #define nullptr NULL + #endif +#endif + +#ifdef _DETECT_MEMORY_LEAK + #ifndef _CRTDBG_MAP_ALLOC + #define _CRTDBG_MAP_ALLOC + #endif +#endif + +#ifdef _USE_MFC + + #ifndef _AFX_ALL_WARNINGS + #define _AFX_ALL_WARNINGS + #endif + + #include + #include + #include + + #ifndef _AFX_NO_OLE_SUPPORT + #include + #endif + + #ifndef _AFX_NO_AFXCMN_SUPPORT + #include + #endif + + #ifndef _NO_RIBBONS_SUPPORT + #include + #endif + +#else + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #ifndef ASSERT + #define ASSERT(f) ATLASSERT(f) + #endif + #ifndef VERIFY + #define VERIFY(f) ATLVERIFY(f) + #endif + + #ifndef TRACE + #include + + #define TRACE AtlTrace + #define TRACE0(f) TRACE(f) + #define TRACE1(f, p1) TRACE(f, p1) + #define TRACE2(f, p1, p2) TRACE(f, p1, p2) + #define TRACE3(f, p1, p2, p3) TRACE(f, p1, p2, p3) + #define TRACE4(f, p1, p2, p3, p4) TRACE(f, p1, p2, p3, p4) + #define TRACE5(f, p1, p2, p3, p4, p5) TRACE(f, p1, p2, p3, p4, p5) + #endif + +#endif + +#ifdef _WINSOCK_SUPPORT + #include + #include + #include +#endif + +#include +#include + +#include "Singleton.h" +#include "Event.h" +#include "Semaphore.h" +#include "CriticalSection.h" +#include "STLHelper.h" +#include "Win32Helper.h" +#include "PrivateHeap.h" +#include "bufferptr.h" + +#if defined (_DEBUG) && defined (_DETECT_MEMORY_LEAK) + #include "debug/win32_crtdbg.h" +#endif diff --git a/Common/Src/PrivateHeap.cpp b/Common/Src/PrivateHeap.cpp new file mode 100644 index 000000000..d3b5b3557 --- /dev/null +++ b/Common/Src/PrivateHeap.cpp @@ -0,0 +1,32 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: PrivateHeap.cpp +Notices: Copyright (c) 2006 Bruce Liang +Purpose: ˽ж. +******************************************************************************/ + +#include "StdAfx.h" +#include "PrivateHeap.h" diff --git a/Common/Src/PrivateHeap.h b/Common/Src/PrivateHeap.h new file mode 100644 index 000000000..f269bb70a --- /dev/null +++ b/Common/Src/PrivateHeap.h @@ -0,0 +1,238 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: PrivateHeap.h +Notices: Copyright (c) 2006 Bruce Liang +Purpose: ˽ж. +Desc: + 1. CPrivateHeap: Զٽ˽ж + ÿһĶ󶼴һ˽ж, + ص: һڶȽϳ + ͨΪȫֶ, ľ̬Ա + һЩijԱ + 2. CPrivateHeapBuffer: ˽жԶͷָСڴ + һںڷͷžֲĶڴ + Ӷ CPrivateHeap::Alloc() + CPrivateHeap::Free() ĵ + +Examples: + CPrivateHeap g_hpPrivate; + + int _tmain(int argc, _TCHAR* argv[]) + { + CPrivateHeapStrBuffer buff(g_hpPrivate, 32); + lstrcpy(buff, _T("ʧ˳ɹ֮ĸ")); + SIZE_T size = buff.Size(); + buff.ReAlloc(40); + size = buff.Size(); + std::cout << (TCHAR*)buff << '\n'; + // OR + // ASSERT(g_hpPrivate.IsValid()); + // TCHAR* pch = (TCHAR*)g_hpPrivate.Alloc(32 * sizeof(TCHAR)); + // lstrcpy(pch, _T("ʧ˳ɹ֮ĸ")); + // SIZE_T size = g_hpPrivate.Size(pch); + // g_hpPrivate.ReAlloc(pch, 40 * sizeof(TCHAR)); + // size = g_hpPrivate.Size(pch); + // std::cout << pch << '\n'; + // g_hpPrivate.Free(pch); + // + return 0; + } + +******************************************************************************/ + +#pragma once + +class CPrivateHeapImpl +{ +public: + PVOID Alloc(SIZE_T dwSize, DWORD dwFlags = 0) + {return ::HeapAlloc(m_hHeap, dwFlags, dwSize);} + + PVOID ReAlloc(PVOID pvMemory, SIZE_T dwSize, DWORD dwFlags = 0) + {return ::HeapReAlloc(m_hHeap, dwFlags, pvMemory, dwSize);} + + SIZE_T Size(PVOID pvMemory, DWORD dwFlags = 0) + {return ::HeapSize(m_hHeap, dwFlags, pvMemory);} + + BOOL Free(PVOID pvMemory, DWORD dwFlags = 0) + {return ::HeapFree(m_hHeap, dwFlags, pvMemory);} + + SIZE_T Compact(DWORD dwFlags = 0) + {return ::HeapCompact(m_hHeap, dwFlags);} + + BOOL IsValid() {return m_hHeap != nullptr;} + + BOOL Reset() + { + if(IsValid()) ::HeapDestroy(m_hHeap); + m_hHeap = ::HeapCreate(m_dwOptions, m_dwInitSize, m_dwMaxSize); + + return IsValid(); + } + +public: + CPrivateHeapImpl(DWORD dwOptions = 0, SIZE_T dwInitSize = 0, SIZE_T dwMaxSize = 0) + : m_dwOptions(dwOptions), m_dwInitSize(dwInitSize), m_dwMaxSize(dwMaxSize) + {m_hHeap = ::HeapCreate(m_dwOptions, m_dwInitSize, m_dwMaxSize);} + + ~CPrivateHeapImpl () {if(IsValid()) ::HeapDestroy(m_hHeap);} + + operator HANDLE () {return m_hHeap;} + +private: + CPrivateHeapImpl(const CPrivateHeapImpl&); + CPrivateHeapImpl operator = (const CPrivateHeapImpl&); + +private: + HANDLE m_hHeap; + DWORD m_dwOptions; + SIZE_T m_dwInitSize; + SIZE_T m_dwMaxSize; +}; + +class CGlobalHeapImpl +{ +public: + PVOID Alloc(SIZE_T dwSize, DWORD dwFlags = 0) + { + PVOID pv = malloc(dwSize); + + if(pv && (dwFlags | HEAP_ZERO_MEMORY)) + ZeroMemory(pv, dwSize); + + return pv; + } + + PVOID ReAlloc(PVOID pvMemory, SIZE_T dwSize, DWORD dwFlags = 0) + { + PVOID pv = realloc(pvMemory, dwSize); + + if(pv && (dwFlags | HEAP_ZERO_MEMORY)) + ZeroMemory(pv, dwSize); + else if(!pv) + free(pvMemory); + + return pv; + } + + BOOL Free(PVOID pvMemory, DWORD dwFlags = 0) + { + if(pvMemory) + { + free(pvMemory); + return TRUE; + } + + return FALSE; + } + + SIZE_T Compact (DWORD dwFlags = 0) {return -1;} + SIZE_T Size (PVOID pvMemory, DWORD dwFlags = 0) {return _msize(pvMemory);} + + BOOL IsValid() {return TRUE;} + BOOL Reset() {return TRUE;} + +public: + CGlobalHeapImpl (DWORD dwOptions = 0, SIZE_T dwInitSize = 0, SIZE_T dwMaxSize = 0) {} + ~CGlobalHeapImpl() {} + + operator HANDLE () {return nullptr;} + +private: + CGlobalHeapImpl(const CGlobalHeapImpl&); + CGlobalHeapImpl operator = (const CGlobalHeapImpl&); +}; + +#ifndef _NOT_USE_PRIVATE_HEAP + typedef CPrivateHeapImpl CPrivateHeap; +#else + typedef CGlobalHeapImpl CPrivateHeap; +#endif + +template +class CPrivateHeapBuffer +{ +public: + CPrivateHeapBuffer(CPrivateHeap& hpPrivate, + SIZE_T dwSize = 0, + DWORD dwAllocFlags = 0, + DWORD dwFreeFlags = 0) + : m_hpPrivate(hpPrivate) + , m_dwAllocFlags(dwAllocFlags) + , m_dwFreeFlags(dwFreeFlags) + , m_pvMemory(nullptr) + { + ASSERT(m_hpPrivate.IsValid()); + Alloc(dwSize); + } + + ~CPrivateHeapBuffer() {Free();} + +public: + + T* Alloc(SIZE_T dwSize) + { + if(IsValid()) + Free(); + + return m_pvMemory = (T*)m_hpPrivate.Alloc(dwSize * sizeof(T), m_dwAllocFlags); + } + + T* ReAlloc(SIZE_T dwSize, DWORD dwFlags = 0) + {return m_pvMemory = (T*)m_hpPrivate.ReAlloc(m_pvMemory, dwSize * sizeof(T), dwFlags);} + + SIZE_T Size(DWORD dwFlags = 0) + {return m_hpPrivate.Size(m_pvMemory, dwFlags);} + + BOOL Free() + { + BOOL isOK = TRUE; + + if(IsValid()) + { + isOK = m_hpPrivate.Free(m_pvMemory, m_dwFreeFlags); + m_pvMemory = nullptr; + } + + return isOK; + } + + BOOL IsValid() {return m_pvMemory != nullptr;} + operator T* () const {return m_pvMemory;} + +private: + CPrivateHeapBuffer(const CPrivateHeapBuffer&); + CPrivateHeapBuffer operator = (const CPrivateHeapBuffer&); + +private: + CPrivateHeap& m_hpPrivate; + T* m_pvMemory; + DWORD m_dwAllocFlags; + DWORD m_dwFreeFlags; +}; + +typedef CPrivateHeapBuffer CPrivateHeapByteBuffer; +typedef CPrivateHeapBuffer CPrivateHeapStrBuffer; diff --git a/Common/Src/RWLock.cpp b/Common/Src/RWLock.cpp new file mode 100644 index 000000000..4cd18e6df --- /dev/null +++ b/Common/Src/RWLock.cpp @@ -0,0 +1,402 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "StdAfx.h" +#include "RWLock.h" + +////////////////////////////////// CSWMR Functions //////////////////////////////////// + +CSWMR::CSWMR() +: m_smRead (MAXLONG) +, m_smWrite (1) +, m_nWaitingReaders (0) +, m_nWaitingWriters (0) +, m_nActive (0) +{ + +} + +CSWMR::~CSWMR() +{ + ASSERT(m_nWaitingReaders == 0); + ASSERT(m_nWaitingWriters == 0); + ASSERT(m_nActive == 0); +} + +VOID CSWMR::WaitToRead() +{ + BOOL fResourceWritePending; + + { + CSpinLock locallock(m_cs); + + fResourceWritePending = (m_nWaitingWriters || (m_nActive < 0)); + + if(fResourceWritePending) + ++m_nWaitingReaders; + else + ++m_nActive; + } + + if(fResourceWritePending) + m_smRead.Wait(); +} + +VOID CSWMR::WaitToWrite() +{ + BOOL fResourceOwned; + + { + CSpinLock locallock(m_cs); + + fResourceOwned = (m_nActive != 0); + + if(fResourceOwned) + ++m_nWaitingWriters; + else + m_nActive = -1; + } + + if(fResourceOwned) + m_smWrite.Wait(); +} + +VOID CSWMR::Done() +{ + CSEM* pSem = nullptr; + LONG lCount = 1; + + { + CSpinLock locallock(m_cs); + + if(m_nActive > 0) + --m_nActive; + else + ++m_nActive; + + if(m_nActive == 0) + { + if(m_nWaitingWriters > 0) + { + m_nActive = -1; + --m_nWaitingWriters; + pSem = &m_smWrite; + } + else if(m_nWaitingReaders > 0) + { + m_nActive = m_nWaitingReaders; + m_nWaitingReaders = 0; + pSem = &m_smRead; + lCount = m_nActive; + } + } + } + + if(pSem != nullptr) + pSem->Release(lCount); +} + +//////////////////////////////// CRWLock Functions ////////////////////////////////// + +#if _WIN32_WINNT >= _WIN32_WINNT_WS08 + +CSlimRWLock::CSlimRWLock() + : m_nActive (0) + , m_nReadCount (0) + , m_dwWriterTID (0) +{ + +} + +CSlimRWLock::~CSlimRWLock() +{ + ASSERT(m_nActive == 0); + ASSERT(m_nReadCount == 0); + ASSERT(m_dwWriterTID == 0); +} + +VOID CSlimRWLock::WaitToRead() +{ + BOOL bWait = FALSE; + + { + CSpinLock locallock(m_cs); + + if(m_nActive > 0) + ++m_nActive; + else if(m_nActive == 0) + { + if(m_smLock.TryWaitToRead()) + { + ++m_nReadCount; + ++m_nActive; + } + else + bWait = TRUE; + } + else if(!IsOwner()) + bWait = TRUE; + } + + if(bWait) + { + m_smLock.WaitToRead(); + + CSpinLock locallock(m_cs); + { + ++m_nReadCount; + ++m_nActive; + } + } +} + +VOID CSlimRWLock::WaitToWrite() +{ + BOOL bWait = FALSE; + + { + CSpinLock locallock(m_cs); + + if(m_nActive > 0) + bWait = TRUE; + else if(m_nActive == 0) + { + if(m_smLock.TryWaitToWrite()) + { + SetOwner(); + --m_nActive; + } + else + bWait = TRUE; + } + else + { + if(IsOwner()) + --m_nActive; + else + bWait = TRUE; + } + } + + if(bWait) + { + m_smLock.WaitToWrite(); + + SetOwner(); + --m_nActive; + } +} + +VOID CSlimRWLock::ReadDone() +{ + ASSERT(m_nActive != 0); + + if(m_nActive > 0) + { + ASSERT(m_nReadCount > 0); + + CSpinLock locallock(m_cs); + + if(--m_nActive == 0) + { + for(; m_nReadCount > 0; --m_nReadCount) + m_smLock.ReadDone(); + } + } + else + ASSERT(IsOwner()); +} + +VOID CSlimRWLock::WriteDone() +{ + ASSERT(m_nActive < 0); + + CSpinLock locallock(m_cs); + + if(++m_nActive == 0) + { + DetachOwner(); + m_smLock.WriteDone(); + } + else + ASSERT(IsOwner()); +} + +#endif + +CSEMRWLock::CSEMRWLock() +: m_smRead (MAXLONG) +, m_smWrite (1) +, m_nWaitingReaders (0) +, m_nWaitingWriters (0) +, m_nActive (0) +, m_dwWriterTID (0) +{ + +} + +CSEMRWLock::~CSEMRWLock() +{ + ASSERT(m_nActive == 0); + ASSERT(m_dwWriterTID == 0); +} + +VOID CSEMRWLock::WaitToRead() +{ + BOOL bWait = FALSE; + + { + CSpinLock locallock(m_cs); + + if(m_nActive > 0) + ++m_nActive; + else if(m_nActive == 0) + { + if(m_nWaitingWriters == 0) + ++m_nActive; + else + { + ++m_nWaitingReaders; + bWait = TRUE; + } + } + else + { + if(!IsOwner()) + { + ++m_nWaitingReaders; + bWait = TRUE; + } + } + } + + if(bWait) + { + m_smRead.Wait(); + } +} + +VOID CSEMRWLock::WaitToWrite() +{ + BOOL bWait = FALSE; + + { + CSpinLock locallock(m_cs); + + if(m_nActive > 0) + { + ++m_nWaitingWriters; + bWait = TRUE; + } + else if(m_nActive == 0) + { + --m_nActive; + SetOwner(); + } + else + { + if(IsOwner()) + --m_nActive; + else + { + ++m_nWaitingWriters; + bWait = TRUE; + } + } + } + + if(bWait) + { + m_smWrite.Wait(); + SetOwner(); + } +} + +VOID CSEMRWLock::ReadDone() +{ + CSEM* pSem = nullptr; + LONG lCount = 0; + + ASSERT(m_nActive != 0); + + if(m_nActive > 0) + { + CSpinLock locallock(m_cs); + + if(--m_nActive == 0) + Done(&pSem, lCount); + } + else + ASSERT(IsOwner()); + + if(pSem != nullptr) + pSem->Release(lCount); +} + +VOID CSEMRWLock::WriteDone() +{ + CSEM* pSem = nullptr; + LONG lCount = 0; + + { + ASSERT(m_nActive < 0); + + CSpinLock locallock(m_cs); + + if(++m_nActive == 0) + { + DetachOwner(); + Done(&pSem, lCount); + } + else + ASSERT(IsOwner()); + } + + if(pSem != nullptr) + pSem->Release(lCount); +} + +VOID CSEMRWLock::Done(CSEM** ppSem, LONG& lCount) +{ + ASSERT(m_nActive == 0); + ASSERT(m_dwWriterTID == 0); + + if(m_nWaitingWriters > 0) + { + --m_nActive; + --m_nWaitingWriters; + + lCount = 1; + *ppSem = &m_smWrite; + } + else if(m_nWaitingReaders > 0) + { + m_nActive = m_nWaitingReaders; + m_nWaitingReaders = 0; + lCount = m_nActive; + *ppSem = &m_smRead; + } +} + +/////////////////////////////////// End of File ///////////////////////////////////// diff --git a/Common/Src/RWLock.h b/Common/Src/RWLock.h new file mode 100644 index 000000000..8fc32a0c9 --- /dev/null +++ b/Common/Src/RWLock.h @@ -0,0 +1,418 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "CriticalSection.h" +#include "Semaphore.h" + +class CSWMR +{ +public: + VOID WaitToRead(); + VOID WaitToWrite(); + VOID ReadDone() {Done();} + VOID WriteDone() {Done();} + +private: + VOID Done(); + +public: + CSWMR(); + ~CSWMR(); + +private: + CSWMR(const CSWMR&); + CSWMR operator = (const CSWMR&); + +private: + int m_nWaitingReaders; + int m_nWaitingWriters; + int m_nActive; + + CSpinGuard m_cs; + CSEM m_smRead; + CSEM m_smWrite; +}; + +#if _WIN32_WINNT >= _WIN32_WINNT_WS08 + +class CSlimLock +{ +public: + VOID WaitToRead() {::AcquireSRWLockShared(&m_lock);} + VOID WaitToWrite() {::AcquireSRWLockExclusive(&m_lock);} + VOID ReadDone() {::ReleaseSRWLockShared(&m_lock);} + VOID WriteDone() {::ReleaseSRWLockExclusive(&m_lock);} + BOOL TryWaitToRead() {return ::TryAcquireSRWLockShared(&m_lock);} + BOOL TryWaitToWrite() {return ::TryAcquireSRWLockExclusive(&m_lock);} + + SRWLOCK* GetObject() {return &m_lock;} + +public: + CSlimLock() {::InitializeSRWLock(&m_lock);} + ~CSlimLock() {} + +private: + CSlimLock(const CSlimLock&); + CSlimLock operator = (const CSlimLock&); + +private: + SRWLOCK m_lock; +}; + +class CSlimRWLock +{ +public: + VOID WaitToRead(); + VOID WaitToWrite(); + VOID ReadDone(); + VOID WriteDone(); + +private: + BOOL IsOwner() {return m_dwWriterTID == ::GetCurrentThreadId();} + VOID SetOwner() {m_dwWriterTID = ::GetCurrentThreadId();} + VOID DetachOwner() {m_dwWriterTID = 0;} + +public: + CSlimRWLock(); + ~CSlimRWLock(); + +private: + CSlimRWLock(const CSlimRWLock&); + CSlimRWLock operator = (const CSlimRWLock&); + +private: + int m_nActive; + int m_nReadCount; + DWORD m_dwWriterTID; + + CSpinGuard m_cs; + CSlimLock m_smLock; +}; + +#endif + +class CSEMRWLock +{ +public: + VOID WaitToRead(); + VOID WaitToWrite(); + VOID ReadDone(); + VOID WriteDone(); + +private: + VOID Done (CSEM** ppSem, LONG& lCount); + BOOL IsOwner() {return m_dwWriterTID == ::GetCurrentThreadId();} + VOID SetOwner() {m_dwWriterTID = ::GetCurrentThreadId();} + VOID DetachOwner() {m_dwWriterTID = 0;} + +public: + CSEMRWLock(); + ~CSEMRWLock(); + +private: + CSEMRWLock(const CSEMRWLock&); + CSEMRWLock operator = (const CSEMRWLock&); + +private: + int m_nWaitingReaders; + int m_nWaitingWriters; + int m_nActive; + DWORD m_dwWriterTID; + + CSpinGuard m_cs; + CSEM m_smRead; + CSEM m_smWrite; +}; + +template class CLocalReadLock +{ +public: + CLocalReadLock(CLockObj& obj) : m_wait(obj) {m_wait.WaitToRead();} + ~CLocalReadLock() {m_wait.ReadDone();} +private: + CLocalReadLock(const CLocalReadLock&); + CLocalReadLock operator = (const CLocalReadLock&); +private: + CLockObj& m_wait; +}; + +template class CLocalWriteLock +{ +public: + CLocalWriteLock(CLockObj& obj) : m_wait(obj) {m_wait.WaitToWrite();} + ~CLocalWriteLock() {m_wait.WriteDone();} +private: + CLocalWriteLock(const CLocalWriteLock&); + CLocalWriteLock operator = (const CLocalWriteLock&); +private: + CLockObj& m_wait; +}; + +#if _WIN32_WINNT >= _WIN32_WINNT_WS08 + typedef CSlimLock CSimpleRWLock; +#else + typedef CSWMR CSimpleRWLock; +#endif + +typedef CLocalReadLock CReadLock; +typedef CLocalWriteLock CWriteLock; + +typedef CSEMRWLock CRWLock; +typedef CLocalReadLock CReentrantReadLock; +typedef CLocalWriteLock CReentrantWriteLock; + +#if _WIN32_WINNT >= _WIN32_WINNT_WS08 + +class ICVCondition +{ +public: + virtual BOOL Detect() = 0; + +public: + virtual ~ICVCondition() {} +}; + +class CCVCriSec +{ +public: + CCVCriSec(CInterCriSec& cs) + : m_cs(cs) + { + ::InitializeConditionVariable(&m_cv); + } + + ~CCVCriSec() {} + + void WaitToRead(ICVCondition* pCondition) + { + Wait(pCondition); + } + + void WaitToWrite(ICVCondition* pCondition) + { + Wait(pCondition); + } + + void ReadDone() + { + Done(); + } + + void WriteDone() + { + Done(); + } + + void WakeUp() + { + ::WakeConditionVariable(&m_cv); + } + + void WakeUpAll() + { + ::WakeAllConditionVariable(&m_cv); + } + +private: + void Wait(ICVCondition* pCondition) + { + ASSERT(pCondition); + + m_cs.Lock(); + + while(!pCondition->Detect()) + ::SleepConditionVariableCS(&m_cv, m_cs.GetObject(), INFINITE); + } + + void Done() + { + m_cs.Unlock(); + } + +private: + CCVCriSec(const CCVCriSec& cs); + CCVCriSec operator = (const CCVCriSec& cs); + +private: + CInterCriSec& m_cs; + CONDITION_VARIABLE m_cv; +}; + +class CCVSlim +{ +public: + CCVSlim(CSlimLock& cs) + : m_cs(cs) + { + ::InitializeConditionVariable(&m_cv); + } + + ~CCVSlim() {} + + void WaitToRead(ICVCondition* pCondition) + { + ASSERT(pCondition); + + m_cs.WaitToRead(); + + while(!pCondition->Detect()) + ::SleepConditionVariableSRW(&m_cv, m_cs.GetObject(), INFINITE, CONDITION_VARIABLE_LOCKMODE_SHARED); + } + + void WaitToWrite(ICVCondition* pCondition) + { + ASSERT(pCondition); + + m_cs.WaitToWrite(); + + while(!pCondition->Detect()) + ::SleepConditionVariableSRW(&m_cv, m_cs.GetObject(), INFINITE, 0); + } + + void ReadDone() + { + m_cs.ReadDone(); + } + + void WriteDone() + { + m_cs.WriteDone(); + } + + void WakeUp() + { + ::WakeConditionVariable(&m_cv); + } + + void WakeUpAll() + { + ::WakeAllConditionVariable(&m_cv); + } + +private: + CCVSlim(const CCVSlim& cs); + CCVSlim operator = (const CCVSlim& cs); + +private: + CSlimLock& m_cs; + CONDITION_VARIABLE m_cv; +}; + +template class CCVGuard +{ +public: + void WaitForProduce() + { + m_cvP.WaitToWrite(m_pcdtProduce); + } + + void WaitForConsume() + { + m_cvC.WaitToRead(m_pcdtConsume); + } + + void ProduceDone() + { + m_cvP.WriteDone(); + } + + void WakeUpProduce() + { + m_cvP.WakeUp(); + } + + void ConsumeDone() + { + m_cvC.ReadDone(); + } + + void WakeUpConsume() + { + m_cvC.WakeUp(); + } + + void WakeUpAllConsumes() + { + m_cvC.WakeUpAll(); + } + +public: + CCVGuard(ICVCondition* pcdtProduce, ICVCondition* pcdtConsume) + : m_cvP(m_cs) + , m_cvC(m_cs) + , m_pcdtProduce(pcdtProduce) + , m_pcdtConsume(pcdtConsume) + { + ASSERT(m_pcdtConsume && m_pcdtProduce); + } + + ~CCVGuard() {} + +private: + CCVGuard(const CCVGuard& cs); + CCVGuard operator = (const CCVGuard& cs); + +private: + ICVCondition* m_pcdtProduce; + ICVCondition* m_pcdtConsume; + + _Lock m_cs; + _Var m_cvP; + _Var m_cvC; +}; + +template class CConsumeLock +{ +public: + CConsumeLock(_GuardObj& obj) : m_guard(obj) {m_guard.WaitForConsume();} + ~CConsumeLock() {m_guard.ConsumeDone();} +private: + CConsumeLock(const CConsumeLock&); + CConsumeLock operator = (const CConsumeLock&); +private: + _GuardObj& m_guard; +}; + +template class CProduceLock +{ +public: + CProduceLock(_GuardObj& obj) : m_guard(obj) {m_guard.WaitForProduce();} + ~CProduceLock() {m_guard.ProduceDone();} +private: + CProduceLock(const CProduceLock&); + CProduceLock operator = (const CProduceLock&); +private: + _GuardObj& m_guard; +}; + +typedef CCVGuard CCVGuardCS; +typedef CCVGuard CCVGuardSRW; +typedef CProduceLock CProduceLockCS; +typedef CConsumeLock CConsumeLockCS; +typedef CProduceLock CProduceLockSRW; +typedef CConsumeLock CConsumeLockSRW; + +#endif diff --git a/Common/Src/RingBuffer.cpp b/Common/Src/RingBuffer.cpp new file mode 100644 index 000000000..b76ea5a18 --- /dev/null +++ b/Common/Src/RingBuffer.cpp @@ -0,0 +1,26 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "RingBuffer.h" diff --git a/Common/Src/RingBuffer.h b/Common/Src/RingBuffer.h new file mode 100644 index 000000000..1aca37ed5 --- /dev/null +++ b/Common/Src/RingBuffer.h @@ -0,0 +1,774 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "CriticalSection.h" + +#define CACHE_LINE 64 +#define PACK_SIZE_OF(T) (CACHE_LINE - sizeof(T) % CACHE_LINE) + +#if !defined (_WIN64) + #pragma pack(push, 4) +#endif + +template class CRingBuffer +{ +public: + static const UINT DEFAULT_EXPECT = 4096; + +public: + BOOL Put(T* pElement) + { + ASSERT(pElement != nullptr); + + { + CLocalLock<_PutGuard> locallock(m_csPut); + + ULONGLONG seqPut = m_seqPut; + + WaitForPut(seqPut); + if(!IsValid()) return FALSE; + + DoPut(pElement, seqPut); + } + + return TRUE; + } + + BOOL TryPut(T* pElement) + { + ASSERT(pElement != nullptr); + + if(!IsValid() || !HasPutSpace(m_seqPut)) + return FALSE; + + { + CLocalLock<_PutGuard> locallock(m_csPut); + + ULONGLONG seqPut = m_seqPut; + + if(!IsValid() || !HasPutSpace(seqPut)) + return FALSE; + + DoPut(pElement, seqPut); + } + + return TRUE; + } + + BOOL PutBatch(T* pElements[], int& iCount) + { + ASSERT(pElements != nullptr && iCount > 0); + + { + CLocalLock<_PutGuard> locallock(m_csPut); + + ULONGLONG seqPut = m_seqPut; + + for(int i = 0; i < iCount; ++i) + { + WaitForPut(seqPut); + + if(!IsValid()) + { + iCount = i; + return FALSE; + } + + DoPut(*(pElements + i), seqPut); + } + } + + return TRUE; + } + + BOOL TryPutBatch(T* pElements[], int& iCount) + { + ASSERT(pElements != nullptr && iCount > 0); + + if(!IsValid() || !HasPutSpace(m_seqPut)) + { + iCount = 0; + return FALSE; + } + + { + CLocalLock<_PutGuard> locallock(m_csPut); + + ULONGLONG seqPut = m_seqPut; + + for(int i = 0; i < iCount; ++i) + { + if(!IsValid() || !HasPutSpace(seqPut)) + { + iCount = i; + return FALSE; + } + + DoPut(*(pElements + i), seqPut); + } + } + + return TRUE; + } + + BOOL Get(T** pElement) + { + ASSERT(pElement != nullptr); + + { + CLocalLock<_GetGuard> locallock(m_csGet); + + ULONGLONG seqGet = m_seqGet; + + WaitForGet(seqGet); + if(!IsValid()) return FALSE; + + DoGet(pElement, seqGet); + } + + return TRUE; + } + + BOOL TryGet(T** pElement) + { + ASSERT(pElement != nullptr); + + if(!IsValid() || !HasGetSpace(m_seqGet)) + return FALSE; + + { + CLocalLock<_GetGuard> locallock(m_csGet); + + ULONGLONG seqGet = m_seqGet; + + if(!IsValid() || !HasGetSpace(seqGet)) + return FALSE; + + DoGet(pElement, seqGet); + } + + return TRUE; + } + + BOOL GetBatch(T* pElements[], int& iCount) + { + ASSERT(pElements != nullptr && iCount > 0); + + { + CLocalLock<_GetGuard> locallock(m_csGet); + + ULONGLONG seqGet = m_seqGet; + + for(int i = 0; i < iCount; ++i) + { + WaitForGet(seqGet); + + if(!IsValid()) + { + iCount = i; + return FALSE; + } + + DoGet(pElements + i, seqGet); + } + } + + return TRUE; + } + + BOOL TryGetBatch(T* pElements[], int& iCount) + { + ASSERT(pElements != nullptr && iCount > 0); + + if(!IsValid() || !HasGetSpace(m_seqGet)) + { + iCount = 0; + return FALSE; + } + + { + CLocalLock<_GetGuard> locallock(m_csGet); + + ULONGLONG seqGet = m_seqGet; + + for(int i = 0; i < iCount; ++i) + { + if(!IsValid() || !HasGetSpace(seqGet)) + { + iCount = i; + return FALSE; + } + + DoGet(pElements + i, seqGet); + } + } + + return TRUE; + } + + BOOL Peek(T** pElement) + { + ASSERT(pElement != nullptr); + + { + //CLocalLock<_GetGuard> locallock(m_csGet); + + ULONGLONG seqGet = m_seqGet; + + if(!IsValid() || !HasGetSpace(seqGet)) + return FALSE; + + DoPeek(pElement, seqGet); + } + + return TRUE; + } + + BOOL Create(DWORD dwExpect = DEFAULT_EXPECT) + { + ASSERT(!IsValid() && dwExpect > 0); + + if(IsValid()) return FALSE; + + m_seqPut = 0; + m_seqGet = 0; + m_dwReal = Revise(dwExpect); + m_pv = (T**)malloc(m_dwReal * sizeof(T*)); + m_bValid = (m_pv != nullptr); + + return IsValid(); + } + + BOOL Destroy() + { + if(IsValid()) + { + m_bValid = FALSE; + + CLocalLock<_PutGuard> locallock1(m_csPut); + CLocalLock<_GetGuard> locallock2(m_csGet); + + free((void*)m_pv); + m_pv = nullptr; + m_dwReal = 0; + m_seqPut = 0; + m_seqGet = 0; + + return TRUE; + } + + return FALSE; + } + +private: + void DoPut(T* pElement, ULONGLONG& seqPut) + { + DWORD index = seqPut & (m_dwReal - 1); + *(m_pv + index) = pElement; + + ++seqPut; + m_seqPut = seqPut; + } + + void DoGet(T** pElement, ULONGLONG& seqGet) + { + DWORD index = seqGet & (m_dwReal - 1); + *(pElement) = *(m_pv + index); + + ++seqGet; + m_seqGet = seqGet; + } + + void DoPeek(T** pElement, ULONGLONG& seqGet) + { + DWORD index = seqGet & (m_dwReal - 1); + *(pElement) = *(m_pv + index); + } + + BOOL HasPutSpace(ULONGLONG seqPut) + { + return (seqPut - m_seqGet < m_dwReal); + } + + void WaitForPut(ULONGLONG seqPut) + { + for(DWORD w = 0; IsValid(); ++w) + { + if(HasPutSpace(seqPut)) + break; + + CSpinGuard::Pause(w); + } + } + + BOOL HasGetSpace(ULONGLONG seqGet) + { + return (m_seqPut - seqGet > 0); + } + + void WaitForGet(ULONGLONG seqGet) + { + for(DWORD w = 0; IsValid(); ++w) + { + if(HasGetSpace(seqGet)) + break; + + CSpinGuard::Pause(w); + } + } + + DWORD Revise(DWORD dwExpect) + { + int index = 0; + int shift = sizeof(DWORD) * 8 - 1; + + for(int i = shift; i >= 0; i--) + { + if(index == 0) + { + if(dwExpect & (1 << i)) + { + index = i; + + if(index == shift) + break; + } + } + else + { + if(dwExpect & (1 << i)) + ++index; + + break; + } + } + + return 1 << index; + } + +public: + CRingBuffer(BOOL bCreate = FALSE, DWORD uiExpect = DEFAULT_EXPECT) + : m_pv(nullptr) + , m_bValid(FALSE) + , m_dwReal(0) + , m_seqPut(0) + , m_seqGet(0) + { + ASSERT(uiExpect > 0); + + if(bCreate) + { + Create(uiExpect); + ASSERT(IsValid()); + } + } + + ~CRingBuffer() + { + Destroy(); + } + + BOOL IsValid() {return m_bValid;} + +private: + CRingBuffer(const CRingBuffer&); + CRingBuffer operator = (const CRingBuffer&); + +private: + BOOL m_bValid; + DWORD m_dwReal; + T** m_pv; + char pack1[PACK_SIZE_OF(T**)]; + volatile ULONGLONG m_seqPut; + char pack4[PACK_SIZE_OF(ULONGLONG)]; + volatile ULONGLONG m_seqGet; + char pack5[PACK_SIZE_OF(ULONGLONG)]; + _PutGuard m_csPut; + char pack2[PACK_SIZE_OF(_PutGuard)]; + _GetGuard m_csGet; + char pack3[PACK_SIZE_OF(_GetGuard)]; +}; + +typedef CRingBuffer CCSRingBuffer; +typedef CRingBuffer CICSRingBuffer; +typedef CRingBuffer CSGRingBuffer; +typedef CRingBuffer CFKRingBuffer; + +template class CRingPool +{ +private: + typedef T* TPTR; + typedef volatile T* VTPTR; + + static TPTR const E_EMPTY; + static TPTR const E_LOCKED; + static TPTR const E_RELEASED; + static TPTR const E_OCCUPIED; + static TPTR const E_MAX_STATUS; +public: + + BOOL TryPut(TPTR pElement) + { + ASSERT(pElement != nullptr); + + BOOL isOK = FALSE; + + while(true) + { + BOOL bOccupy = FALSE; + DWORD seqPut = m_seqPut; + + if(!HasPutSpace(seqPut)) + break; + + DWORD dwIndex = seqPut % m_dwSize; + VTPTR& pValue = *(m_pv + dwIndex); + + if(pValue == E_RELEASED) + { + if(::InterlockedCompareExchangePointer((volatile PVOID*)&pValue, E_OCCUPIED, E_RELEASED) == E_RELEASED) + bOccupy = TRUE; + else + continue; + } + + if(pValue == E_EMPTY || bOccupy) + { + if(::InterlockedCompareExchange(&m_seqPut, seqPut + 1, seqPut) == seqPut) + { + pValue = pElement; + isOK = TRUE; + + break; + } + } + else if(pValue == E_LOCKED) + break; + } + + return isOK; + } + + BOOL TryGet(TPTR* ppElement) + { + ASSERT(ppElement != nullptr); + + BOOL isOK = FALSE; + + while(true) + { + DWORD seqGet = m_seqGet; + + if(!HasGetSpace(seqGet)) + break; + + DWORD dwIndex = seqGet % m_dwSize; + VTPTR& pValue = *(m_pv + dwIndex); + + if(pValue == E_LOCKED) + break; + else if(pValue != E_EMPTY && pValue != E_RELEASED && pValue != E_OCCUPIED) + { + if(::InterlockedCompareExchange(&m_seqGet, seqGet + 1, seqGet) == seqGet) + { + ASSERT(pValue > E_MAX_STATUS); + + *(ppElement) = (TPTR)pValue; + pValue = E_EMPTY; + isOK = TRUE; + + break; + } + } + } + + return isOK; + } + + BOOL TryLock(TPTR* ppElement, DWORD& dwIndex) + { + ASSERT(ppElement != nullptr); + + BOOL isOK = FALSE; + + while(true) + { + DWORD seqGet = m_seqGet; + + if(!HasGetSpace(seqGet)) + break; + + dwIndex = seqGet % m_dwSize; + VTPTR& pValue = *(m_pv + dwIndex); + + if(pValue == E_LOCKED) + break; + else if(pValue != E_EMPTY && pValue != E_RELEASED && pValue != E_OCCUPIED) + { + if(::InterlockedCompareExchange(&m_seqGet, seqGet + 1, seqGet) == seqGet) + { + ASSERT(pValue > E_MAX_STATUS); + + *(ppElement) = (TPTR)pValue; + pValue = E_LOCKED; + isOK = TRUE; + + break; + } + } + } + + return isOK; + } + + void ReleaseLock(TPTR pElement, DWORD dwIndex) + { + ASSERT(dwIndex < m_dwSize); + ASSERT(pElement == nullptr || (UINT_PTR)pElement > (UINT_PTR)E_MAX_STATUS); + + VTPTR& pValue = *(m_pv + dwIndex); + VERIFY(pValue == E_LOCKED); + + if(pElement != nullptr) + { + for(DWORD i = 0; ; i++) + { + if(TryPut(pElement)) + break; + + DWORD dwPutIndex = m_seqPut % m_dwSize; + + if(dwIndex == dwPutIndex) + { + pValue = pElement; + ::InterlockedIncrement(&m_seqPut); + + return; + } + + CSpinGuard::Pause(i); + } + } + + pValue = E_RELEASED; + } + +public: + + void Reset(DWORD dwSize = 0) + { + if(IsValid()) + Destroy(); + if(dwSize > 0) + Create(dwSize); + } + + DWORD Size() {return m_dwSize;} + DWORD Elements() {return m_seqPut - m_seqGet;} + BOOL IsFull() {return Elements() == Size();} + BOOL IsEmpty() {return Elements() == 0;} + BOOL IsValid() {return m_pv != nullptr;} + +private: + + BOOL HasPutSpace(DWORD seqPut) + { + return (seqPut - m_seqGet < m_dwSize); + } + + BOOL HasGetSpace(DWORD seqGet) + { + return (m_seqPut - seqGet > 0); + } + + void Create(DWORD dwSize) + { + ASSERT(!IsValid() && dwSize > 0); + + m_seqPut = 0; + m_seqGet = 0; + m_dwSize = dwSize; + m_pv = (VTPTR*)malloc(m_dwSize * sizeof(TPTR)); + + ::memset(m_pv, (int)E_EMPTY, m_dwSize * sizeof(TPTR)); + } + + void Destroy() + { + ASSERT(IsValid()); + + free((void*)m_pv); + m_pv = nullptr; + m_dwSize = 0; + m_seqPut = 0; + m_seqGet = 0; + } + + +public: + CRingPool(DWORD dwSize = 0) + : m_pv(nullptr) + , m_dwSize(0) + , m_seqPut(0) + , m_seqGet(0) + { + Reset(dwSize); + } + + ~CRingPool() + { + Reset(0); + } + +private: + CRingPool(const CRingPool&); + CRingPool operator = (const CRingPool&); + +private: + DWORD m_dwSize; + VTPTR* m_pv; + char pack1[PACK_SIZE_OF(VTPTR*)]; + volatile DWORD m_seqPut; + char pack4[PACK_SIZE_OF(DWORD)]; + volatile DWORD m_seqGet; + char pack5[PACK_SIZE_OF(DWORD)]; +}; + +template T* const CRingPool::E_EMPTY = (T*)0x00; +template T* const CRingPool::E_LOCKED = (T*)0x01; +template T* const CRingPool::E_RELEASED = (T*)0x02; +template T* const CRingPool::E_OCCUPIED = (T*)0x03; +template T* const CRingPool::E_MAX_STATUS = (T*)0x0F; + +template class CCASQueue +{ +private: + struct Node; + typedef Node* NPTR; + typedef volatile Node* VNPTR; + typedef volatile ULONG VLONG; + + struct Node + { + T* pValue; + VNPTR pNext; + + Node(T* val, NPTR next = nullptr) + : pValue(val), pNext(next) + { + + } + }; + +public: + + void PushBack(T* pVal) + { + ASSERT(pVal != nullptr); + + VNPTR pTail = nullptr; + NPTR pNode = new Node(pVal); + + while(true) + { + pTail = m_pTail; + + if(::InterlockedCompareExchangePointer((volatile PVOID*)&m_pTail->pNext, pNode, nullptr) == nullptr) + break; + } + + ::InterlockedCompareExchangePointer((volatile PVOID*)&m_pTail, pNode, (PVOID)pTail); + ::InterlockedIncrement(&m_lSize); + } + + BOOL PopFront(T** ppVal) + { + ASSERT(ppVal != nullptr); + + BOOL isOK = FALSE; + VNPTR pNext = nullptr; + + while(true) + { + pNext = m_pHead->pNext; + + if(pNext == nullptr) + break; + + if(::InterlockedCompareExchangePointer((volatile PVOID*)&m_pHead->pNext, (PVOID)pNext->pNext, (PVOID)pNext) == pNext) + { + *ppVal = pNext->pValue; + isOK = TRUE; + + if(m_pTail == pNext) + ::InterlockedCompareExchangePointer((volatile PVOID*)&m_pTail, (PVOID)m_pHead, (PVOID)pNext); + + ::InterlockedDecrement(&m_lSize); + + delete pNext; + break; + } + } + + return isOK; + } + +public: + + ULONG Size() {return m_lSize;} + BOOL IsEmpty() {return m_lSize == 0;} + +public: + + CCASQueue() : m_lSize(0) + { + NPTR pHead = new Node(nullptr); + m_pHead = m_pTail = pHead; + } + + ~CCASQueue() + { + ASSERT(m_pHead != nullptr); + ASSERT(m_pHead->pNext == nullptr); + + while(m_pHead != nullptr) + { + VNPTR pNode = m_pHead->pNext; + + delete m_pHead; + m_pHead = pNode; + } + } + +private: + VLONG m_lSize; + VNPTR m_pHead; + VNPTR m_pTail; +}; + +#if !defined (_WIN64) + #pragma pack(pop) +#endif diff --git a/Common/Src/SE.h b/Common/Src/SE.h new file mode 100644 index 000000000..475ec9959 --- /dev/null +++ b/Common/Src/SE.h @@ -0,0 +1,99 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** + +Module: SE.h +Notices: Copyright (c) 2006 Bruce Liang +Purpose: ѽṹ쳣ת C++ 쳣. +Desc: + 1. C++ ʽṹ쳣 + +Usage: + 1. Ŀ -> -> C/C++ -> -> C++ 쳣ѡ"" + 2. Ŀ -> -> C/C++ -> -> "/EHac" + 3. ÿ̵߳ڴ: MapSEx2CppEx() + 4. Ҫṹ쳣ĵطʹ try{...} catch(CSE se){...} + +Rule: + +Example: 1. : TestSE Գ + 2. ĴƬ + void ThreadFunc(PVOID pv) + { + // Must be called before any exceptions are raised + MapSEx2CppEx(); + + try + { + *(PBYTE)0 = 0; // Accesss violation + + int x = 0; + x = 5 / x; // Division by zero + } + catch(CSE& se) + { + switch(se) + { + case EXCEPTION_ACCESS_VIOLATION: + // This code handles an access-violation exception + break; + case EXCEPTION_INT_DIVIDE_BY_ZERO: + // This code handles a division-by-zero exception + break; + default: + // We don't handle any other exceptions; + throw; + } + } + } + +******************************************************************************/ + +#pragma once + +#include + +#define MapSEx2CppEx() CSE::MapSE2CE() + +class CSE +{ +public: + // ṹ쳣ת C++ 쳣. + static void MapSE2CE() {_set_se_translator(TranslateSE2CE);} + + operator DWORD() {return m_er.ExceptionCode;} + + CSE(PEXCEPTION_POINTERS pep) + : m_er(*pep->ExceptionRecord) + , m_context(*pep->ContextRecord) + { + } + + static void _cdecl TranslateSE2CE(UINT ec, PEXCEPTION_POINTERS pep) {throw CSE(pep);} + +private: + EXCEPTION_RECORD m_er; // CPU independent exception informaiton + CONTEXT m_context; // CPU dependent exception informaiton +}; \ No newline at end of file diff --git a/Common/Src/STLHelper.h b/Common/Src/STLHelper.h new file mode 100644 index 000000000..35b6e9434 --- /dev/null +++ b/Common/Src/STLHelper.h @@ -0,0 +1,1124 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "GeneralHelper.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if _MSC_VER >= 1500 + #include + #include + + #define hash_set unordered_set + #define hash_map unordered_map +#else + #include + #include + + #define unorderedhash_set hash_set + #define unordered_map hash_map +#endif + + +using namespace std; +using namespace stdext; +using namespace std::tr1; + +typedef wstring CStdStringW; +typedef string CStdStringA; + +#ifdef _UNICODE + typedef CStdStringW CStdString; +#else + typedef CStdStringA CStdString; +#endif + +typedef list short_list; +typedef list int_list; +typedef list long_list; +typedef list<__int64> int64_list; +typedef list ushort_list; +typedef list uint_list; +typedef list ulong_list; +typedef list uint64_list; +typedef list float_list; +typedef list double_list; +typedef stack short_stack; +typedef stack int_stack; +typedef stack long_stack; +typedef stack<__int64> int64_stack; +typedef stack ushort_stack; +typedef stack uint_stack; +typedef stack ulong_stack; +typedef stack uint64_stack; +typedef stack float_stack; +typedef stack double_stack; +typedef queue short_queue; +typedef queue int_queue; +typedef queue long_queue; +typedef queue<__int64> int64_queue; +typedef queue ushort_queue; +typedef queue uint_queue; +typedef queue ulong_queue; +typedef queue uint64_queue; +typedef queue float_queue; +typedef queue double_queue; +typedef deque short_deque; +typedef deque int_deque; +typedef deque long_deque; +typedef deque<__int64> int64_deque; +typedef deque ushort_deque; +typedef deque uint_deque; +typedef deque ulong_deque; +typedef deque uint64_deque; +typedef deque float_deque; +typedef deque double_deque; +typedef vector short_vector; +typedef vector int_vector; +typedef vector long_vector; +typedef vector<__int64> int64_vector; +typedef vector ushort_vector; +typedef vector uint_vector; +typedef vector ulong_vector; +typedef vector uint64_vector; +typedef vector float_vector; +typedef vector double_vector; +typedef set short_set; +typedef set int_set; +typedef set long_set; +typedef set<__int64> int64_set; +typedef set ushort_set; +typedef set uint_set; +typedef set ulong_set; +typedef set uint64_set; +typedef set float_set; +typedef set double_set; +typedef hash_set short_hash_set; +typedef hash_set int_hash_set; +typedef hash_set long_hash_set; +typedef hash_set<__int64> int64_hash_set; +typedef hash_set ushort_hash_set; +typedef hash_set uint_hash_set; +typedef hash_set ulong_hash_set; +typedef hash_set uint64_hash_set; +typedef hash_set float_hash_set; +typedef hash_set double_hash_set; +typedef unordered_set short_unordered_set; +typedef unordered_set int_unordered_set; +typedef unordered_set long_unordered_set; +typedef unordered_set<__int64> int64_unordered_set; +typedef unordered_set ushort_unordered_set; +typedef unordered_set uint_unordered_set; +typedef unordered_set ulong_unordered_set; +typedef unordered_set uint64_unordered_set; +typedef unordered_set float_unordered_set; +typedef unordered_set double_unordered_set; + +typedef list int_ptr_list; +typedef list long_ptr_list; +typedef list uint_ptr_list; +typedef list ulong_ptr_list; +typedef stack int_ptr_stack; +typedef stack long_ptr_stack; +typedef stack uint_ptr_stack; +typedef stack ulong_ptr_stack; +typedef queue int_ptr_queue; +typedef queue long_ptr_queue; +typedef queue uint_ptr_queue; +typedef queue ulong_ptr_queue; +typedef deque int_ptr_deque; +typedef deque long_ptr_deque; +typedef deque uint_ptr_deque; +typedef deque ulong_ptr_deque; +typedef vector int_ptr_vector; +typedef vector long_ptr_vector; +typedef vector uint_ptr_vector; +typedef vector ulong_ptr_vector; +typedef set int_ptr_set; +typedef set long_ptr_set; +typedef set uint_ptr_set; +typedef set ulong_ptr_set; +typedef hash_set int_ptr_hash_set; +typedef hash_set long_ptr_hash_set; +typedef hash_set uint_ptr_hash_set; +typedef hash_set ulong_ptr_hash_set; +typedef unordered_set int_ptr_unordered_set; +typedef unordered_set long_ptr_unordered_set; +typedef unordered_set uint_ptr_unordered_set; +typedef unordered_set ulong_ptr_unordered_set; + +/*****************************************************************************/ +/******************************** *******************************/ + +/********************************** +: ͨ , vector / list +: + v : vector / list / set + +ֵ: +**********************************/ +template void ClearSet(Set& v) +{ + v.clear(); +} + +template struct Set_Cleaner +{ + static void Clear(Set& v) {ClearSet(v);} +}; + +/********************************** +: ָ뼯 (ǰͷָ), vector / list +: + v : vector / list / set + +ֵ: +**********************************/ +template void ClearPtrSet(PtrSet& v) +{ + for(PtrSet::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + delete (*it); + + v.clear(); +} + +template struct PtrSet_Cleaner +{ + static void Clear(PtrSet& v) {ClearPtrSet(v);} +}; + +/********************************** +: ָ뼯 (ָͬʱָ), vector / list +: + v : vector / list / set + +ֵ: +**********************************/ +template void ClearPtrArraySet(PtrArraySet& v) +{ + for(PtrArraySet::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + delete[] (*it); + + v.clear(); +} + +template struct PtrArraySet_Cleaner +{ + static void Clear(PtrArraySet& v) {ClearPtrArraySet(v);} +}; + +/********************************** +: ͨӰ , map +: + v : map + +ֵ: +**********************************/ +template void ClearMap(Map& v) +{ + v.clear(); +} + +template struct Map_Cleaner +{ + static void Clear(Map& v) {ClearMap(v);} +}; + +/********************************** +: ָӰ (ǰͷָ), map +: + v : map + +ֵ: +**********************************/ +template void ClearPtrMap(PtrMap& v) +{ + for(PtrMap::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + delete it->second; + + v.clear(); +} + +template struct PtrMap_Cleaner +{ + static void Clear(PtrMap& v) {ClearPtrMap(v);} +}; + +/********************************** +: ָӰ (ָͬʱָ), map +: + v : map + +ֵ: +**********************************/ +template void ClearPtrArrayMap(PtrArrayMap& v) +{ + for(PtrArrayMap::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + delete[] it->second; + + v.clear(); +} + +template struct PtrArrayMap_Cleaner +{ + static void Clear(PtrArrayMap& v) {ClearPtrArrayMap(v);} +}; + +/********************************** +: - (ǰڲ), set*> +: + v : vector / list / set + +ֵ: +**********************************/ +template void ClearSetSet(SetSet& v) +{ + for(SetSet::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + (*it)->clear(); + delete (*it); + } + + v.clear(); +} + +template struct SetSet_Cleaner +{ + static void Clear(SetSet& v) {ClearSetSet(v);} +}; + +/********************************** +: ָ뼯- (ǰڲָ뼯), set*> +: + v : vector / list / set + +ֵ: +**********************************/ +template void ClearPtrSetSet(PtrSetSet& v) +{ + for(PtrSetSet::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + ClearPtrSet(**it); + delete (*it); + } + + v.clear(); +} + +template struct PtrSetSet_Cleaner +{ + static void Clear(PtrSetSet& v) {ClearPtrSetSet(v);} +}; + +/********************************** +: ָ鼯Ӱ (ǰָ鼯), map*> +: + v : vector / list / set + +ֵ: +**********************************/ +template void ClearPtrArraySetSet(PtrArraySetSet& v) +{ + for(PtrArraySetSet::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + ClearPtrArraySet(**it); + delete (*it); + } + + v.clear(); +} + +template struct PtrArraySetSet_Cleaner +{ + static void Clear(PtrArraySetSet& v) {ClearPtrArraySetSet(v);} +}; + +/********************************** +: Ӱ (ǰ), map*> +: + v : map + +ֵ: +**********************************/ +template void ClearSetMap(SetMap& v) +{ + for(SetMap::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + it->second->clear(); + delete it->second; + } + + v.clear(); +} + +template struct SetMap_Cleaner +{ + static void Clear(SetMap& v) {ClearSetMap(v);} +}; + +/********************************** +: ָ뼯Ӱ (ǰָ뼯), map*> +: + v : map + +ֵ: +**********************************/ +template void ClearPtrSetMap(PtrSetMap& v) +{ + for(PtrSetMap::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + ClearPtrSet(*(it->second)); + delete it->second; + } + + v.clear(); +} + +template struct PtrSetMap_Cleaner +{ + static void Clear(PtrSetMap& v) {ClearPtrSetMap(v);} +}; + +/********************************** +: ָ鼯Ӱ (ǰָ鼯), map*> +: + v : map + +ֵ: +**********************************/ +template void ClearPtrArraySetMap(PtrArraySetMap& v) +{ + for(PtrArraySetMap::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + ClearPtrArraySet(*(it->second)); + delete it->second; + } + + v.clear(); +} + +template struct PtrArraySetMap_Cleaner +{ + static void Clear(PtrArraySetMap& v) {ClearPtrArraySetMap(v);} +}; + +/********************************** +: ӳ-Ӱ (ǰڲӳ), map*> +: +v : map + +ֵ: +**********************************/ +template void ClearMapMap(MapMap& v) +{ + for(MapMap::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + it->second->clear(); + delete it->second; + } + + v.clear(); +} + +template struct MapMap_Cleaner +{ + static void Clear(MapMap& v) {ClearMapMap(v);} +}; + +/********************************** +: ָӳ-Ӱ (ǰָڲӳ), map*> +: + v : map + +ֵ: +**********************************/ +template void ClearPtrMapMap(PtrMapMap& v) +{ + for(PtrMapMap::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + ClearPtrMap(*(it->second)); + delete it->second; + } + + v.clear(); +} + +template struct PtrMapMap_Cleaner +{ + static void Clear(PtrMapMap& v) {ClearPtrMapMap(v);} +}; + +/********************************** +: ָӳ-Ӱ (ǰָڲӳ), map*> +: + v : map + +ֵ: +**********************************/ +template void ClearPtrArrayMapMap(PtrArrayMapMap& v) +{ + for(PtrArrayMapMap::iterator it = v.begin(), + end = v.end(); + it != end; + ++it) + { + ClearPtrArrayMap(*(it->second)); + delete it->second; + } + + v.clear(); +} + +template struct PtrArrayMapMap_Cleaner +{ + static void Clear(PtrArrayMapMap& v) {ClearPtrArrayMapMap(v);} +}; + +/************************************************************************/ +/* ָ뼯 */ +/************************************************************************/ +template struct SetWrapper +{ + typedef typename Set::iterator iterator; + typedef typename Set::const_iterator const_iterator; + typedef typename Set::value_type value_type; + typedef typename Set::reference reference; + typedef typename Set::const_reference const_reference; + typedef typename Set::pointer pointer; + typedef typename Set::const_pointer const_pointer; + typedef typename Set::size_type size_type; + typedef typename Set::difference_type difference_type; + + SetWrapper() + { + } + + virtual ~SetWrapper() + { + Clear(); + } + + void Clear() + { + if(!IsEmpty()) + { + Cleaner::Clear(m_set); + } + } + + Set& operator * () {return m_set;} + const Set& operator * () const {return m_set;} + Set* operator -> () {return &m_set;} + const Set* operator -> () const {return &m_set;} + Set& Get () {return m_set;} + operator Set& () {return m_set;} + bool IsEmpty () const {return m_set.empty();} + size_t Size () const {return m_set.size();} + +protected: + Set m_set; + + DECLARE_NO_COPY_CLASS(SetWrapper) +}; + +template struct VectorWrapper : public SetWrapper +{ + VectorWrapper() + { + } + + reference operator [] (size_type i) {return m_set[i];} + const_reference operator [] (size_type i) const {return m_set[i];} + + DECLARE_NO_COPY_CLASS(VectorWrapper) +}; + +/************************************************************************/ +/* ָ鼯 */ +/************************************************************************/ + + +/************************************************************************/ +/* ָӳ */ +/************************************************************************/ +template struct MapWrapper +{ + typedef typename Map::iterator iterator; + typedef typename Map::const_iterator const_iterator; + typedef typename Map::key_type key_type; + typedef typename Map::mapped_type mapped_type; + typedef typename Map::value_type value_type; + typedef typename Map::reference reference; + typedef typename Map::const_reference const_reference; + typedef typename Map::pointer pointer; + typedef typename Map::size_type size_type; + typedef typename Map::difference_type difference_type; + + MapWrapper() + { + } + + ~MapWrapper() + { + Clear(); + } + + void Clear() + { + if(!IsEmpty()) + { + Cleaner::Clear(m_map); + } + } + + Map& operator * () {return m_map;} + const Map& operator * () const {return m_map;} + Map* operator -> () {return &m_map;} + const Map* operator -> () const {return &m_map;} + mapped_type& operator [] (const key_type& key) {return m_map[key];} + const mapped_type& operator [] (const key_type& key) const {return m_map[key];} + Map& Get () {return m_map;} + operator Map& () {return m_map;} + bool IsEmpty () const {return m_map.empty();} + size_t Size () const {return m_map.size();} + +private: + Map m_map; + + DECLARE_NO_COPY_CLASS(MapWrapper) +}; + +/************************************************************************/ +/* ȽϷº */ +/************************************************************************/ +struct bool_comp_func +{ + bool operator() (bool v1, bool v2) const + { + if(!v1) + return false; + if(v1 == v2) + return false; + + return true; + } +}; + +template +// T -> (signed / unsigned) short / int / long / __int64 +struct integer_comp_func +{ + bool operator() (T v1, T v2) const + { + return v1 < v2; + } +}; + +typedef integer_comp_func short_comp_func; +typedef integer_comp_func int_comp_func; +typedef integer_comp_func long_comp_func; +typedef integer_comp_func<__int64> int64_comp_func; +typedef integer_comp_func ushort_comp_func; +typedef integer_comp_func uint_comp_func; +typedef integer_comp_func ulong_comp_func; +typedef integer_comp_func uint64_comp_func; + +struct float_comp_func +{ + bool operator() (float v1, float v2) const + { + float disc = v1 - v2; + if(fabsf(disc) < 1E-5) + return false; + + return disc < 0; + } +}; + +struct double_comp_func +{ + bool operator() (double v1, double v2) const + { + double disc = v1 - v2; + if(fabs(disc) < 1E-8) + return false; + + return disc < 0; + } +}; + +template +// T -> (unsigned) char / wchar_t +struct character_comp_func +{ + bool operator() (T v1, T v2) const + { + if(!CASE) + { + if(v1 >= 'A' && v1 <= 'Z') v1 += 32; + if(v2 >= 'A' && v2 <= 'Z') v2 += 32; + } + + return v1 < v2; + } +}; + +typedef character_comp_func char_case_comp_func; +typedef character_comp_func uchar_case_comp_func; +typedef character_comp_func wchar_case_comp_func; +typedef character_comp_func char_ucase_comp_func; +typedef character_comp_func uchar_ucase_comp_func; +typedef character_comp_func wchar_ucase_comp_func; + +template +// T -> TCHAR* / CString +struct str_comp_func +{ + //ȽϺ + bool operator() (const T &A, const T &B) const + { + if(!CASE) + return lstrcmpi((LPCTSTR)A, (LPCTSTR)B) < 0; + else + return lstrcmp((LPCTSTR)A, (LPCTSTR)B) < 0; + } +}; + +typedef str_comp_func case_tchar_comp_func; +typedef str_comp_func uncase_tchar_comp_func; +typedef str_comp_func case_string_comp_func; +typedef str_comp_func uncase_string_comp_func; +typedef case_tchar_comp_func tchar_ptr_case_comp_func; +typedef uncase_tchar_comp_func tchar_ptr_ucase_comp_func; +typedef case_string_comp_func string_case_comp_func; +typedef uncase_string_comp_func string_ucase_comp_func; +/************************************************************************/ +/* º */ +/************************************************************************/ +template +struct bool_sort_func +{ + bool operator() (bool v1, bool v2) const + { + if(v1 == v2) + return false; + + bool result = !v1; + return ASC ? result : !result; + } +}; + +typedef bool_sort_func bool_asc_sort_func; +typedef bool_sort_func bool_desc_sort_func; + +template +// T -> (signed / unsigned) short / int / long / __int64 +struct integer_sort_func +{ + bool operator() (T v1, T v2) const + { + if(v1 == v2) + return false; + + bool result = v1 < v2; + return ASC ? result : !result; + } +}; + +typedef integer_sort_func short_asc_sort_func; +typedef integer_sort_func ushort_asc_sort_func; +typedef integer_sort_func int_asc_sort_func; +typedef integer_sort_func uint_asc_sort_func; +typedef integer_sort_func long_asc_sort_func; +typedef integer_sort_func ulong_asc_sort_func; +typedef integer_sort_func<__int64, true> int64_asc_sort_func; +typedef integer_sort_func uint64_asc_sort_func; +typedef integer_sort_func short_desc_sort_func; +typedef integer_sort_func ushort_desc_sort_func; +typedef integer_sort_func int_desc_sort_func; +typedef integer_sort_func uint_desc_sort_func; +typedef integer_sort_func long_desc_sort_func; +typedef integer_sort_func ulong_desc_sort_func; +typedef integer_sort_func<__int64, false> int64_desc_sort_func; +typedef integer_sort_func uint64_desc_sort_func; + +template +struct float_sort_func +{ + bool operator() (float v1, float v2) const + { + float disc = v1 - v2; + if(fabsf(disc) < 1E-5) + return false; + + bool result = disc < 0; + return ASC ? result : !result; + } +}; + +typedef float_sort_func float_asc_sort_func; +typedef float_sort_func float_desc_sort_func; + +template +struct double_sort_func +{ + bool operator() (double v1, double v2) const + { + double disc = v1 - v2; + if(fabs(disc) < 1E-8) + return false; + + bool result = disc < 0; + return ASC ? result : !result; + } +}; + +typedef double_sort_func double_asc_sort_func; +typedef double_sort_func double_desc_sort_func; + +template +// T -> (unsigned) char / wchar_t +struct character_sort_func +{ + bool operator() (T v1, T v2) const + { + if(!CASE) + { + if(v1 >= 'A' && v1 <= 'Z') v1 += 32; + if(v2 >= 'A' && v2 <= 'Z') v2 += 32; + } + + if(v1 == v2) + return false; + + bool result = v1 < v2; + return ASC ? result : !result; + } +}; + +typedef character_sort_func char_asc_case_sort_func; +typedef character_sort_func uchar_asc_case_sort_func; +typedef character_sort_func wchar_asc_case_sort_func; +typedef character_sort_func char_asc_ucase_sort_func; +typedef character_sort_func uchar_asc_ucase_sort_func; +typedef character_sort_func wchar_asc_ucase_sort_func; +typedef character_sort_func char_desc_case_sort_func; +typedef character_sort_func uchar_desc_case_sort_func; +typedef character_sort_func wchar_desc_case_sort_func; +typedef character_sort_func char_desc_ucase_sort_func; +typedef character_sort_func uchar_desc_ucase_sort_func; +typedef character_sort_func wchar_desc_ucase_sort_func; + +template +// T -> TCHAR* / CString +struct str_sort_func +{ + bool operator() (const T& v1, const T& v2) const + { + bool result; + + if(CASE) + { + int v = lstrcmp((LPCTSTR)v1, (LPCTSTR)v2); + if(v == 0) + result = false; + else + result = v < 0; + } + else + { + int v = lstrcmpi((LPCTSTR)v1, (LPCTSTR)v2); + if(v == 0) + result = false; + else + result = v < 0; + } + + return ASC ? result : !result; + } +}; + +typedef str_sort_func tchar_ptr_asc_case_sort_func; +typedef str_sort_func string_asc_case_sort_func; +typedef str_sort_func tchar_ptr_asc_ucase_sort_func; +typedef str_sort_func string_asc_ucase_sort_func; +typedef str_sort_func tchar_ptr_desc_case_sort_func; +typedef str_sort_func string_desc_case_sort_func; +typedef str_sort_func tchar_ptr_desc_ucase_sort_func; +typedef str_sort_func string_desc_ucase_sort_func; + +/************************************************************************/ +/* smart_ptr ʵָ */ +/************************************************************************/ + +template +struct simple_deleter +{ + static void delete_ptr(_Ty* pv) {delete pv;} +}; + +template +struct global_simple_deleter +{ + static void delete_ptr(_Ty* pv) {::delete pv;} +}; + +template +struct array_deleter +{ + static void delete_ptr(_Ty* pv) {delete[] pv;} +}; + +template +struct global_array_deleter +{ + static void delete_ptr(_Ty* pv) {::delete[] pv;} +}; + +template +class smart_ptr +{ +public: + smart_ptr(_Ty* _Ptr = 0) : _Myptr(_Ptr) {} + smart_ptr(smart_ptr<_Ty, _Deleter>& _Right) : _Myptr(_Right.release()) {} + + ~smart_ptr() + { + reset(); + } + + smart_ptr<_Ty, _Deleter>& reset(_Ty* _Ptr = 0) + { + if (_Ptr != _Myptr) + { + if(_Myptr) + _Deleter::delete_ptr(_Myptr); + + _Myptr = _Ptr; + } + + return *this; + } + + smart_ptr<_Ty, _Deleter>& reset(smart_ptr<_Ty, _Deleter>& _Right) + { + if (this != &_Right) + reset(_Right.release()); + + return *this; + } + + _Ty* release() + { + _Ty* _Ptr = _Myptr; + _Myptr = 0; + + return _Ptr; + } + + smart_ptr<_Ty, _Deleter>& operator = (_Ty* _Ptr) {return reset(_Ptr);} + smart_ptr<_Ty, _Deleter>& operator = (smart_ptr<_Ty, _Deleter>& _Right) {return reset(_Right);} + + bool is_valid () const {return _Myptr != 0;} + _Ty& operator * () const {return *_Myptr;} + _Ty* get () const {return _Myptr;} + _Ty* operator -> () const {return _Myptr;} + operator _Ty* () const {return _Myptr;} + +private: + template smart_ptr<_Ty, _Deleter> (const smart_ptr<_Ty, _Other>&); + template smart_ptr<_Ty, _Deleter>& reset (const smart_ptr<_Ty, _Other>&); + template smart_ptr<_Ty, _Deleter>& operator = (const smart_ptr<_Ty, _Other>&); + + template smart_ptr<_Ty, _Deleter> (const smart_ptr<_Other, _Deleter>&); + template smart_ptr<_Ty, _Deleter>& reset (const smart_ptr<_Other, _Deleter>&); + template smart_ptr<_Ty, _Deleter>& operator = (const smart_ptr<_Other, _Deleter>&); + +protected: + _Ty* _Myptr; +}; + + +/************************************************************************/ +/* smart_simple_ptr ʵָ */ +/************************************************************************/ + +template +class smart_simple_ptr : public smart_ptr<_Ty, simple_deleter<_Ty>> +{ +public: + smart_simple_ptr(_Ty* _Ptr = 0) : smart_ptr(_Ptr) {} + smart_simple_ptr(smart_simple_ptr<_Ty>& _Right) : smart_ptr(_Right) {} + smart_simple_ptr(smart_ptr<_Ty, simple_deleter<_Ty>>& _Right) : smart_ptr(_Right) {} + + smart_simple_ptr<_Ty>& operator = (smart_ptr<_Ty, simple_deleter<_Ty>>& _Right) + {return (smart_simple_ptr<_Ty>&)__super::operator = (_Right);} + + smart_simple_ptr<_Ty>& operator = (smart_simple_ptr<_Ty>& _Right) + {return (smart_simple_ptr<_Ty>&)__super::operator = (_Right);} + + smart_simple_ptr<_Ty>& operator = (_Ty* _Ptr) + {return (smart_simple_ptr<_Ty>&)__super::operator = (_Ptr);} + +private: + template smart_simple_ptr<_Ty> (const smart_ptr<_Ty, _Other>&); + template smart_simple_ptr<_Ty>& operator = (const smart_ptr<_Ty, _Other>&); + + template smart_simple_ptr<_Ty> (const smart_simple_ptr<_Other>&); + template smart_simple_ptr<_Ty>& operator = (const smart_simple_ptr<_Other>&); +}; + +/************************************************************************/ +/* smart_gd_simple_ptr ʵָ (ʹȫ delete) */ +/************************************************************************/ + +template +class smart_gd_simple_ptr : public smart_ptr<_Ty, global_simple_deleter<_Ty>> +{ +public: + smart_gd_simple_ptr(_Ty* _Ptr = 0) : smart_ptr(_Ptr) {} + smart_gd_simple_ptr(smart_gd_simple_ptr<_Ty>& _Right) : smart_ptr(_Right) {} + smart_gd_simple_ptr(smart_ptr<_Ty, global_simple_deleter<_Ty>>& _Right) : smart_ptr(_Right) {} + + smart_gd_simple_ptr<_Ty>& operator = (smart_ptr<_Ty, global_simple_deleter<_Ty>>& _Right) + {return (smart_gd_simple_ptr<_Ty>&)__super::operator = (_Right);} + + smart_gd_simple_ptr<_Ty>& operator = (smart_gd_simple_ptr<_Ty>& _Right) + {return (smart_gd_simple_ptr<_Ty>&)__super::operator = (_Right);} + + smart_gd_simple_ptr<_Ty>& operator = (_Ty* _Ptr) + {return (smart_gd_simple_ptr<_Ty>&)__super::operator = (_Ptr);} + +private: + template smart_gd_simple_ptr<_Ty> (const smart_ptr<_Ty, _Other>&); + template smart_gd_simple_ptr<_Ty>& operator = (const smart_ptr<_Ty, _Other>&); + + template smart_gd_simple_ptr<_Ty> (const smart_gd_simple_ptr<_Other>&); + template smart_gd_simple_ptr<_Ty>& operator = (const smart_gd_simple_ptr<_Other>&); +}; + +/************************************************************************/ +/* smart_array_ptr ָ */ +/************************************************************************/ + +template +class smart_array_ptr : public smart_ptr<_Ty, array_deleter<_Ty>> +{ +public: + smart_array_ptr(_Ty* _Ptr = 0) : smart_ptr(_Ptr) {} + smart_array_ptr(smart_simple_ptr<_Ty>& _Right) : smart_ptr(_Right) {} + smart_array_ptr(smart_ptr<_Ty, array_deleter<_Ty>>& _Right) : smart_ptr(_Right) {} + + smart_array_ptr<_Ty>& operator = (smart_ptr<_Ty, array_deleter<_Ty>>& _Right) + {return (smart_array_ptr<_Ty>&)__super::operator = (_Right);} + + smart_array_ptr<_Ty>& operator = (smart_array_ptr<_Ty>& _Right) + {return (smart_array_ptr<_Ty>&)__super::operator = (_Right);} + + smart_array_ptr<_Ty>& operator = (_Ty* _Ptr) + {return (smart_array_ptr<_Ty>&)__super::operator = (_Ptr);} + +private: + template smart_array_ptr<_Ty> (const smart_ptr<_Ty, _Other>&); + template smart_array_ptr<_Ty>& operator = (const smart_ptr<_Ty, _Other>&); + + template smart_array_ptr<_Ty> (const smart_array_ptr<_Other>&); + template smart_array_ptr<_Ty>& operator = (const smart_array_ptr<_Other>&); +}; + +/************************************************************************/ +/* smart_gd_array_ptr ʵָ (ʹȫ delete) */ +/************************************************************************/ + +template +class smart_gd_array_ptr : public smart_ptr<_Ty, global_array_deleter<_Ty>> +{ +public: + smart_gd_array_ptr(_Ty* _Ptr = 0) : smart_ptr(_Ptr) {} + smart_gd_array_ptr(smart_gd_array_ptr<_Ty>& _Right) : smart_ptr(_Right) {} + smart_gd_array_ptr(smart_ptr<_Ty, global_array_deleter<_Ty>>& _Right) : smart_ptr(_Right) {} + + smart_gd_array_ptr<_Ty>& operator = (smart_ptr<_Ty, global_array_deleter<_Ty>>& _Right) + {return (smart_gd_array_ptr<_Ty>&)__super::operator = (_Right);} + + smart_gd_array_ptr<_Ty>& operator = (smart_gd_array_ptr<_Ty>& _Right) + {return (smart_gd_array_ptr<_Ty>&)__super::operator = (_Right);} + + smart_gd_array_ptr<_Ty>& operator = (_Ty* _Ptr) + {return (smart_gd_array_ptr<_Ty>&)__super::operator = (_Ptr);} + +private: + template smart_gd_array_ptr<_Ty> (const smart_ptr<_Ty, _Other>&); + template smart_gd_array_ptr<_Ty>& operator = (const smart_ptr<_Ty, _Other>&); + + template smart_gd_array_ptr<_Ty> (const smart_gd_array_ptr<_Other>&); + template smart_gd_array_ptr<_Ty>& operator = (const smart_gd_array_ptr<_Other>&); +}; diff --git a/Common/Src/Semaphore.cpp b/Common/Src/Semaphore.cpp new file mode 100644 index 000000000..cc753c71a --- /dev/null +++ b/Common/Src/Semaphore.cpp @@ -0,0 +1,26 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "Semaphore.h" \ No newline at end of file diff --git a/Common/Src/Semaphore.h b/Common/Src/Semaphore.h new file mode 100644 index 000000000..54ee56aa9 --- /dev/null +++ b/Common/Src/Semaphore.h @@ -0,0 +1,70 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +class CSEM +{ +public: + CSEM(LONG lMaximumCount, LONG lInitialCount = 0, LPCTSTR lpName = nullptr, LPSECURITY_ATTRIBUTES pSecurity = nullptr) + { + m_hsem = ::CreateSemaphore(pSecurity, lInitialCount, lMaximumCount, lpName); + ASSERT(IsValid()); + } + + ~CSEM() + { + if(IsValid()) + VERIFY(::CloseHandle(m_hsem)); + } + + BOOL Open(DWORD dwAccess, BOOL bInheritHandle, LPCTSTR pszName) + { + if(IsValid()) + VERIFY(::CloseHandle(m_hsem)); + + m_hsem = ::OpenSemaphore(dwAccess, bInheritHandle, pszName); + return(IsValid()); + } + + void Wait(DWORD dwMilliseconds = INFINITE) + { + ::WaitForSingleObject(m_hsem, dwMilliseconds); + } + + BOOL Release(LONG lReleaseCount = 1, LPLONG lpPreviousCount = nullptr) + { + return ::ReleaseSemaphore(m_hsem, lReleaseCount, lpPreviousCount); + } + + HANDLE& GetHandle () {return m_hsem;} + operator HANDLE () {return m_hsem;} + BOOL IsValid () {return m_hsem != nullptr;} + +private: + CSEM(const CSEM& sem); + CSEM operator = (const CSEM& sem); +private: + HANDLE m_hsem; +}; diff --git a/Common/Src/Singleton.h b/Common/Src/Singleton.h new file mode 100644 index 000000000..c01bb76bb --- /dev/null +++ b/Common/Src/Singleton.h @@ -0,0 +1,111 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#define SINGLETON_THIS(ClassName) ClassName::GetThis() +#define SINGLETON_INSTANCE(ClassName) ClassName::GetInstance() +#define SINGLETON_OBJECT(ObjName) SINGLETON_INSTANCE(C##ObjName) + +#define DEFINE_SINGLETON(ClassName) \ + ClassName* ClassName::m_pThis = nullptr; + +#define DEFINE_P_THIS(ClassName) \ + DEFINE_SINGLETON(ClassName) + +#define DECLARE_SINGLETON_INTERFACE(ClassName) \ +public: \ + static ClassName* GetThis() {return m_pThis;} \ + static ClassName& GetInstance() {return *m_pThis;} \ +protected: \ + static ClassName* m_pThis; + +#define DECLARE_SINGLETON_CREATE_INSTANCE(ClassName) \ +public: \ + static BOOL CreateInstance() \ + { \ + if(!m_pThis) \ + m_pThis = new ClassName; \ + \ + return m_pThis != nullptr; \ + } \ + \ + static BOOL DeleteInstance() \ + { \ + if(m_pThis) \ + { \ + delete m_pThis; \ + m_pThis = nullptr; \ + } \ + \ + return m_pThis == nullptr; \ + } + +#define DECLARE_PRIVATE_DEFAULT_CONSTRUCTOR(ClassName) \ +private: \ + ClassName(){} + +#define DECLARE_PRIVATE_COPY_CONSTRUCTOR(ClassName) \ +private: \ + ClassName(const ClassName&); \ + ClassName& operator = (const ClassName&); + +#define DECLARE_NO_COPY_CLASS(className) \ + DECLARE_PRIVATE_COPY_CONSTRUCTOR(className) + + +#define DECLARE_SINGLETON_IMPLEMENT_NO_CREATE_INSTANCE(ClassName) \ + DECLARE_SINGLETON_INTERFACE(ClassName) \ + DECLARE_PRIVATE_DEFAULT_CONSTRUCTOR(ClassName) \ + DECLARE_PRIVATE_COPY_CONSTRUCTOR(ClassName) + +#define DECLARE_SINGLETON_IMPLEMENT_NO_DEFAULT_CONSTRUCTOR(ClassName) \ + DECLARE_SINGLETON_CREATE_INSTANCE(ClassName) \ + DECLARE_PRIVATE_COPY_CONSTRUCTOR(ClassName) + +#define DECLARE_SINGLETON_IMPLEMENT(ClassName) \ + DECLARE_SINGLETON_IMPLEMENT_NO_DEFAULT_CONSTRUCTOR(ClassName) \ + DECLARE_PRIVATE_DEFAULT_CONSTRUCTOR(ClassName) + +#define DECLARE_SINGLETON_NO_DEFAULT_CONSTRUCTOR(ClassName) \ + DECLARE_SINGLETON_INTERFACE(ClassName) \ + DECLARE_SINGLETON_IMPLEMENT_NO_DEFAULT_CONSTRUCTOR(ClassName) + +#define DECLARE_SINGLETON(ClassName) \ + DECLARE_SINGLETON_NO_DEFAULT_CONSTRUCTOR(ClassName) \ + DECLARE_PRIVATE_DEFAULT_CONSTRUCTOR(ClassName) + + +template +class CSingleObject +{ +public: + CSingleObject () {T::CreateInstance();} + ~CSingleObject () {T::DeleteInstance();} + T* GetPointer () {return T::GetThis();} + T& GetObject () {return T::GetInstance();} + BOOL IsValid () {return GetPointer() != nullptr;} +}; + +#define DECLARE_SINGLE_OBJECT(ClassName) CSingleObject _##ClassName##_Single_Object_; \ No newline at end of file diff --git a/Common/Src/SysHelper.cpp b/Common/Src/SysHelper.cpp new file mode 100644 index 000000000..908674d46 --- /dev/null +++ b/Common/Src/SysHelper.cpp @@ -0,0 +1,72 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "SysHelper.h" +#include "GeneralHelper.h" + +VOID SysGetSystemInfo(LPSYSTEM_INFO pInfo) +{ + ASSERT(pInfo != nullptr); + ::GetNativeSystemInfo(pInfo); +} + +DWORD SysGetNumberOfProcessors() +{ + SYSTEM_INFO si; + SysGetSystemInfo(&si); + + return si.dwNumberOfProcessors; +} + +DWORD SysGetPageSize() +{ + SYSTEM_INFO si; + SysGetSystemInfo(&si); + + return si.dwPageSize; +} + +#if _MSC_VER < 1800 + +BOOL SysGetOSVersionInfo(LPOSVERSIONINFO pInfo, BOOL bInfoEx) +{ + ASSERT(pInfo != nullptr); + + pInfo->dwOSVersionInfoSize = bInfoEx ? sizeof(LPOSVERSIONINFOEX) : sizeof(LPOSVERSIONINFO); + return ::GetVersionEx(pInfo); +} + +DWORD SysGetOSVersion() +{ + OSVERSIONINFO vi; + DWORD dwOSVersion = 0; + + if(SysGetOSVersionInfo(&vi)) + dwOSVersion = (vi.dwMajorVersion << 16) + vi.dwMinorVersion; + + return dwOSVersion; +} + +#endif diff --git a/Common/Src/SysHelper.h b/Common/Src/SysHelper.h new file mode 100644 index 000000000..5059aa2e8 --- /dev/null +++ b/Common/Src/SysHelper.h @@ -0,0 +1,41 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +// ȡϵͳϢ +VOID SysGetSystemInfo(LPSYSTEM_INFO pInfo); +// ȡ CPU +DWORD SysGetNumberOfProcessors(); +// ȡҳС +DWORD SysGetPageSize(); + +#if _MSC_VER < 1800 + +// ȡϵͳ汾 +BOOL SysGetOSVersionInfo(LPOSVERSIONINFO pInfo, BOOL bInfoEx = FALSE); +// ȡϵͳ汾λ˫ֽڣ汾ţλ˫ֽڣ汾ţ +DWORD SysGetOSVersion(); + +#endif diff --git a/Common/Src/Thread.cpp b/Common/Src/Thread.cpp new file mode 100644 index 000000000..b856df4d3 --- /dev/null +++ b/Common/Src/Thread.cpp @@ -0,0 +1,27 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "Thread.h" +#include diff --git a/Common/Src/Thread.h b/Common/Src/Thread.h new file mode 100644 index 000000000..e32477d84 --- /dev/null +++ b/Common/Src/Thread.h @@ -0,0 +1,320 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include "RWLock.h" +#include "STLHelper.h" + +template class CThread +{ +public: + virtual UINT Run(T* lpParam) = 0; + + BOOL Start(T* lpParam = nullptr, int iPriority = THREAD_PRIORITY_NORMAL, UINT uiStackSize = 0, LPSECURITY_ATTRIBUTES lpThreadAttributes = nullptr) + { + BOOL isOK = TRUE; + + if(!IsRunning()) + { + Release(); + + m_lpParam = lpParam; + m_iPriority = iPriority; + m_hThread = (HANDLE)_beginthreadex(lpThreadAttributes, uiStackSize, ThreadProc, (LPVOID)this, 0, nullptr); + isOK = (m_hThread != nullptr); + + if(!isOK) ::SetLastError(_doserrno); + } + else + { + ::SetLastError(ERROR_INVALID_STATE); + isOK = FALSE; + } + + return isOK; + } + + DWORD Join(DWORD dwMilliseconds = INFINITE) + { + return ::WaitForSingleObject(m_hThread, dwMilliseconds); + } + + BOOL IsRunning() + { + DWORD dwExitCode; + + if(GetExitCode(&dwExitCode)) + return dwExitCode == STILL_ACTIVE; + + return FALSE; + } + + VOID Release() + { + if(m_hThread != nullptr) + { + ::CloseHandle(m_hThread); + m_hThread = nullptr; + } + } + + HANDLE Detatch() + { + HANDLE h = m_hThread; + m_hThread = nullptr; + + return h; + } + + CThread& Attatch(HANDLE hThread) + { + if(hThread != m_hThread) + { + Release(); + + m_hThread = hThread; + } + + return *this; + } + +#if _WIN32_WINNT >= _WIN32_WINNT_WS03 + DWORD GetID () {return ::GetThreadId(m_hThread);} +#endif + + BOOL Terminate (DWORD dwExitCode) {return ::TerminateThread(m_hThread, dwExitCode);} + BOOL GetExitCode (LPDWORD lpExitCode) {return ::GetExitCodeThread(m_hThread, lpExitCode);} + DWORD Suspend () {return ::SuspendThread(m_hThread);} + DWORD Resume () {return ::ResumeThread(m_hThread);} + + BOOL IsValid () {return m_hThread != nullptr;} + HANDLE& GetHandle () {return m_hThread;} + operator HANDLE () {return m_hThread;} + +public: + CThread() + : m_hThread(nullptr) + , m_lpParam(nullptr) + , m_iPriority(THREAD_PRIORITY_NORMAL) + { + } + + virtual ~CThread() + { + Release(); + } + +private: + static UINT WINAPI ThreadProc(LPVOID pv) + { + CThread* pThis = (CThread*)pv; + + if(pThis->m_iPriority != THREAD_PRIORITY_NORMAL) + ::SetThreadPriority(GetCurrentThread(), pThis->m_iPriority); + + return pThis->Run(pThis->m_lpParam); + } + +private: + HANDLE m_hThread; + T* m_lpParam; + int m_iPriority; + + DECLARE_NO_COPY_CLASS(CThread) +}; + +template class CTlsObj +{ + typedef unordered_map TLocalMap; + typedef typename TLocalMap::iterator TLocalMapI; + typedef typename TLocalMap::const_iterator TLocalMapCI; + +public: + T* TryGet(DWORD dwTID = 0) + { + T* pValue = nullptr; + if(dwTID == 0) dwTID = ::GetCurrentThreadId(); + + { + CReadLock locallock(m_lock); + TLocalMapCI it = m_map.find(dwTID); + + if(it != m_map.end()) + pValue = it->second; + } + + return pValue; + } + + T* Get() + { + DWORD dwTID = ::GetCurrentThreadId(); + T* pValue = TryGet(dwTID); + + if(pValue == nullptr) + { + CWriteLock locallock(m_lock); + TLocalMapCI it = m_map.find(dwTID); + + if(it != m_map.end()) + pValue = it->second; + + if(pValue == nullptr) + { + pValue = Construct(); + m_map[dwTID] = pValue; + } + } + + return pValue; + } + + T& GetRef() + { + return *Get(); + } + + T* Get(construct_param_type construct_param) + { + DWORD dwTID = ::GetCurrentThreadId(); + T* pValue = TryGet(dwTID); + + if(pValue == nullptr) + { + + CWriteLock locallock(m_lock); + TLocalMapCI it = m_map.find(dwTID); + + if(it != m_map.end()) + pValue = it->second; + + if(pValue == nullptr) + { + pValue = ConstructWithParam(construct_param); + m_map[dwTID] = pValue; + } + } + + return pValue; + } + + T& GetRef(construct_param_type construct_param) + { + return *Get(construct_param); + } + + T* SetAndRetriveOldValue(T* pValue) + { + DWORD dwTID = ::GetCurrentThreadId(); + T* pOldValue = TryGet(dwTID); + + if(pValue != pOldValue) + { + CWriteLock locallock(m_lock); + m_map[dwTID] = pValue; + } + + return pOldValue; + } + + void Set(T* pValue) + { + T* pOldValue = SetAndRetriveOldValue(pValue); + + if(pValue != pOldValue) + Delete(pOldValue); + } + + void Remove() + { + DWORD dwTID = ::GetCurrentThreadId(); + T* pOldValue = TryGet(dwTID); + + Delete(pOldValue); + + { + CWriteLock locallock(m_lock); + m_map.erase(dwTID); + } + } + + void Clear() + { + CWriteLock locallock(m_lock); + + if(!IsEmpty()) + { + for(TLocalMapCI it = m_map.begin(); it != m_map.end(); ++it) + Delete(it->second); + + m_map.clear(); + } + } + + TLocalMap& GetLocalMap() {return m_map;} + const TLocalMap& GetLocalMap() const {return m_map;} + + T* operator -> () {return Get();} + const T* operator -> () const {return Get();} + T& operator * () {return GetRef();} + const T& operator * () const {return GetRef();} + size_t Size () const {return m_map.size();} + bool IsEmpty () const {return m_map.empty();} + +public: + CTlsObj() + { + + } + + ~CTlsObj() + { + Clear(); + } + +private: + static inline void Delete(T* pValue) + { + if(pValue != nullptr) + delete pValue; + } + + static inline T* Construct() + { + return new T; + } + + static inline T* ConstructWithParam(construct_param_type construct_param) + { + return new T(construct_param); + } + +private: + CSimpleRWLock m_lock; + TLocalMap m_map; + + DECLARE_NO_COPY_CLASS(CTlsObj) +}; diff --git a/Common/Src/WaitFor.cpp b/Common/Src/WaitFor.cpp new file mode 100644 index 000000000..31571762e --- /dev/null +++ b/Common/Src/WaitFor.cpp @@ -0,0 +1,150 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "WaitFor.h" +#include "GeneralHelper.h" +#include "CriticalSection.h" + +#include +#pragma comment(lib, "Winmm") + +DWORD TimeGetTime() +{ + return ::timeGetTime(); +} + +DWORD GetTimeGap32(DWORD dwOriginal) +{ + return ::timeGetTime() - dwOriginal; +} + +#if _WIN32_WINNT >= _WIN32_WINNT_WS08 +ULONGLONG GetTimeGap64(ULONGLONG ullOriginal) +{ + return ::GetTickCount64() - ullOriginal; +} +#endif + +BOOL PeekMessageLoop(BOOL bDispatchQuitMsg) +{ + BOOL value = TRUE; + + MSG msg; + while(::PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) + { + if(msg.message == WM_QUIT && !bDispatchQuitMsg) + { + value = FALSE; + break; + } + + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + return value; +} + +DWORD WaitForMultipleObjectsWithMessageLoop(DWORD dwHandles, HANDLE szHandles[], DWORD dwMilliseconds, DWORD dwWakeMask, DWORD dwFlags) +{ + DWORD dwResult = WAIT_FAILED; + DWORD dwBeginTime = (dwMilliseconds == INFINITE) ? INFINITE : ::timeGetTime(); + + while(TRUE) + { + int iWaitTime; + if(dwBeginTime != INFINITE) + { + iWaitTime = dwMilliseconds - (GetTimeGap32(dwBeginTime)); + + if(iWaitTime <= 0) + { + dwResult = WAIT_TIMEOUT; + break; + } + } + else + iWaitTime = INFINITE; + + dwResult = ::MsgWaitForMultipleObjectsEx(dwHandles, szHandles, iWaitTime, dwWakeMask, dwFlags); + ASSERT(dwResult != WAIT_FAILED); + + if(dwResult == (WAIT_OBJECT_0 + dwHandles)) + PeekMessageLoop(); + else + break; + } + + return dwResult; + +} + +BOOL MsgWaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds, DWORD dwWakeMask, DWORD dwFlags) +{ + DWORD dwResult = WaitForMultipleObjectsWithMessageLoop(1, &hHandle, dwMilliseconds, dwWakeMask, dwFlags); + + switch(dwResult) + { + case WAIT_OBJECT_0: + return TRUE; + case WAIT_FAILED: + ASSERT(FALSE); + case WAIT_TIMEOUT: + return FALSE; + default: + ASSERT(FALSE); + } + + return FALSE; +} + +void WaitWithMessageLoop(DWORD dwMilliseconds, DWORD dwWakeMask, DWORD dwFlags) +{ + static CEvt evWait; + + VERIFY(MsgWaitForSingleObject(evWait, dwMilliseconds, dwWakeMask, dwFlags) == FALSE); +} + +void WaitForWorkingQueue(long* plWorkingItemCount, long lMaxWorkingItemCount, DWORD dwCheckInterval) +{ + while(*plWorkingItemCount > lMaxWorkingItemCount) + ::Sleep(dwCheckInterval); +} + +void WaitForComplete(long* plWorkingItemCount, DWORD dwCheckInterval) +{ + WaitForWorkingQueue(plWorkingItemCount, 0, dwCheckInterval); +} + +void MsgWaitForWorkingQueue(long* plWorkingItemCount, long lMaxWorkingItemCount, DWORD dwCheckInterval) +{ + while(*plWorkingItemCount > lMaxWorkingItemCount) + WaitWithMessageLoop(dwCheckInterval); +} + +void MsgWaitForComplete(long* plWorkingItemCount, DWORD dwCheckInterval) +{ + MsgWaitForWorkingQueue(plWorkingItemCount, 0, dwCheckInterval); +} diff --git a/Common/Src/WaitFor.h b/Common/Src/WaitFor.h new file mode 100644 index 000000000..bc6f6bd63 --- /dev/null +++ b/Common/Src/WaitFor.h @@ -0,0 +1,138 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* timeGetTime() װ */ +DWORD TimeGetTime(); + +/********************************** +: ȡǰʱԭʼʱʱ +: + dwOriginal : ԭʼʱ䣨룩ͨ timeGetTime() GetTickCount() ȡ + +ֵ: 뵱ǰ timeGetTime() ֮ʱ +**********************************/ +DWORD GetTimeGap32(DWORD dwOriginal); + +#if _WIN32_WINNT >= _WIN32_WINNT_WS08 +/********************************** +: ȡǰʱԭʼʱʱ +: + ullOriginal : ԭʼʱ䣨룩ͨ GetTickCount64() ȡ + +ֵ: 뵱ǰ GetTickCount64() ֮ʱ +**********************************/ +ULONGLONG GetTimeGap64(ULONGLONG ullOriginal); +#endif + +/********************************** +: WindowsϢ +: + bDispatchQuitMsg : Ƿת WM_QUIT Ϣ + TRUE : תĬϣ + FALSE: ת FALSE + +ֵ: TRUE : Ϣ + FALSE : bDispatchQuitMsg Ϊ FALSE յ WM_QUIT Ϣ +**********************************/ +BOOL PeekMessageLoop(BOOL bDispatchQuitMsg = TRUE); + +/********************************** +: ȴָʱ, ͬʱWindowsϢ +: (ο: MsgWaitForMultipleObjectsEx() ) + dwHandles : Ԫظ + szHandles : + dwMilliseconds : ȴʱ () + dwWakeMask : Ϣ˱ʶ + dwFlags : ȴ + +ֵ: (0 ~ dwHandles - 1): ȴɹ + WAIT_TIMEOUT : ʱ + WAIT_FAILED : ִʧ +**********************************/ +DWORD WaitForMultipleObjectsWithMessageLoop(DWORD dwHandles, HANDLE szHandles[], DWORD dwMilliseconds = INFINITE, DWORD dwWakeMask = QS_ALLINPUT, DWORD dwFlags = MWMO_INPUTAVAILABLE); + +/********************************** +: ȴָʱ, ͬʱWindowsϢ +: (ο: MsgWaitForMultipleObjectsEx() ) + hHandle : + dwMilliseconds : ȴʱ () + dwWakeMask : Ϣ˱ʶ + dwFlags : ȴ + +ֵ: TRUE: ȴɹFALSE: ʱ +**********************************/ +BOOL MsgWaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds = INFINITE, DWORD dwWakeMask = QS_ALLINPUT, DWORD dwFlags = MWMO_INPUTAVAILABLE); + +/********************************** +: ȴָʱ, ͬʱWindowsϢ +: (ο: MsgWaitForMultipleObjectsEx() ) + dwMilliseconds : ȴʱ () + dwWakeMask : Ϣ˱ʶ + dwFlags : ȴ + +ֵ: MsgWaitForMultipleObjectsEx() IJ +**********************************/ +void WaitWithMessageLoop(DWORD dwMilliseconds, DWORD dwWakeMask = QS_ALLINPUT, DWORD dwFlags = MWMO_INPUTAVAILABLE); + +/********************************** +: ȴSleep()ȴijСֵָ +: + plWorkingItemCount : ӱ + lMaxWorkingItemCount : ֵָ + dwCheckInterval : () + +ֵ: +**********************************/ +void WaitForWorkingQueue(long* plWorkingItemCount, long lMaxWorkingItemCount, DWORD dwCheckInterval); +/********************************** +: ȴSleep()ȴijС 0 +: + plWorkingItemCount : ӱ + dwCheckInterval : () + +ֵ: +**********************************/ +void WaitForComplete (long* plWorkingItemCount, DWORD dwCheckInterval); + +/********************************** +: ȴWaitWithMessageLoop()ȴijСֵָ +: + plWorkingItemCount : ӱ + lMaxWorkingItemCount : ֵָ + dwCheckInterval : () + +ֵ: +**********************************/ +void MsgWaitForWorkingQueue (long* plWorkingItemCount, long lMaxWorkingItemCount, DWORD dwCheckInterval = 10); +/********************************** +: ȴWaitWithMessageLoop()ȴijС 0 +: + plWorkingItemCount : ӱ + dwCheckInterval : () + +ֵ: +**********************************/ +void MsgWaitForComplete (long* plWorkingItemCount, DWORD dwCheckInterval = 10); diff --git a/Common/Src/Win32Helper.h b/Common/Src/Win32Helper.h new file mode 100644 index 000000000..83b5d85e9 --- /dev/null +++ b/Common/Src/Win32Helper.h @@ -0,0 +1,819 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "GeneralHelper.h" + +// RECT +#define RC_WIDTH(rc) (rc.right - rc.left) +#define RC_HEIGHT(rc) (rc.bottom - rc.top) +#define RC_CENTER_X(rc) ((rc.right + rc.left) / 2) +#define RC_CENTER_Y(rc) ((rc.bottom + rc.top) / 2) + +/************************************************************************/ +/* Ϣӳ */ +/************************************************************************/ + +/* see: WindowsX.h */ +#define HANDLE_SYS_MSG(hwnd, message, fn) HANDLE_MSG(hwnd, message, fn) + +/* LRESULT Cls_OnMessage(HWND hwnd, WPARAM wParam, LPARAM lParam) */ +#define HANDLE_USER_MSG(hwnd, message, fn) \ + case (message): return (LRESULT)(fn)((hwnd), (wParam), (lParam)) + +#define FORWARD_USER_MSG(hwnd, message, wParam, lParam, fn) \ + (LRESULT)(fn)((hwnd), (message), (wParam), (lParam)) + +#define GET_WND_PROC_INTERNAL(theClass, flag) ((WNDPROC)theClass##flag##WndProc) +#define GET_DLG_PROC_INTERNAL(theClass, flag) ((DLGPROC)theClass##flag##DlgProc) + +#define DECLARE_MSG_MAP_INTERNAL(theClass, flag) \ + static LRESULT CALLBACK theClass##flag##WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + +#define DECLARE_DLG_MSG_MAP_INTERNAL(theClass, flag) \ + static BOOL CALLBACK theClass##flag##DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + +#define BEGIN_MSG_MAP_INTERNAL(theClass, flag) \ + LRESULT theClass##flag##WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) \ + { \ + LRESULT result = 0; \ + \ + switch(msg) \ + { + +#define BEGIN_DLG_MSG_MAP_INTERNAL(theClass, flag) \ + BOOL theClass##flag##DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) \ + { \ + BOOL retVal = TRUE; \ + LRESULT result = 0; \ + \ + switch(msg) \ + { + +// ڹΪеľ̬Ա +#define GET_WND_PROC(theClass) GET_WND_PROC_INTERNAL(theClass, ::) +#define GET_DLG_PROC(theClass) GET_DLG_PROC_INTERNAL(theClass, ::) + +#define DECLARE_MSG_MAP(theClass) \ +public: \ + DECLARE_MSG_MAP_INTERNAL(theClass, ::) + +#define DECLARE_DLG_MSG_MAP(theClass) \ +public: \ + DECLARE_DLG_MSG_MAP_INTERNAL(theClass, ::) + +#define BEGIN_MSG_MAP(theClass) BEGIN_MSG_MAP_INTERNAL(theClass, ::) +#define BEGIN_DLG_MSG_MAP(theClass) BEGIN_DLG_MSG_MAP_INTERNAL(theClass, ::) + +/* Ϣο: HANDLE_MSG */ +#define ADD_MSG_MAP(msg, fn) \ + case (msg): result = HANDLE_##msg((hWnd), (wParam), (lParam), (fn)); break; + +/* LRESULT Cls_OnMessage(HWND hwnd, WPARAM wParam, LPARAM lParam) */ +#define ADD_USER_MSG_MAP(msg, fn) \ + case (msg): result = (LRESULT)(fn)((hWnd), (wParam), (lParam)); break; + +#define END_MSG_MAP() \ + default: \ + result = ::DefWindowProc(hWnd, msg, wParam, lParam); \ + } \ + \ + return result; \ + } + +#define END_DLG_MSG_MAP() \ + default: \ + retVal = FALSE; \ + } \ + \ + if(retVal) \ + SetDlgMsgResult(hWnd, msg, result); \ + \ + return retVal; \ + } + +// ڹΪȫֺ +#define GET_GLOBAL_WND_PROC(theClass) GET_WND_PROC_INTERNAL(theClass, _) +#define DECLARE_GLOBAL_MSG_MAP(theClass) DECLARE_MSG_MAP_INTERNAL(theClass, _) +#define BEGIN_GLOBAL_MSG_MAP(theClass) BEGIN_MSG_MAP_INTERNAL(theClass, _) +#define END_GLOBAL_MSG_MAP() END_MSG_MAP() + +#define GET_GLOBAL_DLG_PROC(theClass) GET_DLG_PROC_INTERNAL(theClass, _) +#define DECLARE_GLOBAL_DLG_MSG_MAP(theClass) DECLARE_DLG_MSG_MAP_INTERNAL(theClass, _) +#define BEGIN_GLOBAL_DLG_MSG_MAP(theClass) BEGIN_DLG_MSG_MAP_INTERNAL(theClass, _) +#define END_GLOBAL_DLG_MSG_MAP() END_DLG_MSG_MAP() + +// 󶨶ָ뵽 +#define ATTACH_OBJ_PTR_TO_WINDOW(hwnd, objPtr) ::SetWindowLongPtr(hwnd, GWL_USERDATA, (LONG_PTR)objPtr) +#define GET_OBJ_PTR_FROM_WINDOW(hwnd, theClass) (theClass*)(LONG_PTR)::GetWindowLongPtr(hwnd, GWL_USERDATA) + +#define DEFINE_OBJ_PTR_FROM_WINDOW(hwnd, theClass, pObj) \ + theClass* pObj = GET_OBJ_PTR_FROM_WINDOW(hwnd, theClass); \ + ASSERT(pObj); + + +/************************************************************************/ +/* ӦóΨһʵ */ +/************************************************************************/ + +class COnlyOneApp +{ +public: + BOOL IsFirstApp () {return m_bIsFirstApp;} + DWORD GetProcID () {return m_dwProcID;} + + COnlyOneApp(LPCTSTR pszAppFlag) + : m_dwProcID(0), m_bIsFirstApp(FALSE) + { + m_hMap = ::CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, sizeof(DWORD), pszAppFlag); + + if(m_hMap) + { + if(::GetLastError() != ERROR_ALREADY_EXISTS) + { + m_bIsFirstApp = TRUE; + m_dwProcID = ::GetCurrentProcessId(); + + LPVOID lpBuff = ::MapViewOfFile(m_hMap, FILE_MAP_WRITE, 0, 0, sizeof(DWORD)); + ASSERT(lpBuff); + + memcpy(lpBuff, &m_dwProcID, sizeof(DWORD)); + ::UnmapViewOfFile(lpBuff); + } + else + { + m_bIsFirstApp = FALSE; + LPVOID lpBuff = ::MapViewOfFile(m_hMap, FILE_MAP_READ, 0, 0, sizeof(DWORD)); + ASSERT(lpBuff); + + memcpy(&m_dwProcID, lpBuff, sizeof(DWORD)); + ::UnmapViewOfFile(lpBuff); + } + } + else + { + ASSERT(FALSE); + } + } + + ~COnlyOneApp() {if(m_hMap) {::CloseHandle(m_hMap); m_hMap = nullptr;}} + +private: + HANDLE m_hMap; + DWORD m_dwProcID; + BOOL m_bIsFirstApp; + + DECLARE_NO_COPY_CLASS(COnlyOneApp) +}; + +class COnlyOneWndApp +{ +public: + BOOL IsFirstApp() {return m_hwndPre == nullptr;} + HWND GetPreInstanceWindow() {return m_hwndPre;} + + COnlyOneWndApp(LPCTSTR lpszClassName, LPCTSTR lpszWindowName = nullptr) + { + m_hwndPre = ::FindWindow(lpszClassName, lpszWindowName); + } + +private: + HWND m_hwndPre; + + DECLARE_NO_COPY_CLASS(COnlyOneWndApp) +}; + +/************************************************************************/ +/* (HANDLE) ܰװ */ +/************************************************************************/ + +template +class auto_handle +{ +public: + auto_handle(HANDLE h = NULL_VALUE) {set(h);} + auto_handle(auto_handle& other) {set(other.release());} + + ~auto_handle() {reset();} + + auto_handle& reset(HANDLE h = NULL_VALUE) + { + if(h != m_h) + { + if(is_valid()) + VERIFY(::CloseHandle(m_h)); + + set(h); + } + + return *this; + } + + auto_handle& reset(auto_handle& other) + { + if(this != &other) + reset(other.release()); + + return *this; + } + + HANDLE release() + { + HANDLE h = get(); + set(NULL_VALUE); + + return h; + } + + operator HANDLE () const {return m_h;} + HANDLE get () const {return m_h;} + HANDLE& get_ref () const {return m_h;} + bool is_valid () const {return m_h != NULL_VALUE;} + + auto_handle& operator = (HANDLE h) {return reset(h);} + auto_handle& operator = (auto_handle& other) {return reset(other);} + + bool operator == (HANDLE h) const {return m_h == h;} + bool operator != (HANDLE h) const {return !(operator == (h)); } + bool operator == (const auto_handle& other) const {return m_h == other.m_h;} + bool operator != (const auto_handle& other) const {return !(operator == (other));} + +private: + void set(HANDLE h) {m_h = h;} + + // ~! do not define these conversion, because it's very easy to making mistake !~ + template auto_handle(const auto_handle<_Other>&); + template auto_handle& operator = (const auto_handle<_Other>&); + +private: + HANDLE m_h; +}; + +typedef auto_handle auto_file_handle; // ļܾ +typedef auto_handle auto_res_handle; // ͨԴܾ + +/************************************************************************/ +/* DC ܰװ */ +/************************************************************************/ + +class auto_dc +{ +public: + auto_dc(HDC h = nullptr, HWND w = nullptr, bool is_create = false) + { + set(h, w, is_create); + } + + auto_dc(auto_dc& other) + { + set(other.m_h, other.m_w, other.m_is_create); + other.release(); + } + + ~auto_dc() {reset();} + + HDC GetDC(HWND hWnd) + { + HDC h = ::GetDC(hWnd); + reset(h, hWnd, false); + + return h; + } + + HDC GetWindowDC(HWND hWnd) + { + HDC h = ::GetWindowDC(hWnd); + reset(h, hWnd, false); + + return h; + } + + HDC GetDCEx(HWND hWnd, HRGN hrgnClip, DWORD flags) + { + HDC h = ::GetDCEx(hWnd, hrgnClip, flags); + reset(h, hWnd, false); + + return h; + } + + HDC CreateDC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, CONST DEVMODE* lpInitData) + { + HDC h = ::CreateDC(lpszDriver, lpszDevice, lpszOutput, lpInitData); + reset(h, nullptr, true); + + return h; + } + + HDC CreateCompatibleDC(HDC hSrc) + { + HDC h = ::CreateCompatibleDC(hSrc); + reset(h, nullptr, true); + + return h; + } + + HGDIOBJ GetCurrentObject(UINT uObjectType) + { + return ::GetCurrentObject(m_h, uObjectType); + } + + HBITMAP _GetCurrentBitmap() + { + return (HBITMAP)GetCurrentObject(OBJ_BITMAP); + } + + HBRUSH _GetCurrentBrush() + { + return (HBRUSH)GetCurrentObject(OBJ_BRUSH); + } + + HPALETTE _GetCurrentPalette() + { + return (HPALETTE)GetCurrentObject(OBJ_PAL); + } + + HPEN _GetCurrentPen() + { + return (HPEN)GetCurrentObject(OBJ_PEN); + } + + HFONT _GetCurrentFont() + { + return (HFONT)GetCurrentObject(OBJ_FONT); + } + + int SelectClipRgn(HRGN hrgn) + { + return ::SelectClipRgn(m_h, hrgn); + } + + int ExtSelectClipRgn(HRGN hrgn, int mode) + { + return ::ExtSelectClipRgn(m_h, hrgn, mode); + } + + HGDIOBJ SelectObject(HGDIOBJ hgdiobj) + { + return ::SelectObject(m_h, hgdiobj); + } + + HPALETTE SelectPalette(HPALETTE hpal, BOOL bForceBackground) + { + return ::SelectPalette(m_h, hpal, bForceBackground); + } + + HBITMAP _SelectBitmap(HBITMAP hbm) + { + return (HBITMAP)SelectObject(hbm); + } + + HBRUSH _SelectBrush(HBRUSH hbr) + { + return (HBRUSH)SelectObject(hbr); + } + + HPEN _SelectPen(HPEN hpen) + { + return (HPEN)SelectObject(hpen); + } + + HRGN _SelectRgn(HRGN hrgn) + { + return (HRGN)SelectObject(hrgn); + } + + HFONT _SelectFont(HFONT hf) + { + return (HFONT)SelectObject(hf); + } + + auto_dc& reset(HDC h = nullptr, HWND w = nullptr, bool is_create = false) + { + if(h != m_h || w != m_w) + { + if(is_valid()) + { + if(m_is_create) + VERIFY(::DeleteDC(m_h)); + else + VERIFY(::ReleaseDC(m_w, m_h)); + } + + set(h, w, is_create); + } + + return *this; + } + + auto_dc& reset(auto_dc& other) + { + if(this != &other) + { + reset(other.m_h, other.m_w, other.m_is_create); + other.release(); + } + + return *this; + } + + HDC release() + { + HDC h = get_dc(); + set(nullptr, nullptr, false); + + return h; + } + + /* + auto_dc& operator = (HDC h) + { + return reset(h); + } + */ + + auto_dc& operator = (auto_dc& other) {return reset(other);} + + operator HDC () const {return m_h;} + HDC get_dc () const {return m_h;} + const HDC& get_dc_ref () const {return m_h;} + HWND get_wnd () const {return m_w;} + bool is_valid () const {return m_h != nullptr;} + bool is_create () const {return m_is_create;} + +private: + void set(HDC h, HWND w, bool is_create) + { + m_h = h; + m_w = w; + m_is_create = is_create; + } + +private: + HDC m_h; + HWND m_w; + bool m_is_create; +}; + +class paint_dc +{ +public: + paint_dc(HWND hwnd) : m_hwnd(hwnd) + { + VERIFY(m_hdc = ::BeginPaint(m_hwnd, &m_ps)); + } + + ~paint_dc() + { + VERIFY(::EndPaint(m_hwnd, &m_ps)); + } + + operator HDC () const {return m_hdc;} + bool is_valid() const {return m_hdc != nullptr;} + +public: + PAINTSTRUCT m_ps; + HWND m_hwnd; + HDC m_hdc; +}; +/************************************************************************/ +/* GDI Object ܰװ */ +/************************************************************************/ + +template +class auto_gdi_obj +{ +public: + auto_gdi_obj(T obj = nullptr) {set(obj);} + auto_gdi_obj(auto_gdi_obj& other) {set(other.release());} + + ~auto_gdi_obj() {reset();} + + auto_gdi_obj& reset(T obj = nullptr) + { + if(obj != m_obj) + { + if(is_valid()) + { + VERIFY(::DeleteObject(m_obj)); + } + + set(obj); + } + + return *this; + } + + auto_gdi_obj& reset(auto_gdi_obj& other) + { + if(this != &other) + reset(other.release()); + + return *this; + } + + T release() + { + T obj = get(); + set(nullptr); + + return obj; + } + + auto_gdi_obj& operator = (T obj) {return reset(obj);} + auto_gdi_obj& operator = (auto_gdi_obj& other) {return reset(other);} + + operator T () const {return m_obj;} + T get () const {return m_obj;} + const T& get_ref () const {return m_obj;} + bool is_valid() const {return m_obj != nullptr;} + +private: + void set(T obj) {m_obj = obj;} + +protected: + T m_obj; +}; + +typedef auto_gdi_obj auto_bitmap_base; +typedef auto_gdi_obj auto_brush_base; +typedef auto_gdi_obj auto_palette_base; +typedef auto_gdi_obj auto_pen_base; +typedef auto_gdi_obj auto_rgn_base; +typedef auto_gdi_obj auto_font_base; + +class auto_bitmap : public auto_bitmap_base +{ +public: + auto_bitmap(HBITMAP obj = nullptr) : auto_bitmap_base(obj) {} + + auto_bitmap& operator = (HBITMAP obj) + { + return (auto_bitmap&)reset(obj); + } + + HBITMAP CreateBitmap(int nWidth, int nHeight, UINT cPlanes, UINT cBitsPerPel, CONST VOID* lpvBits) + { + HBITMAP obj = ::CreateBitmap(nWidth, nHeight, cPlanes, cBitsPerPel, lpvBits); + reset(obj); + + return obj; + } + + HBITMAP CreateBitmapIndirect(CONST BITMAP *lpbm) + { + HBITMAP obj = ::CreateBitmapIndirect(lpbm); + reset(obj); + + return obj; + } + + HBITMAP CreateCompatibleBitmap(HDC hdc, int nWidth, int nHeight) + { + HBITMAP obj = ::CreateCompatibleBitmap(hdc, nWidth, nHeight); + reset(obj); + + return obj; + } + + HBITMAP CreateDIBSection(HDC hdc, const BITMAPINFO* pbmi, UINT iUsage, void** ppvBits, HANDLE hSection, DWORD dwOffset) + { + HBITMAP obj = ::CreateDIBSection(hdc, pbmi, iUsage, ppvBits, hSection, dwOffset); + reset(obj); + + return obj; + } + + HBITMAP LoadBitmap(HINSTANCE hInstance, LPCTSTR lpBitmapName) + { + HBITMAP obj = ::LoadBitmap(hInstance, lpBitmapName); + reset(obj); + + return obj; + } + + int GetBitmap(BITMAP* pBitMap) + { + ASSERT(m_obj != nullptr); + return ::GetObject(m_obj, sizeof(BITMAP), pBitMap); + } + + int GetDIBSection(DIBSECTION* pDIBSection) + { + ASSERT(m_obj != nullptr); + return ::GetObject(m_obj, sizeof(DIBSECTION), pDIBSection); + } +}; + +class auto_brush : public auto_brush_base +{ +public: + auto_brush(HBRUSH obj = nullptr) : auto_brush_base(obj) {} + + auto_brush& operator = (HBRUSH obj) + { + return (auto_brush&)reset(obj); + } + + HBRUSH CreateDIBPatternBrushPt(const void* lpPackedDIB, UINT iUsage) + { + HBRUSH obj = ::CreateDIBPatternBrushPt(lpPackedDIB, iUsage); + reset(obj); + + return obj; + } + + HBRUSH CreatePatternBrush(HBITMAP hbmp) + { + HBRUSH obj = ::CreatePatternBrush(hbmp); + reset(obj); + + return obj; + } + + HBRUSH CreateSolidBrush(COLORREF crColor) + { + HBRUSH obj = ::CreateSolidBrush(crColor); + reset(obj); + + return obj; + } + + int GetLogBrush(LOGBRUSH* pLogBrush) + { + ASSERT(m_obj != nullptr); + return ::GetObject(m_obj, sizeof(LOGBRUSH), pLogBrush); + } +}; + +class auto_palette : public auto_palette_base +{ +public: + auto_palette(HPALETTE obj = nullptr) : auto_palette_base(obj) {} + + auto_palette& operator = (HPALETTE obj) + { + return (auto_palette&)reset(obj); + } + + HPALETTE CreatePalette(CONST LOGPALETTE* lplgpl) + { + HPALETTE obj = ::CreatePalette(lplgpl); + reset(obj); + + return obj; + } + + int GetEntryCount() + { + ASSERT(m_obj != nullptr); + + WORD nEntries; + ::GetObject(m_obj, sizeof(WORD), &nEntries); + return (int)nEntries; + } +}; + +class auto_pen : public auto_pen_base +{ +public: + auto_pen(HPEN obj = nullptr) : auto_pen_base(obj) {} + + auto_pen& operator = (HPEN obj) + { + return (auto_pen&)reset(obj); + } + + HPEN CreatePen(int fnPenStyle, int nWidth, COLORREF crColor) + { + HPEN obj = ::CreatePen(fnPenStyle, nWidth, crColor); + reset(obj); + + return obj; + } + + HPEN CreatePenIndirect(const LOGPEN* lplgpn) + { + HPEN obj = ::CreatePenIndirect(lplgpn); + reset(obj); + + return obj; + } + + int GetLogPen(LOGPEN* pLogPen) + { + ASSERT(m_obj != nullptr); + return ::GetObject(m_obj, sizeof(LOGPEN), pLogPen); + } +}; + +class auto_rgn : public auto_rgn_base +{ +public: + auto_rgn(HRGN obj = nullptr) : auto_rgn_base(obj) {} + + auto_rgn& operator = (HRGN obj) + { + return (auto_rgn&)reset(obj); + } + + HRGN CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) + { + HRGN obj = ::CreateRectRgn(nLeftRect, nTopRect, nRightRect, nBottomRect); + reset(obj); + + return obj; + } + + HRGN CreateRectRgnIndirect(const RECT* lprc) + { + HRGN obj = ::CreateRectRgnIndirect(lprc); + reset(obj); + + return obj; + } +}; + +class auto_font : public auto_font_base +{ +public: + auto_font(HFONT obj = nullptr) : auto_font_base(obj) {} + + auto_font& operator = (HFONT obj) + { + return (auto_font&)reset(obj); + } + + HFONT CreateFont( + int nHeight, // height of font + int nWidth, // average character width + int nEscapement, // angle of escapement + int nOrientation, // base-line orientation angle + int fnWeight, // font weight + DWORD bItalic, // italic attribute option + DWORD bUnderline, // underline attribute option + DWORD cStrikeOut, // strikeout attribute option + DWORD nCharSet, // character set identifier + DWORD nOutPrecision, // output precision + DWORD nClipPrecision, // clipping precision + DWORD nQuality, // output quality + DWORD nPitchAndFamily, // pitch and family + LPCTSTR lpszFace // typeface name + ) + { + HFONT obj = ::CreateFont( + nHeight, + nWidth, + nEscapement, + nOrientation, + fnWeight, + bItalic, + bUnderline, + cStrikeOut, + nCharSet, + nOutPrecision, + nClipPrecision, + nQuality, + nPitchAndFamily, + lpszFace + ); + reset(obj); + + return obj; + } + + HFONT CreateFontIndirect(const LOGFONT* lplf) + { + HFONT obj = ::CreateFontIndirect(lplf); + reset(obj); + + return obj; + } + + int GetLogFont(LOGFONT* pLogFont) + { + ASSERT(m_obj != nullptr); + return ::GetObject(m_obj, sizeof(LOGFONT), pLogFont); + } +}; diff --git a/Common/Src/bufferpool.cpp b/Common/Src/bufferpool.cpp new file mode 100644 index 000000000..e40eca6f9 --- /dev/null +++ b/Common/Src/bufferpool.cpp @@ -0,0 +1,493 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: BufferPool.cpp +Notices: Copyright (c) 2013 Bruce Liang +Purpose: ڴ滺 +Desc: +******************************************************************************/ + +#include "stdafx.h" +#include "bufferpool.h" +#include "SysHelper.h" +#include "WaitFor.h" + +const DWORD TItem::DEFAULT_ITEM_CAPACITY = ::SysGetPageSize(); +const DWORD CItemPool::DEFAULT_ITEM_CAPACITY = TItem::DEFAULT_ITEM_CAPACITY; +const DWORD CItemPool::DEFAULT_POOL_SIZE = 300; +const DWORD CItemPool::DEFAULT_POOL_HOLD = 1200; +const DWORD CBufferPool::DEFAULT_ITEM_CAPACITY = CItemPool::DEFAULT_ITEM_CAPACITY; +const DWORD CBufferPool::DEFAULT_ITEM_POOL_SIZE = CItemPool::DEFAULT_POOL_SIZE; +const DWORD CBufferPool::DEFAULT_ITEM_POOL_HOLD = CItemPool::DEFAULT_POOL_HOLD; +const DWORD CBufferPool::DEFAULT_BUFFER_LOCK_TIME = 10 * 1000; +const DWORD CBufferPool::DEFAULT_BUFFER_POOL_SIZE = 150; +const DWORD CBufferPool::DEFAULT_BUFFER_POOL_HOLD = 600; + +TItem* TItem::Construct(CPrivateHeap& heap, int capacity, BYTE* pData, int length) +{ + ASSERT(capacity > 0); + + int item_size = sizeof(TItem); + TItem* pItem = (TItem*)heap.Alloc(item_size + capacity); + pItem->head = (BYTE*)pItem + item_size; + + pItem->TItem::TItem(heap, capacity, pData, length); + + return pItem; +} + +void TItem::Destruct(TItem* pItem) +{ + ASSERT(pItem != nullptr); + + CPrivateHeap& heap = pItem->heap; + pItem->TItem::~TItem(); + heap.Free(pItem); +} + +inline int TItem::Cat(const BYTE* pData, int length) +{ + ASSERT(pData != nullptr && length > 0); + + int cat = min(Remain(), length); + + if(cat > 0) + { + memcpy(end, pData, cat); + end += cat; + } + + return cat; +} + +inline int TItem::Cat(const TItem& other) +{ + ASSERT(this != &other); + return Cat(other.Ptr(), other.Size()); +} + +inline int TItem::Fetch(BYTE* pData, int length) +{ + ASSERT(pData != nullptr && length > 0); + + int fetch = min(Size(), length); + memcpy(pData, begin, fetch); + begin += fetch; + + return fetch; +} + +inline int TItem::Peek(BYTE* pData, int length) +{ + ASSERT(pData != nullptr && length > 0); + + int peek = min(Size(), length); + memcpy(pData, begin, peek); + + return peek; +} + +inline int TItem::Reduce(int length) +{ + ASSERT(length > 0); + + int reduce = min(Size(), length); + begin += reduce; + + return reduce; +} + +inline void TItem::Reset(int first, int last) +{ + ASSERT(first >= -1 && first <= capacity); + ASSERT(last >= -1 && last <= capacity); + + if(first >= 0) begin = head + min(first, capacity); + if(last >= 0) end = head + min(last, capacity); +} + +int TItemList::Cat(const BYTE* pData, int length) +{ + int remain = length; + + while(remain > 0) + { + TItem* pItem = Back(); + + if(pItem == nullptr || pItem->IsFull()) + pItem = PushBack(itPool.PickFreeItem()); + + int cat = pItem->Cat(pData, remain); + + pData += cat; + remain -= cat; + } + + return length; +} + +int TItemList::Cat(const TItem* pItem) +{ + return Cat(pItem->Ptr(), pItem->Size()); +} + +int TItemList::Cat(const TItemList& other) +{ + ASSERT(this != &other); + + int length = 0; + + for(TItem* pItem = other.Front(); pItem != nullptr; pItem = pItem->next) + length += Cat(pItem); + + return length; +} + +int TItemList::Fetch(BYTE* pData, int length) +{ + int remain = length; + + while(remain > 0 && Size() > 0) + { + TItem* pItem = Front(); + int fetch = pItem->Fetch(pData, remain); + + pData += fetch; + remain -= fetch; + + if(pItem->IsEmpty()) + itPool.PutFreeItem(PopFront()); + } + + return length - remain; +} + +int TItemList::Peek(BYTE* pData, int length) +{ + int remain = length; + TItem* pItem = Front(); + + while(remain > 0 && pItem != nullptr) + { + int peek = pItem->Peek(pData, remain); + + pData += peek; + remain -= peek; + pItem = pItem->next; + } + + return length - remain; +} + +int TItemList::Reduce(int length) +{ + int remain = length; + + while(remain > 0 && Size() > 0) + { + TItem* pItem = Front(); + remain -= pItem->Reduce(remain); + + if(pItem->IsEmpty()) + itPool.PutFreeItem(PopFront()); + } + + return length - remain; +} + +void TItemList::Release() +{ + itPool.PutFreeItem(*this); +} + +void CItemPool::PutFreeItem(TItem* pItem) +{ + ASSERT(pItem != nullptr); + + if(!m_lsFreeItem.TryPut(pItem)) + TItem::Destruct(pItem); +} + +void CItemPool::PutFreeItem(TItemList& lsItem) +{ + if(lsItem.IsEmpty()) + return; + + TItem* pItem; + while((pItem = lsItem.PopFront()) != nullptr) + PutFreeItem(pItem); +} + +TItem* CItemPool::PickFreeItem() +{ + TItem* pItem = nullptr; + + if(m_lsFreeItem.TryGet(&pItem)) + pItem->Reset(); + else + pItem = TItem::Construct(m_heap, m_dwItemCapacity); + + return pItem; +} + +inline void CItemPool::Prepare() +{ + m_lsFreeItem.Reset(m_dwPoolHold); +} + +inline void CItemPool::Clear() +{ + TItem* pItem = nullptr; + + while(m_lsFreeItem.TryGet(&pItem)) + TItem::Destruct(pItem); + + VERIFY(m_lsFreeItem.IsEmpty()); + m_lsFreeItem.Reset(); + + m_heap.Reset(); +} + +TBuffer* TBuffer::Construct(CBufferPool& pool, ULONG_PTR dwID) +{ + ASSERT(dwID != 0); + + CPrivateHeap& heap = pool.GetPrivateHeap(); + TBuffer* pBuffer = (TBuffer*)heap.Alloc(sizeof(TBuffer)); + + pBuffer->TBuffer::TBuffer(heap, pool.GetItemPool(), dwID); + + return pBuffer; +} + +void TBuffer::Destruct(TBuffer* pBuffer) +{ + ASSERT(pBuffer != nullptr); + + CPrivateHeap& heap = pBuffer->heap; + pBuffer->TBuffer::~TBuffer(); + heap.Free(pBuffer); +} + +inline void TBuffer::Reset() +{ + id = 0; + length = 0; + freeTime = ::TimeGetTime(); +} + +int TBuffer::Cat(const BYTE* pData, int len) +{ + items.Cat(pData, len); + return IncreaseLength(len); +} + +int TBuffer::Cat(const TItem* pItem) +{ + items.Cat(pItem); + return IncreaseLength(pItem->Size()); +} + +int TBuffer::Cat(const TItemList& other) +{ + ASSERT(&items != &other); + + for(TItem* pItem = other.Front(); pItem != nullptr; pItem = pItem->next) + Cat(pItem); + + return length; +} + +int TBuffer::Fetch(BYTE* pData, int len) +{ + int fetch = items.Fetch(pData, len); + DecreaseLength(fetch); + + return fetch; +} + +int TBuffer::Peek(BYTE* pData, int len) +{ + return items.Peek(pData, len); +} + +int TBuffer::Reduce(int len) +{ + int reduce = items.Reduce(len); + DecreaseLength(reduce); + + return reduce; +} + +void CBufferPool::PutFreeBuffer(ULONG_PTR dwID) +{ + ASSERT(dwID != 0); + + TBuffer* pBuffer = FindCacheBuffer(dwID); + + if(pBuffer != nullptr) + { + { + CWriteLock locallock(m_csBufferMap); + m_mpBuffer.erase(dwID); + } + + PutFreeBuffer(pBuffer); + } +} + +void CBufferPool::PutFreeBuffer(TBuffer* pBuffer) +{ + if(!pBuffer->IsValid()) + return; + + BOOL bOK = FALSE; + + { + CCriSecLock locallock(pBuffer->cs); + + if(pBuffer->IsValid()) + { + pBuffer->Reset(); + bOK = TRUE; + } + } + + if(bOK) + { + m_itPool.PutFreeItem(pBuffer->items); + + if(!m_lsFreeBuffer.TryPut(pBuffer)) + { + m_lsGCBuffer.PushBack(pBuffer); + + if(m_lsGCBuffer.Size() > m_dwBufferPoolSize) + ReleaseGCBuffer(); + } + } +} + +void CBufferPool::ReleaseGCBuffer(BOOL bForce) +{ + TBuffer* pBuffer = nullptr; + DWORD now = ::TimeGetTime(); + + while(m_lsGCBuffer.PopFront(&pBuffer)) + { + if(bForce || (now - pBuffer->freeTime) >= m_dwBufferLockTime) + TBuffer::Destruct(pBuffer); + else + { + m_lsGCBuffer.PushBack(pBuffer); + break; + } + } +} + +TBuffer* CBufferPool::PutCacheBuffer(ULONG_PTR dwID) +{ + ASSERT(dwID != 0); + + TBuffer* pBuffer = PickFreeBuffer(dwID); + + { + CWriteLock locallock(m_csBufferMap); + m_mpBuffer[dwID] = pBuffer; + } + + return pBuffer; +} + +TBuffer* CBufferPool::PickFreeBuffer(ULONG_PTR dwID) +{ + ASSERT( dwID != 0); + + DWORD dwIndex; + TBuffer* pBuffer = nullptr; + + if(m_lsFreeBuffer.TryLock(&pBuffer, dwIndex)) + { + if(::GetTimeGap32(pBuffer->freeTime) >= m_dwBufferLockTime) + m_lsFreeBuffer.ReleaseLock(nullptr, dwIndex); + else + { + m_lsFreeBuffer.ReleaseLock(pBuffer, dwIndex); + pBuffer = nullptr; + } + } + + if(pBuffer) pBuffer->id = dwID; + else pBuffer = TBuffer::Construct(*this, dwID); + + ASSERT(pBuffer); + return pBuffer; +} + +TBuffer* CBufferPool::FindCacheBuffer(ULONG_PTR dwID) +{ + ASSERT(dwID != 0); + + TBuffer* pBuffer = nullptr; + + CReadLock locallock(m_csBufferMap); + + TBufferPtrMapCI it = m_mpBuffer.find(dwID); + if(it != m_mpBuffer.end()) + pBuffer = it->second; + + return pBuffer; +} + +void CBufferPool::Prepare() +{ + m_itPool.Prepare(); + m_lsFreeBuffer.Reset(m_dwBufferPoolHold); +} + +void CBufferPool::Clear() +{ + { + CWriteLock locallock(m_csBufferMap); + + for(TBufferPtrMapCI it = m_mpBuffer.begin(), end = m_mpBuffer.end(); it != end; ++it) + TBuffer::Destruct(it->second); + + m_mpBuffer.clear(); + } + + TBuffer* pBuffer = nullptr; + + while(m_lsFreeBuffer.TryGet(&pBuffer)) + TBuffer::Destruct(pBuffer); + + VERIFY(m_lsFreeBuffer.IsEmpty()); + m_lsFreeBuffer.Reset(); + + ReleaseGCBuffer(TRUE); + VERIFY(m_lsGCBuffer.IsEmpty()); + + m_itPool.Clear(); + m_heap.Reset(); +} diff --git a/Common/Src/bufferpool.h b/Common/Src/bufferpool.h new file mode 100644 index 000000000..986a1578a --- /dev/null +++ b/Common/Src/bufferpool.h @@ -0,0 +1,635 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: BufferPool.h +Notices: Copyright (c) 2013 Bruce Liang +Purpose: ڴ滺 +Desc: +******************************************************************************/ + +#pragma once + +#include "RWLock.h" +#include "Singleton.h" +#include "STLHelper.h" +#include "RingBuffer.h" +#include "PrivateHeap.h" + +struct TItem +{ + template + friend struct TSimpleList; + friend struct TItemList; + friend class CItemPool; + friend struct TBuffer; + +public: + inline int Cat (const BYTE* pData, int length); + inline int Cat (const TItem& other); + inline int Fetch (BYTE* pData, int length); + inline int Peek (BYTE* pData, int length); + inline int Reduce (int length); + inline void Reset (int first = 0, int last = 0); + + BYTE* Ptr () {return begin;} + const BYTE* Ptr () const {return begin;} + int Size () const {return (int)(end - begin);} + int Remain () const {return capacity - (int)(end - head);} + int Capacity() const {return capacity;} + bool IsEmpty () const {return Size() == 0;} + bool IsFull () const {return Remain() == 0;} + +public: + operator BYTE* () {return Ptr();} + operator const BYTE* () const {return Ptr();} + +public: + static TItem* Construct(CPrivateHeap& heap, + int capacity = DEFAULT_ITEM_CAPACITY, + BYTE* pData = nullptr, + int length = 0); + + static void Destruct(TItem* pItem); + +private: + TItem(CPrivateHeap& hp, int cap = DEFAULT_ITEM_CAPACITY, BYTE* pData = nullptr, int length = 0) + : heap(hp), capacity(cap), begin(head), end(head), next(nullptr), last(nullptr) + { + if(pData != nullptr && length != 0) + Cat(pData, length); + } + + ~TItem() {} + + DECLARE_NO_COPY_CLASS(TItem) + +public: + static const DWORD DEFAULT_ITEM_CAPACITY; + +private: + CPrivateHeap& heap; + +private: + TItem* next; + TItem* last; + + int capacity; + BYTE* head; + BYTE* begin; + BYTE* end; +}; + +template struct TSimpleList +{ +public: + T* PushFront(T* pItem) + { + if(pFront != nullptr) + { + pFront->last = pItem; + pItem->next = pFront; + } + else + { + pItem->last = nullptr; + pItem->next = nullptr; + pBack = pItem; + } + + pFront = pItem; + ++size; + + return pItem; + } + + T* PushBack(T* pItem) + { + if(pBack != nullptr) + { + pBack->next = pItem; + pItem->last = pBack; + } + else + { + pItem->last = nullptr; + pItem->next = nullptr; + pFront = pItem; + } + + pBack = pItem; + ++size; + + return pItem; + } + + T* PopFront() + { + T* pItem = pFront; + + if(pFront != pBack) + { + pFront = pFront->next; + pFront->last = nullptr; + } + else if(pFront != nullptr) + { + pFront = nullptr; + pBack = nullptr; + } + + if(pItem != nullptr) + { + pItem->next = nullptr; + pItem->last = nullptr; + + --size; + } + + return pItem; + } + + T* PopBack() + { + T* pItem = pBack; + + if(pFront != pBack) + { + pBack = pBack->last; + pBack->next = nullptr; + } + else if(pBack != nullptr) + { + pFront = nullptr; + pBack = nullptr; + } + + if(pItem != nullptr) + { + pItem->next = nullptr; + pItem->last = nullptr; + + --size; + } + + return pItem; + } + + TSimpleList& Shift(TSimpleList& other) + { + if(&other != this && other.size > 0) + { + if(size > 0) + { + pBack->next = other.pFront; + other.pFront->last = pBack; + } + else + { + pFront = other.pFront; + } + + pBack = other.pBack; + size += other.size; + + other.Reset(); + } + + return *this; + } + + void Clear() + { + if(size > 0) + { + T* pItem; + while((pItem = PopFront()) != nullptr) + T::Destruct(pItem); + } + } + + T* Front () const {return pFront;} + T* Back () const {return pBack;} + int Size () const {return size;} + bool IsEmpty () const {return size == 0;} + +public: + TSimpleList() {Reset();} + ~TSimpleList() {Clear();} + + DECLARE_NO_COPY_CLASS(TSimpleList) + +private: + void Reset() + { + pFront = nullptr; + pBack = nullptr; + size = 0; + } + +private: + int size; + T* pFront; + T* pBack; +}; + +struct TItemList : public TSimpleList +{ +public: + int Cat (const BYTE* pData, int length); + int Cat (const TItem* pItem); + int Cat (const TItemList& other); + int Fetch (BYTE* pData, int length); + int Peek (BYTE* pData, int length); + int Reduce (int length); + void Release(); + +public: + TItemList(CItemPool& pool) : itPool(pool) + { + } + +private: + CItemPool& itPool; +}; + +struct TItemListEx : public TItemList +{ +public: + TItem* PushFront(TItem* pItem) + { + length += pItem->Size(); + return __super::PushFront(pItem); + } + + TItem* PushBack(TItem* pItem) + { + length += pItem->Size(); + return __super::PushBack(pItem); + } + + TItem* PopFront() + { + TItem* pItem = __super::PopFront(); + + if(pItem != nullptr) + length -= pItem->Size(); + + return pItem; + } + + TItem* PopBack() + { + TItem* pItem = __super::PopBack(); + + if(pItem != nullptr) + length -= pItem->Size(); + + return pItem; + } + + TItemListEx& Shift(TItemListEx& other) + { + if(&other != this && other.length > 0) + { + length += other.length; + other.length = 0; + + __super::Shift(other); + } + + return *this; + } + + void Clear() + { + __super::Clear(); + length = 0; + } + + void Release() + { + __super::Release(); + length = 0; + } + +public: + int Cat(const BYTE* pData, int length) + { + int cat = __super::Cat(pData, length); + this->length += cat; + + return cat; + } + + int Cat(const TItem* pItem) + { + int cat = __super::Cat(pItem->Ptr(), pItem->Size()); + this->length += cat; + + return cat; + } + + int Cat(const TItemList& other) + { + int cat = __super::Cat(other); + this->length += cat; + + return cat; + } + + int Fetch(BYTE* pData, int length) + { + int fetch = __super::Fetch(pData, length); + this->length -= fetch; + + return fetch; + } + + int Reduce(int length) + { + int reduce = __super::Reduce(length); + this->length -= reduce; + + return reduce; + } + + int Length() const {return length;} + +public: + TItemListEx(CItemPool& pool) : TItemList(pool), length(0) + { + } + + ~TItemListEx() + { + ASSERT(length >= 0); + } + + DECLARE_NO_COPY_CLASS(TItemListEx) + +private: + int length; +}; + +class CItemPool +{ +public: + void PutFreeItem (TItem* pItem); + void PutFreeItem (TItemList& lsItem); + TItem* PickFreeItem (); + + inline void Prepare(); + inline void Clear(); + +public: + void SetItemCapacity(DWORD dwItemCapacity) {m_dwItemCapacity = dwItemCapacity;} + void SetPoolSize (DWORD dwPoolSize) {m_dwPoolSize = dwPoolSize;} + void SetPoolHold (DWORD dwPoolHold) {m_dwPoolHold = dwPoolHold;} + DWORD GetItemCapacity () {return m_dwItemCapacity;} + DWORD GetPoolSize () {return m_dwPoolSize;} + DWORD GetPoolHold () {return m_dwPoolHold;} + +public: + CItemPool( DWORD dwPoolSize = DEFAULT_POOL_SIZE, + DWORD dwPoolHold = DEFAULT_POOL_HOLD, + DWORD dwItemCapacity = DEFAULT_ITEM_CAPACITY) + : m_dwPoolSize(dwPoolSize) + , m_dwPoolHold(dwPoolHold) + , m_dwItemCapacity(dwItemCapacity) + { + } + + ~CItemPool() {Clear();} + + DECLARE_NO_COPY_CLASS(CItemPool) + +public: + static const DWORD DEFAULT_ITEM_CAPACITY; + static const DWORD DEFAULT_POOL_SIZE; + static const DWORD DEFAULT_POOL_HOLD; + +private: + CPrivateHeap m_heap; + + DWORD m_dwItemCapacity; + DWORD m_dwPoolSize; + DWORD m_dwPoolHold; + + CRingPool m_lsFreeItem; +}; + +struct TItemPtr +{ +public: + TItem* Reset(TItem* pItem = nullptr) + { + if(m_pItem != nullptr) + itPool.PutFreeItem(m_pItem); + + m_pItem = pItem; + + return m_pItem; + } + + TItem* Attach(TItem* pItem) + { + return Reset(pItem); + } + + TItem* Detach() + { + TItem* pItem = m_pItem; + m_pItem = nullptr; + + return pItem; + } + + bool IsValid () {return m_pItem != nullptr;} + TItem* operator -> () {return m_pItem;} + TItem* operator = (TItem* pItem) {return Reset(pItem);} + operator TItem* () {return m_pItem;} + TItem* Ptr () {return m_pItem;} + const TItem* Ptr () const {return m_pItem;} + operator const TItem* () const {return m_pItem;} + +public: + TItemPtr(CItemPool& pool, TItem* pItem = nullptr) + : itPool(pool), m_pItem(pItem) + { + + } + + ~TItemPtr() + { + Reset(); + } + + DECLARE_NO_COPY_CLASS(TItemPtr) + +private: + CItemPool& itPool; + TItem* m_pItem; +}; + +struct TBuffer +{ + template friend struct TSimpleList; + friend class CBufferPool; + +public: + static TBuffer* Construct(CBufferPool& pool, ULONG_PTR dwID); + static void Destruct(TBuffer* pBuffer); + +public: + int Cat (const BYTE* pData, int len); + int Cat (const TItem* pItem); + int Cat (const TItemList& other); + int Fetch (BYTE* pData, int length); + int Peek (BYTE* pData, int length); + int Reduce (int len); + +public: + CCriSec& CriSec () {return cs;} + TItemList& ItemList() {return items;} + + ULONG_PTR ID () const {return id;} + int Length () const {return length;} + bool IsValid () const {return id != 0;} + +private: + int IncreaseLength (int len) {return (length += len);} + int DecreaseLength (int len) {return (length -= len);} + + inline void Reset (); + +private: + TBuffer(CPrivateHeap& hp, CItemPool& itPool, ULONG_PTR dwID = 0) + : heap(hp), items(itPool), id(dwID), length(0) + { + } + + ~TBuffer() {} + + DECLARE_NO_COPY_CLASS(TBuffer) + +private: + CPrivateHeap& heap; + +private: + ULONG_PTR id; + int length; + DWORD freeTime; + +private: + TBuffer* next; + TBuffer* last; + + CCriSec cs; + TItemList items; +}; + +class CBufferPool +{ + typedef CRingPool TBufferList; + typedef CCASQueue TBufferQueue; + + typedef unordered_map TBufferPtrMap; + typedef TBufferPtrMap::iterator TBufferPtrMapI; + typedef TBufferPtrMap::const_iterator TBufferPtrMapCI; + +public: + void PutFreeBuffer (ULONG_PTR dwID); + TBuffer* PutCacheBuffer (ULONG_PTR dwID); + TBuffer* FindCacheBuffer (ULONG_PTR dwID); + TBuffer* PickFreeBuffer (ULONG_PTR dwID); + void PutFreeBuffer (TBuffer* pBuffer); + + void Prepare (); + void Clear (); + +private: + void ReleaseGCBuffer (BOOL bForce = FALSE); + +public: + void SetItemCapacity (DWORD dwItemCapacity) {m_itPool.SetItemCapacity(dwItemCapacity);} + void SetItemPoolSize (DWORD dwItemPoolSize) {m_itPool.SetPoolSize(dwItemPoolSize);} + void SetItemPoolHold (DWORD dwItemPoolHold) {m_itPool.SetPoolHold(dwItemPoolHold);} + + void SetBufferLockTime (DWORD dwBufferLockTime) {m_dwBufferLockTime = dwBufferLockTime;} + void SetBufferPoolSize (DWORD dwBufferPoolSize) {m_dwBufferPoolSize = dwBufferPoolSize;} + void SetBufferPoolHold (DWORD dwBufferPoolHold) {m_dwBufferPoolHold = dwBufferPoolHold;} + + DWORD GetItemCapacity () {return m_itPool.GetItemCapacity();} + DWORD GetItemPoolSize () {return m_itPool.GetPoolSize();} + DWORD GetItemPoolHold () {return m_itPool.GetPoolHold();} + + DWORD GetBufferLockTime () {return m_dwBufferLockTime;} + DWORD GetBufferPoolSize () {return m_dwBufferPoolSize;} + DWORD GetBufferPoolHold () {return m_dwBufferPoolHold;} + + TBuffer* operator [] (ULONG_PTR dwID) {return FindCacheBuffer(dwID);} + +public: + CBufferPool(DWORD dwPoolSize = DEFAULT_BUFFER_POOL_SIZE, + DWORD dwPoolHold = DEFAULT_BUFFER_POOL_HOLD, + DWORD dwLockTime = DEFAULT_BUFFER_LOCK_TIME, + DWORD dwItemCapacity = DEFAULT_ITEM_CAPACITY) + : m_dwBufferPoolSize(dwPoolSize) + , m_dwBufferPoolHold(dwPoolHold) + , m_dwBufferLockTime(dwLockTime) + { + m_itPool.SetItemCapacity(dwItemCapacity); + } + + ~CBufferPool() {Clear();} + + DECLARE_NO_COPY_CLASS(CBufferPool) + +public: + CPrivateHeap& GetPrivateHeap() {return m_heap;} + CItemPool& GetItemPool() {return m_itPool;} + +public: + static const DWORD DEFAULT_ITEM_CAPACITY; + static const DWORD DEFAULT_ITEM_POOL_SIZE; + static const DWORD DEFAULT_ITEM_POOL_HOLD; + static const DWORD DEFAULT_BUFFER_LOCK_TIME; + static const DWORD DEFAULT_BUFFER_POOL_SIZE; + static const DWORD DEFAULT_BUFFER_POOL_HOLD; + +private: + DWORD m_dwBufferLockTime; + DWORD m_dwBufferPoolSize; + DWORD m_dwBufferPoolHold; + + CPrivateHeap m_heap; + CItemPool m_itPool; + + CSimpleRWLock m_csBufferMap; + TBufferPtrMap m_mpBuffer; + + TBufferList m_lsFreeBuffer; + TBufferQueue m_lsGCBuffer; +}; diff --git a/Common/Src/bufferptr.cpp b/Common/Src/bufferptr.cpp new file mode 100644 index 000000000..129d42972 --- /dev/null +++ b/Common/Src/bufferptr.cpp @@ -0,0 +1,26 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "bufferptr.h" diff --git a/Common/Src/bufferptr.h b/Common/Src/bufferptr.h new file mode 100644 index 000000000..af818be0f --- /dev/null +++ b/Common/Src/bufferptr.h @@ -0,0 +1,184 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +template +class CBufferPtrT +{ +public: + explicit CBufferPtrT(size_t size = 0, bool zero = false) {Reset(); Malloc(size, zero);} + explicit CBufferPtrT(const T* pch, size_t size) {Reset(); Copy(pch, size);} + CBufferPtrT(const CBufferPtrT& other) {Reset(); Copy(other);} + template CBufferPtrT(const CBufferPtrT& other) {Reset(); Copy(other);} + + ~CBufferPtrT() {Free();} + + T* Malloc(size_t size = 1, bool zero = false) + { + Free(); + return Alloc(size, zero, false); + } + + T* Realloc(size_t size, bool zero = false) + { + return Alloc(size, zero, true); + } + + void Free() + { + if(m_pch) + { + free(m_pch); + Reset(); + } + } + + template CBufferPtrT& Copy(const CBufferPtrT& other) + { + if((void*)&other != (void*)this) + Copy(other.Ptr(), other.Size()); + + return *this; + } + + CBufferPtrT& Copy(const T* pch, size_t size) + { + Malloc(size); + + if(m_pch) + memcpy(m_pch, pch, size * sizeof(T)); + + return *this; + } + + template CBufferPtrT& Cat(const CBufferPtrT& other) + { + if((void*)&other != (void*)this) + Cat(other.Ptr(), other.Size()); + + return *this; + } + + CBufferPtrT& Cat(const T* pch, size_t size = 1) + { + size_t pre_size = m_size; + Realloc(m_size + size); + + if(m_pch) + memcpy(m_pch + pre_size, pch, size * sizeof(T)); + + return *this; + } + + template bool Equal(const CBufferPtrT& other) const + { + if((void*)&other == (void*)this) + return true; + else if(m_size != other.Size()) + return false; + else if(m_size == 0) + return true; + else + return (memcmp(m_pch, other.Ptr(), m_size * sizeof(T)) == 0); + } + + bool Equal(T* pch) const + { + if(m_pch == pch) + return true; + else if(!m_pch || !pch) + return false; + else + return (memcmp(m_pch, pch, m_size * sizeof(T)) == 0); + } + + T* Ptr() {return m_pch;} + const T* Ptr() const {return m_pch;} + T& Get(int i) {return *(m_pch + i);} + const T& Get(int i) const {return *(m_pch + i);} + size_t Size() const {return m_size;} + bool IsValid() const {return m_pch != 0;} + + operator T* () {return Ptr();} + operator const T* () const {return Ptr();} + T& operator [] (int i) {return Get(i);} + const T& operator [] (int i) const {return Get(i);} + bool operator == (T* pv) const {return Equal(pv);} + template bool operator == (const CBufferPtrT& other) {return Equal(other);} + CBufferPtrT& operator = (const CBufferPtrT& other) {return Copy(other);} + template CBufferPtrT& operator = (const CBufferPtrT& other) {return Copy(other);} + +private: + void Reset() {m_pch = 0; m_size = 0; m_capacity = 0;} + size_t GetAllocSize(size_t size) {return max(size, min(size * 2, m_size + MAX_CACHE_SIZE));} + + T* Alloc(size_t size, bool zero = false, bool is_realloc = false) + { + if(size >= 0 && size != m_size) + { + size_t rsize = GetAllocSize(size); + if(size > m_capacity || rsize < m_size) + { + m_pch = is_realloc ? + (T*)realloc(m_pch, rsize * sizeof(T)) : + (T*)malloc(rsize * sizeof(T)) ; + + if(m_pch || rsize == 0) + { + m_size = size; + m_capacity = rsize; + } + else + Reset(); + } + else + m_size = size; + } + + if(zero && m_pch) + memset(m_pch, 0, m_size * sizeof(T)); + + return m_pch; + } + +private: + T* m_pch; + size_t m_size; + size_t m_capacity; +}; + +typedef CBufferPtrT CCharBufferPtr; +typedef CBufferPtrT CWCharBufferPtr; +typedef CBufferPtrT CByteBufferPtr; +typedef CByteBufferPtr CBufferPtr; + +#ifdef _UNICODE + typedef CWCharBufferPtr CTCharBufferPtr; +#else + typedef CCharBufferPtr CTCharBufferPtr; +#endif diff --git a/Common/Src/debug/win32_crtdbg.cpp b/Common/Src/debug/win32_crtdbg.cpp new file mode 100644 index 000000000..a24cbe1f3 --- /dev/null +++ b/Common/Src/debug/win32_crtdbg.cpp @@ -0,0 +1,32 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "win32_crtdbg.h" + +#if defined _DEBUG && defined _DETECT_MEMORY_LEAK + +__dbg_impl::CDebugEnv __dbgEnv; + +#endif // _DEBUG && defined _DETECT_MEMORY_LEAK diff --git a/Common/Src/debug/win32_crtdbg.h b/Common/Src/debug/win32_crtdbg.h new file mode 100644 index 000000000..1607e6641 --- /dev/null +++ b/Common/Src/debug/win32_crtdbg.h @@ -0,0 +1,138 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 2.3.11 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#if defined _DEBUG && defined _DETECT_MEMORY_LEAK + +#ifdef new + #undef new +#endif + +#ifdef delete + #undef delete +#endif + +#ifndef _CRTDBG_MAP_ALLOC + #define _CRTDBG_MAP_ALLOC +#endif + +#include + +namespace __dbg_impl +{ + class CDebugEnv + { + public: + CDebugEnv() + { + ::_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); + ::_CrtMemCheckpoint(&s1); + } + + ~CDebugEnv() + { + ::_CrtMemCheckpoint(&s2); + + if (::_CrtMemDifference( &s3, &s1, &s2)) + { + TRACE("!! Memory stats !!\n"); + TRACE("----------------------------------------\n"); + ::_CrtMemDumpStatistics(&s3); + TRACE("----------------------------------------\n"); + } + } + + private: + _CrtMemState s1, s2, s3; + }; + + static __dbg_impl::CDebugEnv __dbgEnv; +} + +inline void* __cdecl operator new(size_t nSize, const char* lpszFileName, int nLine) +{ + // __dbg_impl::CGuard guard; + return ::_malloc_dbg(nSize, _NORMAL_BLOCK, lpszFileName, nLine); +} + +inline void* __cdecl operator new[](size_t nSize, const char* lpszFileName, int nLine) +{ + return operator new(nSize, lpszFileName, nLine); +} + +inline void* __cdecl operator new(size_t nSize) +{ + return operator new(nSize, __FILE__, __LINE__); +} + +inline void* __cdecl operator new[](size_t nSize) +{ + return operator new(nSize, __FILE__, __LINE__); +} + +inline void* __cdecl operator new(size_t nSize, const std::nothrow_t&) +{ + return operator new(nSize, __FILE__, __LINE__); +} + +inline void* __cdecl operator new[](size_t nSize, const std::nothrow_t&) +{ + return operator new(nSize, __FILE__, __LINE__); +} + +inline void __cdecl operator delete(void* p) +{ + // __dbg_impl::CGuard guard; + ::_free_dbg(p, _NORMAL_BLOCK); +} + +inline void __cdecl operator delete[](void* p) +{ + operator delete(p); +} + +inline void __cdecl operator delete(void* p, const char* lpszFileName, int nLine) +{ + operator delete(p); +} + +inline void __cdecl operator delete[](void* p, const char* lpszFileName, int nLine) +{ + operator delete(p); +} + +inline void __cdecl operator delete(void *p, const std::nothrow_t&) +{ + operator delete(p); +} + +inline void __cdecl operator delete[](void *p, const std::nothrow_t&) +{ + operator delete(p); +} + +#define new new(__FILE__, __LINE__) + +#endif // _DEBUG && defined _DETECT_MEMORY_LEAK diff --git a/Doc/HP-Socket Class Diagram - v3.4.jpg b/Doc/HP-Socket Class Diagram - v3.4.jpg new file mode 100644 index 000000000..636652052 Binary files /dev/null and b/Doc/HP-Socket Class Diagram - v3.4.jpg differ diff --git a/Doc/HP-Socket Class Diagram - v3.4.uml b/Doc/HP-Socket Class Diagram - v3.4.uml new file mode 100644 index 000000000..0d2d10bc4 --- /dev/null +++ b/Doc/HP-Socket Class Diagram - v3.4.uml @@ -0,0 +1,26733 @@ + + + + + + +UMLStandard + + + + +HP-Socket +5 + +Use Case Model +UMLStandard +useCaseModel +eUBxTmzIc0q+cSu3hl5+hQAA + + +Analysis Model +UMLStandard +analysisModel +eUBxTmzIc0q+cSu3hl5+hQAA + + +Design Model +UMLStandard +designModel +eUBxTmzIc0q+cSu3hl5+hQAA +7 + +IAgent +jvfBmo6uGkC61ckI99TMgAAA + +7r43eRqUAUeehz+M/cmZ+wAA +13 + +clMaroon +$00B9FFFF +10 +400 +212 +616 +596 +True +SqNjwMrIrEaWmScJhNPQOwAA + + +3 +IComplexSocket + + +False + + +False + + + +False +SqNjwMrIrEaWmScJhNPQOwAA + + +SqNjwMrIrEaWmScJhNPQOwAA + + +False +SqNjwMrIrEaWmScJhNPQOwAA + + + +clMaroon +$00B9FFFF +10 +408 +908 +601 +84 +True +tc20+9LmREuR1dUMSybNdQAA + + +1 +IAgent + + +False + + +False + + + +False +tc20+9LmREuR1dUMSybNdQAA + + +tc20+9LmREuR1dUMSybNdQAA + + +False +tc20+9LmREuR1dUMSybNdQAA + + + +clMaroon +$00B9FFFF +10 +708,908;708,807 +dx6I5RGr20SmTHCEMdZ9nAAA +S5CdZWL+bEWmCJb9qIaNogAA +QK3KaQ4YV0Wt4DUTuGttgwAA + +False +1.5707963267949 +15 +dx6I5RGr20SmTHCEMdZ9nAAA + + +False +1.5707963267949 +30 +dx6I5RGr20SmTHCEMdZ9nAAA + + +False +-1.5707963267949 +15 +dx6I5RGr20SmTHCEMdZ9nAAA + + + +clMaroon +$00ACFFD6 +10 +392 +1068 +630 +180 +True +ilTzVOgexUSPHrK2FSqS9wAA + + +1 +ITcpAgent + + +False + + +False + + + +False +ilTzVOgexUSPHrK2FSqS9wAA + + +ilTzVOgexUSPHrK2FSqS9wAA + + +False +ilTzVOgexUSPHrK2FSqS9wAA + + + +clMaroon +$00B9FFFF +10 +707,1068;708,991 +T7qvCRD8oEeFVhOYfk7D4wAA +QK3KaQ4YV0Wt4DUTuGttgwAA +qWQ9xcWqTk+Q37ac+Zc5cwAA + +False +1.5707963267949 +15 +T7qvCRD8oEeFVhOYfk7D4wAA + + +False +1.5707963267949 +30 +T7qvCRD8oEeFVhOYfk7D4wAA + + +False +-1.5707963267949 +15 +T7qvCRD8oEeFVhOYfk7D4wAA + + + +clMaroon +$0000C4C4 +10 +820 +1268 +411 +84 +True +BaqYQl/65Uy16GMJC7nLawAA + + +1 +IPullSocket + + +False + + +False + + + +False +BaqYQl/65Uy16GMJC7nLawAA + + +BaqYQl/65Uy16GMJC7nLawAA + + +False +BaqYQl/65Uy16GMJC7nLawAA + + + +clMaroon +$00FFD9FF +10 +724 +1440 +279 +68 +True +QvkeGvTpWU2SJ0MXVIx/AwAA + + +1 +ITcpPullAgent + + +False + + +False + + + +False +QvkeGvTpWU2SJ0MXVIx/AwAA + + +QvkeGvTpWU2SJ0MXVIx/AwAA + + +False +QvkeGvTpWU2SJ0MXVIx/AwAA + + + +clMaroon +$00B9FFFF +10 +896,1440;984,1351 +krwZJNbQpUee1OjG3HesgAAA +XJoHYNGE7keWE488T/cGaQAA ++2HvTQsUAk+HjQ5fXiU8owAA + +False +1.5707963267949 +15 +krwZJNbQpUee1OjG3HesgAAA + + +False +1.5707963267949 +30 +krwZJNbQpUee1OjG3HesgAAA + + +False +-1.5707963267949 +15 +krwZJNbQpUee1OjG3HesgAAA + + + +clMaroon +$00B9FFFF +10 +847,1440;751,1247 +Vo9KdG21TU67s/EtgyfoVQAA +qWQ9xcWqTk+Q37ac+Zc5cwAA ++2HvTQsUAk+HjQ5fXiU8owAA + +False +1.5707963267949 +15 +Vo9KdG21TU67s/EtgyfoVQAA + + +False +1.5707963267949 +30 +Vo9KdG21TU67s/EtgyfoVQAA + + +False +-1.5707963267949 +15 +Vo9KdG21TU67s/EtgyfoVQAA + + + +clMaroon +$0000C4C4 +10 +160 +1268 +332 +116 +True +Pv24uWWaqUu82r7VGD3ZNwAA + + +1 +IPackSocket + + +False + + +False + + + +False +Pv24uWWaqUu82r7VGD3ZNwAA + + +Pv24uWWaqUu82r7VGD3ZNwAA + + +False +Pv24uWWaqUu82r7VGD3ZNwAA + + + +clMaroon +$00FFD9FF +10 +408 +1440 +291 +68 +True +vjFkGLWb/kSPpbp9R+skbAAA + + +1 +ITcpPackAgent + + +False + + +False + + + +False +vjFkGLWb/kSPpbp9R+skbAAA + + +vjFkGLWb/kSPpbp9R+skbAAA + + +False +vjFkGLWb/kSPpbp9R+skbAAA + + + +clMaroon +$00B9FFFF +502,1440;414,1383 +WUHNHDfka0O+CbvKWj/7kQAA +2NPkGxsE60eclahgOjVMgAAA +mDfdT1ptZk64YFRjy+qMOgAA + +False +1.5707963267949 +15 +WUHNHDfka0O+CbvKWj/7kQAA + + +False +1.5707963267949 +30 +WUHNHDfka0O+CbvKWj/7kQAA + + +False +-1.5707963267949 +15 +WUHNHDfka0O+CbvKWj/7kQAA + + + +clMaroon +$00B9FFFF +569,1440;662,1247 +lqZ7xgrWKkewtFXoEKU2+AAA +qWQ9xcWqTk+Q37ac+Zc5cwAA +mDfdT1ptZk64YFRjy+qMOgAA + +False +1.5707963267949 +15 +lqZ7xgrWKkewtFXoEKU2+AAA + + +False +1.5707963267949 +30 +lqZ7xgrWKkewtFXoEKU2+AAA + + +False +-1.5707963267949 +15 +lqZ7xgrWKkewtFXoEKU2+AAA + + + + + +IServer +jvfBmo6uGkC61ckI99TMgAAA + +XkkHyTpx50CZnVOHpJQXdAAA +15 + +clMaroon +$00AAFFD5 +10 +796 +992 +356 +164 +True +KqnhKB+uXkKxW6LqS8YzcgAA + + +1 +IUdpServer + + +False + + +False + + + +False +KqnhKB+uXkKxW6LqS8YzcgAA + + +KqnhKB+uXkKxW6LqS8YzcgAA + + +False +KqnhKB+uXkKxW6LqS8YzcgAA + + + +clMaroon +$00FFE1FF +10 +692 +1420 +289 +68 +True +gJKazn/X+U6+FJp/F2soRAAA + + +1 +ITcpPullServer + + +False + + +False + + + +False +gJKazn/X+U6+FJp/F2soRAAA + + +gJKazn/X+U6+FJp/F2soRAAA + + +False +gJKazn/X+U6+FJp/F2soRAAA + + + +clMaroon +$00AAFFD5 +10 +152 +992 +630 +212 +True +YNdJIJRIm0SpW7CG17MtyAAA + + +1 +ITcpServer + + +False + + +False + + + +False +YNdJIJRIm0SpW7CG17MtyAAA + + +YNdJIJRIm0SpW7CG17MtyAAA + + +False +YNdJIJRIm0SpW7CG17MtyAAA + + + +clMaroon +$00B9FFFF +10 +802,1420;576,1203 +RvwWYNXraU2xkdsooYM/NwAA +yPFqE92KlUeCTsjNeQePJAAA +PK1lPcGwCkO4ClijCg6U4QAA + +False +1.5707963267949 +15 +RvwWYNXraU2xkdsooYM/NwAA + + +False +1.5707963267949 +30 +RvwWYNXraU2xkdsooYM/NwAA + + +False +-1.5707963267949 +15 +RvwWYNXraU2xkdsooYM/NwAA + + + +clMaroon +$00B9FFFF +10 +360 +824 +485 +68 +True +GoHMKPRtzES/2hlDzLtwnAAA + + +1 +IServer + + +False + + +False + + + +False +GoHMKPRtzES/2hlDzLtwnAAA + + +GoHMKPRtzES/2hlDzLtwnAAA + + +False +GoHMKPRtzES/2hlDzLtwnAAA + + + +clMaroon +$00B9FFFF +10 +526,992;583,891 +qrDg6u3xU0KpgYiFoJBZ1AAA +P2r46P+bY0avZFfVkwtncQAA +yPFqE92KlUeCTsjNeQePJAAA + +False +1.5707963267949 +15 +qrDg6u3xU0KpgYiFoJBZ1AAA + + +False +1.5707963267949 +30 +qrDg6u3xU0KpgYiFoJBZ1AAA + + +False +-1.5707963267949 +15 +qrDg6u3xU0KpgYiFoJBZ1AAA + + + +clMaroon +$00B9FFFF +10 +834,992;660,891 +rcZqqPur/USLxxaOeNdjswAA +P2r46P+bY0avZFfVkwtncQAA +DCejEAT0mUabtDsSdi+dvQAA + +False +1.5707963267949 +15 +rcZqqPur/USLxxaOeNdjswAA + + +False +1.5707963267949 +30 +rcZqqPur/USLxxaOeNdjswAA + + +False +-1.5707963267949 +15 +rcZqqPur/USLxxaOeNdjswAA + + + +clMaroon +$00B9FFFF +10 +296 +116 +616 +596 +True +SqNjwMrIrEaWmScJhNPQOwAA + + +3 +IComplexSocket + + +False + + +False + + + +False +SqNjwMrIrEaWmScJhNPQOwAA + + +SqNjwMrIrEaWmScJhNPQOwAA + + +False +SqNjwMrIrEaWmScJhNPQOwAA + + + +clMaroon +$00B9FFFF +10 +602,824;602,711 +9BTtNyRQHEu7yKoNswewcQAA +MbT+AK7qSEilQO9f6kF5ugAA +P2r46P+bY0avZFfVkwtncQAA + +False +1.5707963267949 +15 +9BTtNyRQHEu7yKoNswewcQAA + + +False +1.5707963267949 +30 +9BTtNyRQHEu7yKoNswewcQAA + + +False +-1.5707963267949 +15 +9BTtNyRQHEu7yKoNswewcQAA + + + +clMaroon +$0000C4C4 +10 +740 +1244 +411 +84 +True +BaqYQl/65Uy16GMJC7nLawAA + + +1 +IPullSocket + + +False + + +False + + + +False +BaqYQl/65Uy16GMJC7nLawAA + + +BaqYQl/65Uy16GMJC7nLawAA + + +False +BaqYQl/65Uy16GMJC7nLawAA + + + +clMaroon +$00B9FFFF +10 +857,1420;918,1327 +ETiy7j/ak0iclwwFrOCPHwAA +RHC6AHfVy0Gw4f4lr8UMCwAA +PK1lPcGwCkO4ClijCg6U4QAA + +False +1.5707963267949 +15 +ETiy7j/ak0iclwwFrOCPHwAA + + +False +1.5707963267949 +30 +ETiy7j/ak0iclwwFrOCPHwAA + + +False +-1.5707963267949 +15 +ETiy7j/ak0iclwwFrOCPHwAA + + + +clMaroon +$0000C4C4 +10 +104 +1244 +332 +116 +True +Pv24uWWaqUu82r7VGD3ZNwAA + + +1 +IPackSocket + + +False + + +False + + + +False +Pv24uWWaqUu82r7VGD3ZNwAA + + +Pv24uWWaqUu82r7VGD3ZNwAA + + +False +Pv24uWWaqUu82r7VGD3ZNwAA + + + +clMaroon +$00FFE1FF +10 +316 +1420 +301 +68 +True +aDgNVKZkT029alZKzju1xAAA + + +1 +ITcpPackServer + + +False + + +False + + + +False +aDgNVKZkT029alZKzju1xAAA + + +aDgNVKZkT029alZKzju1xAAA + + +False +aDgNVKZkT029alZKzju1xAAA + + + +clMaroon +$00B9FFFF +423,1420;344,1359 +sgmcH4+s1Em05SzAjJdHjAAA +XsluK/m59E+/IMf4Y9b0rAAA +IxgSYDxQe0qqAConM0HORwAA + +False +1.5707963267949 +15 +sgmcH4+s1Em05SzAjJdHjAAA + + +False +1.5707963267949 +30 +sgmcH4+s1Em05SzAjJdHjAAA + + +False +-1.5707963267949 +15 +sgmcH4+s1Em05SzAjJdHjAAA + + + +clMaroon +$00B9FFFF +466,1420;466,1203 +nzQ/3s2PQEG5Cz2AX+hkOgAA +yPFqE92KlUeCTsjNeQePJAAA +IxgSYDxQe0qqAConM0HORwAA + +False +1.5707963267949 +15 +nzQ/3s2PQEG5Cz2AX+hkOgAA + + +False +1.5707963267949 +30 +nzQ/3s2PQEG5Cz2AX+hkOgAA + + +False +-1.5707963267949 +15 +nzQ/3s2PQEG5Cz2AX+hkOgAA + + + + + +IClient +jvfBmo6uGkC61ckI99TMgAAA + +uCy/ysBYx02nqqthkKdfbgAA +15 + +clMaroon +$00B9FFFF +10 +744 +264 +503 +324 +True +R8hLgFt1fEaSSxBO7KbEBQAA + + +1 +IClient + + +False + + +False + + + +False +R8hLgFt1fEaSSxBO7KbEBQAA + + +R8hLgFt1fEaSSxBO7KbEBQAA + + +False +R8hLgFt1fEaSSxBO7KbEBQAA + + + +clMaroon +$00B0FFD8 +10 +404 +668 +510 +148 +True +CqUqbTfjd0mBGFOXrmWVDgAA + + +1 +ITcpClient + + +False + + +False + + + +False +CqUqbTfjd0mBGFOXrmWVDgAA + + +CqUqbTfjd0mBGFOXrmWVDgAA + + +False +CqUqbTfjd0mBGFOXrmWVDgAA + + + +clMaroon +$00B9FFFF +10 +736,668;822,587 +dOpAHC5JfkymmNyAgeRwWAAA +IxwL95gLAk2VVqCaT07mZwAA +nQs4ohjRpkGJ66FalNzxdwAA + +False +1.5707963267949 +15 +dOpAHC5JfkymmNyAgeRwWAAA + + +False +1.5707963267949 +30 +dOpAHC5JfkymmNyAgeRwWAAA + + +False +-1.5707963267949 +15 +dOpAHC5JfkymmNyAgeRwWAAA + + + +clMaroon +$00B0FFD8 +10 +1160 +668 +356 +132 +True +s/XSjWMZB0WwUzzarQOzNgAA + + +1 +IUdpClient + + +False + + +False + + + +False +s/XSjWMZB0WwUzzarQOzNgAA + + +s/XSjWMZB0WwUzzarQOzNgAA + + +False +s/XSjWMZB0WwUzzarQOzNgAA + + + +clMaroon +$00B9FFFF +10 +1265,668;1175,587 +VhVmNVhKIEyRJWflThCsqQAA +IxwL95gLAk2VVqCaT07mZwAA +F1H1FgAQo0KwYhAVsIoSYQAA + +False +1.5707963267949 +15 +VhVmNVhKIEyRJWflThCsqQAA + + +False +1.5707963267949 +30 +VhVmNVhKIEyRJWflThCsqQAA + + +False +-1.5707963267949 +15 +VhVmNVhKIEyRJWflThCsqQAA + + + +clMaroon +$00B0FFD8 +10 +1160 +856 +496 +244 +True +6HMIzI9avUGHDCpvqmkdqQAA + + +1 +IUdpCast + + +False + + +False + + + +False +6HMIzI9avUGHDCpvqmkdqQAA + + +6HMIzI9avUGHDCpvqmkdqQAA + + +False +6HMIzI9avUGHDCpvqmkdqQAA + + + +clMaroon +$00B9FFFF +10 +1160,976;1140,976;1038,587 +MejA8cLC00G/Y3QcvCU6BgAA +IxwL95gLAk2VVqCaT07mZwAA +pliWbIwkj0yRgSGaHICnEAAA + +False +1.5707963267949 +15 +MejA8cLC00G/Y3QcvCU6BgAA + + +False +1.5707963267949 +30 +MejA8cLC00G/Y3QcvCU6BgAA + + +False +-1.5707963267949 +15 +MejA8cLC00G/Y3QcvCU6BgAA + + + +clMaroon +$0000C4C4 +10 +796 +852 +291 +84 +True +LPfLjDLmzkKy/sn51dyX7gAA + + +1 +IPullClient + + +False + + +False + + + +False +LPfLjDLmzkKy/sn51dyX7gAA + + +LPfLjDLmzkKy/sn51dyX7gAA + + +False +LPfLjDLmzkKy/sn51dyX7gAA + + + +clMaroon +$00FFE1FF +10 +724 +1032 +265 +68 +True +SjUoRiw3TUOE/FQirpeMogAA + + +1 +ITcpPullClient + + +False + + +False + + + +False +SjUoRiw3TUOE/FQirpeMogAA + + +SjUoRiw3TUOE/FQirpeMogAA + + +False +SjUoRiw3TUOE/FQirpeMogAA + + + +clMaroon +$00B9FFFF +10 +872,1032;920,935 +wIyBqLGeaEauN2RIkujQrAAA +KeV/t2xsK0+PmCUPXcqplgAA +zqmdKXYEt0GXqYV17S23CAAA + +False +1.5707963267949 +15 +wIyBqLGeaEauN2RIkujQrAAA + + +False +1.5707963267949 +30 +wIyBqLGeaEauN2RIkujQrAAA + + +False +-1.5707963267949 +15 +wIyBqLGeaEauN2RIkujQrAAA + + + +clMaroon +$00B9FFFF +10 +836,1032;703,815 +GJ1pEOa7xE+Vx6DHIVvLbwAA +nQs4ohjRpkGJ66FalNzxdwAA +zqmdKXYEt0GXqYV17S23CAAA + +False +1.5707963267949 +15 +GJ1pEOa7xE+Vx6DHIVvLbwAA + + +False +1.5707963267949 +30 +GJ1pEOa7xE+Vx6DHIVvLbwAA + + +False +-1.5707963267949 +15 +GJ1pEOa7xE+Vx6DHIVvLbwAA + + + +clMaroon +$0000C4C4 +10 +252 +852 +332 +116 +True +tvyRlzR70kaEb8akK1WldwAA + + +1 +IPackClient + + +False + + +False + + + +False +tvyRlzR70kaEb8akK1WldwAA + + +tvyRlzR70kaEb8akK1WldwAA + + +False +tvyRlzR70kaEb8akK1WldwAA + + + +clMaroon +$00FFE1FF +10 +432 +1032 +277 +68 +True +NI0md/XcXk+UFEOqL+89owAA + + +1 +ITcpPackClient + + +False + + +False + + + +False +NI0md/XcXk+UFEOqL+89owAA + + +NI0md/XcXk+UFEOqL+89owAA + + +False +NI0md/XcXk+UFEOqL+89owAA + + + +clMaroon +$00B9FFFF +538,1032;474,967 +xly9lJtUukKwQ90VKrZR2AAA +iW4CiDDhyEqlkb7itLSOuQAA +q5juGoWzLEGEpbKgLo4flwAA + +False +1.5707963267949 +15 +xly9lJtUukKwQ90VKrZR2AAA + + +False +1.5707963267949 +30 +xly9lJtUukKwQ90VKrZR2AAA + + +False +-1.5707963267949 +15 +xly9lJtUukKwQ90VKrZR2AAA + + + +clMaroon +$00B9FFFF +579,1032;638,815 +l44zgodkDEuj17c7XdoPSQAA +nQs4ohjRpkGJ66FalNzxdwAA +q5juGoWzLEGEpbKgLo4flwAA + +False +1.5707963267949 +15 +l44zgodkDEuj17c7XdoPSQAA + + +False +1.5707963267949 +30 +l44zgodkDEuj17c7XdoPSQAA + + +False +-1.5707963267949 +15 +l44zgodkDEuj17c7XdoPSQAA + + + + + +IServerListener +jvfBmo6uGkC61ckI99TMgAAA + +xn9zLgCPSEOGJJQt03HCoAAA +7 + +clMaroon +$00B9FFFF +10 +516 +132 +571 +132 +9FsvxqZjkEyUqc9w2NDcQgAA + + +1 +IComplexSocketListener + + +False + + +False + + + +False +9FsvxqZjkEyUqc9w2NDcQgAA + + +9FsvxqZjkEyUqc9w2NDcQgAA + + +False +9FsvxqZjkEyUqc9w2NDcQgAA + + + +clMaroon +$00B9FFFF +10 +640 +328 +321 +52 +SX/KZkmsDk+r8uamHH4ZLgAA + + +1 +IServerListener + + +False + + +False + + + +False +SX/KZkmsDk+r8uamHH4ZLgAA + + +SX/KZkmsDk+r8uamHH4ZLgAA + + +False +SX/KZkmsDk+r8uamHH4ZLgAA + + + +clMaroon +$00B9FFFF +10 +800,328;800,263 +sCzG9DqxZkGTaKemcfKYcAAA +EY7frgNjn025AVRzjddHWgAA +1XW3u/7OaUqWSnACglXKhgAA + +False +1.5707963267949 +15 +sCzG9DqxZkGTaKemcfKYcAAA + + +False +1.5707963267949 +30 +sCzG9DqxZkGTaKemcfKYcAAA + + +False +-1.5707963267949 +15 +sCzG9DqxZkGTaKemcfKYcAAA + + + +clMaroon +$00FFFFDF +10 +784 +444 +452 +52 +True +ZMn2cmFZr0+GuJk5rQoyDgAA + + +1 +IUdpServerListener + + +False + + +False + + + +False +ZMn2cmFZr0+GuJk5rQoyDgAA + + +ZMn2cmFZr0+GuJk5rQoyDgAA + + +False +ZMn2cmFZr0+GuJk5rQoyDgAA + + + +clMaroon +$00B9FFFF +10 +964,444;847,379 +xHgTfxe+SkyBHjq4gN29qAAA +1XW3u/7OaUqWSnACglXKhgAA +Zp5gWO2/s0iv2bqlRzbEeAAA + +False +1.5707963267949 +15 +xHgTfxe+SkyBHjq4gN29qAAA + + +False +1.5707963267949 +30 +xHgTfxe+SkyBHjq4gN29qAAA + + +False +-1.5707963267949 +15 +xHgTfxe+SkyBHjq4gN29qAAA + + + +clMaroon +$00FFFFDF +10 +376 +444 +400 +52 +True +h8NmVuBtVUWgcCSKCdxePgAA + + +1 +ITcpServerListener + + +False + + +False + + + +False +h8NmVuBtVUWgcCSKCdxePgAA + + +h8NmVuBtVUWgcCSKCdxePgAA + + +False +h8NmVuBtVUWgcCSKCdxePgAA + + + +clMaroon +$00B9FFFF +623,444;749,379 +2uOeA48ekEWyQBc6HVdLyAAA +1XW3u/7OaUqWSnACglXKhgAA +1gWIbf39QUqjUn/XGJtmLwAA + +False +1.5707963267949 +15 +2uOeA48ekEWyQBc6HVdLyAAA + + +False +1.5707963267949 +30 +2uOeA48ekEWyQBc6HVdLyAAA + + +False +-1.5707963267949 +15 +2uOeA48ekEWyQBc6HVdLyAAA + + + + + +IAgentListener +jvfBmo6uGkC61ckI99TMgAAA + +e6yvsmhXAEqtOj6MD3c4IAAA +5 + +clMaroon +$00B9FFFF +10 +352 +156 +571 +132 +True +9FsvxqZjkEyUqc9w2NDcQgAA + + +1 +IComplexSocketListener + + +False + + +False + + + +False +9FsvxqZjkEyUqc9w2NDcQgAA + + +9FsvxqZjkEyUqc9w2NDcQgAA + + +False +9FsvxqZjkEyUqc9w2NDcQgAA + + + +clMaroon +$00B9FFFF +10 +416 +372 +444 +68 +True +lJ5FZia7y0evV31w/xLmsAAA + + +1 +IAgentListener + + +False + + +False + + + +False +lJ5FZia7y0evV31w/xLmsAAA + + +lJ5FZia7y0evV31w/xLmsAAA + + +False +lJ5FZia7y0evV31w/xLmsAAA + + + +clMaroon +$00B9FFFF +10 +637,372;637,287 +u7n8K/7SVEOrbQ7qqBgw5gAA +DW2yUJIctUaEVCg8tu3QxAAA +J0BFOQn6q0qGw65bKVVPEwAA + +False +1.5707963267949 +15 +u7n8K/7SVEOrbQ7qqBgw5gAA + + +False +1.5707963267949 +30 +u7n8K/7SVEOrbQ7qqBgw5gAA + + +False +-1.5707963267949 +15 +u7n8K/7SVEOrbQ7qqBgw5gAA + + + +clMaroon +$00FFFFE1 +10 +572 +512 +130 +36 +True +skl0Nm/UIUCTsqkUAIXmzAAA + + +1 +ITcpAgentListener + + +False + + +False + + + +False +skl0Nm/UIUCTsqkUAIXmzAAA + + +skl0Nm/UIUCTsqkUAIXmzAAA + + +False +skl0Nm/UIUCTsqkUAIXmzAAA + + + +clMaroon +$00B9FFFF +10 +636,512;637,439 +9cmaeBE4CUK4eiysDAdUBAAA +J0BFOQn6q0qGw65bKVVPEwAA +amWQQ3AliU6mio+Jb/FaJAAA + +False +1.5707963267949 +15 +9cmaeBE4CUK4eiysDAdUBAAA + + +False +1.5707963267949 +30 +9cmaeBE4CUK4eiysDAdUBAAA + + +False +-1.5707963267949 +15 +9cmaeBE4CUK4eiysDAdUBAAA + + + + + +IClientListener +jvfBmo6uGkC61ckI99TMgAAA + +l4NlnvJShk695D9BRlEbzAAA +7 + +clMaroon +$00B9FFFF +10 +416 +120 +543 +148 +BZTI/4OA7kG+nFfsclldCgAA + + +1 +IClientListener + + +False + + +False + + + +False +BZTI/4OA7kG+nFfsclldCgAA + + +BZTI/4OA7kG+nFfsclldCgAA + + +False +BZTI/4OA7kG+nFfsclldCgAA + + + +clMaroon +$00FFFFEC +10 +460 +364 +126 +36 +HwLi+AyuiUa754Eutz2k5AAA + + +1 +ITcpClientListener + + +False + + +False + + + +False +HwLi+AyuiUa754Eutz2k5AAA + + +HwLi+AyuiUa754Eutz2k5AAA + + +False +HwLi+AyuiUa754Eutz2k5AAA + + + +clMaroon +$00B9FFFF +10 +537,364;622,267 +LHdDVg405EStLqtC9ACaJgAA +q36mxdXyZE6WTwmuKuQ2vAAA +e/+kw8IbbkOctNvnX+LZsQAA + +False +1.5707963267949 +15 +LHdDVg405EStLqtC9ACaJgAA + + +False +1.5707963267949 +30 +LHdDVg405EStLqtC9ACaJgAA + + +False +-1.5707963267949 +15 +LHdDVg405EStLqtC9ACaJgAA + + + +clMaroon +$00FFFFEC +10 +792 +364 +121 +36 +r22NFz2+L0aq+kmESgCiYAAA + + +1 +IUdpCastListener + + +False + + +False + + + +False +r22NFz2+L0aq+kmESgCiYAAA + + +r22NFz2+L0aq+kmESgCiYAAA + + +False +r22NFz2+L0aq+kmESgCiYAAA + + + +clMaroon +$00B9FFFF +10 +837,364;752,267 +iH3ueDodB0OuqZ5awdjDeQAA +q36mxdXyZE6WTwmuKuQ2vAAA +i1mju6goyUCpVQPExOMCbwAA + +False +1.5707963267949 +15 +iH3ueDodB0OuqZ5awdjDeQAA + + +False +1.5707963267949 +30 +iH3ueDodB0OuqZ5awdjDeQAA + + +False +-1.5707963267949 +15 +iH3ueDodB0OuqZ5awdjDeQAA + + + +clMaroon +$00FFFFEC +10 +624 +364 +128 +36 +/JHLRlaovkibrttO8nZPPgAA + + +1 +IUdpClientListener + + +False + + +False + + + +False +/JHLRlaovkibrttO8nZPPgAA + + +/JHLRlaovkibrttO8nZPPgAA + + +False +/JHLRlaovkibrttO8nZPPgAA + + + +clMaroon +$00B9FFFF +10 +687,364;687,267 +sN55Dgbmo0WZvNqCj0OqQwAA +q36mxdXyZE6WTwmuKuQ2vAAA +giFfOL+L5EqS2RmY8ylUDQAA + +False +1.5707963267949 +15 +sN55Dgbmo0WZvNqCj0OqQwAA + + +False +1.5707963267949 +30 +sN55Dgbmo0WZvNqCj0OqQwAA + + +False +-1.5707963267949 +15 +sN55Dgbmo0WZvNqCj0OqQwAA + + + + + +HP-Socket Class Diagram - v3.4 +jvfBmo6uGkC61ckI99TMgAAA + +ze/Hc/i6d0uBL3aw+cFlmwAA +114 + +clMaroon +$00EDDADA +10 +304 +1988 +118 +116 +True +False +3KsfqnlMb0ieGw/IAO5hFQAA + + +1 +EnServiceState + + +<<enumeration>> + + +False + + + +3KsfqnlMb0ieGw/IAO5hFQAA + + +False +3KsfqnlMb0ieGw/IAO5hFQAA + + + +clMaroon +$00EDDADA +10 +304 +2128 +133 +148 +True +False +bcrguJxo002HtvMUNvyx5QAA + + +1 +EnSocketOperation + + +<<enumeration>> + + +False + + + +bcrguJxo002HtvMUNvyx5QAA + + +False +bcrguJxo002HtvMUNvyx5QAA + + + +clMaroon +$00EDDADA +10 +496 +1988 +118 +100 +True +False +2khtjHI2AUSz1nm7UQu8uwAA + + +1 +EnHandleResult + + +<<enumeration>> + + +False + + + +2khtjHI2AUSz1nm7UQu8uwAA + + +False +2khtjHI2AUSz1nm7UQu8uwAA + + + +clMaroon +$00EDDADA +10 +492 +2128 +156 +100 +True +False +VQDDk4BU6UmBmig6SmOuoQAA + + +1 +EnFetchResult + + +<<enumeration>> + + +False + + + +VQDDk4BU6UmBmig6SmOuoQAA + + +False +VQDDk4BU6UmBmig6SmOuoQAA + + + +clMaroon +$00EDDADA +10 +716 +1988 +118 +100 +True +False +p4RvBvwp3kOxyo/4mj2ZKwAA + + +1 +EnSendPolicy + + +<<enumeration>> + + +False + + + +p4RvBvwp3kOxyo/4mj2ZKwAA + + +False +p4RvBvwp3kOxyo/4mj2ZKwAA + + + +clMaroon +$00EDDADA +10 +884 +1988 +198 +292 +True +False +R9EXi7T78E6Gt882nRMyDwAA + + +1 +EnSocketError + + +<<enumeration>> + + +False + + + +R9EXi7T78E6Gt882nRMyDwAA + + +False +R9EXi7T78E6Gt882nRMyDwAA + + + +clMaroon +$00EDDADA +10 +716 +2128 +118 +84 +True +False +6zImDSI92UG9tawjYrSv0AAA + + +1 +EnCastMode + + +<<enumeration>> + + +False + + + +6zImDSI92UG9tawjYrSv0AAA + + +False +6zImDSI92UG9tawjYrSv0AAA + + + +clMaroon +$00B9FFFF +10 +2132 +8 +239 +132 +True +False +9FsvxqZjkEyUqc9w2NDcQgAA + + +1 +IComplexSocketListener + + +False + + +False + + + +False +9FsvxqZjkEyUqc9w2NDcQgAA + + +9FsvxqZjkEyUqc9w2NDcQgAA + + +False +9FsvxqZjkEyUqc9w2NDcQgAA + + + +clMaroon +$00B9FFFF +10 +2064 +888 +122 +52 +True +False +SX/KZkmsDk+r8uamHH4ZLgAA + + +1 +IServerListener + + +False + + +False + + + +False +SX/KZkmsDk+r8uamHH4ZLgAA + + +SX/KZkmsDk+r8uamHH4ZLgAA + + +False +SX/KZkmsDk+r8uamHH4ZLgAA + + + +clMaroon +$00B9FFFF +10 +2128,888;2241,139 +sCzG9DqxZkGTaKemcfKYcAAA +gL3x0HKKs0C7DDVK9HdhLwAA +yfVKcgxjhUa+TjjPZrtVYQAA + +False +1.5707963267949 +15 +sCzG9DqxZkGTaKemcfKYcAAA + + +False +1.5707963267949 +30 +sCzG9DqxZkGTaKemcfKYcAAA + + +False +-1.5707963267949 +15 +sCzG9DqxZkGTaKemcfKYcAAA + + + +clMaroon +$00BDFFDE +10 +1960 +1072 +134 +52 +True +False +h8NmVuBtVUWgcCSKCdxePgAA + + +1 +ITcpServerListener + + +False + + +False + + + +False +h8NmVuBtVUWgcCSKCdxePgAA + + +h8NmVuBtVUWgcCSKCdxePgAA + + +False +h8NmVuBtVUWgcCSKCdxePgAA + + + +clMaroon +$00B9FFFF +10 +2039,1072;2110,939 +2uOeA48ekEWyQBc6HVdLyAAA +yfVKcgxjhUa+TjjPZrtVYQAA +bxQFxtW+e0KFZlCcgFO9AAAA + +False +1.5707963267949 +15 +2uOeA48ekEWyQBc6HVdLyAAA + + +False +1.5707963267949 +30 +2uOeA48ekEWyQBc6HVdLyAAA + + +False +-1.5707963267949 +15 +2uOeA48ekEWyQBc6HVdLyAAA + + + +clMaroon +$00B9FFFF +10 +1956 +1408 +137 +116 +True +False +nhHxAccKxEm2g0sPkFAnhwAA + + +1 +CTcpServerListener + + +False + + +False + + + +False +nhHxAccKxEm2g0sPkFAnhwAA + + +nhHxAccKxEm2g0sPkFAnhwAA + + +False +nhHxAccKxEm2g0sPkFAnhwAA + + + +clMaroon +$00B9FFFF +10 +2024,1408;2026,1123 +oU9IW4eh8ESLIhPxMDNlogAA +bxQFxtW+e0KFZlCcgFO9AAAA +afZfzoCg4Eq/XSFKvRAWKAAA + +False +1.5707963267949 +15 +oU9IW4eh8ESLIhPxMDNlogAA + + +False +1.5707963267949 +30 +oU9IW4eh8ESLIhPxMDNlogAA + + +False +-1.5707963267949 +15 +oU9IW4eh8ESLIhPxMDNlogAA + + + +clMaroon +$00B9FFFF +10 +1944 +2668 +159 +68 +True +False +9yFTOYs1vEa8s69V7MjeDgAA + + +1 +CTcpPullServerListener + + +False + + +False + + + +False +9yFTOYs1vEa8s69V7MjeDgAA + + +9yFTOYs1vEa8s69V7MjeDgAA + + +False +9yFTOYs1vEa8s69V7MjeDgAA + + + +clMaroon +$00B9FFFF +10 +2023,2668;2024,1523 +08VC9kxGKEmdHNOlu6NmbwAA +afZfzoCg4Eq/XSFKvRAWKAAA +120BkdYky02f0xbh3EF3XwAA + +False +1.5707963267949 +15 +08VC9kxGKEmdHNOlu6NmbwAA + + +False +1.5707963267949 +30 +08VC9kxGKEmdHNOlu6NmbwAA + + +False +-1.5707963267949 +15 +08VC9kxGKEmdHNOlu6NmbwAA + + + +clMaroon +$00BDFFDE +10 +2144 +1072 +136 +52 +True +False +ZMn2cmFZr0+GuJk5rQoyDgAA + + +1 +IUdpServerListener + + +False + + +False + + + +False +ZMn2cmFZr0+GuJk5rQoyDgAA + + +ZMn2cmFZr0+GuJk5rQoyDgAA + + +False +ZMn2cmFZr0+GuJk5rQoyDgAA + + + +clMaroon +$00B9FFFF +10 +2199,1072;2136,939 +xHgTfxe+SkyBHjq4gN29qAAA +yfVKcgxjhUa+TjjPZrtVYQAA +GAyMC/pBC0uNZTrkQ2VX4wAA + +False +1.5707963267949 +15 +xHgTfxe+SkyBHjq4gN29qAAA + + +False +1.5707963267949 +30 +xHgTfxe+SkyBHjq4gN29qAAA + + +False +-1.5707963267949 +15 +xHgTfxe+SkyBHjq4gN29qAAA + + + +clMaroon +$00B9FFFF +10 +2140 +1408 +139 +116 +True +False +Z797Ei2tSUi6O/GTUGUZfgAA + + +1 +CUdpServerListener + + +False + + +False + + + +False +Z797Ei2tSUi6O/GTUGUZfgAA + + +Z797Ei2tSUi6O/GTUGUZfgAA + + +False +Z797Ei2tSUi6O/GTUGUZfgAA + + + +clMaroon +$00B9FFFF +10 +2209,1408;2211,1123 +7wiMv4rx/0CjGXfkMJ+fBgAA +GAyMC/pBC0uNZTrkQ2VX4wAA +58PT+RQQQEeK5sPeQ8LchgAA + +False +1.5707963267949 +15 +7wiMv4rx/0CjGXfkMJ+fBgAA + + +False +1.5707963267949 +30 +7wiMv4rx/0CjGXfkMJ+fBgAA + + +False +-1.5707963267949 +15 +7wiMv4rx/0CjGXfkMJ+fBgAA + + + +clMaroon +$00B9FFFF +10 +2332 +888 +135 +68 +True +False +lJ5FZia7y0evV31w/xLmsAAA + + +1 +IAgentListener + + +False + + +False + + + +False +lJ5FZia7y0evV31w/xLmsAAA + + +lJ5FZia7y0evV31w/xLmsAAA + + +False +lJ5FZia7y0evV31w/xLmsAAA + + + +clMaroon +$00B9FFFF +10 +2393,888;2262,139 +u7n8K/7SVEOrbQ7qqBgw5gAA +gL3x0HKKs0C7DDVK9HdhLwAA +AD2hOL2vpE+3hsFwE/MFuwAA + +False +1.5707963267949 +15 +u7n8K/7SVEOrbQ7qqBgw5gAA + + +False +1.5707963267949 +30 +u7n8K/7SVEOrbQ7qqBgw5gAA + + +False +-1.5707963267949 +15 +u7n8K/7SVEOrbQ7qqBgw5gAA + + + +clMaroon +$00BDFFDE +10 +2332 +1072 +130 +36 +True +False +skl0Nm/UIUCTsqkUAIXmzAAA + + +1 +ITcpAgentListener + + +False + + +False + + + +False +skl0Nm/UIUCTsqkUAIXmzAAA + + +skl0Nm/UIUCTsqkUAIXmzAAA + + +False +skl0Nm/UIUCTsqkUAIXmzAAA + + + +clMaroon +$00B9FFFF +10 +2396,1072;2398,955 +9cmaeBE4CUK4eiysDAdUBAAA +AD2hOL2vpE+3hsFwE/MFuwAA +lZ1Q7w+edEej4hQluAnhMgAA + +False +1.5707963267949 +15 +9cmaeBE4CUK4eiysDAdUBAAA + + +False +1.5707963267949 +30 +9cmaeBE4CUK4eiysDAdUBAAA + + +False +-1.5707963267949 +15 +9cmaeBE4CUK4eiysDAdUBAAA + + + +clMaroon +$00B9FFFF +10 +2328 +1408 +135 +116 +True +False +HjFZEYW1wEOsKFuTmPnHegAA + + +1 +CTcpAgentListener + + +False + + +False + + + +False +HjFZEYW1wEOsKFuTmPnHegAA + + +HjFZEYW1wEOsKFuTmPnHegAA + + +False +HjFZEYW1wEOsKFuTmPnHegAA + + + +clMaroon +$00B9FFFF +10 +2395,1408;2396,1107 +RRh8s6Oze0Sz3Sygnu9oMQAA +lZ1Q7w+edEej4hQluAnhMgAA +geKQC6XZkEefI3E4l/VkGAAA + +False +1.5707963267949 +15 +RRh8s6Oze0Sz3Sygnu9oMQAA + + +False +1.5707963267949 +30 +RRh8s6Oze0Sz3Sygnu9oMQAA + + +False +-1.5707963267949 +15 +RRh8s6Oze0Sz3Sygnu9oMQAA + + + +clMaroon +$00B9FFFF +10 +2312 +2668 +155 +68 +True +False +hNuH1fWUHU2IT4Poty2GiwAA + + +1 +CTcpPullAgentListener + + +False + + +False + + + +False +hNuH1fWUHU2IT4Poty2GiwAA + + +hNuH1fWUHU2IT4Poty2GiwAA + + +False +hNuH1fWUHU2IT4Poty2GiwAA + + + +clMaroon +$00B9FFFF +10 +2389,2668;2395,1523 +xj1q7c1vdUK4s8CkFyDE3wAA +geKQC6XZkEefI3E4l/VkGAAA +eYGlKkdZLEutBTtuUOVCFAAA + +False +1.5707963267949 +15 +xj1q7c1vdUK4s8CkFyDE3wAA + + +False +1.5707963267949 +30 +xj1q7c1vdUK4s8CkFyDE3wAA + + +False +-1.5707963267949 +15 +xj1q7c1vdUK4s8CkFyDE3wAA + + + +clMaroon +$00B9FFFF +10 +1372 +332 +156 +324 +True +False +R8hLgFt1fEaSSxBO7KbEBQAA + + +1 +IClient + + +False + + +False + + + +False +R8hLgFt1fEaSSxBO7KbEBQAA + + +R8hLgFt1fEaSSxBO7KbEBQAA + + +False +R8hLgFt1fEaSSxBO7KbEBQAA + + + +clMaroon +$00B9FFFF +10 +700 +332 +184 +148 +True +False +BZTI/4OA7kG+nFfsclldCgAA + + +1 +IClientListener + + +False + + +False + + + +False +BZTI/4OA7kG+nFfsclldCgAA + + +BZTI/4OA7kG+nFfsclldCgAA + + +False +BZTI/4OA7kG+nFfsclldCgAA + + + +clMaroon +$00BDFFDE +10 +543 +1072 +126 +36 +True +False +HwLi+AyuiUa754Eutz2k5AAA + + +1 +ITcpClientListener + + +False + + +False + + + +False +HwLi+AyuiUa754Eutz2k5AAA + + +HwLi+AyuiUa754Eutz2k5AAA + + +False +HwLi+AyuiUa754Eutz2k5AAA + + + +clMaroon +$00B9FFFF +10 +610,1072;771,479 +LHdDVg405EStLqtC9ACaJgAA +KrTYF4Cl0UWAT3s9Q59oBAAA +lkeOHiiD8k61jW8z3Jdf1AAA + +False +1.5707963267949 +15 +LHdDVg405EStLqtC9ACaJgAA + + +False +1.5707963267949 +30 +LHdDVg405EStLqtC9ACaJgAA + + +False +-1.5707963267949 +15 +LHdDVg405EStLqtC9ACaJgAA + + + +clMaroon +$00B9FFFF +10 +536 +1408 +135 +100 +True +False +c38EVYXmckWErbW5Cl4UwgAA + + +1 +CTcpClientListener + + +False + + +False + + + +False +c38EVYXmckWErbW5Cl4UwgAA + + +c38EVYXmckWErbW5Cl4UwgAA + + +False +c38EVYXmckWErbW5Cl4UwgAA + + + +clMaroon +$00B9FFFF +10 +603,1408;605,1107 +jMwPdcNgf0KaJMKQBOazIgAA +lkeOHiiD8k61jW8z3Jdf1AAA +JvAeKTqBzE+W2Tw+N4ESXQAA + +False +1.5707963267949 +15 +jMwPdcNgf0KaJMKQBOazIgAA + + +False +1.5707963267949 +30 +jMwPdcNgf0KaJMKQBOazIgAA + + +False +-1.5707963267949 +15 +jMwPdcNgf0KaJMKQBOazIgAA + + + +clMaroon +$00B9FFFF +10 +528 +1656 +151 +68 +True +False +4OTsa4LGqUqntun16mJ7kAAA + + +1 +CTcpPullClientListener + + +False + + +False + + + +False +4OTsa4LGqUqntun16mJ7kAAA + + +4OTsa4LGqUqntun16mJ7kAAA + + +False +4OTsa4LGqUqntun16mJ7kAAA + + + +clMaroon +$00B9FFFF +10 +603,1656;603,1507 +x9j97vQnoEStugksSdPSBwAA +JvAeKTqBzE+W2Tw+N4ESXQAA +7UPYyBmTk0StzHZNW+YJswAA + +False +1.5707963267949 +15 +x9j97vQnoEStugksSdPSBwAA + + +False +1.5707963267949 +30 +x9j97vQnoEStugksSdPSBwAA + + +False +-1.5707963267949 +15 +x9j97vQnoEStugksSdPSBwAA + + + +clMaroon +$00BDFFDE +10 +732 +1072 +128 +36 +True +False +/JHLRlaovkibrttO8nZPPgAA + + +1 +IUdpClientListener + + +False + + +False + + + +False +/JHLRlaovkibrttO8nZPPgAA + + +/JHLRlaovkibrttO8nZPPgAA + + +False +/JHLRlaovkibrttO8nZPPgAA + + + +clMaroon +$00B9FFFF +10 +795,1072;791,479 +sN55Dgbmo0WZvNqCj0OqQwAA +KrTYF4Cl0UWAT3s9Q59oBAAA +4X4YjiGr1keUOnRkcKUhTQAA + +False +1.5707963267949 +15 +sN55Dgbmo0WZvNqCj0OqQwAA + + +False +1.5707963267949 +30 +sN55Dgbmo0WZvNqCj0OqQwAA + + +False +-1.5707963267949 +15 +sN55Dgbmo0WZvNqCj0OqQwAA + + + +clMaroon +$00B9FFFF +10 +729 +1407 +135 +100 +True +False +eLrcJo0DgE2AjvOF61yczQAA + + +1 +CUdpClientListener + + +False + + +False + + + +False +eLrcJo0DgE2AjvOF61yczQAA + + +eLrcJo0DgE2AjvOF61yczQAA + + +False +eLrcJo0DgE2AjvOF61yczQAA + + + +clMaroon +$00B9FFFF +10 +796,1407;795,1107 +ckrUyHyNEkqEIaDRIjKBrAAA +4X4YjiGr1keUOnRkcKUhTQAA +awRPnutzt0yg7s50bGBGLQAA + +False +1.5707963267949 +15 +ckrUyHyNEkqEIaDRIjKBrAAA + + +False +1.5707963267949 +30 +ckrUyHyNEkqEIaDRIjKBrAAA + + +False +-1.5707963267949 +15 +ckrUyHyNEkqEIaDRIjKBrAAA + + + +clMaroon +$00BDFFDE +10 +928 +1072 +121 +36 +True +False +r22NFz2+L0aq+kmESgCiYAAA + + +1 +IUdpCastListener + + +False + + +False + + + +False +r22NFz2+L0aq+kmESgCiYAAA + + +r22NFz2+L0aq+kmESgCiYAAA + + +False +r22NFz2+L0aq+kmESgCiYAAA + + + +clMaroon +$00B9FFFF +10 +983,1072;812,479 +iH3ueDodB0OuqZ5awdjDeQAA +KrTYF4Cl0UWAT3s9Q59oBAAA +IpuoRM7390mIm+qG9Hl2bgAA + +False +1.5707963267949 +15 +iH3ueDodB0OuqZ5awdjDeQAA + + +False +1.5707963267949 +30 +iH3ueDodB0OuqZ5awdjDeQAA + + +False +-1.5707963267949 +15 +iH3ueDodB0OuqZ5awdjDeQAA + + + +clMaroon +$00B9FFFF +10 +920 +1407 +135 +100 +True +False +sJBjmKjtoEWtenBeaDLnjwAA + + +1 +CUdpCastListener + + +False + + +False + + + +False +sJBjmKjtoEWtenBeaDLnjwAA + + +sJBjmKjtoEWtenBeaDLnjwAA + + +False +sJBjmKjtoEWtenBeaDLnjwAA + + + +clMaroon +$00B9FFFF +10 +987,1407;988,1107 +FoyTfxOKQ0CcM6uuMKewkwAA +IpuoRM7390mIm+qG9Hl2bgAA +zefMvmnz2UK+gAC3E0jXgQAA + +False +1.5707963267949 +15 +FoyTfxOKQ0CcM6uuMKewkwAA + + +False +1.5707963267949 +30 +FoyTfxOKQ0CcM6uuMKewkwAA + + +False +-1.5707963267949 +15 +FoyTfxOKQ0CcM6uuMKewkwAA + + + +clMaroon +$00B9FFFF +10 +2884 +8 +199 +596 +True +False +SqNjwMrIrEaWmScJhNPQOwAA + + +3 +IComplexSocket + + +False + + +False + + + +False +SqNjwMrIrEaWmScJhNPQOwAA + + +SqNjwMrIrEaWmScJhNPQOwAA + + +False +SqNjwMrIrEaWmScJhNPQOwAA + + + +clMaroon +$00B9FFFF +10 +2736 +888 +126 +68 +True +False +GoHMKPRtzES/2hlDzLtwnAAA + + +1 +IServer + + +False + + +False + + + +False +GoHMKPRtzES/2hlDzLtwnAAA + + +GoHMKPRtzES/2hlDzLtwnAAA + + +False +GoHMKPRtzES/2hlDzLtwnAAA + + + +clMaroon +$00B9FFFF +10 +2861,895;2944,860;2962,603 +9BTtNyRQHEu7yKoNswewcQAA +eiN6oYelCU++QjaXKMX8mAAA +kiHq/1vHX0WZ96N8FA/STwAA + +False +1.5707963267949 +15 +9BTtNyRQHEu7yKoNswewcQAA + + +False +1.5707963267949 +30 +9BTtNyRQHEu7yKoNswewcQAA + + +False +-1.5707963267949 +15 +9BTtNyRQHEu7yKoNswewcQAA + + + +clMaroon +$00FFE3C8 +10 +2864 +1072 +156 +212 +True +False +YNdJIJRIm0SpW7CG17MtyAAA + + +1 +ITcpServer + + +False + + +False + + + +False +YNdJIJRIm0SpW7CG17MtyAAA + + +YNdJIJRIm0SpW7CG17MtyAAA + + +False +YNdJIJRIm0SpW7CG17MtyAAA + + + +clMaroon +$00B9FFFF +10 +2882,1072;2817,955 +qrDg6u3xU0KpgYiFoJBZ1AAA +kiHq/1vHX0WZ96N8FA/STwAA +Ll1QQzy89EqZaHquqLut4QAA + +False +1.5707963267949 +15 +qrDg6u3xU0KpgYiFoJBZ1AAA + + +False +1.5707963267949 +30 +qrDg6u3xU0KpgYiFoJBZ1AAA + + +False +-1.5707963267949 +15 +qrDg6u3xU0KpgYiFoJBZ1AAA + + + +clMaroon +$00FFE3C8 +10 +2584 +1072 +150 +164 +True +False +KqnhKB+uXkKxW6LqS8YzcgAA + + +1 +IUdpServer + + +False + + +False + + + +False +KqnhKB+uXkKxW6LqS8YzcgAA + + +KqnhKB+uXkKxW6LqS8YzcgAA + + +False +KqnhKB+uXkKxW6LqS8YzcgAA + + + +clMaroon +$00B9FFFF +10 +2707,1072;2778,955 +rcZqqPur/USLxxaOeNdjswAA +kiHq/1vHX0WZ96N8FA/STwAA +jbo8sT+vKUaLco+wapuQhwAA + +False +1.5707963267949 +15 +rcZqqPur/USLxxaOeNdjswAA + + +False +1.5707963267949 +30 +rcZqqPur/USLxxaOeNdjswAA + + +False +-1.5707963267949 +15 +rcZqqPur/USLxxaOeNdjswAA + + + +clMaroon +$00B9FFFF +10 +3400 +888 +122 +84 +True +False +tc20+9LmREuR1dUMSybNdQAA + + +1 +IAgent + + +False + + +False + + + +False +tc20+9LmREuR1dUMSybNdQAA + + +tc20+9LmREuR1dUMSybNdQAA + + +False +tc20+9LmREuR1dUMSybNdQAA + + + +clMaroon +$00B9FFFF +10 +3400,917;3108,860;3050,603 +dx6I5RGr20SmTHCEMdZ9nAAA +eiN6oYelCU++QjaXKMX8mAAA +n3rJyl0++kq9uoOsANKAUwAA + +False +1.5707963267949 +15 +dx6I5RGr20SmTHCEMdZ9nAAA + + +False +1.5707963267949 +30 +dx6I5RGr20SmTHCEMdZ9nAAA + + +False +-1.5707963267949 +15 +dx6I5RGr20SmTHCEMdZ9nAAA + + + +clMaroon +$00FFE3C8 +10 +3388 +1072 +145 +180 +True +False +ilTzVOgexUSPHrK2FSqS9wAA + + +1 +ITcpAgent + + +False + + +False + + + +False +ilTzVOgexUSPHrK2FSqS9wAA + + +ilTzVOgexUSPHrK2FSqS9wAA + + +False +ilTzVOgexUSPHrK2FSqS9wAA + + + +clMaroon +$00B9FFFF +10 +3460,1072;3460,971 +T7qvCRD8oEeFVhOYfk7D4wAA +n3rJyl0++kq9uoOsANKAUwAA +ROm4wdRu3kujC5L3DT4IAAAA + +False +1.5707963267949 +15 +T7qvCRD8oEeFVhOYfk7D4wAA + + +False +1.5707963267949 +30 +T7qvCRD8oEeFVhOYfk7D4wAA + + +False +-1.5707963267949 +15 +T7qvCRD8oEeFVhOYfk7D4wAA + + + +clMaroon +$00FFE3C8 +10 +1376 +1072 +145 +148 +True +False +CqUqbTfjd0mBGFOXrmWVDgAA + + +1 +ITcpClient + + +False + + +False + + + +False +CqUqbTfjd0mBGFOXrmWVDgAA + + +CqUqbTfjd0mBGFOXrmWVDgAA + + +False +CqUqbTfjd0mBGFOXrmWVDgAA + + + +clMaroon +$00B9FFFF +10 +1448,1072;1449,655 +dOpAHC5JfkymmNyAgeRwWAAA +ylsx02qZaUiyvMjQBrZn+gAA +J8pneqLZKkaDgX4DgXGzJwAA + +False +1.5707963267949 +15 +dOpAHC5JfkymmNyAgeRwWAAA + + +False +1.5707963267949 +30 +dOpAHC5JfkymmNyAgeRwWAAA + + +False +-1.5707963267949 +15 +dOpAHC5JfkymmNyAgeRwWAAA + + + +clMaroon +$00FFE3C8 +10 +1136 +1072 +150 +132 +True +False +s/XSjWMZB0WwUzzarQOzNgAA + + +1 +IUdpClient + + +False + + +False + + + +False +s/XSjWMZB0WwUzzarQOzNgAA + + +s/XSjWMZB0WwUzzarQOzNgAA + + +False +s/XSjWMZB0WwUzzarQOzNgAA + + + +clMaroon +$00B9FFFF +10 +1234,1072;1389,655 +VhVmNVhKIEyRJWflThCsqQAA +ylsx02qZaUiyvMjQBrZn+gAA +oleTxFsjKEWwtZuXdUKCNQAA + +False +1.5707963267949 +15 +VhVmNVhKIEyRJWflThCsqQAA + + +False +1.5707963267949 +30 +VhVmNVhKIEyRJWflThCsqQAA + + +False +-1.5707963267949 +15 +VhVmNVhKIEyRJWflThCsqQAA + + + +clMaroon +$00FFE3C8 +10 +1704 +1072 +150 +244 +True +False +6HMIzI9avUGHDCpvqmkdqQAA + + +1 +IUdpCast + + +False + + +False + + + +False +6HMIzI9avUGHDCpvqmkdqQAA + + +6HMIzI9avUGHDCpvqmkdqQAA + + +False +6HMIzI9avUGHDCpvqmkdqQAA + + + +clMaroon +$00B9FFFF +10 +1721,1072;1525,655 +MejA8cLC00G/Y3QcvCU6BgAA +ylsx02qZaUiyvMjQBrZn+gAA +YHlypkK/9EmsY5l1e8kckgAA + +False +1.5707963267949 +15 +MejA8cLC00G/Y3QcvCU6BgAA + + +False +1.5707963267949 +30 +MejA8cLC00G/Y3QcvCU6BgAA + + +False +-1.5707963267949 +15 +MejA8cLC00G/Y3QcvCU6BgAA + + + +clMaroon +$0000C4C4 +10 +2816 +2460 +165 +84 +True +False +BaqYQl/65Uy16GMJC7nLawAA + + +1 +IPullSocket + + +False + + +False + + + +False +BaqYQl/65Uy16GMJC7nLawAA + + +BaqYQl/65Uy16GMJC7nLawAA + + +False +BaqYQl/65Uy16GMJC7nLawAA + + + +clMaroon +$0000C4C4 +10 +1700 +2460 +159 +84 +True +False +LPfLjDLmzkKy/sn51dyX7gAA + + +1 +IPullClient + + +False + + +False + + + +False +LPfLjDLmzkKy/sn51dyX7gAA + + +LPfLjDLmzkKy/sn51dyX7gAA + + +False +LPfLjDLmzkKy/sn51dyX7gAA + + + +clMaroon +$00B9FFFF +10 +2496 +2668 +103 +68 +True +False +gJKazn/X+U6+FJp/F2soRAAA + + +1 +ITcpPullServer + + +False + + +False + + + +False +gJKazn/X+U6+FJp/F2soRAAA + + +gJKazn/X+U6+FJp/F2soRAAA + + +False +gJKazn/X+U6+FJp/F2soRAAA + + + +clMaroon +$00B9FFFF +10 +2598,2672;2824,2543 +ETiy7j/ak0iclwwFrOCPHwAA +a0c9acKJG0SO2mD4HdFWdAAA +vwPKwpBbd0GUOwpQTiwJIwAA + +False +1.5707963267949 +15 +ETiy7j/ak0iclwwFrOCPHwAA + + +False +1.5707963267949 +30 +ETiy7j/ak0iclwwFrOCPHwAA + + +False +-1.5707963267949 +15 +ETiy7j/ak0iclwwFrOCPHwAA + + + +clMaroon +$00B9FFFF +10 +2567,2668;2788,2312;2788,1352;2864,1265 +RvwWYNXraU2xkdsooYM/NwAA +Ll1QQzy89EqZaHquqLut4QAA +vwPKwpBbd0GUOwpQTiwJIwAA + +False +1.5707963267949 +15 +RvwWYNXraU2xkdsooYM/NwAA + + +False +1.5707963267949 +30 +RvwWYNXraU2xkdsooYM/NwAA + + +False +-1.5707963267949 +15 +RvwWYNXraU2xkdsooYM/NwAA + + + +clMaroon +$00B9FFFF +10 +2852 +2668 +99 +68 +True +False +QvkeGvTpWU2SJ0MXVIx/AwAA + + +1 +ITcpPullAgent + + +False + + +False + + + +False +QvkeGvTpWU2SJ0MXVIx/AwAA + + +QvkeGvTpWU2SJ0MXVIx/AwAA + + +False +QvkeGvTpWU2SJ0MXVIx/AwAA + + + +clMaroon +$00B9FFFF +10 +2901,2668;2899,2543 +krwZJNbQpUee1OjG3HesgAAA +a0c9acKJG0SO2mD4HdFWdAAA +bfxTyfA02Ue+pDo34ZXTAQAA + +False +1.5707963267949 +15 +krwZJNbQpUee1OjG3HesgAAA + + +False +1.5707963267949 +30 +krwZJNbQpUee1OjG3HesgAAA + + +False +-1.5707963267949 +15 +krwZJNbQpUee1OjG3HesgAAA + + + +clMaroon +$00B9FFFF +10 +2927,2668;3140,2392;3140,1376;3388,1209 +Vo9KdG21TU67s/EtgyfoVQAA +ROm4wdRu3kujC5L3DT4IAAAA +bfxTyfA02Ue+pDo34ZXTAQAA + +False +1.5707963267949 +15 +Vo9KdG21TU67s/EtgyfoVQAA + + +False +1.5707963267949 +30 +Vo9KdG21TU67s/EtgyfoVQAA + + +False +-1.5707963267949 +15 +Vo9KdG21TU67s/EtgyfoVQAA + + + +clMaroon +$00B9FFFF +10 +1768 +2672 +95 +68 +True +False +SjUoRiw3TUOE/FQirpeMogAA + + +1 +ITcpPullClient + + +False + + +False + + + +False +SjUoRiw3TUOE/FQirpeMogAA + + +SjUoRiw3TUOE/FQirpeMogAA + + +False +SjUoRiw3TUOE/FQirpeMogAA + + + +clMaroon +$00B9FFFF +10 +1809,2672;1786,2543 +wIyBqLGeaEauN2RIkujQrAAA +3G0QePyBUU2U+ZdFBZdeaQAA +JO73WwZwyUit/u2y4GvaEQAA + +False +1.5707963267949 +15 +wIyBqLGeaEauN2RIkujQrAAA + + +False +1.5707963267949 +30 +wIyBqLGeaEauN2RIkujQrAAA + + +False +-1.5707963267949 +15 +wIyBqLGeaEauN2RIkujQrAAA + + + +clMaroon +$00B9FFFF +10 +1772,2672;1628,2560;1628,1412;1498,1219 +GJ1pEOa7xE+Vx6DHIVvLbwAA +J8pneqLZKkaDgX4DgXGzJwAA +JO73WwZwyUit/u2y4GvaEQAA + +False +1.5707963267949 +15 +GJ1pEOa7xE+Vx6DHIVvLbwAA + + +False +1.5707963267949 +30 +GJ1pEOa7xE+Vx6DHIVvLbwAA + + +False +-1.5707963267949 +15 +GJ1pEOa7xE+Vx6DHIVvLbwAA + + + +clMaroon +$00DCB9FF +10 +3356 +1408 +199 +804 +True +False ++hvdtNLBPUeUmdoy9WnIywAA + + +1 +CTcpAgent + + +False + + +False + + + +False ++hvdtNLBPUeUmdoy9WnIywAA + + ++hvdtNLBPUeUmdoy9WnIywAA + + +False ++hvdtNLBPUeUmdoy9WnIywAA + + + +clMaroon +$00B9FFFF +10 +3458,1408;3459,1251 +M9A+DWOIeUGk+YFgByCYmAAA +ROm4wdRu3kujC5L3DT4IAAAA +nninAmAC7U2238tYjDUvxQAA + +False +1.5707963267949 +15 +M9A+DWOIeUGk+YFgByCYmAAA + + +False +1.5707963267949 +30 +M9A+DWOIeUGk+YFgByCYmAAA + + +False +-1.5707963267949 +15 +M9A+DWOIeUGk+YFgByCYmAAA + + + +clMaroon +$00FFC8FF +10 +1368 +1408 +164 +468 +True +False +rNsPUCIqcESb1NED1xr04AAA + + +1 +CTcpClient + + +False + + +False + + + +False +rNsPUCIqcESb1NED1xr04AAA + + +rNsPUCIqcESb1NED1xr04AAA + + +False +rNsPUCIqcESb1NED1xr04AAA + + + +clMaroon +$00B9FFFF +10 +1449,1408;1448,1219 +hwXxX+YbkkG6mY/KLykG4AAA +J8pneqLZKkaDgX4DgXGzJwAA +PGFFeARNxk+lxLKoUolRcgAA + +False +1.5707963267949 +15 +hwXxX+YbkkG6mY/KLykG4AAA + + +False +1.5707963267949 +30 +hwXxX+YbkkG6mY/KLykG4AAA + + +False +-1.5707963267949 +15 +hwXxX+YbkkG6mY/KLykG4AAA + + + +clMaroon +$00DCB9FF +10 +2980 +2668 +185 +100 +True +False +JJbEayVgmEyWvR4C1WYpsAAA + + +1 +CTcpPullAgent + + +False + + +False + + + +False +JJbEayVgmEyWvR4C1WYpsAAA + + +JJbEayVgmEyWvR4C1WYpsAAA + + +False +JJbEayVgmEyWvR4C1WYpsAAA + + + +clMaroon +$00B9FFFF +10 +3033,2668;2932,2543 +SWj0s9+zMUW6Sa0s98LfDgAA +a0c9acKJG0SO2mD4HdFWdAAA +91D3350Tx0G/REKMBgAVcgAA + +False +1.5707963267949 +15 +SWj0s9+zMUW6Sa0s98LfDgAA + + +False +1.5707963267949 +30 +SWj0s9+zMUW6Sa0s98LfDgAA + + +False +-1.5707963267949 +15 +SWj0s9+zMUW6Sa0s98LfDgAA + + + +clMaroon +$00B9FFFF +10 +3139,2668;3200,2624;3200,2180;3356,1953 +IDQB44Q61kudclcYwyYEMwAA +nninAmAC7U2238tYjDUvxQAA +91D3350Tx0G/REKMBgAVcgAA + +False +1.5707963267949 +15 +IDQB44Q61kudclcYwyYEMwAA + + +False +1.5707963267949 +30 +IDQB44Q61kudclcYwyYEMwAA + + +False +-1.5707963267949 +15 +IDQB44Q61kudclcYwyYEMwAA + + + +clMaroon +$00FFC8FF +10 +1532 +2672 +184 +100 +True +False +dUFVpJ56j0WxczyDxsGS+gAA + + +1 +CTcpPullClient + + +False + + +False + + + +False +dUFVpJ56j0WxczyDxsGS+gAA + + +dUFVpJ56j0WxczyDxsGS+gAA + + +False +dUFVpJ56j0WxczyDxsGS+gAA + + + +clMaroon +$00B9FFFF +10 +1658,2672;1749,2543 +t7BFiOV+U0+3Fzwd6nXwzgAA +3G0QePyBUU2U+ZdFBZdeaQAA +pHz4Yn9KW0u1EHHgf7i2PQAA + +False +1.5707963267949 +15 +t7BFiOV+U0+3Fzwd6nXwzgAA + + +False +1.5707963267949 +30 +t7BFiOV+U0+3Fzwd6nXwzgAA + + +False +-1.5707963267949 +15 +t7BFiOV+U0+3Fzwd6nXwzgAA + + + +clMaroon +$00B9FFFF +10 +1615,2672;1487,1875 +ZNw4OjQkUkmijjdgoAjX+gAA +PGFFeARNxk+lxLKoUolRcgAA +pHz4Yn9KW0u1EHHgf7i2PQAA + +False +1.5707963267949 +15 +ZNw4OjQkUkmijjdgoAjX+gAA + + +False +1.5707963267949 +30 +ZNw4OjQkUkmijjdgoAjX+gAA + + +False +-1.5707963267949 +15 +ZNw4OjQkUkmijjdgoAjX+gAA + + + +clMaroon +$00A6D2FF +10 +2628 +2668 +190 +100 +True +False +5tmwPyb6D0Ki98vc8dVPhQAA + + +1 +CTcpPullServer + + +False + + +False + + + +False +5tmwPyb6D0Ki98vc8dVPhQAA + + +5tmwPyb6D0Ki98vc8dVPhQAA + + +False +5tmwPyb6D0Ki98vc8dVPhQAA + + + +clMaroon +$00B9FFFF +10 +2762,2668;2864,2543 +DLbR09fsFE6Bx8bzfHmD6AAA +a0c9acKJG0SO2mD4HdFWdAAA +pH4m1vGfz0+s2Byn9+X25QAA + +False +1.5707963267949 +15 +DLbR09fsFE6Bx8bzfHmD6AAA + + +False +1.5707963267949 +30 +DLbR09fsFE6Bx8bzfHmD6AAA + + +False +-1.5707963267949 +15 +DLbR09fsFE6Bx8bzfHmD6AAA + + + +clMaroon +$00A6D2FF +10 +2840 +1408 +199 +820 +True +False +gWn1z7ujyEu9Gf7LdRrPIAAA + + +1 +CTcpServer + + +False + + +False + + + +False +gWn1z7ujyEu9Gf7LdRrPIAAA + + +gWn1z7ujyEu9Gf7LdRrPIAAA + + +False +gWn1z7ujyEu9Gf7LdRrPIAAA + + + +clMaroon +$00B9FFFF +10 +2940,1408;2941,1283 +O5dkSXpa9UWV4M9yJ7QzIwAA +Ll1QQzy89EqZaHquqLut4QAA +b5sh7cGyAEG5dKPNO5ax0wAA + +False +1.5707963267949 +15 +O5dkSXpa9UWV4M9yJ7QzIwAA + + +False +1.5707963267949 +30 +O5dkSXpa9UWV4M9yJ7QzIwAA + + +False +-1.5707963267949 +15 +O5dkSXpa9UWV4M9yJ7QzIwAA + + + +clMaroon +$00B9FFFF +10 +2734,2668;2840,2227 +UT9syzbMZEyZsIIcEMpphAAA +b5sh7cGyAEG5dKPNO5ax0wAA +pH4m1vGfz0+s2Byn9+X25QAA + +False +1.5707963267949 +15 +UT9syzbMZEyZsIIcEMpphAAA + + +False +1.5707963267949 +30 +UT9syzbMZEyZsIIcEMpphAAA + + +False +-1.5707963267949 +15 +UT9syzbMZEyZsIIcEMpphAAA + + + +clMaroon +$00FFC8FF +10 +1696 +1408 +158 +548 +True +False +ukpy8IZAy0KEameLGY9mtQAA + + +1 +CUdpCast + + +False + + +False + + + +False +ukpy8IZAy0KEameLGY9mtQAA + + +ukpy8IZAy0KEameLGY9mtQAA + + +False +ukpy8IZAy0KEameLGY9mtQAA + + + +clMaroon +$00B9FFFF +10 +1776,1408;1777,1315 +Mrk3QXUHNk2R1/cHV9/5pAAA +YHlypkK/9EmsY5l1e8kckgAA +19i0QowlNkm9OgeAWSgS4wAA + +False +1.5707963267949 +15 +Mrk3QXUHNk2R1/cHV9/5pAAA + + +False +1.5707963267949 +30 +Mrk3QXUHNk2R1/cHV9/5pAAA + + +False +-1.5707963267949 +15 +Mrk3QXUHNk2R1/cHV9/5pAAA + + + +clMaroon +$00FFC8FF +10 +1128 +1408 +165 +436 +True +False +ecegk3x5sEKpNtWGALy6NAAA + + +1 +CUdpClient + + +False + + +False + + + +False +ecegk3x5sEKpNtWGALy6NAAA + + +ecegk3x5sEKpNtWGALy6NAAA + + +False +ecegk3x5sEKpNtWGALy6NAAA + + + +clMaroon +$00B9FFFF +10 +1210,1408;1210,1203 +TevsU+ekCkCxrYsp/lugswAA +oleTxFsjKEWwtZuXdUKCNQAA +c825HJK3kEKsHWC48ErTtwAA + +False +1.5707963267949 +15 +TevsU+ekCkCxrYsp/lugswAA + + +False +1.5707963267949 +30 +TevsU+ekCkCxrYsp/lugswAA + + +False +-1.5707963267949 +15 +TevsU+ekCkCxrYsp/lugswAA + + + +clMaroon +$00A6D2FF +10 +2548 +1408 +199 +772 +True +False +W+YbXZBJDU6NfEjOApatvwAA + + +1 +CUdpServer + + +False + + +False + + + +False +W+YbXZBJDU6NfEjOApatvwAA + + +W+YbXZBJDU6NfEjOApatvwAA + + +False +W+YbXZBJDU6NfEjOApatvwAA + + + +clMaroon +$00B9FFFF +10 +2654,1408;2657,1235 +j09xKlrPNkS8/NZ3JXD5MwAA +jbo8sT+vKUaLco+wapuQhwAA +bwCisxwrCEKKPJ3Eu3K44AAA + +False +1.5707963267949 +15 +j09xKlrPNkS8/NZ3JXD5MwAA + + +False +1.5707963267949 +30 +j09xKlrPNkS8/NZ3JXD5MwAA + + +False +-1.5707963267949 +15 +j09xKlrPNkS8/NZ3JXD5MwAA + + + +clMaroon +$00CCE8F4 +10 +600 +1880 +114 +42 +True +False +G8TfQngB3UemVJWZg5KbggAA + + +1 +CONNID + + +<<CppTypedef>> + + +False + + + +False +G8TfQngB3UemVJWZg5KbggAA + + +False +G8TfQngB3UemVJWZg5KbggAA + + +False +G8TfQngB3UemVJWZg5KbggAA + + + +clMaroon +$0000C4C4 +10 +1032 +2460 +165 +116 +True +False +tvyRlzR70kaEb8akK1WldwAA + + +1 +IPackClient + + +False + + +False + + + +False +tvyRlzR70kaEb8akK1WldwAA + + +tvyRlzR70kaEb8akK1WldwAA + + +False +tvyRlzR70kaEb8akK1WldwAA + + + +clMaroon +$00B9FFFF +10 +1100 +2672 +103 +68 +True +False +NI0md/XcXk+UFEOqL+89owAA + + +1 +ITcpPackClient + + +False + + +False + + + +False +NI0md/XcXk+UFEOqL+89owAA + + +NI0md/XcXk+UFEOqL+89owAA + + +False +NI0md/XcXk+UFEOqL+89owAA + + + +clMaroon +$00B9FFFF +1145,2672;1126,2575 +xly9lJtUukKwQ90VKrZR2AAA +Yb89wcpcAk2cxvunkv6qmgAA +32lcn4ak5UeWCJbHkp/gUwAA + +False +1.5707963267949 +15 +xly9lJtUukKwQ90VKrZR2AAA + + +False +1.5707963267949 +30 +xly9lJtUukKwQ90VKrZR2AAA + + +False +-1.5707963267949 +15 +xly9lJtUukKwQ90VKrZR2AAA + + + +clMaroon +$00B9FFFF +1202,2674;1332,2596;1332,1400;1414,1219 +l44zgodkDEuj17c7XdoPSQAA +J8pneqLZKkaDgX4DgXGzJwAA +32lcn4ak5UeWCJbHkp/gUwAA + +False +1.5707963267949 +15 +l44zgodkDEuj17c7XdoPSQAA + + +False +1.5707963267949 +30 +l44zgodkDEuj17c7XdoPSQAA + + +False +-1.5707963267949 +15 +l44zgodkDEuj17c7XdoPSQAA + + + +clMaroon +$00FFC8FF +10 +1292 +2672 +190 +158 +True +False +L/mIC87mmUWQBG3Zhl0iGQAA + + +1 +CTcpPackClient + + +False + + +False + + + +L/mIC87mmUWQBG3Zhl0iGQAA + + +L/mIC87mmUWQBG3Zhl0iGQAA + + +False +L/mIC87mmUWQBG3Zhl0iGQAA + + + +clMaroon +$00B9FFFF +1417,2672;1448,2596;1449,1875 +PhcJjlYZKkK5/K0LejildAAA +PGFFeARNxk+lxLKoUolRcgAA +yhdU0K3mvEeeVvCvv3kUNQAA + +False +1.5707963267949 +15 +PhcJjlYZKkK5/K0LejildAAA + + +False +1.5707963267949 +30 +PhcJjlYZKkK5/K0LejildAAA + + +False +-1.5707963267949 +15 +PhcJjlYZKkK5/K0LejildAAA + + + +clMaroon +$00B9FFFF +1295,2672;1182,2575 +N9PjlD8Kvk26PvXMITpM2QAA +Yb89wcpcAk2cxvunkv6qmgAA +yhdU0K3mvEeeVvCvv3kUNQAA + +False +1.5707963267949 +15 +N9PjlD8Kvk26PvXMITpM2QAA + + +False +1.5707963267949 +30 +N9PjlD8Kvk26PvXMITpM2QAA + + +False +-1.5707963267949 +15 +N9PjlD8Kvk26PvXMITpM2QAA + + + +clMaroon +$0000C4C4 +10 +3384 +2460 +171 +116 +False +Pv24uWWaqUu82r7VGD3ZNwAA + + +1 +IPackSocket + + +False + + +False + + + +False +Pv24uWWaqUu82r7VGD3ZNwAA + + +Pv24uWWaqUu82r7VGD3ZNwAA + + +False +Pv24uWWaqUu82r7VGD3ZNwAA + + + +clMaroon +$00B9FFFF +10 +3200 +2668 +111 +68 +False +aDgNVKZkT029alZKzju1xAAA + + +1 +ITcpPackServer + + +False + + +False + + + +False +aDgNVKZkT029alZKzju1xAAA + + +aDgNVKZkT029alZKzju1xAAA + + +False +aDgNVKZkT029alZKzju1xAAA + + + +clMaroon +$00B9FFFF +3293,2668;3401,2575 +sgmcH4+s1Em05SzAjJdHjAAA +o4hWQrYZQkOmrY1zgQbErQAA +kTpvQ8TEEkmzpYp6oZMMXwAA + +False +1.5707963267949 +15 +sgmcH4+s1Em05SzAjJdHjAAA + + +False +1.5707963267949 +30 +sgmcH4+s1Em05SzAjJdHjAAA + + +False +-1.5707963267949 +15 +sgmcH4+s1Em05SzAjJdHjAAA + + + +clMaroon +$00B9FFFF +3255,2668;3256,1376;3019,1226 +nzQ/3s2PQEG5Cz2AX+hkOgAA +Ll1QQzy89EqZaHquqLut4QAA +kTpvQ8TEEkmzpYp6oZMMXwAA + +False +1.5707963267949 +15 +nzQ/3s2PQEG5Cz2AX+hkOgAA + + +False +1.5707963267949 +30 +nzQ/3s2PQEG5Cz2AX+hkOgAA + + +False +-1.5707963267949 +15 +nzQ/3s2PQEG5Cz2AX+hkOgAA + + + +clMaroon +$00A6D2FF +10 +3344 +2668 +196 +164 +False +1ED6OCTjl0y7E7dMMSTJqgAA + + +1 +CTcpPackServer + + +False + + +False + + + +False +1ED6OCTjl0y7E7dMMSTJqgAA + + +1ED6OCTjl0y7E7dMMSTJqgAA + + +False +1ED6OCTjl0y7E7dMMSTJqgAA + + + +clMaroon +$00B9FFFF +3451,2668;3462,2575 +OH/WIarq+EioSJWJSZjh6AAA +o4hWQrYZQkOmrY1zgQbErQAA +3Oc58Cgr6Uet0hJOu0xXvgAA + +False +1.5707963267949 +15 +OH/WIarq+EioSJWJSZjh6AAA + + +False +1.5707963267949 +30 +OH/WIarq+EioSJWJSZjh6AAA + + +False +-1.5707963267949 +15 +OH/WIarq+EioSJWJSZjh6AAA + + + +clMaroon +$00B9FFFF +3344,2680;2936,2392;2937,2227 +aQ1uf7mN+EuF/eGcASNwmgAA +b5sh7cGyAEG5dKPNO5ax0wAA +3Oc58Cgr6Uet0hJOu0xXvgAA + +False +1.5707963267949 +15 +aQ1uf7mN+EuF/eGcASNwmgAA + + +False +1.5707963267949 +30 +aQ1uf7mN+EuF/eGcASNwmgAA + + +False +-1.5707963267949 +15 +aQ1uf7mN+EuF/eGcASNwmgAA + + + +clMaroon +$00B9FFFF +10 +3572 +2668 +107 +68 +False +vjFkGLWb/kSPpbp9R+skbAAA + + +1 +ITcpPackAgent + + +False + + +False + + + +False +vjFkGLWb/kSPpbp9R+skbAAA + + +vjFkGLWb/kSPpbp9R+skbAAA + + +False +vjFkGLWb/kSPpbp9R+skbAAA + + + +clMaroon +$00B9FFFF +3597,2668;3518,2575 +WUHNHDfka0O+CbvKWj/7kQAA +o4hWQrYZQkOmrY1zgQbErQAA +kXZKbMdJjEWlFo6Q0wMKUwAA + +False +1.5707963267949 +15 +WUHNHDfka0O+CbvKWj/7kQAA + + +False +1.5707963267949 +30 +WUHNHDfka0O+CbvKWj/7kQAA + + +False +-1.5707963267949 +15 +WUHNHDfka0O+CbvKWj/7kQAA + + + +clMaroon +$00B9FFFF +3625,2668;3624,1376;3529,1251 +lqZ7xgrWKkewtFXoEKU2+AAA +ROm4wdRu3kujC5L3DT4IAAAA +kXZKbMdJjEWlFo6Q0wMKUwAA + +False +1.5707963267949 +15 +lqZ7xgrWKkewtFXoEKU2+AAA + + +False +1.5707963267949 +30 +lqZ7xgrWKkewtFXoEKU2+AAA + + +False +-1.5707963267949 +15 +lqZ7xgrWKkewtFXoEKU2+AAA + + + +clMaroon +$00DCB9FF +10 +3712 +2668 +191 +164 +False +P+YM5jdCmESvfv1Fet1QqAAA + + +1 +CTcpPackAgent + + +False + + +False + + + +False +P+YM5jdCmESvfv1Fet1QqAAA + + +P+YM5jdCmESvfv1Fet1QqAAA + + +False +P+YM5jdCmESvfv1Fet1QqAAA + + + +clMaroon +$00B9FFFF +3712,2684;3554,2575 +v+HDY4XmuEqbLAgnV9F1XgAA +o4hWQrYZQkOmrY1zgQbErQAA +D/2eg6bkTEKcTZu0rbkM1wAA + +False +1.5707963267949 +15 +v+HDY4XmuEqbLAgnV9F1XgAA + + +False +1.5707963267949 +30 +v+HDY4XmuEqbLAgnV9F1XgAA + + +False +-1.5707963267949 +15 +v+HDY4XmuEqbLAgnV9F1XgAA + + + +clMaroon +$00B9FFFF +3807,2668;3808,2064;3554,1881 +YVPRQLCk1keYCHnO8PWR/AAA +nninAmAC7U2238tYjDUvxQAA +D/2eg6bkTEKcTZu0rbkM1wAA + +False +1.5707963267949 +15 +YVPRQLCk1keYCHnO8PWR/AAA + + +False +1.5707963267949 +30 +YVPRQLCk1keYCHnO8PWR/AAA + + +False +-1.5707963267949 +15 +YVPRQLCk1keYCHnO8PWR/AAA + + + + +116 + +EnServiceState +jvfBmo6uGkC61ckI99TMgAAA +3 +/Hg9sU6SmkaAX3wqfKf/lAAA +wPOn+zBnJ02Mf+2m4vEdbwAA +8vi/z6yaDUShoIWb1X8UvgAA +8 +9ze/PvOnvU2I3wuW3sw7dgAA +bb0LhDAaoUWNpOxTYJKZFwAA +ovLyeMCsGU+CSwChq6MhOQAA +fPFZ9bkoRkSS9IXDRWQPhQAA +3O88wlYsrUS175Djzxc2dAAA +F9rQZp8vdkS+d68SMN96wwAA +4wHcw6tqd0mfon0oAGPsCgAA +dZbcHxIwz0KDNKb0mYF2sAAA +4 + +SS_STARTING +3KsfqnlMb0ieGw/IAO5hFQAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +0 +BUAg5V47OEmKqbfsSVGSZQAA + + + +SS_STARTED +3KsfqnlMb0ieGw/IAO5hFQAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +1 +x45Shq4m3UCyyhhHgqIauwAA + + + +SS_STOPPING +3KsfqnlMb0ieGw/IAO5hFQAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +2 +lRR5ieVM/kiOUDwCIMzM3gAA + + + +SS_STOPPED +3KsfqnlMb0ieGw/IAO5hFQAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +3 +CdW6GmQJlkaZO1o+SoZgAQAA + + + + +EnSocketOperation +jvfBmo6uGkC61ckI99TMgAAA +3 +NQa42WghXU2XZMat6ngMLgAA +taqRhJZSJEeDgM2FarHi8gAA +Cjh6qO8sB0qDMc5eq2ww/AAA +2 +GsWmM9R3lUSKuiHhl55jQAAA +c0UAA1N5nkuBLBDAo1fUewAA +6 + +SO_UNKNOWN +bcrguJxo002HtvMUNvyx5QAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +0 +xnhXkWFrI0mA7yhIClHMigAA + + + +SO_ACCEPT +bcrguJxo002HtvMUNvyx5QAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +1 +WpQiSMOAokio6w6T3QFhkwAA + + + +SO_CONNECT +bcrguJxo002HtvMUNvyx5QAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +2 +H/x8WMv+e0mjCuRuGPCPjQAA + + + +SO_SEND +bcrguJxo002HtvMUNvyx5QAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +3 +SqubH1/udUiyUV0J7SlCIgAA + + + +SO_RECEIVE +bcrguJxo002HtvMUNvyx5QAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +4 +1kgrtl72TESkbs8gun55PgAA + + + +SO_CLOSE +bcrguJxo002HtvMUNvyx5QAA + + + +EnHandleResult +jvfBmo6uGkC61ckI99TMgAAA +3 +VuiSEv/w/0a3Oyyjh1kWkwAA +s36P0ZvCVk+oLhDzfoBY/wAA +Ccn2Qg6Ma0Oyp8pHjMlFegAA +49 +adaDOGBgWEuCyAylwAKDbwAA +LKJX3bvnsk6vJvlAQjut0wAA +06GIZLg5kUu1jMwim/j9MwAA +ZxW8hBULKEKS8QsvyzcoigAA +6hVTBeqVykikY3wlTXGVXgAA +WfkGxxQdYUa2AUzANYMLIAAA +gLXAiSzN8EeIm6ptjUGojAAA +H71ci98jC0GqvM9CL6QFvwAA +4wFtCW9ADU6mxvYcCiih/QAA +XbVeFUXU/0qIZNZuWncJ3AAA +verhfpStQ0q7ybsoXzjJmAAA +jWvVyG07wEKz1rZUJGto6gAA +cMKqz0jfYEOUlGK6OoqJSAAA +x5E1tLg4okSUlXXGkiXoNAAA +KVcDJlFPdEKBwEb63GZHDwAA ++kyz9TzlwEOGr567KsdQbgAA +CGfhoHA1+kCfX5eudHvMyAAA +VHpO2Urm4UKDsxJJKv7UVQAA +HRTN5SeH2EqZj07PKO4MbwAA +czOPYdfAqkqdUEnG5y0MWwAA +e2QxhXDEBU6D/pkzmcYdPQAA +lU5XcMc9okaBSAVBWsm1DQAA +jKugxgnbGEOf7ghemafM9QAA +CZu7XXSPekWt71bArtW9VgAA +CHeb3wK9hEKOi1Wg7mF/cgAA +8OCVGl+B8UC3cN+S0rNjpwAA +HLq+5xH68Eek3UdUGPGMIQAA +vICY5hZhEkWn3DqaryPJNgAA +mGcatlPrLkWuiazxUJssqgAA +XSj/S5qyr0GLIcRVuV3xygAA +0q8VMJNFb0e6fv1yroePMQAA +ZdZcc/0iG06a6y8+0Pr7nQAA +6TV8ZwoT8EePU/EWnp0pDAAA +l67sTf2QREuHk1xFJnymkQAA +APKmn8VhHEmBVtpJP3zg7gAA +lsQyu0ke5UGZrFqARPYfVQAA +cvUxCXjQAESP5jzbDqf1pwAA +LklFArEZXk6pIAAUrbxCPQAA +7KlhuuZ5Gkq2zUoqeLeOzAAA +C4rQEoPqcUWjWLgJhz2nXQAA +dKZf/ThZ6UOXM9sbrQ0yggAA +WD8EL7wwvUCI3wp1oirhQwAA +LYd6Auppx0ivXco5b3eMmAAA +nT2vdzgUcUOIXPmjqsOWjQAA +yvTAoZ0GSk+621GFie3/SgAA +0heWroKSDkiWbUj62lsy9QAA +VbWC+1lZ9kKjKxambR7PvwAA +dCmV6rFUskClp5cFhzktuwAA +B6hfL/aJ7UuAED1idXsjvgAA +3 + +HR_OK +2khtjHI2AUSz1nm7UQu8uwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +0 +JM8lTQ8G102A2skNePFfmgAA + + + +HR_IGNORE +2khtjHI2AUSz1nm7UQu8uwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +1 +MN1C0/kmi0OhE3TdoTOEngAA + + + +HR_ERROR +2khtjHI2AUSz1nm7UQu8uwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +2 +leMhmMQ/cEOq84sQ6Hj2+QAA + + + + +EnFetchResult +jvfBmo6uGkC61ckI99TMgAAA +3 +9QjjQOhUJkivVQsgrhoMHQAA +4MOlIJOFnU6pDDZDKQohBAAA +79m3E4wU40GjURBEYh9i5gAA +10 +MwV7fGPluUy5cG052ia1ZQAA +Qnh5SR3mR0qR3je2xAm9lgAA +pSBQQfHuKUOafNF157wmYQAA +plHgQTYLi0+3qeTBQ/JSFwAA +KSLVzFuCPkKqj999rwzYjwAA +waVlE2AELEa3IP3T3FU9zAAA +0euLPVEbvU2gmXRfU5F26gAA +mE+GEhh7m0e91ic9rXIpeQAA +Omil8R9+aU6mMpn2pRj3/wAA +f0yLJEhj1kC+z+SSR+IASQAA +3 + +FR_OK +VQDDk4BU6UmBmig6SmOuoQAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +0 +7aUIc74hv0a2Dav+FeSHnQAA + + + +FR_LENGTH_TOO_LONG +VQDDk4BU6UmBmig6SmOuoQAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +1 +KoTT/DUbc0indnFvADPv7gAA + + + +FR_DATA_NOT_FOUND +VQDDk4BU6UmBmig6SmOuoQAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +2 +Mc7HjCaoAE6heKNVpuoP7wAA + + + + +EnSendPolicy +jvfBmo6uGkC61ckI99TMgAAA +3 +E1WYKeJPNUWB7buQHR+sigAA +uaCECG+u80iyzyWf+IWAZwAA +IVsrBaUSWkaj79k27/BwoAAA +8 +1EHzYGXWPE2MUmWYdtI7kAAA +XNP++PGwFUmR+dtq0ZbchAAA ++q3NsfXI8kSg3B73YWi1/QAA +cQe2CrUccUans1pbj67KbwAA +nbJaN9nP4ECrwbuLiFO9+AAA +LXoI55nFcEqRumCnnXHYcAAA +TkPZUvHM+0OI1ABKjX8i+wAA +zlY5tvQ3XU6NmtOqD0mCCgAA +3 + +SP_PACK +p4RvBvwp3kOxyo/4mj2ZKwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +0 +RMnP0ysf8ESt8v1xLYqyCAAA + + + +SP_SAFE +p4RvBvwp3kOxyo/4mj2ZKwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +1 +bchy+/eMkEGwtflyFgXo8wAA + + + +SP_DIRECT +p4RvBvwp3kOxyo/4mj2ZKwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +2 +WgMrZyglOECmy0BcYsXHjQAA + + + + +EnRecvPolicy +jvfBmo6uGkC61ckI99TMgAAA +2 + +RP_SERIAL +vMd4FzYm40iDH4xBw/j9ogAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +0 +bFPFaMQcXkGNRuBeBbe64QAA + + + +RP_PARALLEL +vMd4FzYm40iDH4xBw/j9ogAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +1 +YXOWHmaGjESUsyOfPfas1gAA + + + + +EnSocketError +jvfBmo6uGkC61ckI99TMgAAA +3 +LUyoKimFt0KJG7+H2NuqEwAA +4ZEt1AuH+EaeHK+e1JY5jQAA +5SaxfJha/UOmVXU5e/n0ZwAA +8 +T35PsWmhyk+ZtRWGvqiIUAAA +UJVfPYV+aEq9rcSe/zX6GgAA +VrYcL5m/W0qGcPiWE0cN/AAA +zDkL/nxTgE2455rOh53S6AAA +Q3/ttXPTbEuCVf5/ZV5x5gAA +3XicrDatxkWJ/aeboujmRQAA +so4uYcVcmE2+ihdJmQPwHQAA +vKQBvyphHk+Ant1YP79wrwAA +15 + +SE_OK +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +NO_ERROR +KaCVWp+Jj0q8cZlQLF6ZbgAA + + + +SE_ILLEGAL_STATE +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +1 +arqDwKNsN06o13X1u+Lf5gAA + + + +SE_INVALID_PARAM +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +2 +vigWJvW9pE2aQ9p+y9msJwAA + + + +SE_SOCKET_CREATE +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +3 +QvOGV4dJfk2aL8K8PfqS7AAA + + + +SE_SOCKET_BIND +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +4 +MhhrBArXfUWWFpbAGAdWHAAA + + + +SE_SOCKET_PREPARE +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +5 +soC6ImijCkiLLnEl1SvDzgAA + + + +SE_SOCKET_LISTEN +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +6 +tW0Mrk6QWEKb0Ch9ISr60wAA + + + +SE_CP_CREATE +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +7 +7rT4RztGj0+pnJkc0Cp+XAAA + + + +SE_WORKER_THREAD_CREATE +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +8 +ztTGikfe+EWJNzAdWJh14QAA + + + +SE_DETECT_THREAD_CREATE +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +9 +lW+r6J+OxEmCgUQpQfFNdQAA + + + +SE_SOCKE_ATTACH_TO_CP +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +10 +/Trt2Kp1HUSND1UbbxbktwAA + + + +SE_CONNECT_SERVER +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +11 +F17dxSPkMkyF5sfoD0ku9QAA + + + +SE_NETWORK +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +12 +VZelwoo8Y0ipPYjw4Sx1XwAA + + + +SE_DATA_PROC +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +13 +vTvXc97soke8UflqYudhOQAA + + + +SE_DATA_SEND +R9EXi7T78E6Gt882nRMyDwAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +14 +RY+VKABQX0uJPu0+bRCQOwAA + + + + +EnCastMode +jvfBmo6uGkC61ckI99TMgAAA +3 +31uacB4TTkObrBVv8UmT/QAA +Xf9AliEOfUyltztpODKuBAAA +EwQxRQhrz0S3t87I5MNmjgAA +4 ++b6DANHm0U+ItjJPjpe/7gAA +KTy9RH4DjEKRdPjXPPuUewAA +qVINKJ7Vnk+cRsT1N5FwSgAA +1fkxDagKXUu0KbeEcCsrnwAA +2 + +CM_MULTICAST +6zImDSI92UG9tawjYrSv0AAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +0 +GWBYbzhUv0+kIkD2JIYceAAA + + + +CM_BROADCAST +6zImDSI92UG9tawjYrSv0AAA +1 + +Cpp +CppEnumLiteral +CppEnumLiteralValue +1 +DBSQKvW2i0KGL/L59DI6fAAA + + + + +IComplexSocketListener +jvfBmo6uGkC61ckI99TMgAAA +12 +EY7frgNjn025AVRzjddHWgAA +MfJ0iWFEkECmzH73O2Dp7wAA +zdTNFj3TYkKiuUcbyDjROgAA +8AFozj/zhkOAcMcdh7vuGAAA +DW2yUJIctUaEVCg8tu3QxAAA +iDScEs//eEWja+mMZJrnzQAA +OQMMF2P3xEyDMxiRGKKtFgAA +VedRmlfVqUGE3cYFLQ1fTQAA +gL3x0HKKs0C7DDVK9HdhLwAA +b91ip+1A2ESDZbW6PMkCWwAA +BYK0thKYJUafEJaG8HeqAAAA +YPxm8lYQ+EqzffI83webHwAA +2 +sCzG9DqxZkGTaKemcfKYcAAA +u7n8K/7SVEOrbQ7qqBgw5gAA +6 + +OnSend +True +9FsvxqZjkEyUqc9w2NDcQgAA +1 + +Cpp +CppVirtual +CppVirtual +True +UxnEnbNIqECt7ocz3bOr+gAA + +4 + +dwConnID +UxnEnbNIqECt7ocz3bOr+gAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +UxnEnbNIqECt7ocz3bOr+gAA +2 + +Cpp +CppConst +CppConst +True +lr3HsJ1XyE6eI1g6PwolIgAA + + +Cpp +CppPointer +CppPointer +* +lr3HsJ1XyE6eI1g6PwolIgAA + + + +iLength +int +UxnEnbNIqECt7ocz3bOr+gAA + + +return +pdkReturn +UxnEnbNIqECt7ocz3bOr+gAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnReceive +True +9FsvxqZjkEyUqc9w2NDcQgAA +1 + +Cpp +CppVirtual +CppVirtual +True +tZzokQADmUmETGvWx6ra5wAA + +4 + +dwConnID +tZzokQADmUmETGvWx6ra5wAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +tZzokQADmUmETGvWx6ra5wAA +2 + +Cpp +CppConst +CppConst +True +T0aJ1Eb3r0idgTJhb0WziwAA + + +Cpp +CppPointer +CppPointer +* +T0aJ1Eb3r0idgTJhb0WziwAA + + + +iLength +int +tZzokQADmUmETGvWx6ra5wAA + + +return +pdkReturn +tZzokQADmUmETGvWx6ra5wAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnReceive +True +9FsvxqZjkEyUqc9w2NDcQgAA +1 + +Cpp +CppVirtual +CppVirtual +True +NTlj89mrXUm8y2h0jOEsagAA + +3 + +dwConnID +NTlj89mrXUm8y2h0jOEsagAA +G8TfQngB3UemVJWZg5KbggAA + + +iLength +int +NTlj89mrXUm8y2h0jOEsagAA + + +return +pdkReturn +NTlj89mrXUm8y2h0jOEsagAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnClose +True +9FsvxqZjkEyUqc9w2NDcQgAA +1 + +Cpp +CppVirtual +CppVirtual +True +W+0RtP4kuUGJJl73XG3xzAAA + +4 + +pdkReturn +W+0RtP4kuUGJJl73XG3xzAAA +2khtjHI2AUSz1nm7UQu8uwAA + + +dwConnID +W+0RtP4kuUGJJl73XG3xzAAA +G8TfQngB3UemVJWZg5KbggAA + + +enOperation +W+0RtP4kuUGJJl73XG3xzAAA +bcrguJxo002HtvMUNvyx5QAA + + +iErrorCode +int +W+0RtP4kuUGJJl73XG3xzAAA + + + +OnShutdown +True +9FsvxqZjkEyUqc9w2NDcQgAA +1 + +Cpp +CppVirtual +CppVirtual +True +OD5t/+LJmE+25cl69KkvbAAA + +1 + +return +pdkReturn +OD5t/+LJmE+25cl69KkvbAAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +IComplexSocketListener +UMLStandard +destroy +vkPrivate +9FsvxqZjkEyUqc9w2NDcQgAA + + + +IServerListener +jvfBmo6uGkC61ckI99TMgAAA +8 +1XW3u/7OaUqWSnACglXKhgAA +8vq0S4pRcUKVy6uUspcN9gAA +52/x+av5JUKCcHOiIwVcVgAA +t2ozgFgpTk+Zi/h7ApLuiQAA +yfVKcgxjhUa+TjjPZrtVYQAA +dN+nn1z/O0OANAhlqFiRgwAA +MxkgcMdnQ0qUEGGvVflOpAAA +EvMw+zdmhkC5E5eKqwVdqAAA +1 +sCzG9DqxZkGTaKemcfKYcAAA +2 +2uOeA48ekEWyQBc6HVdLyAAA +xHgTfxe+SkyBHjq4gN29qAAA +1 + +OnPrepareListen +True +SX/KZkmsDk+r8uamHH4ZLgAA +1 + +Cpp +CppVirtual +CppVirtual +True +fKE7pYliQE+yhyR8VLWoiwAA + +2 + +soListen +SOCKET +fKE7pYliQE+yhyR8VLWoiwAA + + +return +pdkReturn +fKE7pYliQE+yhyR8VLWoiwAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +ITcpServerListener +jvfBmo6uGkC61ckI99TMgAAA +8 +1gWIbf39QUqjUn/XGJtmLwAA +xKO2OpFba0+BlXb3lslqzgAA +CDo2UE1S0kGNMdasSrcaSwAA +CdqpKkq/OECFSyxGwx0DlAAA +bxQFxtW+e0KFZlCcgFO9AAAA +3CBczl2GTkmNq/Y2WNdaigAA +1WXbaiPyB0Wpfi1qH2OUqgAA +W6ru1KYeHk6CNd3bmRc8awAA +1 +2uOeA48ekEWyQBc6HVdLyAAA +1 +oU9IW4eh8ESLIhPxMDNlogAA +1 + +OnAccept +True +h8NmVuBtVUWgcCSKCdxePgAA +1 + +Cpp +CppVirtual +CppVirtual +True +ahWZrAQVRkC0+dgeHf1ryAAA + +3 + +dwConnID +ahWZrAQVRkC0+dgeHf1ryAAA +G8TfQngB3UemVJWZg5KbggAA + + +soClient +SOCKET +ahWZrAQVRkC0+dgeHf1ryAAA + + +return +pdkReturn +ahWZrAQVRkC0+dgeHf1ryAAA +2khtjHI2AUSz1nm7UQu8uwAA + + +3 +tW7BVXw750CVMd+46YfU4gAA +m0VjNIF00UeJ9xj8Mli6YAAA +nRjXsyaRi0OblwNRuNtT6gAA + + +CTcpServerListener +jvfBmo6uGkC61ckI99TMgAAA +4 +afZfzoCg4Eq/XSFKvRAWKAAA +j3d9XZKJP0eYmNvWGYJmQgAA +DBvDCrp4+kmRyNyjRHdwCQAA +yMoaILNISESSsyXGf7gF3AAA +1 +oU9IW4eh8ESLIhPxMDNlogAA +1 +08VC9kxGKEmdHNOlu6NmbwAA +5 + +OnReceive +nhHxAccKxEm2g0sPkFAnhwAA +1 + +Cpp +CppVirtual +CppVirtual +True +KyWMgoW1e0ahSyohip+itQAA + +3 + +dwConnID +KyWMgoW1e0ahSyohip+itQAA +G8TfQngB3UemVJWZg5KbggAA + + +iLength +int +KyWMgoW1e0ahSyohip+itQAA + + +return +pdkReturn +KyWMgoW1e0ahSyohip+itQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnSend +nhHxAccKxEm2g0sPkFAnhwAA +1 + +Cpp +CppVirtual +CppVirtual +True +oQ/mgYHQGE+mzLjttwXHQgAA + +4 + +dwConnID +oQ/mgYHQGE+mzLjttwXHQgAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +oQ/mgYHQGE+mzLjttwXHQgAA +2 + +Cpp +CppConst +CppConst +True +nwpLSWWS1UupVB3nLpfqlAAA + + +Cpp +CppPointer +CppPointer +* +nwpLSWWS1UupVB3nLpfqlAAA + + + +iLength +int +oQ/mgYHQGE+mzLjttwXHQgAA + + +return +pdkReturn +oQ/mgYHQGE+mzLjttwXHQgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnPrepareListen +nhHxAccKxEm2g0sPkFAnhwAA +1 + +Cpp +CppVirtual +CppVirtual +True +DawAolJMTkejEoqsILJHNQAA + +2 + +soListen +SOCKET +DawAolJMTkejEoqsILJHNQAA + + +return +pdkReturn +DawAolJMTkejEoqsILJHNQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnAccept +nhHxAccKxEm2g0sPkFAnhwAA +1 + +Cpp +CppVirtual +CppVirtual +True +RZRhFb+hPEWiHU6MFeHslAAA + +3 + +dwConnID +RZRhFb+hPEWiHU6MFeHslAAA +G8TfQngB3UemVJWZg5KbggAA + + +soClient +SOCKET +RZRhFb+hPEWiHU6MFeHslAAA + + +return +pdkReturn +RZRhFb+hPEWiHU6MFeHslAAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnShutdown +nhHxAccKxEm2g0sPkFAnhwAA +1 + +Cpp +CppVirtual +CppVirtual +True +CfcT+Z8ZEkOQkAxhtGPnagAA + +1 + +return +pdkReturn +CfcT+Z8ZEkOQkAxhtGPnagAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +CTcpPullServerListener +jvfBmo6uGkC61ckI99TMgAAA +4 +120BkdYky02f0xbh3EF3XwAA +9AqPt40PaE22WxmDRG48uwAA +fvXv+QcBKkeZYNBhlGpfaQAA +08IKw2Y+TE6PBeFX79S2hwAA +1 +08VC9kxGKEmdHNOlu6NmbwAA +2 + +OnReceive +True +9yFTOYs1vEa8s69V7MjeDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +JDbgW2br+k+KnXnUnpu2YgAA + +3 + +dwConnID +JDbgW2br+k+KnXnUnpu2YgAA +G8TfQngB3UemVJWZg5KbggAA + + +iLength +int +JDbgW2br+k+KnXnUnpu2YgAA + + +return +pdkReturn +JDbgW2br+k+KnXnUnpu2YgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnReceive +9yFTOYs1vEa8s69V7MjeDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +NXBEdo9S+0eGI0mGn2oHdgAA + +4 + +dwConnID +NXBEdo9S+0eGI0mGn2oHdgAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +NXBEdo9S+0eGI0mGn2oHdgAA +2 + +Cpp +CppConst +CppConst +True +N/5tzT4ibEWm6NBNoI8FVAAA + + +Cpp +CppPointer +CppPointer +* +N/5tzT4ibEWm6NBNoI8FVAAA + + + +iLength +int +NXBEdo9S+0eGI0mGn2oHdgAA + + +return +pdkReturn +NXBEdo9S+0eGI0mGn2oHdgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +IUdpServerListener +jvfBmo6uGkC61ckI99TMgAAA +8 +Zp5gWO2/s0iv2bqlRzbEeAAA +n5rEvTbXwEibt/4IeDaIjAAA +JfJM4IFeE0WUWDSt8BeZdgAA +kidl8YEgRUK8sxP6Ry3NmwAA +GAyMC/pBC0uNZTrkQ2VX4wAA +KwxhqlDc5k6Es/QTnOeo2AAA +5nBdwLvgnEuQKs0zhUit7gAA +OOwyADMn+Emi6NAveiMXcgAA +1 +xHgTfxe+SkyBHjq4gN29qAAA +1 +7wiMv4rx/0CjGXfkMJ+fBgAA +1 + +OnAccept +True +ZMn2cmFZr0+GuJk5rQoyDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +pENbBQ1SD0WZlH3bC40IRAAA + +3 + +dwConnID +pENbBQ1SD0WZlH3bC40IRAAA +G8TfQngB3UemVJWZg5KbggAA + + +pSockAddr +SOCKADDR_IN +pENbBQ1SD0WZlH3bC40IRAAA +2 + +Cpp +CppConst +CppConst +True +QVn9m6TbLk+VMvvw+5Ht6QAA + + +Cpp +CppPointer +CppPointer +* +QVn9m6TbLk+VMvvw+5Ht6QAA + + + +return +pdkReturn +pENbBQ1SD0WZlH3bC40IRAAA +2khtjHI2AUSz1nm7UQu8uwAA + + +1 +xXvRk1+KjEC2XroCTRCe9AAA + + +CUdpServerListener +jvfBmo6uGkC61ckI99TMgAAA +4 +58PT+RQQQEeK5sPeQ8LchgAA +9ohN9hsnNUmyec5H8WeR8QAA +OSXyev2glUOY8EyYWGHFtwAA +hozlBZ/kl0ylG0sCmq7uvgAA +1 +7wiMv4rx/0CjGXfkMJ+fBgAA +5 + +OnReceive +Z797Ei2tSUi6O/GTUGUZfgAA +1 + +Cpp +CppVirtual +CppVirtual +True +dciDleepcUGUbGexhJfdfAAA + +3 + +dwConnID +dciDleepcUGUbGexhJfdfAAA +G8TfQngB3UemVJWZg5KbggAA + + +iLength +int +dciDleepcUGUbGexhJfdfAAA + + +return +pdkReturn +dciDleepcUGUbGexhJfdfAAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnSend +Z797Ei2tSUi6O/GTUGUZfgAA +1 + +Cpp +CppVirtual +CppVirtual +True +v0lOjkkjXU6/0xXkBr8dZgAA + +4 + +dwConnID +v0lOjkkjXU6/0xXkBr8dZgAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +v0lOjkkjXU6/0xXkBr8dZgAA +2 + +Cpp +CppConst +CppConst +True +s30XsPO53k6Q7Yh32zrCdQAA + + +Cpp +CppPointer +CppPointer +* +s30XsPO53k6Q7Yh32zrCdQAA + + + +iLength +int +v0lOjkkjXU6/0xXkBr8dZgAA + + +return +pdkReturn +v0lOjkkjXU6/0xXkBr8dZgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnPrepareListen +Z797Ei2tSUi6O/GTUGUZfgAA +1 + +Cpp +CppVirtual +CppVirtual +True +9+xZIEolXU6woUFK/xjYhwAA + +2 + +soListen +SOCKET +9+xZIEolXU6woUFK/xjYhwAA + + +return +pdkReturn +9+xZIEolXU6woUFK/xjYhwAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnAccept +Z797Ei2tSUi6O/GTUGUZfgAA +1 + +Cpp +CppVirtual +CppVirtual +True +2GrhsKxh9ketLTsf6rjdPQAA + +3 + +dwConnID +2GrhsKxh9ketLTsf6rjdPQAA +G8TfQngB3UemVJWZg5KbggAA + + +pSockAddr +SOCKADDR_IN +2GrhsKxh9ketLTsf6rjdPQAA +2 + +Cpp +CppConst +CppConst +True +PTs4LtfZSEKTEmdCjogwMgAA + + +Cpp +CppPointer +CppPointer +* +PTs4LtfZSEKTEmdCjogwMgAA + + + +return +pdkReturn +2GrhsKxh9ketLTsf6rjdPQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnShutdown +Z797Ei2tSUi6O/GTUGUZfgAA +1 + +Cpp +CppVirtual +CppVirtual +True +yp9GhYfsGkWhy0mm5WeV+gAA + +1 + +return +pdkReturn +yp9GhYfsGkWhy0mm5WeV+gAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +IAgentListener +jvfBmo6uGkC61ckI99TMgAAA +8 +J0BFOQn6q0qGw65bKVVPEwAA +PgvmDuxXxEm1ew/FnpSlEwAA +i8KjcDF8JEuTITYQLqZ31AAA +L21BJ1KQkE6I6T13U+XAhAAA +AD2hOL2vpE+3hsFwE/MFuwAA +gXN/4Xj/XkW21C7QR2UdwAAA +aFNt0wkd2kCPf+eJPEcIBQAA +PfSM520ahk+6gsfkZN9HVgAA +1 +u7n8K/7SVEOrbQ7qqBgw5gAA +1 +9cmaeBE4CUK4eiysDAdUBAAA +2 + +OnPrepareConnect +True +lJ5FZia7y0evV31w/xLmsAAA +1 + +Cpp +CppVirtual +CppVirtual +True +ae18fyvu70uIuDanh/ojVAAA + +3 + +dwConnID +ae18fyvu70uIuDanh/ojVAAA +G8TfQngB3UemVJWZg5KbggAA + + +socket +SOCKET +ae18fyvu70uIuDanh/ojVAAA + + +return +pdkReturn +ae18fyvu70uIuDanh/ojVAAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnConnect +True +lJ5FZia7y0evV31w/xLmsAAA +1 + +Cpp +CppVirtual +CppVirtual +True ++Nfu3WsbMke/yyZshTwy4AAA + +2 + +dwConnID ++Nfu3WsbMke/yyZshTwy4AAA +G8TfQngB3UemVJWZg5KbggAA + + +return +pdkReturn ++Nfu3WsbMke/yyZshTwy4AAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +ITcpAgentListener +jvfBmo6uGkC61ckI99TMgAAA +8 +amWQQ3AliU6mio+Jb/FaJAAA +y32UCDfJskOui4hrgxPnBAAA +6qqKArvKaUqYO5ybYpsSuwAA +aXPAXk9eREqVDZuU6r9aZQAA +lZ1Q7w+edEej4hQluAnhMgAA +N2bIGJ0bIk+UX/xAKvGIigAA +avyXCSFI4UKZlmRGlM2OwgAA +PM0VSuCv7ECCQIqp/qjFrQAA +1 +9cmaeBE4CUK4eiysDAdUBAAA +1 +RRh8s6Oze0Sz3Sygnu9oMQAA +3 +SOpFN5D6dUi/yOIJ1NO6NAAA +1IzM6A2aLECcC/0wa1pI4QAA +VbMBZfCU/0ivBlGkfv9qEwAA + + +CTcpAgentListener +jvfBmo6uGkC61ckI99TMgAAA +4 +geKQC6XZkEefI3E4l/VkGAAA +0daMKRm3xEWLTB3Gsta92AAA +2WZ8bRUlWkivK1OSadnvUAAA +JpBIJldPmUGxAopD7fU+XQAA +1 +RRh8s6Oze0Sz3Sygnu9oMQAA +1 +xj1q7c1vdUK4s8CkFyDE3wAA +5 + +OnReceive +HjFZEYW1wEOsKFuTmPnHegAA +1 + +Cpp +CppVirtual +CppVirtual +True +Pq2O6++E5U6nep84wmLP+gAA + +3 + +dwConnID +Pq2O6++E5U6nep84wmLP+gAA +G8TfQngB3UemVJWZg5KbggAA + + +iLength +int +Pq2O6++E5U6nep84wmLP+gAA + + +return +pdkReturn +Pq2O6++E5U6nep84wmLP+gAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnSend +HjFZEYW1wEOsKFuTmPnHegAA +1 + +Cpp +CppVirtual +CppVirtual +True +15PwTCSBcEWts23fUQ7FGQAA + +4 + +dwConnID +15PwTCSBcEWts23fUQ7FGQAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +15PwTCSBcEWts23fUQ7FGQAA +2 + +Cpp +CppConst +CppConst +True +fIRiky/SV0SQdW/cO/uHHAAA + + +Cpp +CppPointer +CppPointer +* +fIRiky/SV0SQdW/cO/uHHAAA + + + +iLength +int +15PwTCSBcEWts23fUQ7FGQAA + + +return +pdkReturn +15PwTCSBcEWts23fUQ7FGQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnPrepareConnect +HjFZEYW1wEOsKFuTmPnHegAA +1 + +Cpp +CppVirtual +CppVirtual +True +xhKIRbevWE6uWDzyVSO6GgAA + +3 + +dwConnID +xhKIRbevWE6uWDzyVSO6GgAA +G8TfQngB3UemVJWZg5KbggAA + + +socket +SOCKET +xhKIRbevWE6uWDzyVSO6GgAA + + +return +pdkReturn +xhKIRbevWE6uWDzyVSO6GgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnConnect +HjFZEYW1wEOsKFuTmPnHegAA +1 + +Cpp +CppVirtual +CppVirtual +True +1ya73XA+PkaGRV297OxDrwAA + +2 + +dwConnID +1ya73XA+PkaGRV297OxDrwAA +G8TfQngB3UemVJWZg5KbggAA + + +return +pdkReturn +1ya73XA+PkaGRV297OxDrwAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnShutdown +HjFZEYW1wEOsKFuTmPnHegAA +1 + +Cpp +CppVirtual +CppVirtual +True +FXyIYFuXoEeUjlqnqExqdQAA + +1 + +return +pdkReturn +FXyIYFuXoEeUjlqnqExqdQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +CTcpPullAgentListener +jvfBmo6uGkC61ckI99TMgAAA +4 +eYGlKkdZLEutBTtuUOVCFAAA +TZL2lX8FF0Wegrqz+P046AAA +0OraRAUZvUK105OwHzbt1QAA +Z5LyeK29CkeW8JGl/9sC3wAA +1 +xj1q7c1vdUK4s8CkFyDE3wAA +2 + +OnReceive +True +hNuH1fWUHU2IT4Poty2GiwAA +1 + +Cpp +CppVirtual +CppVirtual +True +JDX7FarFvEqDV2ov8G0MjQAA + +3 + +dwConnID +JDX7FarFvEqDV2ov8G0MjQAA +G8TfQngB3UemVJWZg5KbggAA + + +iLength +int +JDX7FarFvEqDV2ov8G0MjQAA + + +return +pdkReturn +JDX7FarFvEqDV2ov8G0MjQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnReceive +hNuH1fWUHU2IT4Poty2GiwAA +1 + +Cpp +CppVirtual +CppVirtual +True +gYGNXG5a0ki4z69Yh0WWCwAA + +4 + +dwConnID +gYGNXG5a0ki4z69Yh0WWCwAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +gYGNXG5a0ki4z69Yh0WWCwAA +2 + +Cpp +CppConst +CppConst +True +r088UTjRNU6QtSab5PR2FQAA + + +Cpp +CppPointer +CppPointer +* +r088UTjRNU6QtSab5PR2FQAA + + + +iLength +int +gYGNXG5a0ki4z69Yh0WWCwAA + + +return +pdkReturn +gYGNXG5a0ki4z69Yh0WWCwAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +IClient +jvfBmo6uGkC61ckI99TMgAAA +8 +IxwL95gLAk2VVqCaT07mZwAA +5LoScxDICkiLOJ1Jd+SNywAA +eVFjHaVUSkC3e4KQDrXbjAAA +pWVU633N3Em3oXPPEfXMSgAA +ylsx02qZaUiyvMjQBrZn+gAA +BO6bxMMKLUSip/JxYYbmXgAA +tZSW1mDNLEGspe67eOzH9AAA +v2u4ybdn70GcAZiUJBSrxQAA +3 +dOpAHC5JfkymmNyAgeRwWAAA +VhVmNVhKIEyRJWflThCsqQAA +MejA8cLC00G/Y3QcvCU6BgAA +18 + +Start +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +FXn2QPx7IkSUIpKABOcfdQAA + +4 + +pszRemoteAddress +LPCTSTR +FXn2QPx7IkSUIpKABOcfdQAA + + +usPort +USHORT +FXn2QPx7IkSUIpKABOcfdQAA + + +bAsyncConnect +BOOL +FXn2QPx7IkSUIpKABOcfdQAA + + +return +pdkReturn +BOOL +FXn2QPx7IkSUIpKABOcfdQAA + + + +Stop +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +iJL0LOxsGUin/7UJ35qrxAAA + +1 + +return +pdkReturn +BOOL +iJL0LOxsGUin/7UJ35qrxAAA + + + +Send +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +JrCkLmYUWkat79J8z/33OAAA + +4 + +pBuffer +BYTE +JrCkLmYUWkat79J8z/33OAAA +2 + +Cpp +CppConst +CppConst +True +jZQzKWFl8kiiRjLcXSK2QwAA + + +Cpp +CppPointer +CppPointer +* +jZQzKWFl8kiiRjLcXSK2QwAA + + + +iLength +int +JrCkLmYUWkat79J8z/33OAAA + + +iOffset +int +JrCkLmYUWkat79J8z/33OAAA + + +return +pdkReturn +BOOL +JrCkLmYUWkat79J8z/33OAAA + + + +SendPackets +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +ati5pb1+XUG/z7in3SkPKgAA + +3 + +pBuffers +WSABUF +ati5pb1+XUG/z7in3SkPKgAA +1 + +Cpp +CppConst +CppConst +True +tx28NDlZt0KsunxC6w7hwQAA + + + +iCount +int +ati5pb1+XUG/z7in3SkPKgAA + + +return +pdkReturn +BOOL +ati5pb1+XUG/z7in3SkPKgAA + + + +SetExtra +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +fIga02e49kO9JeWdJjDeVAAA + +2 + +pExtra +PVOID +fIga02e49kO9JeWdJjDeVAAA + + +return +pdkReturn +void +fIga02e49kO9JeWdJjDeVAAA + + + +GetExtra +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +HO4br1mJdUq3858p4q9MIgAA + +1 + +return +pdkReturn +PVOID +HO4br1mJdUq3858p4q9MIgAA + + + +HasStarted +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +ke39qO+O/kGCPlPHSysfUgAA + +1 + +return +pdkReturn +BOOL +ke39qO+O/kGCPlPHSysfUgAA + + + +GetState +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +TJsIJga3a0yF9owtdqlnQAAA + +1 + +return +pdkReturn +TJsIJga3a0yF9owtdqlnQAAA +3KsfqnlMb0ieGw/IAO5hFQAA + + + +GetLastError +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +1k4Gz4a0MUqMQyanW0tnpQAA + +1 + +return +pdkReturn +1k4Gz4a0MUqMQyanW0tnpQAA +R9EXi7T78E6Gt882nRMyDwAA + + + +GetLastErrorDesc +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +lOtLMfPKKkefaQ9POQWclgAA + +1 + +return +pdkReturn +LPCTSTR +lOtLMfPKKkefaQ9POQWclgAA + + + +GetConnectionID +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +yExTFiz2cEmjButPjIDYewAA + +1 + +return +pdkReturn +yExTFiz2cEmjButPjIDYewAA +G8TfQngB3UemVJWZg5KbggAA + + + +GetLocalAddress +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +ljf21pXk+US2qWhmXPrO6gAA + +4 + +lpszAddress +TCHAR +ljf21pXk+US2qWhmXPrO6gAA + + +iAddressLen +int +ljf21pXk+US2qWhmXPrO6gAA +1 + +Cpp +CppPointer +CppPointer +& +DJGg2+/IIECOhUv5xPq6EgAA + + + +usPort +USHORT +ljf21pXk+US2qWhmXPrO6gAA +1 + +Cpp +CppPointer +CppPointer +& +pq0DZio5FEqFfW3dxVALSQAA + + + +return +pdkReturn +BOOL +ljf21pXk+US2qWhmXPrO6gAA + + + +GetPendingDataLength +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +o5k5FaNQrkC4mTPiP3m0PQAA + +2 + +iPending +int +o5k5FaNQrkC4mTPiP3m0PQAA +1 + +Cpp +CppPointer +CppPointer +& +PPmHy6vQDkCdWD/+pTeAZgAA + + + +return +pdkReturn +BOOL +o5k5FaNQrkC4mTPiP3m0PQAA + + + +SetFreeBufferPoolSize +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +nzXKRMY/90KhHgA24NR0QwAA + +2 + +dwFreeBufferPoolSize +DWORD +nzXKRMY/90KhHgA24NR0QwAA + + +return +pdkReturn +void +nzXKRMY/90KhHgA24NR0QwAA + + + +SetFreeBufferPoolHold +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +kcsWlk7PC0Kls1b4WiHMHgAA + +2 + +dwFreeBufferPoolHold +DWORD +kcsWlk7PC0Kls1b4WiHMHgAA + + +return +pdkReturn +void +kcsWlk7PC0Kls1b4WiHMHgAA + + + +GetFreeBufferPoolSize +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +SWnPGMqQUUKWSOZ9TrQ93QAA + +1 + +return +pdkReturn +DWORD +SWnPGMqQUUKWSOZ9TrQ93QAA + + + +GetFreeBufferPoolHold +True +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppVirtual +CppVirtual +True +eQINpdFDDka6qk5ae9JFQgAA + +1 + +return +pdkReturn +DWORD +eQINpdFDDka6qk5ae9JFQgAA + + + +IClient +UMLStandard +destroy +vkPrivate +R8hLgFt1fEaSSxBO7KbEBQAA + +22 +YxFg6r2YOkexVpf82lVuHQAA +CBO2PV4XcEWn5rY+ZCfFVAAA +H2wEbGIARkqtYmyD0PaihQAA +pmySIaVL0UWlEmfbi5p20QAA +0yLRzmFX2USh21tzHf4PzwAA +uet5/xytWE+Y+HxB5EWqNQAA +lDJnw2EQwkatABSjfTTdLwAA +WQx6R2HbRkWAAJygT5gE2wAA +NIsPKnZwCUinp+ihfbmq1gAA +hZe7shhXxEGqWZ6x53ebigAA +TAPbNz9s+0+dvRpyncYzGgAA +WK0j7Dh5RkujG3h92NIpywAA +uLitAE/RmEmT8MTf7jFLzAAA +EO4LQ1l+V0abYC2euaHh3AAA +jtCyaHP02kqlCiRduN2KbgAA +CPJR9wqW+kmgeMNICz+bCgAA +ZZ0/QmxwIEm7SYTFiP6JOwAA +QHYmqV28kkmKffvJogsHoAAA +k9GjEva9xU6lvenWrCCIUQAA +ui8T/xO9oEiXpayGYfJlwwAA +fenI/tCbCEGzso47imi01gAA +gIgg7x4VeUqsHSn2rpR+6QAA + + +IClientListener +jvfBmo6uGkC61ckI99TMgAAA +8 +q36mxdXyZE6WTwmuKuQ2vAAA +iN4Jd+Ojd0COjmqa9I8xCQAA +SCydOgNR5EqglVeO7b4/RwAA +KouIiKxDzkKFtN6oehIqGAAA +KrTYF4Cl0UWAT3s9Q59oBAAA +Kqp8aDnYvEOviwoQzcalVwAA +wSBU+Ruy102l0L4LNn2NwAAA +SirmtBr3Ike2SyQIonk8XQAA +3 +LHdDVg405EStLqtC9ACaJgAA +sN55Dgbmo0WZvNqCj0OqQwAA +iH3ueDodB0OuqZ5awdjDeQAA +7 + +OnPrepareConnect +True +BZTI/4OA7kG+nFfsclldCgAA +1 + +Cpp +CppVirtual +CppVirtual +True +GBHZFShIoUSrYFqBTCc06wAA + +3 + +pClient +GBHZFShIoUSrYFqBTCc06wAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +YxFg6r2YOkexVpf82lVuHQAA + + + +socket +SOCKET +GBHZFShIoUSrYFqBTCc06wAA + + +return +pdkReturn +GBHZFShIoUSrYFqBTCc06wAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnConnect +True +BZTI/4OA7kG+nFfsclldCgAA +1 + +Cpp +CppVirtual +CppVirtual +True +ADLKSSjg3EubcWcdSqu8zgAA + +2 + +pClient +ADLKSSjg3EubcWcdSqu8zgAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +CBO2PV4XcEWn5rY+ZCfFVAAA + + + +return +pdkReturn +ADLKSSjg3EubcWcdSqu8zgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnSend +True +BZTI/4OA7kG+nFfsclldCgAA +1 + +Cpp +CppVirtual +CppVirtual +True +GQwbh5HQvEq3kmL1kt2gDQAA + +4 + +pClient +GQwbh5HQvEq3kmL1kt2gDQAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +H2wEbGIARkqtYmyD0PaihQAA + + + +pData +BYTE +GQwbh5HQvEq3kmL1kt2gDQAA +2 + +Cpp +CppConst +CppConst +True +l7k0dyaHD0SXfyAqTJ1PyAAA + + +Cpp +CppPointer +CppPointer +* +l7k0dyaHD0SXfyAqTJ1PyAAA + + + +iLength +int +GQwbh5HQvEq3kmL1kt2gDQAA + + +return +pdkReturn +GQwbh5HQvEq3kmL1kt2gDQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnReceive +True +BZTI/4OA7kG+nFfsclldCgAA +1 + +Cpp +CppVirtual +CppVirtual +True +gf5fQytuNUOTndmYMUDdWwAA + +4 + +pClient +gf5fQytuNUOTndmYMUDdWwAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +pmySIaVL0UWlEmfbi5p20QAA + + + +pData +BYTE +gf5fQytuNUOTndmYMUDdWwAA +2 + +Cpp +CppConst +CppConst +True +BTV+roe04kiIM5Z0FNqmMgAA + + +Cpp +CppPointer +CppPointer +* +BTV+roe04kiIM5Z0FNqmMgAA + + + +iLength +int +gf5fQytuNUOTndmYMUDdWwAA + + +return +pdkReturn +gf5fQytuNUOTndmYMUDdWwAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnReceive +True +BZTI/4OA7kG+nFfsclldCgAA +1 + +Cpp +CppVirtual +CppVirtual +True +EjVLrt/8lUeEtNKFy9rrXQAA + +3 + +pClient +EjVLrt/8lUeEtNKFy9rrXQAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +0yLRzmFX2USh21tzHf4PzwAA + + + +iLength +int +EjVLrt/8lUeEtNKFy9rrXQAA + + +return +pdkReturn +EjVLrt/8lUeEtNKFy9rrXQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnClose +True +BZTI/4OA7kG+nFfsclldCgAA +1 + +Cpp +CppVirtual +CppVirtual +True +xn+7q7ogyU2w3D7ewAcvcgAA + +4 + +pdkReturn +xn+7q7ogyU2w3D7ewAcvcgAA +2khtjHI2AUSz1nm7UQu8uwAA + + +pClient +xn+7q7ogyU2w3D7ewAcvcgAA +R8hLgFt1fEaSSxBO7KbEBQAA + + +enOperation +xn+7q7ogyU2w3D7ewAcvcgAA +bcrguJxo002HtvMUNvyx5QAA + + +iErrorCode +int +xn+7q7ogyU2w3D7ewAcvcgAA + + + +IClientListener +UMLStandard +destroy +vkPrivate +BZTI/4OA7kG+nFfsclldCgAA + + + +ITcpClientListener +jvfBmo6uGkC61ckI99TMgAAA +8 +e/+kw8IbbkOctNvnX+LZsQAA +frD7XZPrh0G8wNyQFzpOKwAA +IgBs6Ne6dE2ZKySR5TNwmgAA +jFB7Xkk3PEu8PVZeQiB/fwAA +lkeOHiiD8k61jW8z3Jdf1AAA +02wTaJmioUCIk1oqfsunrAAA +Peic2oQXl0WmD++Z8ZL+mgAA +HM49ymshZkGKnJh3DPyxVQAA +1 +LHdDVg405EStLqtC9ACaJgAA +1 +jMwPdcNgf0KaJMKQBOazIgAA +3 +zFezEQ9xPkK/0POS3GJN3AAA +O/zc/hQ0+EOg3dj2SV2i6wAA +2htC5RYGCkmqkKaQAQy/zgAA + + +CTcpClientListener +jvfBmo6uGkC61ckI99TMgAAA +4 +JvAeKTqBzE+W2Tw+N4ESXQAA +kI+4CvpvPEK2Q4J7r3xYlAAA +8QGRQEWtrEWU+EAuQD2QjQAA +wBPb7rx7+0yECdGqYZOb9AAA +1 +jMwPdcNgf0KaJMKQBOazIgAA +1 +x9j97vQnoEStugksSdPSBwAA +4 + +OnReceive +c38EVYXmckWErbW5Cl4UwgAA +1 + +Cpp +CppVirtual +CppVirtual +True +DFjV9XVOcEKP0ucdvRI2kAAA + +3 + +pClient +DFjV9XVOcEKP0ucdvRI2kAAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +uet5/xytWE+Y+HxB5EWqNQAA + + + +iLength +int +DFjV9XVOcEKP0ucdvRI2kAAA + + +return +pdkReturn +DFjV9XVOcEKP0ucdvRI2kAAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnSend +c38EVYXmckWErbW5Cl4UwgAA +1 + +Cpp +CppVirtual +CppVirtual +True +4VxsTJ0fNkidIE80/xE3vQAA + +4 + +pClient +4VxsTJ0fNkidIE80/xE3vQAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +lDJnw2EQwkatABSjfTTdLwAA + + + +pData +BYTE +4VxsTJ0fNkidIE80/xE3vQAA +2 + +Cpp +CppConst +CppConst +True +zqShxQaNmUG2iKMT5icQiAAA + + +Cpp +CppPointer +CppPointer +* +zqShxQaNmUG2iKMT5icQiAAA + + + +iLength +int +4VxsTJ0fNkidIE80/xE3vQAA + + +return +pdkReturn +4VxsTJ0fNkidIE80/xE3vQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnPrepareConnect +c38EVYXmckWErbW5Cl4UwgAA +1 + +Cpp +CppVirtual +CppVirtual +True +YKnpS54TcEqys7yO6C62KQAA + +3 + +pClient +YKnpS54TcEqys7yO6C62KQAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +WQx6R2HbRkWAAJygT5gE2wAA + + + +socket +SOCKET +YKnpS54TcEqys7yO6C62KQAA + + +return +pdkReturn +YKnpS54TcEqys7yO6C62KQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnConnect +c38EVYXmckWErbW5Cl4UwgAA +1 + +Cpp +CppVirtual +CppVirtual +True +LTEGtNqskE6IZMKLEuWEKQAA + +2 + +pClient +LTEGtNqskE6IZMKLEuWEKQAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +NIsPKnZwCUinp+ihfbmq1gAA + + + +return +pdkReturn +LTEGtNqskE6IZMKLEuWEKQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +CTcpPullClientListener +jvfBmo6uGkC61ckI99TMgAAA +4 +7UPYyBmTk0StzHZNW+YJswAA +aWqhXMD8VkuncGYU/TRa4gAA +sIl6IF1p3UGFGurhgur7lAAA +gTvis3oVbUSIlt4iTC6FtgAA +1 +x9j97vQnoEStugksSdPSBwAA +2 + +OnReceive +True +4OTsa4LGqUqntun16mJ7kAAA +1 + +Cpp +CppVirtual +CppVirtual +True +E70BYUdhrUiv0pOi5jgrIgAA + +3 + +pClient +E70BYUdhrUiv0pOi5jgrIgAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +hZe7shhXxEGqWZ6x53ebigAA + + + +iLength +int +E70BYUdhrUiv0pOi5jgrIgAA + + +return +pdkReturn +E70BYUdhrUiv0pOi5jgrIgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnReceive +4OTsa4LGqUqntun16mJ7kAAA +1 + +Cpp +CppVirtual +CppVirtual +True +dhjA69HBI0CkIFDeZ6/zOgAA + +4 + +pClient +dhjA69HBI0CkIFDeZ6/zOgAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +TAPbNz9s+0+dvRpyncYzGgAA + + + +pData +BYTE +dhjA69HBI0CkIFDeZ6/zOgAA +2 + +Cpp +CppConst +CppConst +True +VlEVjRcvVkyzzaS1YsN+VQAA + + +Cpp +CppPointer +CppPointer +* +VlEVjRcvVkyzzaS1YsN+VQAA + + + +iLength +int +dhjA69HBI0CkIFDeZ6/zOgAA + + +return +pdkReturn +dhjA69HBI0CkIFDeZ6/zOgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +IUdpClientListener +jvfBmo6uGkC61ckI99TMgAAA +8 +giFfOL+L5EqS2RmY8ylUDQAA +QmuKGJ3UKkW1vpncakImhgAA +HVXQCHfixU6cMyHIXMomHwAA +ZI6Rsbi3bUmBDVhICf/9ogAA +4X4YjiGr1keUOnRkcKUhTQAA +BIw0ociJiEqXe/JIg4d71wAA +5D0fKX7E6kyfL3rEsGn4AAAA +rrbk06awQUyDwU+m1fcWwwAA +1 +sN55Dgbmo0WZvNqCj0OqQwAA +1 +ckrUyHyNEkqEIaDRIjKBrAAA +1 +fd40Q5EVIE+le0pAEDqLewAA + + +CUdpClientListener +jvfBmo6uGkC61ckI99TMgAAA +4 +awRPnutzt0yg7s50bGBGLQAA +R65AsCp7/kKZEEuN6mJnAQAA +h8T9WjSbKkO/KlPFlNUStQAA +b2WBJ8foHkeE1RlZcb+EowAA +1 +ckrUyHyNEkqEIaDRIjKBrAAA +4 + +OnReceive +eLrcJo0DgE2AjvOF61yczQAA +1 + +Cpp +CppVirtual +CppVirtual +True +oQMqBMuQkEKCy+/TIPqLpAAA + +3 + +pClient +oQMqBMuQkEKCy+/TIPqLpAAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +WK0j7Dh5RkujG3h92NIpywAA + + + +iLength +int +oQMqBMuQkEKCy+/TIPqLpAAA + + +return +pdkReturn +oQMqBMuQkEKCy+/TIPqLpAAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnSend +eLrcJo0DgE2AjvOF61yczQAA +1 + +Cpp +CppVirtual +CppVirtual +True +U8DQwiQCD06SOBdKXxw1GAAA + +4 + +pClient +U8DQwiQCD06SOBdKXxw1GAAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +uLitAE/RmEmT8MTf7jFLzAAA + + + +pData +BYTE +U8DQwiQCD06SOBdKXxw1GAAA +2 + +Cpp +CppConst +CppConst +True +LprziFespUK+5FcjZh7+lgAA + + +Cpp +CppPointer +CppPointer +* +LprziFespUK+5FcjZh7+lgAA + + + +iLength +int +U8DQwiQCD06SOBdKXxw1GAAA + + +return +pdkReturn +U8DQwiQCD06SOBdKXxw1GAAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnPrepareConnect +eLrcJo0DgE2AjvOF61yczQAA +1 + +Cpp +CppVirtual +CppVirtual +True +NGoGfq3L9EmWEgXzhoqvpQAA + +3 + +pClient +NGoGfq3L9EmWEgXzhoqvpQAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +EO4LQ1l+V0abYC2euaHh3AAA + + + +socket +SOCKET +NGoGfq3L9EmWEgXzhoqvpQAA + + +return +pdkReturn +NGoGfq3L9EmWEgXzhoqvpQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnConnect +eLrcJo0DgE2AjvOF61yczQAA +1 + +Cpp +CppVirtual +CppVirtual +True +//DbaUCPhkKZNbBRpKkh8AAA + +2 + +pClient +//DbaUCPhkKZNbBRpKkh8AAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +jtCyaHP02kqlCiRduN2KbgAA + + + +return +pdkReturn +//DbaUCPhkKZNbBRpKkh8AAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +IUdpCastListener +jvfBmo6uGkC61ckI99TMgAAA +8 +i1mju6goyUCpVQPExOMCbwAA +GNZxlybcjEuVm9e2423k3wAA +eSUqEmUtqk2V8ShtXkjvewAA +XSJs3T7YI0iYoqr4xV+M0wAA +IpuoRM7390mIm+qG9Hl2bgAA +wLF3P92IA0GWrx4jIj1iSAAA +2mzTzKV7XE6/vIM2AXv+7wAA +9YNzBKM7eU2f/irQU7KT2AAA +1 +iH3ueDodB0OuqZ5awdjDeQAA +1 +FoyTfxOKQ0CcM6uuMKewkwAA +1 +EyoF0ndo9kCFpkNwo8KVngAA + + +CUdpCastListener +jvfBmo6uGkC61ckI99TMgAAA +4 +zefMvmnz2UK+gAC3E0jXgQAA +gl4HGvhATkSKNdqisWaX2QAA +qRSzJ3+ZYEKttt6Ymal/bQAA +UGOw8wdZZEOul39oThjtQgAA +1 +FoyTfxOKQ0CcM6uuMKewkwAA +4 + +OnReceive +sJBjmKjtoEWtenBeaDLnjwAA +1 + +Cpp +CppVirtual +CppVirtual +True +hXT8VyZLG0euMH0fGT4wIgAA + +3 + +pClient +hXT8VyZLG0euMH0fGT4wIgAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +CPJR9wqW+kmgeMNICz+bCgAA + + + +iLength +int +hXT8VyZLG0euMH0fGT4wIgAA + + +return +pdkReturn +hXT8VyZLG0euMH0fGT4wIgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnSend +sJBjmKjtoEWtenBeaDLnjwAA +1 + +Cpp +CppVirtual +CppVirtual +True +GRNy2b34Qkq0rj+XW+JNHgAA + +4 + +pClient +GRNy2b34Qkq0rj+XW+JNHgAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +ZZ0/QmxwIEm7SYTFiP6JOwAA + + + +pData +BYTE +GRNy2b34Qkq0rj+XW+JNHgAA +2 + +Cpp +CppConst +CppConst +True +8MCAbb35GUOxgFx4hIQK6AAA + + +Cpp +CppPointer +CppPointer +* +8MCAbb35GUOxgFx4hIQK6AAA + + + +iLength +int +GRNy2b34Qkq0rj+XW+JNHgAA + + +return +pdkReturn +GRNy2b34Qkq0rj+XW+JNHgAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnPrepareConnect +sJBjmKjtoEWtenBeaDLnjwAA +1 + +Cpp +CppVirtual +CppVirtual +True +yw8ouM59IUug/cTb7x46YQAA + +3 + +pClient +yw8ouM59IUug/cTb7x46YQAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +QHYmqV28kkmKffvJogsHoAAA + + + +socket +SOCKET +yw8ouM59IUug/cTb7x46YQAA + + +return +pdkReturn +yw8ouM59IUug/cTb7x46YQAA +2khtjHI2AUSz1nm7UQu8uwAA + + + +OnConnect +sJBjmKjtoEWtenBeaDLnjwAA +1 + +Cpp +CppVirtual +CppVirtual +True +h0nCj5ZeHEeqxlogOpjm5QAA + +2 + +pClient +h0nCj5ZeHEeqxlogOpjm5QAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +k9GjEva9xU6lvenWrCCIUQAA + + + +return +pdkReturn +h0nCj5ZeHEeqxlogOpjm5QAA +2khtjHI2AUSz1nm7UQu8uwAA + + + + +IComplexSocket +True +jvfBmo6uGkC61ckI99TMgAAA +12 +S5CdZWL+bEWmCJb9qIaNogAA +yr076N5YYk+5AJxr/7e0fgAA +M9HJ8lGtoUiYAR/5adzcvQAA +uTrKQgpGAUaBG62XQZwHsgAA +MbT+AK7qSEilQO9f6kF5ugAA +MMzgr7pCD0myYUlV5NJ0YwAA +eYcDoVNH0kyd2JFyLPF0BAAA +VR8cKxmMoEuRejDm+U6K2gAA +eiN6oYelCU++QjaXKMX8mAAA ++f/giJSktUeJScC43ABmQwAA +nuVR3t+r2U2HlwLOGxQyMwAA +KGnW+YGME0KohOLr2dhRqwAA +2 +9BTtNyRQHEu7yKoNswewcQAA +dx6I5RGr20SmTHCEMdZ9nAAA +35 + +Stop +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +r7TqTazDpEqD42pJhcNAXQAA + +1 + +return +pdkReturn +BOOL +r7TqTazDpEqD42pJhcNAXQAA + + + +Send +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +19uLfCRXEUSEciA7RL2DpwAA + +5 + +dwConnID +19uLfCRXEUSEciA7RL2DpwAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffer +BYTE +19uLfCRXEUSEciA7RL2DpwAA +2 + +Cpp +CppConst +CppConst +True +A3cdPR3hs0CwwyzsznJEYwAA + + +Cpp +CppPointer +CppPointer +* +A3cdPR3hs0CwwyzsznJEYwAA + + + +iLength +int +19uLfCRXEUSEciA7RL2DpwAA + + +iOffset +int +19uLfCRXEUSEciA7RL2DpwAA + + +return +pdkReturn +BOOL +19uLfCRXEUSEciA7RL2DpwAA + + + +SendPackets +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +XqSrlxsCyUq/UZb72peiNgAA + +4 + +dwConnID +XqSrlxsCyUq/UZb72peiNgAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffers +WSABUF +XqSrlxsCyUq/UZb72peiNgAA +1 + +Cpp +CppConst +CppConst +True +rxBnNrSp70yIoHsKjRRxjAAA + + + +iCount +int +XqSrlxsCyUq/UZb72peiNgAA + + +return +pdkReturn +BOOL +XqSrlxsCyUq/UZb72peiNgAA + + + +Disconnect +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +31patCIkWkqS/WsfyrCsXwAA + +3 + +dwConnID +31patCIkWkqS/WsfyrCsXwAA +G8TfQngB3UemVJWZg5KbggAA + + +bForce +BOOL +31patCIkWkqS/WsfyrCsXwAA + + +return +pdkReturn +BOOL +31patCIkWkqS/WsfyrCsXwAA + + + +DisconnectLongConnections +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +6aamqDSDNk+1aKYg+DYpbAAA + +3 + +dwPeriod +DWORD +6aamqDSDNk+1aKYg+DYpbAAA + + +bForce +BOOL +6aamqDSDNk+1aKYg+DYpbAAA + + +return +pdkReturn +BOOL +6aamqDSDNk+1aKYg+DYpbAAA + + + +DisconnectSilenceConnections +True +SqNjwMrIrEaWmScJhNPQOwAA +3 + +pdkReturn +BOOL +NT1IUqefdU+UoSBoCrbN0gAA + + +dwPeriod +DWORD +NT1IUqefdU+UoSBoCrbN0gAA + + +bForce +BOOL +NT1IUqefdU+UoSBoCrbN0gAA + + + +SetConnectionExtra +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +Up+HOi8Q1ESEyfDvFdbEtQAA + +3 + +dwConnID +Up+HOi8Q1ESEyfDvFdbEtQAA +G8TfQngB3UemVJWZg5KbggAA + + +pExtra +PVOID +Up+HOi8Q1ESEyfDvFdbEtQAA + + +return +pdkReturn +BOOL +Up+HOi8Q1ESEyfDvFdbEtQAA + + + +GetConnectionExtra +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +fQ0U6nVhIkmuda8ZugjGAAAA + +3 + +dwConnID +fQ0U6nVhIkmuda8ZugjGAAAA +G8TfQngB3UemVJWZg5KbggAA + + +ppExtra +PVOID +fQ0U6nVhIkmuda8ZugjGAAAA +1 + +Cpp +CppPointer +CppPointer +* +OgfhRcvOb0CCQ80VWK1pzAAA + + + +return +pdkReturn +BOOL +fQ0U6nVhIkmuda8ZugjGAAAA + + + +HasStarted +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +Y2yL4VhT4kukWGvfGwlxiwAA + +1 + +return +pdkReturn +BOOL +Y2yL4VhT4kukWGvfGwlxiwAA + + + +GetState +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +3LN60l+NZkGQMAzGtnUQPwAA + +1 + +return +pdkReturn +3LN60l+NZkGQMAzGtnUQPwAA +3KsfqnlMb0ieGw/IAO5hFQAA + + + +GetConnectionCount +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +pebyhRCnJ0ifcWHgEhT1pwAA + +1 + +return +pdkReturn +DWORD +pebyhRCnJ0ifcWHgEhT1pwAA + + + +GetAllConnectionIDs +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +o1tJpKl5S0WyVuixJq83twAA + +3 + +pIDs +o1tJpKl5S0WyVuixJq83twAA +G8TfQngB3UemVJWZg5KbggAA + + +dwCount +DWORD +o1tJpKl5S0WyVuixJq83twAA +1 + +Cpp +CppPointer +CppPointer +& +kLTZp+F/NkmmOJtSUpw9NgAA + + + +return +pdkReturn +BOOL +o1tJpKl5S0WyVuixJq83twAA + + + +GetConnectPeriod +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +tp933m4+fUOFzWiZ5nmCRQAA + +3 + +dwConnID +tp933m4+fUOFzWiZ5nmCRQAA +G8TfQngB3UemVJWZg5KbggAA + + +dwPeriod +DWORD +tp933m4+fUOFzWiZ5nmCRQAA +1 + +Cpp +CppPointer +CppPointer +& +yG+E2iZeIk2FRzOCZtXa9gAA + + + +return +pdkReturn +BOOL +tp933m4+fUOFzWiZ5nmCRQAA + + + +GetSilencePeriod +True +SqNjwMrIrEaWmScJhNPQOwAA +3 + +pdkReturn +BOOL +MPSD6gvTfEqHKGb0KDJHUQAA + + +dwConnID +MPSD6gvTfEqHKGb0KDJHUQAA +G8TfQngB3UemVJWZg5KbggAA + + +dwPeriod +DWORD +MPSD6gvTfEqHKGb0KDJHUQAA + + + +GetRemoteAddress +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +RlA0zt5WP06tvUIKaiK1SgAA + +5 + +dwConnID +RlA0zt5WP06tvUIKaiK1SgAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszAddress +TCHAR +RlA0zt5WP06tvUIKaiK1SgAA + + +iAddressLen +int +RlA0zt5WP06tvUIKaiK1SgAA +1 + +Cpp +CppPointer +CppPointer +& +iSpDjfxk3k+aeFhLkukZbAAA + + + +usPort +USHORT +RlA0zt5WP06tvUIKaiK1SgAA +1 + +Cpp +CppPointer +CppPointer +& +k5UjunLhk0SDPXbKQv+LfgAA + + + +return +pdkReturn +BOOL +RlA0zt5WP06tvUIKaiK1SgAA + + + +GetLastError +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +J8GJKLKchk6COQdadmFghAAA + +1 + +return +pdkReturn +J8GJKLKchk6COQdadmFghAAA +R9EXi7T78E6Gt882nRMyDwAA + + + +GetLastErrorDesc +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +uzTuxMmBYkaG+e+LcmRPqgAA + +1 + +return +pdkReturn +LPCTSTR +uzTuxMmBYkaG+e+LcmRPqgAA + + + +GetPendingDataLength +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +SHtSToWPIU2D9h+8ClS7EwAA + +3 + +dwConnID +SHtSToWPIU2D9h+8ClS7EwAA +G8TfQngB3UemVJWZg5KbggAA + + +iPending +int +SHtSToWPIU2D9h+8ClS7EwAA +1 + +Cpp +CppPointer +CppPointer +& +cHI9PDA4E0Sy78sXHx5gFAAA + + + +return +pdkReturn +BOOL +SHtSToWPIU2D9h+8ClS7EwAA + + + +SetSendPolicy +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +l0HgpaaXrEmcBwqw/QXksQAA + +2 + +enSendPolicy +l0HgpaaXrEmcBwqw/QXksQAA +p4RvBvwp3kOxyo/4mj2ZKwAA + + +return +pdkReturn +void +l0HgpaaXrEmcBwqw/QXksQAA + + + +SetMarkSilence +True +SqNjwMrIrEaWmScJhNPQOwAA +2 + +pdkReturn +void ++4/wR3EDaU2wwoA0lsI+0QAA + + +bMarkSilence +BOOL ++4/wR3EDaU2wwoA0lsI+0QAA + + + +IsMarkSilence +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +pdkReturn +BOOL +hr1CQBzpzkWXNv8Oh578HQAA + + + +SetFreeSocketObjLockTime +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +rScGrml5zk6QMZsraNJn7QAA + +2 + +dwFreeSocketObjLockTime +DWORD +rScGrml5zk6QMZsraNJn7QAA + + +return +pdkReturn +void +rScGrml5zk6QMZsraNJn7QAA + + + +SetFreeSocketObjPool +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +9eJ4BBO5CUGqV2C/5PK8NgAA + +2 + +dwFreeSocketObjPool +DWORD +9eJ4BBO5CUGqV2C/5PK8NgAA + + +return +pdkReturn +void +9eJ4BBO5CUGqV2C/5PK8NgAA + + + +SetFreeBufferObjPool +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +donlXTJEKUGAZSU5Ns39dgAA + +2 + +dwFreeBufferObjPool +DWORD +donlXTJEKUGAZSU5Ns39dgAA + + +return +pdkReturn +void +donlXTJEKUGAZSU5Ns39dgAA + + + +SetFreeSocketObjHold +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +62tGcLoVbkevQKeSv8VsWwAA + +2 + +dwFreeSocketObjHold +DWORD +62tGcLoVbkevQKeSv8VsWwAA + + +return +pdkReturn +void +62tGcLoVbkevQKeSv8VsWwAA + + + +SetFreeBufferObjHold +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +SofrhIopnUq1WnF4nOO1JQAA + +2 + +dwFreeBufferObjHold +DWORD +SofrhIopnUq1WnF4nOO1JQAA + + +return +pdkReturn +void +SofrhIopnUq1WnF4nOO1JQAA + + + +SetWorkerThreadCount +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +xAdxxCxOTEmzRmSf+WQeZgAA + +2 + +dwWorkerThreadCount +DWORD +xAdxxCxOTEmzRmSf+WQeZgAA + + +return +pdkReturn +void +xAdxxCxOTEmzRmSf+WQeZgAA + + + +GetSendPolicy +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +CctQwD98hUq0RNTHM+HGagAA + +1 + +return +pdkReturn +CctQwD98hUq0RNTHM+HGagAA +p4RvBvwp3kOxyo/4mj2ZKwAA + + + +GetFreeSocketObjLockTime +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +xidfDSpG2E+hDsIb1oet9AAA + +1 + +return +pdkReturn +DWORD +xidfDSpG2E+hDsIb1oet9AAA + + + +GetFreeSocketObjPool +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +WoKXrowhsk2C/8ln1tMKxAAA + +1 + +return +pdkReturn +DWORD +WoKXrowhsk2C/8ln1tMKxAAA + + + +GetFreeBufferObjPool +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +fqzWpvGeqUWyUHRkJpkNQAAA + +1 + +return +pdkReturn +DWORD +fqzWpvGeqUWyUHRkJpkNQAAA + + + +GetFreeSocketObjHold +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +9cRf++26PE61b58/1/PsyQAA + +1 + +return +pdkReturn +DWORD +9cRf++26PE61b58/1/PsyQAA + + + +GetFreeBufferObjHold +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +rWsLrjN5ykeAah07ANA2fAAA + +1 + +return +pdkReturn +DWORD +rWsLrjN5ykeAah07ANA2fAAA + + + +GetWorkerThreadCount +True +SqNjwMrIrEaWmScJhNPQOwAA +1 + +Cpp +CppVirtual +CppVirtual +True +7pbK12sjrE6jOS6I0oMwiwAA + +1 + +return +pdkReturn +DWORD +7pbK12sjrE6jOS6I0oMwiwAA + + + +IComplexSocket +UMLStandard +destroy +vkPrivate +SqNjwMrIrEaWmScJhNPQOwAA + + + +IServer +jvfBmo6uGkC61ckI99TMgAAA +8 +P2r46P+bY0avZFfVkwtncQAA +U+2vSeTQcEyminV5ZMl7hgAA +jhzi6RR5eUSN0z6xssNTLgAA +Dp1UvgXSr0qmgg0Dj8CkywAA +kiHq/1vHX0WZ96N8FA/STwAA +XfmkXbSBqUesgGOU31U6twAA +HJXmvf1NFUW1QJwZmKqIqAAA +3CMU3cRgXEaJSTyFgdGswAAA +1 +9BTtNyRQHEu7yKoNswewcQAA +2 +qrDg6u3xU0KpgYiFoJBZ1AAA +rcZqqPur/USLxxaOeNdjswAA +2 + +Start +True +GoHMKPRtzES/2hlDzLtwnAAA +1 + +Cpp +CppVirtual +CppVirtual +True +PmbmwYUu706e1OsZfkgJiAAA + +3 + +pszBindAddress +LPCTSTR +PmbmwYUu706e1OsZfkgJiAAA + + +usPort +USHORT +PmbmwYUu706e1OsZfkgJiAAA + + +return +pdkReturn +BOOL +PmbmwYUu706e1OsZfkgJiAAA + + + +GetListenAddress +True +GoHMKPRtzES/2hlDzLtwnAAA +1 + +Cpp +CppVirtual +CppVirtual +True +snljPe+wp0i+3aS0Mt5NfAAA + +4 + +lpszAddress +TCHAR +snljPe+wp0i+3aS0Mt5NfAAA + + +iAddressLen +int +snljPe+wp0i+3aS0Mt5NfAAA +1 + +Cpp +CppPointer +CppPointer +& +Rc+9fR0eVkK+9TdEL4YrgQAA + + + +usPort +USHORT +snljPe+wp0i+3aS0Mt5NfAAA +1 + +Cpp +CppPointer +CppPointer +& +VpwDS551Kku/Ie5vHkjuagAA + + + +return +pdkReturn +BOOL +snljPe+wp0i+3aS0Mt5NfAAA + + +2 +da6KPUpOnkuM7gM+HBH1FwAA +lqZIR9zpP0y49VT0gCv6swAA + + +ITcpServer +jvfBmo6uGkC61ckI99TMgAAA +8 +yPFqE92KlUeCTsjNeQePJAAA +c3kbsLUpIU+IoldAvlcAzAAA +SVhhd4Ot00Kt7iIQ1QU75QAA +ycv+4FO25Eq7POPM8wgp7QAA +Ll1QQzy89EqZaHquqLut4QAA +/67o0SGCe0C1Z1NqBYJXjQAA +K8KCiu1Hfkiph40MpJieUQAA +Nd/XiGxagE2dXNRoHl0nBgAA +1 +qrDg6u3xU0KpgYiFoJBZ1AAA +3 +RvwWYNXraU2xkdsooYM/NwAA +O5dkSXpa9UWV4M9yJ7QzIwAA +nzQ/3s2PQEG5Cz2AX+hkOgAA +11 + +SendSmallFile +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +DtRcQ8vVZkKZQMYjOp4dQAAA + +5 + +dwConnID +DtRcQ8vVZkKZQMYjOp4dQAAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszFileName +LPCTSTR +DtRcQ8vVZkKZQMYjOp4dQAAA + + +pHead +LPWSABUF +DtRcQ8vVZkKZQMYjOp4dQAAA +1 + +Cpp +CppConst +CppConst +True +3Sz9+wNt5UmJ3IA2w+B8KAAA + + + +pTail +LPWSABUF +DtRcQ8vVZkKZQMYjOp4dQAAA +1 + +Cpp +CppConst +CppConst +True +qpaQtsmN+E2cXF5/t4nT2gAA + + + +return +pdkReturn +BOOL +DtRcQ8vVZkKZQMYjOp4dQAAA + + + +SetAcceptSocketCount +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +CYhGsUzNaE2Ai85n3Dg6vQAA + +2 + +dwAcceptSocketCount +DWORD +CYhGsUzNaE2Ai85n3Dg6vQAA + + +return +pdkReturn +void +CYhGsUzNaE2Ai85n3Dg6vQAA + + + +SetSocketBufferSize +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +BrPH6t/O/Eavt0knyBW9swAA + +2 + +dwSocketBufferSize +DWORD +BrPH6t/O/Eavt0knyBW9swAA + + +return +pdkReturn +void +BrPH6t/O/Eavt0knyBW9swAA + + + +SetSocketListenQueue +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +iMy7nEJR1UmMuL/0AgUmOwAA + +2 + +dwSocketListenQueue +DWORD +iMy7nEJR1UmMuL/0AgUmOwAA + + +return +pdkReturn +void +iMy7nEJR1UmMuL/0AgUmOwAA + + + +SetKeepAliveTime +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Hbfn9MEPkk65Y8NPcUSv7gAA + +2 + +dwKeepAliveTime +DWORD +Hbfn9MEPkk65Y8NPcUSv7gAA + + +return +pdkReturn +void +Hbfn9MEPkk65Y8NPcUSv7gAA + + + +SetKeepAliveInterval +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +z2r39MbCskWU+pH3My4LIgAA + +2 + +dwKeepAliveInterval +DWORD +z2r39MbCskWU+pH3My4LIgAA + + +return +pdkReturn +void +z2r39MbCskWU+pH3My4LIgAA + + + +GetAcceptSocketCount +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +GI4gRkiQGUqtrSz6LeJv7AAA + +1 + +return +pdkReturn +DWORD +GI4gRkiQGUqtrSz6LeJv7AAA + + + +GetSocketBufferSize +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +fHwqxR5MKkWZx4uhitro+wAA + +1 + +return +pdkReturn +DWORD +fHwqxR5MKkWZx4uhitro+wAA + + + +GetSocketListenQueue +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +WoyWsr3kLk6I4SvGp0Nb4gAA + +1 + +return +pdkReturn +DWORD +WoyWsr3kLk6I4SvGp0Nb4gAA + + + +GetKeepAliveTime +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +UGcFbVLapE6yxk3HKOmFuwAA + +1 + +return +pdkReturn +DWORD +UGcFbVLapE6yxk3HKOmFuwAA + + + +GetKeepAliveInterval +True +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppVirtual +CppVirtual +True +lt/OkYOw0kmu+W+vu47YPAAA + +1 + +return +pdkReturn +DWORD +lt/OkYOw0kmu+W+vu47YPAAA + + +2 +4lYcEooM20qvD7Cm0s0sHAAA +azDXhAug/kC0UeL/V3c2qQAA + + +IUdpServer +jvfBmo6uGkC61ckI99TMgAAA +8 +DCejEAT0mUabtDsSdi+dvQAA +KCMzPB1qAUOmDFaYNXhn9gAA +MT2IUousdkmJLsH8R1G+5gAA +C7ihFARq9k69+4LhuFqYUgAA +jbo8sT+vKUaLco+wapuQhwAA +kRMZ1WDaT0CDHIyXe/g98QAA +E9j1LERMfUibIU9hm/yXlAAA +Muo2FdUAk0qtx4FlLa/XugAA +1 +rcZqqPur/USLxxaOeNdjswAA +1 +j09xKlrPNkS8/NZ3JXD5MwAA +8 + +SetMaxDatagramSize +True +KqnhKB+uXkKxW6LqS8YzcgAA +1 + +Cpp +CppVirtual +CppVirtual +True +54UjSc47Sk2EPNDG+O4RFQAA + +2 + +dwMaxDatagramSize +DWORD +54UjSc47Sk2EPNDG+O4RFQAA + + +return +pdkReturn +void +54UjSc47Sk2EPNDG+O4RFQAA + + + +GetMaxDatagramSize +True +KqnhKB+uXkKxW6LqS8YzcgAA +1 + +Cpp +CppVirtual +CppVirtual +True +/Mr/JuV3n0iqtBCvrqN47AAA + +1 + +return +pdkReturn +DWORD +/Mr/JuV3n0iqtBCvrqN47AAA + + + +SetPostReceiveCount +True +KqnhKB+uXkKxW6LqS8YzcgAA +1 + +Cpp +CppVirtual +CppVirtual +True +jds7eFHADk22AWlypc0IHwAA + +2 + +dwPostReceiveCount +DWORD +jds7eFHADk22AWlypc0IHwAA + + +return +pdkReturn +void +jds7eFHADk22AWlypc0IHwAA + + + +GetPostReceiveCount +True +KqnhKB+uXkKxW6LqS8YzcgAA +1 + +Cpp +CppVirtual +CppVirtual +True +OlSWj+gIVUuCVgzGpVp5xQAA + +1 + +return +pdkReturn +DWORD +OlSWj+gIVUuCVgzGpVp5xQAA + + + +SetDetectAttempts +True +KqnhKB+uXkKxW6LqS8YzcgAA +1 + +Cpp +CppVirtual +CppVirtual +True +C8zOmWLd+Uef2OaGAGApigAA + +2 + +dwDetectAttempts +DWORD +C8zOmWLd+Uef2OaGAGApigAA + + +return +pdkReturn +void +C8zOmWLd+Uef2OaGAGApigAA + + + +SetDetectInterval +True +KqnhKB+uXkKxW6LqS8YzcgAA +1 + +Cpp +CppVirtual +CppVirtual +True +oC7rA0H27Eui6YYItFm80gAA + +2 + +dwDetectInterval +DWORD +oC7rA0H27Eui6YYItFm80gAA + + +return +pdkReturn +void +oC7rA0H27Eui6YYItFm80gAA + + + +GetDetectAttempts +True +KqnhKB+uXkKxW6LqS8YzcgAA +1 + +Cpp +CppVirtual +CppVirtual +True +ce18DuJ8o0u+Gh2db9eh2AAA + +1 + +return +pdkReturn +DWORD +ce18DuJ8o0u+Gh2db9eh2AAA + + + +GetDetectInterval +True +KqnhKB+uXkKxW6LqS8YzcgAA +1 + +Cpp +CppVirtual +CppVirtual +True +njzHWCq720mFdJ/cxI6isQAA + +1 + +return +pdkReturn +DWORD +njzHWCq720mFdJ/cxI6isQAA + + + + +IAgent +jvfBmo6uGkC61ckI99TMgAAA +8 +QK3KaQ4YV0Wt4DUTuGttgwAA +d98jvr45mESQHO7iF++khgAA +YnauoJtfBEiqxZird8oOoAAA +t3yoKlNmVkOZ28u5oLPqTwAA +n3rJyl0++kq9uoOsANKAUwAA +nVz76ek5BkuEIpKxEQMhHQAA +TcLytb4cw0yi2DYYX1oKzgAA +7pzMZAcbI0mt5/1lojtchwAA +1 +dx6I5RGr20SmTHCEMdZ9nAAA +1 +T7qvCRD8oEeFVhOYfk7D4wAA +3 + +Start +True +tc20+9LmREuR1dUMSybNdQAA +1 + +Cpp +CppVirtual +CppVirtual +True +iHUQ+nD/QU+DS2MXGUMLmgAA + +3 + +pszBindAddress +LPCTSTR +iHUQ+nD/QU+DS2MXGUMLmgAA + + +bAsyncConnect +BOOL +iHUQ+nD/QU+DS2MXGUMLmgAA + + +return +pdkReturn +BOOL +iHUQ+nD/QU+DS2MXGUMLmgAA + + + +Connect +True +tc20+9LmREuR1dUMSybNdQAA +1 + +Cpp +CppVirtual +CppVirtual +True +SnDOnAla2Um3FMHR6Ey02AAA + +4 + +pszRemoteAddress +LPCTSTR +SnDOnAla2Um3FMHR6Ey02AAA + + +usPort +USHORT +SnDOnAla2Um3FMHR6Ey02AAA + + +pdwConnID +SnDOnAla2Um3FMHR6Ey02AAA +G8TfQngB3UemVJWZg5KbggAA +1 + +Cpp +CppPointer +CppPointer +* +06q418O6FEOlWfOa7XazAwAA + + + +return +pdkReturn +BOOL +SnDOnAla2Um3FMHR6Ey02AAA + + + +GetLocalAddress +True +tc20+9LmREuR1dUMSybNdQAA +1 + +Cpp +CppVirtual +CppVirtual +True +3QdspoNdE0Ss+lJNCD19KQAA + +5 + +dwConnID +3QdspoNdE0Ss+lJNCD19KQAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszAddress +TCHAR +3QdspoNdE0Ss+lJNCD19KQAA + + +iAddressLen +int +3QdspoNdE0Ss+lJNCD19KQAA +1 + +Cpp +CppPointer +CppPointer +& +vGUh1BbfXEW5oaOw58q48AAA + + + +usPort +USHORT +3QdspoNdE0Ss+lJNCD19KQAA +1 + +Cpp +CppPointer +CppPointer +& +SUXXk/RRbkae2QRsY76taQAA + + + +return +pdkReturn +BOOL +3QdspoNdE0Ss+lJNCD19KQAA + + +2 +yjAKf34ydEKKe2mdOjqgcwAA +pLUAAVD3Ik2vyLatRkbfrwAA + + +ITcpAgent +jvfBmo6uGkC61ckI99TMgAAA +8 +qWQ9xcWqTk+Q37ac+Zc5cwAA +pcufE4+jn06P9qY5kOB0igAA +0AqeOo3lzkOKaHT8cVPOgwAA +KjM4n5nIiE+eRcpRAEvLxgAA +ROm4wdRu3kujC5L3DT4IAAAA +HscRBT2RF0ya0BniWbeBWgAA +BIZOrVMNP0CjjWzVDb046AAA +1mLXSQUoU0eSLvw5y382owAA +1 +T7qvCRD8oEeFVhOYfk7D4wAA +3 +Vo9KdG21TU67s/EtgyfoVQAA +M9A+DWOIeUGk+YFgByCYmAAA +lqZ7xgrWKkewtFXoEKU2+AAA +9 + +SendSmallFile +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +CS+Gf2rD80uQOiFgk6MPdAAA + +5 + +dwConnID +CS+Gf2rD80uQOiFgk6MPdAAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszFileName +LPCTSTR +CS+Gf2rD80uQOiFgk6MPdAAA + + +pHead +LPWSABUF +CS+Gf2rD80uQOiFgk6MPdAAA +1 + +Cpp +CppConst +CppConst +True +1kp2cLTJ0E+sp1NuK5DXgQAA + + + +pTail +LPWSABUF +CS+Gf2rD80uQOiFgk6MPdAAA +1 + +Cpp +CppConst +CppConst +True +aN92oYF9O0We6AlfeJZcaQAA + + + +return +pdkReturn +BOOL +CS+Gf2rD80uQOiFgk6MPdAAA + + + +SetReuseAddress +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +EkJSFECEG0aY6zofSGap2gAA + +2 + +bReuseAddress +BOOL +EkJSFECEG0aY6zofSGap2gAA + + +return +pdkReturn +void +EkJSFECEG0aY6zofSGap2gAA + + + +IsReuseAddress +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +BeXRLytDm0qiDrI3bg/nWwAA + +1 + +return +pdkReturn +BOOL +BeXRLytDm0qiDrI3bg/nWwAA + + + +SetSocketBufferSize +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +IQlykAwKEUqNWD7FBcxaPgAA + +2 + +dwSocketBufferSize +DWORD +IQlykAwKEUqNWD7FBcxaPgAA + + +return +pdkReturn +void +IQlykAwKEUqNWD7FBcxaPgAA + + + +SetKeepAliveTime +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +6r+0ccAOLESUUriUMzLw1QAA + +2 + +dwKeepAliveTime +DWORD +6r+0ccAOLESUUriUMzLw1QAA + + +return +pdkReturn +void +6r+0ccAOLESUUriUMzLw1QAA + + + +SetKeepAliveInterval +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +IU2iCGjMZ06PKPtNYha4eAAA + +2 + +dwKeepAliveInterval +DWORD +IU2iCGjMZ06PKPtNYha4eAAA + + +return +pdkReturn +void +IU2iCGjMZ06PKPtNYha4eAAA + + + +GetSocketBufferSize +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +pECSrcTQYUiJVILwr84WrwAA + +1 + +return +pdkReturn +DWORD +pECSrcTQYUiJVILwr84WrwAA + + + +GetKeepAliveTime +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +CGqRbpw5M0OThgy9rErkSAAA + +1 + +return +pdkReturn +DWORD +CGqRbpw5M0OThgy9rErkSAAA + + + +GetKeepAliveInterval +True +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppVirtual +CppVirtual +True +O4Z61Ft1P0ivrrL4Hs/OWwAA + +1 + +return +pdkReturn +DWORD +O4Z61Ft1P0ivrrL4Hs/OWwAA + + +2 +HhGV7MnAEUSpUJYBiZ94UQAA +R2exw8R6DE6K1lw0TUkI2wAA + + +ITcpClient +jvfBmo6uGkC61ckI99TMgAAA +8 +nQs4ohjRpkGJ66FalNzxdwAA +dOO9/G7idUO0ZtyANx7O4QAA +lqqukuulmU6NID3lb+2q/AAA +FExQG0+/OE+cyf1ApccbnwAA +J8pneqLZKkaDgX4DgXGzJwAA +Beg2+/tFx0yjXKd9UQEdGgAA +hpC8z/rHwkmqPSxPKaAk3wAA +XSRXz/S8HkSLA1P5fEI4vwAA +1 +dOpAHC5JfkymmNyAgeRwWAAA +3 +GJ1pEOa7xE+Vx6DHIVvLbwAA +hwXxX+YbkkG6mY/KLykG4AAA +l44zgodkDEuj17c7XdoPSQAA +7 + +SendSmallFile +True +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +HZZAVH0FIU6ZVBzk208coQAA + +4 + +lpszFileName +LPCTSTR +HZZAVH0FIU6ZVBzk208coQAA + + +pHead +LPWSABUF +HZZAVH0FIU6ZVBzk208coQAA +1 + +Cpp +CppConst +CppConst +True +DiQ9kwx73UGrvS8/ef1AIQAA + + + +pTail +LPWSABUF +HZZAVH0FIU6ZVBzk208coQAA +1 + +Cpp +CppConst +CppConst +True +y49IejYoY0qSqeLBBoRK8AAA + + + +return +pdkReturn +BOOL +HZZAVH0FIU6ZVBzk208coQAA + + + +SetSocketBufferSize +True +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +RsjErIAYP0em72A7wdfIOAAA + +2 + +dwSocketBufferSize +DWORD +RsjErIAYP0em72A7wdfIOAAA + + +return +pdkReturn +void +RsjErIAYP0em72A7wdfIOAAA + + + +SetKeepAliveTime +True +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +xHkjUhQkwka9X6Iq+CC49wAA + +2 + +dwKeepAliveTime +DWORD +xHkjUhQkwka9X6Iq+CC49wAA + + +return +pdkReturn +void +xHkjUhQkwka9X6Iq+CC49wAA + + + +SetKeepAliveInterval +True +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +9ZxyNAhwhECwOA0fhgCFIAAA + +2 + +dwKeepAliveInterval +DWORD +9ZxyNAhwhECwOA0fhgCFIAAA + + +return +pdkReturn +void +9ZxyNAhwhECwOA0fhgCFIAAA + + + +GetSocketBufferSize +True +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +AFPw5GUrXUaMtDPcjOPi1QAA + +1 + +return +pdkReturn +DWORD +AFPw5GUrXUaMtDPcjOPi1QAA + + + +GetKeepAliveTime +True +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +DYAha7DikUSv8zn5eYLNywAA + +1 + +return +pdkReturn +DWORD +DYAha7DikUSv8zn5eYLNywAA + + + +GetKeepAliveInterval +True +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppVirtual +CppVirtual +True +xMQXtcaJQEa/fvrIFZiCsQAA + +1 + +return +pdkReturn +DWORD +xMQXtcaJQEa/fvrIFZiCsQAA + + +2 +8vajZ8HVQUWLlEKb77MjdwAA +XwIYEdJyaU+OBOCXAgFkDQAA + + +IUdpClient +jvfBmo6uGkC61ckI99TMgAAA +8 +F1H1FgAQo0KwYhAVsIoSYQAA +jbJHR08NXUGCbuGNgp0cOgAA +A/qe+2hseUW9UB30SiWYewAA +8YqTxFjKE0eO5ZR6s7KJQAAA +oleTxFsjKEWwtZuXdUKCNQAA +mu+wwFogcUaHAV1TyiDrlgAA +nGY0WS1b7UuLarVAvDm1HwAA +eMxGh8/HPEOWDLBKq6da9wAA +1 +VhVmNVhKIEyRJWflThCsqQAA +1 +TevsU+ekCkCxrYsp/lugswAA +6 + +SetMaxDatagramSize +True +s/XSjWMZB0WwUzzarQOzNgAA +1 + +Cpp +CppVirtual +CppVirtual +True +LkezD0dty0WGYzWhoYrR+gAA + +2 + +dwMaxDatagramSize +DWORD +LkezD0dty0WGYzWhoYrR+gAA + + +return +pdkReturn +void +LkezD0dty0WGYzWhoYrR+gAA + + + +GetMaxDatagramSize +True +s/XSjWMZB0WwUzzarQOzNgAA +1 + +Cpp +CppVirtual +CppVirtual +True +wL7crcury0eeUEw8kwS5ogAA + +1 + +return +pdkReturn +DWORD +wL7crcury0eeUEw8kwS5ogAA + + + +SetDetectAttempts +True +s/XSjWMZB0WwUzzarQOzNgAA +1 + +Cpp +CppVirtual +CppVirtual +True +PkuxOPbSdkG/5vOQ595hbgAA + +2 + +dwDetectAttempts +DWORD +PkuxOPbSdkG/5vOQ595hbgAA + + +return +pdkReturn +void +PkuxOPbSdkG/5vOQ595hbgAA + + + +SetDetectInterval +True +s/XSjWMZB0WwUzzarQOzNgAA +1 + +Cpp +CppVirtual +CppVirtual +True +G//IssPd2kuG5PYQ1/R5AQAA + +2 + +dwDetectInterval +DWORD +G//IssPd2kuG5PYQ1/R5AQAA + + +return +pdkReturn +void +G//IssPd2kuG5PYQ1/R5AQAA + + + +GetDetectAttempts +True +s/XSjWMZB0WwUzzarQOzNgAA +1 + +Cpp +CppVirtual +CppVirtual +True +ciGmHJgAyEGxiGhk8PljIgAA + +1 + +return +pdkReturn +DWORD +ciGmHJgAyEGxiGhk8PljIgAA + + + +GetDetectInterval +True +s/XSjWMZB0WwUzzarQOzNgAA +1 + +Cpp +CppVirtual +CppVirtual +True +0aFR6DV9lUKHGSz772XcVQAA + +1 + +return +pdkReturn +DWORD +0aFR6DV9lUKHGSz772XcVQAA + + + + +IUdpCast +jvfBmo6uGkC61ckI99TMgAAA +8 +pliWbIwkj0yRgSGaHICnEAAA +GFjVGz0h0UKHtQSekLUdFAAA +h9lDPjAO20uIyIh2EQBEegAA +EWByVZkFRkeKOTEbtBNHzgAA +YHlypkK/9EmsY5l1e8kckgAA +VLGusEwIGUevSmatPhh72wAA +aakwU3ZJpE+Ypf0KR6wLAgAA +ThixXfNMcES7+lt9FDiJ3QAA +1 +MejA8cLC00G/Y3QcvCU6BgAA +1 +Mrk3QXUHNk2R1/cHV9/5pAAA +13 + +SetBindAdddress +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +XpPnHpkY8UCry5joPqhedAAA + +2 + +pszBindAddress +LPCTSTR +XpPnHpkY8UCry5joPqhedAAA + + +return +pdkReturn +void +XpPnHpkY8UCry5joPqhedAAA + + + +GetBindAdddress +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +lfbUe6ke+0umVF3yRAi50QAA + +1 + +return +pdkReturn +LPCTSTR +lfbUe6ke+0umVF3yRAi50QAA + + + +SetMaxDatagramSize +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +Lemeh+D7bk+SiasFqSu2PQAA + +2 + +dwMaxDatagramSize +DWORD +Lemeh+D7bk+SiasFqSu2PQAA + + +return +pdkReturn +void +Lemeh+D7bk+SiasFqSu2PQAA + + + +GetMaxDatagramSize +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +FrmhusvHAk656SCbpUhHCgAA + +1 + +return +pdkReturn +DWORD +FrmhusvHAk656SCbpUhHCgAA + + + +SetReuseAddress +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +nVw3S5A0rUa8tcQ5NiVASwAA + +2 + +bReuseAddress +BOOL +nVw3S5A0rUa8tcQ5NiVASwAA + + +return +pdkReturn +void +nVw3S5A0rUa8tcQ5NiVASwAA + + + +IsReuseAddress +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +I2XkxXkysU2alUt0LfhJ4gAA + +1 + +return +pdkReturn +BOOL +I2XkxXkysU2alUt0LfhJ4gAA + + + +SetCastMode +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +2tLZ0e+je0+HgFYwvmKGSwAA + +2 + +enCastMode +2tLZ0e+je0+HgFYwvmKGSwAA +6zImDSI92UG9tawjYrSv0AAA + + +return +pdkReturn +void +2tLZ0e+je0+HgFYwvmKGSwAA + + + +GetCastMode +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +84h86FOjyEy24Gj6kEbBxwAA + +1 + +return +pdkReturn +84h86FOjyEy24Gj6kEbBxwAA +6zImDSI92UG9tawjYrSv0AAA + + + +SetMultiCastTtl +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +aMsKFuLGwk6Tuk9/yYvdrQAA + +2 + +iMCTtl +int +aMsKFuLGwk6Tuk9/yYvdrQAA + + +return +pdkReturn +void +aMsKFuLGwk6Tuk9/yYvdrQAA + + + +GetMultiCastTtl +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +f2mBky6Obk61jx3S39FmcAAA + +1 + +return +pdkReturn +int +f2mBky6Obk61jx3S39FmcAAA + + + +SetMultiCastLoop +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +UHQaBohb3EO396LQltE0DwAA + +2 + +bMCLoop +BOOL +UHQaBohb3EO396LQltE0DwAA + + +return +pdkReturn +void +UHQaBohb3EO396LQltE0DwAA + + + +IsMultiCastLoop +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +2kje4RSx/EGCqq5mU5J/3wAA + +1 + +return +pdkReturn +BOOL +2kje4RSx/EGCqq5mU5J/3wAA + + + +GetRemoteAddress +True +6HMIzI9avUGHDCpvqmkdqQAA +1 + +Cpp +CppVirtual +CppVirtual +True +0Pbk1BkkzU6td8aNoIU6XAAA + +4 + +lpszAddress +TCHAR +0Pbk1BkkzU6td8aNoIU6XAAA + + +iAddressLen +int +0Pbk1BkkzU6td8aNoIU6XAAA +1 + +Cpp +CppPointer +CppPointer +& +c2v5Ay4KK0mu77xDqfW8vAAA + + + +usPort +USHORT +0Pbk1BkkzU6td8aNoIU6XAAA +1 + +Cpp +CppPointer +CppPointer +& +3Vh4Sq/CgEebsPlah8nukAAA + + + +return +pdkReturn +BOOL +0Pbk1BkkzU6td8aNoIU6XAAA + + + + +IPullSocket +jvfBmo6uGkC61ckI99TMgAAA +12 +XJoHYNGE7keWE488T/cGaQAA +zzs8DI25UUCNQ43/MQ+qVAAA +jSQfkWH1OkmUyiATCqE/DwAA +KtTRZu7JbEKDKjsZkk0IdAAA +RHC6AHfVy0Gw4f4lr8UMCwAA +KBfLPUZWk0qvj+vMol6VOgAA +w/haTVdteEORvPvvEHgaowAA +Ck0SZdeQBkGHx/n+RpQ/vQAA +a0c9acKJG0SO2mD4HdFWdAAA +tw1IrAx/fESMVbbUMfR0hwAA +t2cW3RTa00GUioEfEZBe9AAA +yGyum2zi9Uq1SmcgGwWodgAA +4 +ETiy7j/ak0iclwwFrOCPHwAA +krwZJNbQpUee1OjG3HesgAAA +SWj0s9+zMUW6Sa0s98LfDgAA +DLbR09fsFE6Bx8bzfHmD6AAA +3 + +Fetch +True +BaqYQl/65Uy16GMJC7nLawAA +1 + +Cpp +CppVirtual +CppVirtual +True +cgO4XXJjlU+jp30SASdXGgAA + +4 + +dwConnID +cgO4XXJjlU+jp30SASdXGgAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +cgO4XXJjlU+jp30SASdXGgAA +1 + +Cpp +CppPointer +CppPointer +* +Og9kZ1Xu102smEyFTAhnmgAA + + + +iLength +int +cgO4XXJjlU+jp30SASdXGgAA + + +return +pdkReturn +cgO4XXJjlU+jp30SASdXGgAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +Peek +True +BaqYQl/65Uy16GMJC7nLawAA +1 + +Cpp +CppVirtual +CppVirtual +True +jLPCsPfjI0CNcXSMzge3MQAA + +4 + +dwConnID +jLPCsPfjI0CNcXSMzge3MQAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +jLPCsPfjI0CNcXSMzge3MQAA +1 + +Cpp +CppPointer +CppPointer +* +yTMeI76WDUqqh6NHP6HtVwAA + + + +iLength +int +jLPCsPfjI0CNcXSMzge3MQAA + + +return +pdkReturn +jLPCsPfjI0CNcXSMzge3MQAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +IPullSocket +UMLStandard +destroy +vkPrivate +BaqYQl/65Uy16GMJC7nLawAA + +4 +D3LgOgnPC0mo2/9kRF5CzAAA +WMCkhXUbiUeaUViuDxIS7gAA +N26WeATCm0+5rYzcDRu3eAAA +g5GpNbyCk0OP7608E9Vd2gAA + + +IPullClient +jvfBmo6uGkC61ckI99TMgAAA +8 +KeV/t2xsK0+PmCUPXcqplgAA +Oht2zSUFtUiVLtO5Bv1fegAA +BRdhWHD9IEiTyIhhQMyINwAA +sWYnea/l+kmBg00TdIdrswAA +3G0QePyBUU2U+ZdFBZdeaQAA +b9fWwFLP3UWkdotR2hgX2wAA +uM+mWaXW9UqOjgaWdHMa7gAA +3zzDQ4ljXUyXzpIsW3LQiwAA +2 +wIyBqLGeaEauN2RIkujQrAAA +t7BFiOV+U0+3Fzwd6nXwzgAA +3 + +Fetch +True +LPfLjDLmzkKy/sn51dyX7gAA +1 + +Cpp +CppVirtual +CppVirtual +True +b5f9MD0AtkeuN79sme+E2gAA + +3 + +pData +BYTE +b5f9MD0AtkeuN79sme+E2gAA +1 + +Cpp +CppPointer +CppPointer +* +P3+N+MgvJ0ey6Qk0Vf6+VQAA + + + +iLength +int +b5f9MD0AtkeuN79sme+E2gAA + + +return +pdkReturn +b5f9MD0AtkeuN79sme+E2gAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +Peek +True +LPfLjDLmzkKy/sn51dyX7gAA +1 + +Cpp +CppVirtual +CppVirtual +True +YASw0VxOv0y6F5IlJt9dMQAA + +3 + +pData +BYTE +YASw0VxOv0y6F5IlJt9dMQAA +1 + +Cpp +CppPointer +CppPointer +* +/zh3zudhYkOgxTZTUfQ28gAA + + + +iLength +int +YASw0VxOv0y6F5IlJt9dMQAA + + +return +pdkReturn +YASw0VxOv0y6F5IlJt9dMQAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +IPullClient +UMLStandard +destroy +vkPrivate +LPfLjDLmzkKy/sn51dyX7gAA + +2 +ykScGgFhYECpgmHks746nwAA +8Dmc2hy1qkCg3B1+LncpMAAA + + +ITcpPullServer +jvfBmo6uGkC61ckI99TMgAAA +8 +PK1lPcGwCkO4ClijCg6U4QAA +kmMKQofMq06NVuB9xv0DEwAA +Pbd7421jwUOfRSrw7NrAjQAA +tN7A8f0zdUCaEQ9ttQrqgAAA +vwPKwpBbd0GUOwpQTiwJIwAA +SVKltLfsBEKO65EbcGVLfAAA +nFpsCSVN4EywibH/eGe5ggAA +JAvzaxKf8kqnc39M6uNJ4gAA +2 +ETiy7j/ak0iclwwFrOCPHwAA +RvwWYNXraU2xkdsooYM/NwAA +2 + +ToPull +skClassifier +gJKazn/X+U6+FJp/F2soRAAA +1 + +Cpp +CppMemberFunction +CppInline +True +a22XnjLylkC6pPrM063G6AAA + +2 + +pServer +a22XnjLylkC6pPrM063G6AAA +GoHMKPRtzES/2hlDzLtwnAAA +1 + +Cpp +CppPointer +CppPointer +* +da6KPUpOnkuM7gM+HBH1FwAA + + + +return +pdkReturn +a22XnjLylkC6pPrM063G6AAA +BaqYQl/65Uy16GMJC7nLawAA +1 + +Cpp +CppPointer +CppPointer +* +D3LgOgnPC0mo2/9kRF5CzAAA + + + + +ToServer +skClassifier +gJKazn/X+U6+FJp/F2soRAAA +1 + +Cpp +CppMemberFunction +CppInline +True +nfMtOxpMvkiYqWPhEk+eswAA + +2 + +pPullSocket +nfMtOxpMvkiYqWPhEk+eswAA +BaqYQl/65Uy16GMJC7nLawAA +1 + +Cpp +CppPointer +CppPointer +* +WMCkhXUbiUeaUViuDxIS7gAA + + + +return +pdkReturn +nfMtOxpMvkiYqWPhEk+eswAA +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppPointer +CppPointer +* +4lYcEooM20qvD7Cm0s0sHAAA + + + + + +ITcpPullAgent +jvfBmo6uGkC61ckI99TMgAAA +8 ++2HvTQsUAk+HjQ5fXiU8owAA +Zt9ux3apgU2A9+dT3PlLuQAA +U1iV73eD/EKDcYBLLs8SbgAA +F+kjP5IVjkCktmcV7GpefwAA +bfxTyfA02Ue+pDo34ZXTAQAA +uz3bs+otU06psOTqopWQ5wAA +qresWiI5R022VvwFyq1FmAAA +n2zOZxJZCUeRutQvVzK48gAA +2 +krwZJNbQpUee1OjG3HesgAAA +Vo9KdG21TU67s/EtgyfoVQAA +2 + +ToPull +skClassifier +QvkeGvTpWU2SJ0MXVIx/AwAA +1 + +Cpp +CppMemberFunction +CppInline +True +g8FWrwrOsk2xaSWwzLwBywAA + +2 + +pAgent +g8FWrwrOsk2xaSWwzLwBywAA +tc20+9LmREuR1dUMSybNdQAA +1 + +Cpp +CppPointer +CppPointer +* +yjAKf34ydEKKe2mdOjqgcwAA + + + +return +pdkReturn +g8FWrwrOsk2xaSWwzLwBywAA +BaqYQl/65Uy16GMJC7nLawAA +1 + +Cpp +CppPointer +CppPointer +* +N26WeATCm0+5rYzcDRu3eAAA + + + + +ToAgent +skClassifier +QvkeGvTpWU2SJ0MXVIx/AwAA +1 + +Cpp +CppMemberFunction +CppInline +True +6kTzFyp0yEKHWiBeqCP9CwAA + +2 + +pPullSocket +6kTzFyp0yEKHWiBeqCP9CwAA +BaqYQl/65Uy16GMJC7nLawAA +1 + +Cpp +CppPointer +CppPointer +* +g5GpNbyCk0OP7608E9Vd2gAA + + + +return +pdkReturn +6kTzFyp0yEKHWiBeqCP9CwAA +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppPointer +CppPointer +* +HhGV7MnAEUSpUJYBiZ94UQAA + + + + + +ITcpPullClient +jvfBmo6uGkC61ckI99TMgAAA +8 +zqmdKXYEt0GXqYV17S23CAAA +lPLDWCSrwEm0x6QoK6wnYwAA +HpX+r8mvDkWEvQ5BNbiD1AAA +QVYcuhXqMUW+ghNJaNocdAAA +JO73WwZwyUit/u2y4GvaEQAA +iqHHrnOvgEG+TiaUqXhfcAAA +1irNlD+XQE2AlX5OA+9pvQAA +geszcr8n/02Tb1vHjXTQwwAA +2 +wIyBqLGeaEauN2RIkujQrAAA +GJ1pEOa7xE+Vx6DHIVvLbwAA +2 + +ToPull +skClassifier +SjUoRiw3TUOE/FQirpeMogAA +1 + +Cpp +CppMemberFunction +CppInline +True +rTXsgR4NCE+yYN3Y/oufiwAA + +2 + +pClient +rTXsgR4NCE+yYN3Y/oufiwAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +ui8T/xO9oEiXpayGYfJlwwAA + + + +return +pdkReturn +rTXsgR4NCE+yYN3Y/oufiwAA +LPfLjDLmzkKy/sn51dyX7gAA +1 + +Cpp +CppPointer +CppPointer +* +ykScGgFhYECpgmHks746nwAA + + + + +ToClient +skClassifier +SjUoRiw3TUOE/FQirpeMogAA +1 + +Cpp +CppMemberFunction +CppInline +True +c0Hq5A+WekCceKwhN0b2JAAA + +2 + +pPullClient +c0Hq5A+WekCceKwhN0b2JAAA +LPfLjDLmzkKy/sn51dyX7gAA +1 + +Cpp +CppPointer +CppPointer +* +8Dmc2hy1qkCg3B1+LncpMAAA + + + +return +pdkReturn +c0Hq5A+WekCceKwhN0b2JAAA +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppPointer +CppPointer +* +8vajZ8HVQUWLlEKb77MjdwAA + + + + + +CTcpAgent +jvfBmo6uGkC61ckI99TMgAAA +4 +nninAmAC7U2238tYjDUvxQAA +zeqFNx3vlkOe+49bdxZASgAA +DJNQ3zQI+kKgTIhce2m20AAA +96iOMQyyKkG+yRyQ3G4aYwAA +1 +M9A+DWOIeUGk+YFgByCYmAAA +2 +IDQB44Q61kudclcYwyYEMwAA +YVPRQLCk1keYCHnO8PWR/AAA +48 + +CTcpAgent +UMLStandard +create +vkPrivate ++hvdtNLBPUeUmdoy9WnIywAA +1 + +psoListener +GaiMwJEmnEyxBdXScBG+5AAA +skl0Nm/UIUCTsqkUAIXmzAAA +1 + +Cpp +CppPointer +CppPointer +* +SOpFN5D6dUi/yOIJ1NO6NAAA + + + + +CTcpAgent +UMLStandard +destroy +vkPrivate ++hvdtNLBPUeUmdoy9WnIywAA + + +Start ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +8XybYNS2vkWssa0TFIab8QAA + +3 + +pszBindAddress +LPCTSTR +8XybYNS2vkWssa0TFIab8QAA + + +bAsyncConnect +BOOL +8XybYNS2vkWssa0TFIab8QAA + + +return +pdkReturn +BOOL +8XybYNS2vkWssa0TFIab8QAA + + + +Stop ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +OvWhIJQIpEasTYe5OT0a5QAA + +1 + +return +pdkReturn +BOOL +OvWhIJQIpEasTYe5OT0a5QAA + + + +Connect ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +jV8C++Q20k6V5b5C45yvlQAA + +4 + +pszRemoteAddress +LPCTSTR +jV8C++Q20k6V5b5C45yvlQAA + + +usPort +USHORT +jV8C++Q20k6V5b5C45yvlQAA + + +pdwConnID +jV8C++Q20k6V5b5C45yvlQAA +G8TfQngB3UemVJWZg5KbggAA +1 + +Cpp +CppPointer +CppPointer +* +51I86s1DOke3qJOgWgqVLAAA + + + +return +pdkReturn +BOOL +jV8C++Q20k6V5b5C45yvlQAA + + + +Send ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +QbKluSBULUy5qEYXN8aUXQAA + +5 + +dwConnID +QbKluSBULUy5qEYXN8aUXQAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffer +BYTE +QbKluSBULUy5qEYXN8aUXQAA +2 + +Cpp +CppConst +CppConst +True +lCjagAwFNU+5cleJOF3xKgAA + + +Cpp +CppPointer +CppPointer +* +lCjagAwFNU+5cleJOF3xKgAA + + + +iLength +int +QbKluSBULUy5qEYXN8aUXQAA + + +iOffset +int +QbKluSBULUy5qEYXN8aUXQAA + + +return +pdkReturn +BOOL +QbKluSBULUy5qEYXN8aUXQAA + + + +SendPackets ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +dUzn/H61rEmo9KhmXUge/AAA + +4 + +dwConnID +dUzn/H61rEmo9KhmXUge/AAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffers +WSABUF +dUzn/H61rEmo9KhmXUge/AAA +1 + +Cpp +CppConst +CppConst +True +oijLFD+Irku57XRr5yAdowAA + + + +iCount +int +dUzn/H61rEmo9KhmXUge/AAA + + +return +pdkReturn +BOOL +dUzn/H61rEmo9KhmXUge/AAA + + + +SendSmallFile ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +NetK/QLhnUOrgXRav/oWLQAA + +5 + +dwConnID +NetK/QLhnUOrgXRav/oWLQAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszFileName +LPCTSTR +NetK/QLhnUOrgXRav/oWLQAA + + +pHead +LPWSABUF +NetK/QLhnUOrgXRav/oWLQAA +1 + +Cpp +CppConst +CppConst +True +34pql+rKb068K55aNtPybAAA + + + +pTail +LPWSABUF +NetK/QLhnUOrgXRav/oWLQAA +1 + +Cpp +CppConst +CppConst +True +Ngwv0oukGEaJ1b3xUicOkQAA + + + +return +pdkReturn +BOOL +NetK/QLhnUOrgXRav/oWLQAA + + + +HasStarted ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +zjmHffbWIEyP/4UAEzbaSwAA + +1 + +return +pdkReturn +BOOL +zjmHffbWIEyP/4UAEzbaSwAA + + + +GetState ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +bF5bqhXvlEyg3a7oWRu0LAAA + +1 + +return +pdkReturn +bF5bqhXvlEyg3a7oWRu0LAAA +3KsfqnlMb0ieGw/IAO5hFQAA + + + +Disconnect ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +LKp1L65IvEWRUpalbHj4egAA + +3 + +dwConnID +LKp1L65IvEWRUpalbHj4egAA +G8TfQngB3UemVJWZg5KbggAA + + +bForce +BOOL +LKp1L65IvEWRUpalbHj4egAA + + +return +pdkReturn +BOOL +LKp1L65IvEWRUpalbHj4egAA + + + +DisconnectLongConnections ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +YeF3cYkzY02JYlqPOsoG9QAA + +3 + +dwPeriod +DWORD +YeF3cYkzY02JYlqPOsoG9QAA + + +bForce +BOOL +YeF3cYkzY02JYlqPOsoG9QAA + + +return +pdkReturn +BOOL +YeF3cYkzY02JYlqPOsoG9QAA + + + +DisconnectSilenceConnections ++hvdtNLBPUeUmdoy9WnIywAA +3 + +pdkReturn +BOOL +GHqlBeCMIU61oJNe1G8VzAAA + + +dwPeriod +DWORD +GHqlBeCMIU61oJNe1G8VzAAA + + +bForce +BOOL +GHqlBeCMIU61oJNe1G8VzAAA + + + +GetLocalAddress ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +X90qAsY0iUeJUPXmi7tYwQAA + +5 + +dwConnID +X90qAsY0iUeJUPXmi7tYwQAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszAddress +TCHAR +X90qAsY0iUeJUPXmi7tYwQAA + + +iAddressLen +int +X90qAsY0iUeJUPXmi7tYwQAA +1 + +Cpp +CppPointer +CppPointer +& +pisUlDEWBEK4f3uFIq8iDgAA + + + +usPort +USHORT +X90qAsY0iUeJUPXmi7tYwQAA +1 + +Cpp +CppPointer +CppPointer +& +DzcTtkf8Pk6Xg58T5iHgSwAA + + + +return +pdkReturn +BOOL +X90qAsY0iUeJUPXmi7tYwQAA + + + +GetRemoteAddress ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +LlkEypQ56kGa3EIOg6ZPHAAA + +5 + +dwConnID +LlkEypQ56kGa3EIOg6ZPHAAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszAddress +TCHAR +LlkEypQ56kGa3EIOg6ZPHAAA + + +iAddressLen +int +LlkEypQ56kGa3EIOg6ZPHAAA +1 + +Cpp +CppPointer +CppPointer +& +7g4dBOnE+kuoj720ok4LRAAA + + + +usPort +USHORT +LlkEypQ56kGa3EIOg6ZPHAAA +1 + +Cpp +CppPointer +CppPointer +& +3w08v5MbB06w2W8fUK0M9AAA + + + +return +pdkReturn +BOOL +LlkEypQ56kGa3EIOg6ZPHAAA + + + +GetPendingDataLength ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +5sX7kgB8mk+wWgFB8uUTPgAA + +3 + +dwConnID +5sX7kgB8mk+wWgFB8uUTPgAA +G8TfQngB3UemVJWZg5KbggAA + + +iPending +int +5sX7kgB8mk+wWgFB8uUTPgAA +1 + +Cpp +CppPointer +CppPointer +& +RXkYq3BY3Eu3qH03Re/QrwAA + + + +return +pdkReturn +BOOL +5sX7kgB8mk+wWgFB8uUTPgAA + + + +GetConnectionCount ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +SDISs2LqsEW28yH/0QinXwAA + +1 + +return +pdkReturn +DWORD +SDISs2LqsEW28yH/0QinXwAA + + + +GetAllConnectionIDs ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +akGyv9Hjikq5bCPXoYb0PwAA + +3 + +pIDs +akGyv9Hjikq5bCPXoYb0PwAA +G8TfQngB3UemVJWZg5KbggAA + + +dwCount +DWORD +akGyv9Hjikq5bCPXoYb0PwAA +1 + +Cpp +CppPointer +CppPointer +& +iM1GtPsaEkmMQSevsCV42gAA + + + +return +pdkReturn +BOOL +akGyv9Hjikq5bCPXoYb0PwAA + + + +GetConnectPeriod ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +c6Y3A96vz0qa9lNSWqp8PAAA + +3 + +dwConnID +c6Y3A96vz0qa9lNSWqp8PAAA +G8TfQngB3UemVJWZg5KbggAA + + +dwPeriod +DWORD +c6Y3A96vz0qa9lNSWqp8PAAA +1 + +Cpp +CppPointer +CppPointer +& +Tmb6KGr370qC38kgmsHZOwAA + + + +return +pdkReturn +BOOL +c6Y3A96vz0qa9lNSWqp8PAAA + + + +GetSilencePeriod ++hvdtNLBPUeUmdoy9WnIywAA +3 + +pdkReturn +BOOL +vYwz3XqhHUKUn56sA0KXEAAA + + +dwConnID +vYwz3XqhHUKUn56sA0KXEAAA +G8TfQngB3UemVJWZg5KbggAA + + +dwPeriod +DWORD +vYwz3XqhHUKUn56sA0KXEAAA + + + +GetLastError ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +c2KWKu9jI0OpuyEwMjKbKQAA + +1 + +return +pdkReturn +c2KWKu9jI0OpuyEwMjKbKQAA +R9EXi7T78E6Gt882nRMyDwAA + + + +GetLastErrorDesc ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +5uQT36vT7EWILdyXEI2jkwAA + +1 + +return +pdkReturn +LPCTSTR +5uQT36vT7EWILdyXEI2jkwAA + + + +SetConnectionExtra ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +gyT6/s9EQkKCoP/R/htYJwAA + +3 + +dwConnID +gyT6/s9EQkKCoP/R/htYJwAA +G8TfQngB3UemVJWZg5KbggAA + + +pExtra +PVOID +gyT6/s9EQkKCoP/R/htYJwAA + + +return +pdkReturn +BOOL +gyT6/s9EQkKCoP/R/htYJwAA + + + +GetConnectionExtra ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +AIwVPn57FE2A8qcqAnVqZgAA + +3 + +dwConnID +AIwVPn57FE2A8qcqAnVqZgAA +G8TfQngB3UemVJWZg5KbggAA + + +ppExtra +PVOID +AIwVPn57FE2A8qcqAnVqZgAA +1 + +Cpp +CppPointer +CppPointer +* +w0NeYcz8tEySRo8rScz37gAA + + + +return +pdkReturn +BOOL +AIwVPn57FE2A8qcqAnVqZgAA + + + +SetSendPolicy ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +2jNtUUJ/4keRYENj9zta7QAA + +2 + +enSendPolicy +2jNtUUJ/4keRYENj9zta7QAA +p4RvBvwp3kOxyo/4mj2ZKwAA + + +return +pdkReturn +void +2jNtUUJ/4keRYENj9zta7QAA + + + +SetMarkSilence ++hvdtNLBPUeUmdoy9WnIywAA +2 + +pdkReturn +void +TLv4U1BAO0aKP6eeHTFmOgAA + + +bMarkSilence +BOOL +TLv4U1BAO0aKP6eeHTFmOgAA + + + +IsMarkSilence ++hvdtNLBPUeUmdoy9WnIywAA +1 + +pdkReturn +BOOL +HKLLo5ga3U63NFS7OHfcWAAA + + + +SetWorkerThreadCount ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +bzOhz/m1gUO5kLQM5c1LMAAA + +2 + +dwWorkerThreadCount +DWORD +bzOhz/m1gUO5kLQM5c1LMAAA + + +return +pdkReturn +void +bzOhz/m1gUO5kLQM5c1LMAAA + + + +SetSocketBufferSize ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +wFj0pIlekE60HZEZyQmksgAA + +2 + +dwSocketBufferSize +DWORD +wFj0pIlekE60HZEZyQmksgAA + + +return +pdkReturn +void +wFj0pIlekE60HZEZyQmksgAA + + + +SetFreeSocketObjLockTime ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +Mr3If0x/7ECGuwq6Jk1phQAA + +2 + +dwFreeSocketObjLockTime +DWORD +Mr3If0x/7ECGuwq6Jk1phQAA + + +return +pdkReturn +void +Mr3If0x/7ECGuwq6Jk1phQAA + + + +SetFreeSocketObjPool ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +D4Zg1YB0skmTL2K7XdIK0QAA + +2 + +dwFreeSocketObjPool +DWORD +D4Zg1YB0skmTL2K7XdIK0QAA + + +return +pdkReturn +void +D4Zg1YB0skmTL2K7XdIK0QAA + + + +SetFreeBufferObjPool ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +OrZbYP5Ar0mKSPILWqzi6wAA + +2 + +dwFreeBufferObjPool +DWORD +OrZbYP5Ar0mKSPILWqzi6wAA + + +return +pdkReturn +void +OrZbYP5Ar0mKSPILWqzi6wAA + + + +SetFreeSocketObjHold ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +mxZjDqE1KUiPCBUNJCjnFwAA + +2 + +dwFreeSocketObjHold +DWORD +mxZjDqE1KUiPCBUNJCjnFwAA + + +return +pdkReturn +void +mxZjDqE1KUiPCBUNJCjnFwAA + + + +SetFreeBufferObjHold ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +0hpPphLtykq4+LRMszgTWAAA + +2 + +dwFreeBufferObjHold +DWORD +0hpPphLtykq4+LRMszgTWAAA + + +return +pdkReturn +void +0hpPphLtykq4+LRMszgTWAAA + + + +SetKeepAliveTime ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +BnE583tGokSuJUvgsb+CcwAA + +2 + +dwKeepAliveTime +DWORD +BnE583tGokSuJUvgsb+CcwAA + + +return +pdkReturn +void +BnE583tGokSuJUvgsb+CcwAA + + + +SetKeepAliveInterval ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +4sOac3NFLEa2Ktjn6GXfkAAA + +2 + +dwKeepAliveInterval +DWORD +4sOac3NFLEa2Ktjn6GXfkAAA + + +return +pdkReturn +void +4sOac3NFLEa2Ktjn6GXfkAAA + + + +SetReuseAddress ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +jYmhcvk/KkCi98wxVyxlgQAA + +2 + +bReuseAddress +BOOL +jYmhcvk/KkCi98wxVyxlgQAA + + +return +pdkReturn +void +jYmhcvk/KkCi98wxVyxlgQAA + + + +GetSendPolicy ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +FVmUlcrLIE2kc9PpzlIhMAAA + +1 + +return +pdkReturn +FVmUlcrLIE2kc9PpzlIhMAAA +p4RvBvwp3kOxyo/4mj2ZKwAA + + + +GetWorkerThreadCount ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +6AuN4iAs2k2LSP2yMYljVAAA + +1 + +return +pdkReturn +DWORD +6AuN4iAs2k2LSP2yMYljVAAA + + + +GetSocketBufferSize ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True ++PGe7N2/FE6XtIk4s5JVAwAA + +1 + +return +pdkReturn +DWORD ++PGe7N2/FE6XtIk4s5JVAwAA + + + +GetFreeSocketObjLockTime ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +W79yrdGkN0KA5XGVec0dwwAA + +1 + +return +pdkReturn +DWORD +W79yrdGkN0KA5XGVec0dwwAA + + + +GetFreeSocketObjPool ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +mIKLuqW66EyF4y2uWImVuwAA + +1 + +return +pdkReturn +DWORD +mIKLuqW66EyF4y2uWImVuwAA + + + +GetFreeBufferObjPool ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +45ZSCQbOWU6wJTNVUtN+xQAA + +1 + +return +pdkReturn +DWORD +45ZSCQbOWU6wJTNVUtN+xQAA + + + +GetFreeSocketObjHold ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True ++ehGpW8yUkmrFNu0LRJgKgAA + +1 + +return +pdkReturn +DWORD ++ehGpW8yUkmrFNu0LRJgKgAA + + + +GetFreeBufferObjHold ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +XTafu99nxkeEJcL+cgJQLgAA + +1 + +return +pdkReturn +DWORD +XTafu99nxkeEJcL+cgJQLgAA + + + +GetKeepAliveTime ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +1+U2OC8YKE+6LWY0VE2ZCgAA + +1 + +return +pdkReturn +DWORD +1+U2OC8YKE+6LWY0VE2ZCgAA + + + +GetKeepAliveInterval ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +qRcbFHSM90qXO0CV4Lq79gAA + +1 + +return +pdkReturn +DWORD +qRcbFHSM90qXO0CV4Lq79gAA + + + +IsReuseAddress ++hvdtNLBPUeUmdoy9WnIywAA +1 + +Cpp +CppVirtual +CppVirtual +True +mZTRn52mzUKy479NHeRbNAAA + +1 + +return +pdkReturn +BOOL +mZTRn52mzUKy479NHeRbNAAA + + + + +CTcpClient +jvfBmo6uGkC61ckI99TMgAAA +4 +PGFFeARNxk+lxLKoUolRcgAA +bhq+EKQMh0mJ5HMPBgvYmgAA +IZzOP8acO0GJJlNhV+/wsAAA +1Ep9fPeyp02DLG+kWwBmAgAA +1 +hwXxX+YbkkG6mY/KLykG4AAA +2 +ZNw4OjQkUkmijjdgoAjX+gAA +PhcJjlYZKkK5/K0LejildAAA +27 + +Start +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +xqIYrcUgnkSQ1GQGjhpGJgAA + +4 + +pszRemoteAddress +LPCTSTR +xqIYrcUgnkSQ1GQGjhpGJgAA + + +usPort +USHORT +xqIYrcUgnkSQ1GQGjhpGJgAA + + +bAsyncConnect +BOOL +xqIYrcUgnkSQ1GQGjhpGJgAA + + +return +pdkReturn +BOOL +xqIYrcUgnkSQ1GQGjhpGJgAA + + + +Stop +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +/Qhmo/fLEkuF39ZikfRjFQAA + +1 + +return +pdkReturn +BOOL +/Qhmo/fLEkuF39ZikfRjFQAA + + + +Send +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +iJFqK2IVl0+NVNtTEkyl/wAA + +4 + +pBuffer +BYTE +iJFqK2IVl0+NVNtTEkyl/wAA +2 + +Cpp +CppConst +CppConst +True +LuALeibffEexnFyOS/DuGQAA + + +Cpp +CppPointer +CppPointer +* +LuALeibffEexnFyOS/DuGQAA + + + +iLength +int +iJFqK2IVl0+NVNtTEkyl/wAA + + +iOffset +int +iJFqK2IVl0+NVNtTEkyl/wAA + + +return +pdkReturn +BOOL +iJFqK2IVl0+NVNtTEkyl/wAA + + + +SendPackets +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +MSFxfox08EGCuO6P2TauPAAA + +3 + +pBuffers +WSABUF +MSFxfox08EGCuO6P2TauPAAA +1 + +Cpp +CppConst +CppConst +True +H59cxWwCJU+FyKrezLgc4wAA + + + +iCount +int +MSFxfox08EGCuO6P2TauPAAA + + +return +pdkReturn +BOOL +MSFxfox08EGCuO6P2TauPAAA + + + +SendSmallFile +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +a7csUxLGw0Cx5cCnwo7QPgAA + +4 + +lpszFileName +LPCTSTR +a7csUxLGw0Cx5cCnwo7QPgAA + + +pHead +LPWSABUF +a7csUxLGw0Cx5cCnwo7QPgAA +1 + +Cpp +CppConst +CppConst +True +Z3eIW+13y0WDUo0h1/zbhQAA + + + +pTail +LPWSABUF +a7csUxLGw0Cx5cCnwo7QPgAA +1 + +Cpp +CppConst +CppConst +True +kRkXXIyT206L0QntlJ0zhgAA + + + +return +pdkReturn +BOOL +a7csUxLGw0Cx5cCnwo7QPgAA + + + +HasStarted +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +oAZrKOgYfkabqeEVBol75wAA + +1 + +return +pdkReturn +BOOL +oAZrKOgYfkabqeEVBol75wAA + + + +GetState +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +FXzC/uhRnkSq4Tn7EFpBdAAA + +1 + +return +pdkReturn +FXzC/uhRnkSq4Tn7EFpBdAAA +3KsfqnlMb0ieGw/IAO5hFQAA + + + +GetConnectionID +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +Mnewg9gaLk+kyV625IT+qwAA + +1 + +return +pdkReturn +Mnewg9gaLk+kyV625IT+qwAA +G8TfQngB3UemVJWZg5KbggAA + + + +GetLocalAddress +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +i8zfzrzwzUeHHM7W/v2Q9AAA + +4 + +lpszAddress +TCHAR +i8zfzrzwzUeHHM7W/v2Q9AAA + + +iAddressLen +int +i8zfzrzwzUeHHM7W/v2Q9AAA +1 + +Cpp +CppPointer +CppPointer +& +IUdrnSu8vEKgvsUmKByPygAA + + + +usPort +USHORT +i8zfzrzwzUeHHM7W/v2Q9AAA +1 + +Cpp +CppPointer +CppPointer +& +EhuWL/p8eUC0D7EyOy9qMwAA + + + +return +pdkReturn +BOOL +i8zfzrzwzUeHHM7W/v2Q9AAA + + + +GetPendingDataLength +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +DDVc7sPaVkKo3YUXBWrVVAAA + +2 + +iPending +int +DDVc7sPaVkKo3YUXBWrVVAAA +1 + +Cpp +CppPointer +CppPointer +& +DoofxA6q2U2ETRQvxZyHJQAA + + + +return +pdkReturn +BOOL +DDVc7sPaVkKo3YUXBWrVVAAA + + + +GetLastError +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +q2xTwE7EsUahHc9cWDtNbAAA + +1 + +return +pdkReturn +q2xTwE7EsUahHc9cWDtNbAAA +R9EXi7T78E6Gt882nRMyDwAA + + + +GetLastErrorDesc +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +Xii7BTbFWk2PzgC3n50LBAAA + +1 + +return +pdkReturn +LPCTSTR +Xii7BTbFWk2PzgC3n50LBAAA + + + +SetSocketBufferSize +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +p2dByb32SEaJkvGIKCAk6wAA + +2 + +dwSocketBufferSize +DWORD +p2dByb32SEaJkvGIKCAk6wAA + + +return +pdkReturn +void +p2dByb32SEaJkvGIKCAk6wAA + + + +SetKeepAliveTime +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +1KlKL/wo3kOj+s3bVLTc2gAA + +2 + +dwKeepAliveTime +DWORD +1KlKL/wo3kOj+s3bVLTc2gAA + + +return +pdkReturn +void +1KlKL/wo3kOj+s3bVLTc2gAA + + + +SetKeepAliveInterval +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +bRE3GkXMI0yASmgUvQF/ggAA + +2 + +dwKeepAliveInterval +DWORD +bRE3GkXMI0yASmgUvQF/ggAA + + +return +pdkReturn +void +bRE3GkXMI0yASmgUvQF/ggAA + + + +SetFreeBufferPoolSize +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +X6HZZFjZk0OgRu/CRXrLIAAA + +2 + +dwFreeBufferPoolSize +DWORD +X6HZZFjZk0OgRu/CRXrLIAAA + + +return +pdkReturn +void +X6HZZFjZk0OgRu/CRXrLIAAA + + + +SetFreeBufferPoolHold +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +F8IdpATIL0CSxwuBBR71HgAA + +2 + +dwFreeBufferPoolHold +DWORD +F8IdpATIL0CSxwuBBR71HgAA + + +return +pdkReturn +void +F8IdpATIL0CSxwuBBR71HgAA + + + +SetExtra +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +WfS57xBtK0KpkWXHtYbhJAAA + +2 + +pExtra +PVOID +WfS57xBtK0KpkWXHtYbhJAAA + + +return +pdkReturn +void +WfS57xBtK0KpkWXHtYbhJAAA + + + +GetSocketBufferSize +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +1+abGFrwsUCjf4ddwKhhkwAA + +1 + +return +pdkReturn +DWORD +1+abGFrwsUCjf4ddwKhhkwAA + + + +GetKeepAliveTime +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +hobqM1NX0US+XJW0vn9xsAAA + +1 + +return +pdkReturn +DWORD +hobqM1NX0US+XJW0vn9xsAAA + + + +GetKeepAliveInterval +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +76xwRulW5UWszv+8CTgVOAAA + +1 + +return +pdkReturn +DWORD +76xwRulW5UWszv+8CTgVOAAA + + + +GetFreeBufferPoolSize +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +6v1bjl9EjkS1MQ4AErwwjgAA + +1 + +return +pdkReturn +DWORD +6v1bjl9EjkS1MQ4AErwwjgAA + + + +GetFreeBufferPoolHold +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +4byDgL/4nU+5Ri/VX5RnmQAA + +1 + +return +pdkReturn +DWORD +4byDgL/4nU+5Ri/VX5RnmQAA + + + +GetExtra +rNsPUCIqcESb1NED1xr04AAA +1 + +Cpp +CppVirtual +CppVirtual +True +EKN6QyrYA0uX2qMfahWTWQAA + +1 + +return +pdkReturn +PVOID +EKN6QyrYA0uX2qMfahWTWQAA + + + +CTcpClient +UMLStandard +create +vkPrivate +rNsPUCIqcESb1NED1xr04AAA +1 + +psoListener +HH8IxhnEe02DYLKVHG2PFQAA +HwLi+AyuiUa754Eutz2k5AAA +1 + +Cpp +CppPointer +CppPointer +* +zFezEQ9xPkK/0POS3GJN3AAA + + + + +CTcpClient +UMLStandard +destroy +vkPrivate +rNsPUCIqcESb1NED1xr04AAA + + +Cpp +CppMacro +vkPrivate +rNsPUCIqcESb1NED1xr04AAA + + + +CTcpPullAgent +jvfBmo6uGkC61ckI99TMgAAA +4 +91D3350Tx0G/REKMBgAVcgAA +/1i+zUrJvEOaccA5WyubogAA +1223ya+RA0+ICvNgzySMZgAA +u0jv0auiuUeMCmshH1Lc/AAA +2 +SWj0s9+zMUW6Sa0s98LfDgAA +IDQB44Q61kudclcYwyYEMwAA +4 + +Fetch +JJbEayVgmEyWvR4C1WYpsAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Zd5pVcvt30yz6A/gXbfW/AAA + +4 + +dwConnID +Zd5pVcvt30yz6A/gXbfW/AAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +Zd5pVcvt30yz6A/gXbfW/AAA +1 + +Cpp +CppPointer +CppPointer +* +zj0ZssKRBk+8OJuLyr+2WQAA + + + +iLength +int +Zd5pVcvt30yz6A/gXbfW/AAA + + +return +pdkReturn +Zd5pVcvt30yz6A/gXbfW/AAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +Peek +JJbEayVgmEyWvR4C1WYpsAAA +1 + +Cpp +CppVirtual +CppVirtual +True +KcPeQjykq0KpiMC/A6pQQwAA + +4 + +dwConnID +KcPeQjykq0KpiMC/A6pQQwAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +KcPeQjykq0KpiMC/A6pQQwAA +1 + +Cpp +CppPointer +CppPointer +* +T3WXjYz9Q0ODShUTa0iTlgAA + + + +iLength +int +KcPeQjykq0KpiMC/A6pQQwAA + + +return +pdkReturn +KcPeQjykq0KpiMC/A6pQQwAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +CTcpPullAgent +UMLStandard +create +vkPrivate +JJbEayVgmEyWvR4C1WYpsAAA +1 + +psoListener +bHjGpU8TVEaljiK4zrOw5wAA +skl0Nm/UIUCTsqkUAIXmzAAA +1 + +Cpp +CppPointer +CppPointer +* +1IzM6A2aLECcC/0wa1pI4QAA + + + + +CTcpPullAgent +UMLStandard +destroy +vkPrivate +JJbEayVgmEyWvR4C1WYpsAAA + + + +CTcpPullClient +jvfBmo6uGkC61ckI99TMgAAA +4 +pHz4Yn9KW0u1EHHgf7i2PQAA +buSF1GY2aUe2XvnVYnG63AAA +XcKh1JxMxUOeZp3VWu5kfQAA +HQnHkxQ1v0+FWvVWfOgiMgAA +2 +t7BFiOV+U0+3Fzwd6nXwzgAA +ZNw4OjQkUkmijjdgoAjX+gAA +4 + +Fetch +dUFVpJ56j0WxczyDxsGS+gAA +1 + +Cpp +CppVirtual +CppVirtual +True +6pYLE5ejyUOt4qpc0d5NMQAA + +3 + +pData +BYTE +6pYLE5ejyUOt4qpc0d5NMQAA +1 + +Cpp +CppPointer +CppPointer +* +J56gOs/VDUmPeZsS48dM0wAA + + + +iLength +int +6pYLE5ejyUOt4qpc0d5NMQAA + + +return +pdkReturn +6pYLE5ejyUOt4qpc0d5NMQAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +Peek +dUFVpJ56j0WxczyDxsGS+gAA +1 + +Cpp +CppVirtual +CppVirtual +True +ANgjWVq5XkmV2+smTSXUdgAA + +3 + +pData +BYTE +ANgjWVq5XkmV2+smTSXUdgAA +1 + +Cpp +CppPointer +CppPointer +* +iHnpUUGwd02F376uArpcdgAA + + + +iLength +int +ANgjWVq5XkmV2+smTSXUdgAA + + +return +pdkReturn +ANgjWVq5XkmV2+smTSXUdgAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +CTcpPullClient +UMLStandard +create +vkPrivate +dUFVpJ56j0WxczyDxsGS+gAA +1 + +psoListener +CbYIiPZdTE2NK+6wqArbagAA +HwLi+AyuiUa754Eutz2k5AAA +1 + +Cpp +CppPointer +CppPointer +* +O/zc/hQ0+EOg3dj2SV2i6wAA + + + + +CTcpPullClient +UMLStandard +destroy +vkPrivate +dUFVpJ56j0WxczyDxsGS+gAA + + + +CTcpPullServer +jvfBmo6uGkC61ckI99TMgAAA +4 +pH4m1vGfz0+s2Byn9+X25QAA +Xd0IheJaBky2v052QS7rnAAA +HnrKwuRzYUCnstMyLcCzqAAA +fl4mh0o9/UmBWuN3JGYJHwAA +2 +DLbR09fsFE6Bx8bzfHmD6AAA +UT9syzbMZEyZsIIcEMpphAAA +4 + +Fetch +5tmwPyb6D0Ki98vc8dVPhQAA +1 + +Cpp +CppVirtual +CppVirtual +True +8tjq927oxEy5KAfYp2WjHgAA + +4 + +dwConnID +8tjq927oxEy5KAfYp2WjHgAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +8tjq927oxEy5KAfYp2WjHgAA +1 + +Cpp +CppPointer +CppPointer +* +CCPKQzHShkWpxv/S9OoM2QAA + + + +iLength +int +8tjq927oxEy5KAfYp2WjHgAA + + +return +pdkReturn +8tjq927oxEy5KAfYp2WjHgAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +Peek +5tmwPyb6D0Ki98vc8dVPhQAA +1 + +Cpp +CppVirtual +CppVirtual +True +SFhs11NkLkS7UCRXRseYMQAA + +4 + +dwConnID +SFhs11NkLkS7UCRXRseYMQAA +G8TfQngB3UemVJWZg5KbggAA + + +pData +BYTE +SFhs11NkLkS7UCRXRseYMQAA +1 + +Cpp +CppPointer +CppPointer +* +AyetOz7XDEyaTE8NIVFNTQAA + + + +iLength +int +SFhs11NkLkS7UCRXRseYMQAA + + +return +pdkReturn +SFhs11NkLkS7UCRXRseYMQAA +VQDDk4BU6UmBmig6SmOuoQAA + + + +CTcpPullServer +UMLStandard +create +vkPrivate +5tmwPyb6D0Ki98vc8dVPhQAA +1 + +psoListener +IfitnXZWGUyv3p7NgZt7MQAA +h8NmVuBtVUWgcCSKCdxePgAA +1 + +Cpp +CppPointer +CppPointer +* +tW7BVXw750CVMd+46YfU4gAA + + + + +CTcpPullServer +UMLStandard +destroy +vkPrivate +5tmwPyb6D0Ki98vc8dVPhQAA + + + +CTcpServer +jvfBmo6uGkC61ckI99TMgAAA +4 +b5sh7cGyAEG5dKPNO5ax0wAA +UZW5tMzLckaYSBfL3b99rAAA +YiRb6U9yg0C7AYu3iGL3zAAA +zp5oS4yR6EabvfVBnp6QggAA +1 +O5dkSXpa9UWV4M9yJ7QzIwAA +2 +UT9syzbMZEyZsIIcEMpphAAA +aQ1uf7mN+EuF/eGcASNwmgAA +49 + +CTcpServer +UMLStandard +create +vkPrivate +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +psoListener +HicZjKBDlkul3a45zfbrWwAA +h8NmVuBtVUWgcCSKCdxePgAA +1 + +Cpp +CppPointer +CppPointer +* +m0VjNIF00UeJ9xj8Mli6YAAA + + + + +CTcpServer +UMLStandard +destroy +vkPrivate +gWn1z7ujyEu9Gf7LdRrPIAAA + + +Start +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +WNuECjxTO0OV54fk7z5qgQAA + +3 + +pszBindAddress +LPCTSTR +WNuECjxTO0OV54fk7z5qgQAA + + +usPort +USHORT +WNuECjxTO0OV54fk7z5qgQAA + + +return +pdkReturn +BOOL +WNuECjxTO0OV54fk7z5qgQAA + + + +Stop +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +PSUfVIv7VUqY6IAJm44/OwAA + +1 + +return +pdkReturn +BOOL +PSUfVIv7VUqY6IAJm44/OwAA + + + +Send +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Qa3sZx75kkeGpKq4oQxYCwAA + +5 + +dwConnID +Qa3sZx75kkeGpKq4oQxYCwAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffer +BYTE +Qa3sZx75kkeGpKq4oQxYCwAA +2 + +Cpp +CppConst +CppConst +True +YgnG9IYTiES//4wNL7CiUAAA + + +Cpp +CppPointer +CppPointer +* +YgnG9IYTiES//4wNL7CiUAAA + + + +iLength +int +Qa3sZx75kkeGpKq4oQxYCwAA + + +iOffset +int +Qa3sZx75kkeGpKq4oQxYCwAA + + +return +pdkReturn +BOOL +Qa3sZx75kkeGpKq4oQxYCwAA + + + +SendPackets +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Xg8k8XUkX0uSMjg8Xh1lzQAA + +4 + +dwConnID +Xg8k8XUkX0uSMjg8Xh1lzQAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffers +WSABUF +Xg8k8XUkX0uSMjg8Xh1lzQAA +1 + +Cpp +CppConst +CppConst +True +dz+d2kpwWk2KKxRAFyeONQAA + + + +iCount +int +Xg8k8XUkX0uSMjg8Xh1lzQAA + + +return +pdkReturn +BOOL +Xg8k8XUkX0uSMjg8Xh1lzQAA + + + +SendSmallFile +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +voEgbJeJL06UjR81AqCJCwAA + +5 + +dwConnID +voEgbJeJL06UjR81AqCJCwAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszFileName +LPCTSTR +voEgbJeJL06UjR81AqCJCwAA + + +pHead +LPWSABUF +voEgbJeJL06UjR81AqCJCwAA +1 + +Cpp +CppConst +CppConst +True +va71ehMsLkuWlyY7owFAmwAA + + + +pTail +LPWSABUF +voEgbJeJL06UjR81AqCJCwAA +1 + +Cpp +CppConst +CppConst +True +iesXqVX0Jk69xBvbUAeCGwAA + + + +return +pdkReturn +BOOL +voEgbJeJL06UjR81AqCJCwAA + + + +HasStarted +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +3P4DBT/2w0qzvxF6ErfvXwAA + +1 + +return +pdkReturn +BOOL +3P4DBT/2w0qzvxF6ErfvXwAA + + + +GetState +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +4lLln52JB0+y6UmWps2l2QAA + +1 + +return +pdkReturn +4lLln52JB0+y6UmWps2l2QAA +3KsfqnlMb0ieGw/IAO5hFQAA + + + +Disconnect +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +ZudCe9Se/kiozXsnycfrOgAA + +3 + +dwConnID +ZudCe9Se/kiozXsnycfrOgAA +G8TfQngB3UemVJWZg5KbggAA + + +bForce +BOOL +ZudCe9Se/kiozXsnycfrOgAA + + +return +pdkReturn +BOOL +ZudCe9Se/kiozXsnycfrOgAA + + + +DisconnectLongConnections +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +bxl6cH2dS0ShdTXysP5sZAAA + +3 + +dwPeriod +DWORD +bxl6cH2dS0ShdTXysP5sZAAA + + +bForce +BOOL +bxl6cH2dS0ShdTXysP5sZAAA + + +return +pdkReturn +BOOL +bxl6cH2dS0ShdTXysP5sZAAA + + + +DisconnectSilenceConnections +gWn1z7ujyEu9Gf7LdRrPIAAA +3 + +pdkReturn +BOOL +da6aw9lovUWsafF1lyOfUgAA + + +dwPeriod +DWORD +da6aw9lovUWsafF1lyOfUgAA + + +bForce +BOOL +da6aw9lovUWsafF1lyOfUgAA + + + +GetListenAddress +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +bab2ob9uq0miNrVxXSnE8QAA + +4 + +lpszAddress +TCHAR +bab2ob9uq0miNrVxXSnE8QAA + + +iAddressLen +int +bab2ob9uq0miNrVxXSnE8QAA +1 + +Cpp +CppPointer +CppPointer +& +P4tGl06gY0GjYF4QZiSgmQAA + + + +usPort +USHORT +bab2ob9uq0miNrVxXSnE8QAA +1 + +Cpp +CppPointer +CppPointer +& ++dzmgJA/cEis65UtkNrr+AAA + + + +return +pdkReturn +BOOL +bab2ob9uq0miNrVxXSnE8QAA + + + +GetRemoteAddress +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +HGusc9p4aU+/j0G3p11t4gAA + +5 + +dwConnID +HGusc9p4aU+/j0G3p11t4gAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszAddress +TCHAR +HGusc9p4aU+/j0G3p11t4gAA + + +iAddressLen +int +HGusc9p4aU+/j0G3p11t4gAA +1 + +Cpp +CppPointer +CppPointer +& +1c8J5/6oLEWhIXx4UMUmFwAA + + + +usPort +USHORT +HGusc9p4aU+/j0G3p11t4gAA +1 + +Cpp +CppPointer +CppPointer +& +MwI5/wHU1k6nNhe+1FlJoAAA + + + +return +pdkReturn +BOOL +HGusc9p4aU+/j0G3p11t4gAA + + + +GetPendingDataLength +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +5enMiFrhpkiNU531KDOX/QAA + +3 + +dwConnID +5enMiFrhpkiNU531KDOX/QAA +G8TfQngB3UemVJWZg5KbggAA + + +iPending +int +5enMiFrhpkiNU531KDOX/QAA +1 + +Cpp +CppPointer +CppPointer +& +9X/b1+6z2kW05/IbJ+tkKgAA + + + +return +pdkReturn +BOOL +5enMiFrhpkiNU531KDOX/QAA + + + +GetConnectionCount +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +98cGDEFsZ0208oMr9tVrMgAA + +1 + +return +pdkReturn +DWORD +98cGDEFsZ0208oMr9tVrMgAA + + + +GetAllConnectionIDs +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +1H+gT//0/0WQwZ2jVWDzggAA + +3 + +pIDs +1H+gT//0/0WQwZ2jVWDzggAA +G8TfQngB3UemVJWZg5KbggAA + + +dwCount +DWORD +1H+gT//0/0WQwZ2jVWDzggAA +1 + +Cpp +CppPointer +CppPointer +& +ojL1tzU6qEaOS3pvKi6P1AAA + + + +return +pdkReturn +BOOL +1H+gT//0/0WQwZ2jVWDzggAA + + + +GetConnectPeriod +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +E9WaC1aE+kiRmbmsTe+UPgAA + +3 + +dwConnID +E9WaC1aE+kiRmbmsTe+UPgAA +G8TfQngB3UemVJWZg5KbggAA + + +dwPeriod +DWORD +E9WaC1aE+kiRmbmsTe+UPgAA +1 + +Cpp +CppPointer +CppPointer +& +7X1Uj1YsWk2xAt9Xfi5uGgAA + + + +return +pdkReturn +BOOL +E9WaC1aE+kiRmbmsTe+UPgAA + + + +GetSilencePeriod +gWn1z7ujyEu9Gf7LdRrPIAAA +3 + +pdkReturn +BOOL +xFUPIaEZGUyGgZCCCAhAcgAA + + +dwConnID +xFUPIaEZGUyGgZCCCAhAcgAA +G8TfQngB3UemVJWZg5KbggAA + + +dwPeriod +DWORD +xFUPIaEZGUyGgZCCCAhAcgAA + + + +GetLastError +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +J6pe/JR6f0+OL+tlZiq8nQAA + +1 + +return +pdkReturn +J6pe/JR6f0+OL+tlZiq8nQAA +R9EXi7T78E6Gt882nRMyDwAA + + + +GetLastErrorDesc +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +6QItk0+fhki3/lXH5AvyigAA + +1 + +return +pdkReturn +LPCTSTR +6QItk0+fhki3/lXH5AvyigAA + + + +SetConnectionExtra +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +mtzoTUHVJkG9ujUoG4CTOwAA + +3 + +dwConnID +mtzoTUHVJkG9ujUoG4CTOwAA +G8TfQngB3UemVJWZg5KbggAA + + +pExtra +PVOID +mtzoTUHVJkG9ujUoG4CTOwAA + + +return +pdkReturn +BOOL +mtzoTUHVJkG9ujUoG4CTOwAA + + + +GetConnectionExtra +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +yuoDnIFJxUqeZBpzSlUtGwAA + +3 + +dwConnID +yuoDnIFJxUqeZBpzSlUtGwAA +G8TfQngB3UemVJWZg5KbggAA + + +ppExtra +PVOID +yuoDnIFJxUqeZBpzSlUtGwAA +1 + +Cpp +CppPointer +CppPointer +* +9gEOcpiaHkS5bu551ImwmAAA + + + +return +pdkReturn +BOOL +yuoDnIFJxUqeZBpzSlUtGwAA + + + +SetSendPolicy +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +i2AR5hxEb0ugpJYc+CQRXAAA + +2 + +enSendPolicy +i2AR5hxEb0ugpJYc+CQRXAAA +p4RvBvwp3kOxyo/4mj2ZKwAA + + +return +pdkReturn +void +i2AR5hxEb0ugpJYc+CQRXAAA + + + +SetMarkSilence +gWn1z7ujyEu9Gf7LdRrPIAAA +2 + +pdkReturn +void +ZP0sZjpgOkOEnlHkczpKKgAA + + +bMarkSilence +BOOL +ZP0sZjpgOkOEnlHkczpKKgAA + + + +IsMarkSilence +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +pdkReturn +BOOL +Qs0Hp3qbY0KUonjBPBZQuAAA + + + +SetWorkerThreadCount +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True ++fKMpf0aSUirUgyZMTGBSwAA + +2 + +dwWorkerThreadCount +DWORD ++fKMpf0aSUirUgyZMTGBSwAA + + +return +pdkReturn +void ++fKMpf0aSUirUgyZMTGBSwAA + + + +SetSocketListenQueue +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +SExY330NS02NgiVI7+JoMgAA + +2 + +dwSocketListenQueue +DWORD +SExY330NS02NgiVI7+JoMgAA + + +return +pdkReturn +void +SExY330NS02NgiVI7+JoMgAA + + + +SetAcceptSocketCount +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +ncjAYEgC8USbMG0ddB7L5wAA + +2 + +dwAcceptSocketCount +DWORD +ncjAYEgC8USbMG0ddB7L5wAA + + +return +pdkReturn +void +ncjAYEgC8USbMG0ddB7L5wAA + + + +SetSocketBufferSize +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +yMzlCNfHdEScjW2OJ1M4/AAA + +2 + +dwSocketBufferSize +DWORD +yMzlCNfHdEScjW2OJ1M4/AAA + + +return +pdkReturn +void +yMzlCNfHdEScjW2OJ1M4/AAA + + + +SetFreeSocketObjLockTime +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Nge/Hdjqg0GbGc98UvGyVgAA + +2 + +dwFreeSocketObjLockTime +DWORD +Nge/Hdjqg0GbGc98UvGyVgAA + + +return +pdkReturn +void +Nge/Hdjqg0GbGc98UvGyVgAA + + + +SetFreeSocketObjPool +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +0aUKEtluIEqD5wx4cR4RswAA + +2 + +dwFreeSocketObjPool +DWORD +0aUKEtluIEqD5wx4cR4RswAA + + +return +pdkReturn +void +0aUKEtluIEqD5wx4cR4RswAA + + + +SetFreeBufferObjPool +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +FHgTKiJJJEyK9en+2x2M8AAA + +2 + +dwFreeBufferObjPool +DWORD +FHgTKiJJJEyK9en+2x2M8AAA + + +return +pdkReturn +void +FHgTKiJJJEyK9en+2x2M8AAA + + + +SetFreeSocketObjHold +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +E55zoB+p50GnLHOutUr2zwAA + +2 + +dwFreeSocketObjHold +DWORD +E55zoB+p50GnLHOutUr2zwAA + + +return +pdkReturn +void +E55zoB+p50GnLHOutUr2zwAA + + + +SetFreeBufferObjHold +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +5rULNVIvxkOj5fOPHEmYCAAA + +2 + +dwFreeBufferObjHold +DWORD +5rULNVIvxkOj5fOPHEmYCAAA + + +return +pdkReturn +void +5rULNVIvxkOj5fOPHEmYCAAA + + + +SetKeepAliveTime +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +8A5JZLJU4EKE6PZSBa1JVwAA + +2 + +dwKeepAliveTime +DWORD +8A5JZLJU4EKE6PZSBa1JVwAA + + +return +pdkReturn +void +8A5JZLJU4EKE6PZSBa1JVwAA + + + +SetKeepAliveInterval +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +njKp69GCz025yL6sXubKVQAA + +2 + +dwKeepAliveInterval +DWORD +njKp69GCz025yL6sXubKVQAA + + +return +pdkReturn +void +njKp69GCz025yL6sXubKVQAA + + + +GetSendPolicy +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +riEuS0bzp0yO0nzoKjWV2gAA + +1 + +return +pdkReturn +riEuS0bzp0yO0nzoKjWV2gAA +p4RvBvwp3kOxyo/4mj2ZKwAA + + + +GetWorkerThreadCount +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +jbMxTClSLUaCjYTt40yPDwAA + +1 + +return +pdkReturn +DWORD +jbMxTClSLUaCjYTt40yPDwAA + + + +GetSocketListenQueue +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +eKGTZ+RPZ0Ss89HiQrobzgAA + +1 + +return +pdkReturn +DWORD +eKGTZ+RPZ0Ss89HiQrobzgAA + + + +GetAcceptSocketCount +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Vx3+1yqd40qlorW55XK9lQAA + +1 + +return +pdkReturn +DWORD +Vx3+1yqd40qlorW55XK9lQAA + + + +GetSocketBufferSize +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +8O3Qx26yyU24lcOdwSzEwwAA + +1 + +return +pdkReturn +DWORD +8O3Qx26yyU24lcOdwSzEwwAA + + + +GetFreeSocketObjLockTime +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +UQuO/yXPpU+DxpN0tmv1LAAA + +1 + +return +pdkReturn +DWORD +UQuO/yXPpU+DxpN0tmv1LAAA + + + +GetFreeSocketObjPool +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +hPVCc5OGBUq31Xm+Jrj1SwAA + +1 + +return +pdkReturn +DWORD +hPVCc5OGBUq31Xm+Jrj1SwAA + + + +GetFreeBufferObjPool +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +bOV+KRWj2kma45eDcmjCwgAA + +1 + +return +pdkReturn +DWORD +bOV+KRWj2kma45eDcmjCwgAA + + + +GetFreeSocketObjHold +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +o0UvM9u6AkyUqa/ncC+5/QAA + +1 + +return +pdkReturn +DWORD +o0UvM9u6AkyUqa/ncC+5/QAA + + + +GetFreeBufferObjHold +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Fkcm0tDQJk2Bx6tGsXzyfwAA + +1 + +return +pdkReturn +DWORD +Fkcm0tDQJk2Bx6tGsXzyfwAA + + + +GetKeepAliveTime +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +MF0ti+aW+Ei/jomjMk92KQAA + +1 + +return +pdkReturn +DWORD +MF0ti+aW+Ei/jomjMk92KQAA + + + +GetKeepAliveInterval +gWn1z7ujyEu9Gf7LdRrPIAAA +1 + +Cpp +CppVirtual +CppVirtual +True +EGoeJjga2UKOA4Q9Pky91QAA + +1 + +return +pdkReturn +DWORD +EGoeJjga2UKOA4Q9Pky91QAA + + + + +CUdpCast +jvfBmo6uGkC61ckI99TMgAAA +4 +19i0QowlNkm9OgeAWSgS4wAA +/AI6I93qBU6Dgo5pPu5AvwAA +437lb/H8rkK+pp5JkdAQgAAA +FUkNog+BvkaMSCSFGgVRRwAA +1 +Mrk3QXUHNk2R1/cHV9/5pAAA +32 + +Start +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +s+EMwnAUekS+sLJVWEA3ygAA + +4 + +pszRemoteAddress +LPCTSTR +s+EMwnAUekS+sLJVWEA3ygAA + + +usPort +USHORT +s+EMwnAUekS+sLJVWEA3ygAA + + +bAsyncConnect +BOOL +s+EMwnAUekS+sLJVWEA3ygAA + + +return +pdkReturn +BOOL +s+EMwnAUekS+sLJVWEA3ygAA + + + +Stop +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +BRqxpPnJB02Z7yNhe5WLlgAA + +1 + +return +pdkReturn +BOOL +BRqxpPnJB02Z7yNhe5WLlgAA + + + +Send +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +ZKwCOozZGU2U3e4J0sZm/AAA + +4 + +pBuffer +BYTE +ZKwCOozZGU2U3e4J0sZm/AAA +2 + +Cpp +CppConst +CppConst +True +Gri9o6KcbkaavMrAe6YZDAAA + + +Cpp +CppPointer +CppPointer +* +Gri9o6KcbkaavMrAe6YZDAAA + + + +iLength +int +ZKwCOozZGU2U3e4J0sZm/AAA + + +iOffset +int +ZKwCOozZGU2U3e4J0sZm/AAA + + +return +pdkReturn +BOOL +ZKwCOozZGU2U3e4J0sZm/AAA + + + +SendPackets +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +/BCbW0oDoE21y44ENIBWEgAA + +3 + +pBuffers +WSABUF +/BCbW0oDoE21y44ENIBWEgAA +1 + +Cpp +CppConst +CppConst +True +JNk1hyTzqUSAyxMA6ZehsgAA + + + +iCount +int +/BCbW0oDoE21y44ENIBWEgAA + + +return +pdkReturn +BOOL +/BCbW0oDoE21y44ENIBWEgAA + + + +HasStarted +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +Pb6paLdxBUmwv1LwvOSuyQAA + +1 + +return +pdkReturn +BOOL +Pb6paLdxBUmwv1LwvOSuyQAA + + + +GetState +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +BW3q+IxsSkqKTi2HASdcuAAA + +1 + +return +pdkReturn +BW3q+IxsSkqKTi2HASdcuAAA +3KsfqnlMb0ieGw/IAO5hFQAA + + + +GetConnectionID +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +hfOGgSAI5kGonyA1fDaxJwAA + +1 + +return +pdkReturn +hfOGgSAI5kGonyA1fDaxJwAA +G8TfQngB3UemVJWZg5KbggAA + + + +GetLocalAddress +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +CNfYEnKVOkiRNm/bqkhS/gAA + +4 + +lpszAddress +TCHAR +CNfYEnKVOkiRNm/bqkhS/gAA + + +iAddressLen +int +CNfYEnKVOkiRNm/bqkhS/gAA +1 + +Cpp +CppPointer +CppPointer +& +fI4gwHeX7USmxxEEvQmNvAAA + + + +usPort +USHORT +CNfYEnKVOkiRNm/bqkhS/gAA +1 + +Cpp +CppPointer +CppPointer +& +oFhL8l0vCUSl5jE5q7VfSQAA + + + +return +pdkReturn +BOOL +CNfYEnKVOkiRNm/bqkhS/gAA + + + +GetPendingDataLength +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +XylyyfePc0mZAaSowiSqxgAA + +2 + +iPending +int +XylyyfePc0mZAaSowiSqxgAA +1 + +Cpp +CppPointer +CppPointer +& +PA5UCcn+1kKTYJgD4F/O3AAA + + + +return +pdkReturn +BOOL +XylyyfePc0mZAaSowiSqxgAA + + + +GetLastError +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +aCa+NEE+HkuXuh2sgengYAAA + +1 + +return +pdkReturn +aCa+NEE+HkuXuh2sgengYAAA +R9EXi7T78E6Gt882nRMyDwAA + + + +GetLastErrorDesc +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +sRAwmVO8ekK0uBQQXvvTDAAA + +1 + +return +pdkReturn +LPCTSTR +sRAwmVO8ekK0uBQQXvvTDAAA + + + +SetMaxDatagramSize +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +lxI+T5gKnkGjPVmfm7ji+QAA + +2 + +dwMaxDatagramSize +DWORD +lxI+T5gKnkGjPVmfm7ji+QAA + + +return +pdkReturn +void +lxI+T5gKnkGjPVmfm7ji+QAA + + + +SetFreeBufferPoolSize +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +dpnyRE06okaoRqmS55GE7AAA + +2 + +dwFreeBufferPoolSize +DWORD +dpnyRE06okaoRqmS55GE7AAA + + +return +pdkReturn +void +dpnyRE06okaoRqmS55GE7AAA + + + +SetFreeBufferPoolHold +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +ZxJFhePYmEafWALwp7C/ewAA + +2 + +dwFreeBufferPoolHold +DWORD +ZxJFhePYmEafWALwp7C/ewAA + + +return +pdkReturn +void +ZxJFhePYmEafWALwp7C/ewAA + + + +SetReuseAddress +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +1biIWbHvkU+ufQyuNDUv5wAA + +2 + +bReuseAddress +BOOL +1biIWbHvkU+ufQyuNDUv5wAA + + +return +pdkReturn +void +1biIWbHvkU+ufQyuNDUv5wAA + + + +SetBindAdddress +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +cHXkppysJ024F5Lau8X1swAA + +2 + +pszBindAddress +LPCTSTR +cHXkppysJ024F5Lau8X1swAA + + +return +pdkReturn +void +cHXkppysJ024F5Lau8X1swAA + + + +SetCastMode +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +BFDDJ3+amUS0VsVJmaI3JAAA + +2 + +enCastMode +BFDDJ3+amUS0VsVJmaI3JAAA +6zImDSI92UG9tawjYrSv0AAA + + +return +pdkReturn +void +BFDDJ3+amUS0VsVJmaI3JAAA + + + +SetMultiCastTtl +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +HiK7peKXAUaP2oWNKIbatQAA + +2 + +iMCTtl +int +HiK7peKXAUaP2oWNKIbatQAA + + +return +pdkReturn +void +HiK7peKXAUaP2oWNKIbatQAA + + + +SetMultiCastLoop +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +H/9A0sY+/0+tq31v58qkDQAA + +2 + +bMCLoop +BOOL +H/9A0sY+/0+tq31v58qkDQAA + + +return +pdkReturn +void +H/9A0sY+/0+tq31v58qkDQAA + + + +SetExtra +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +Kfcy4yTWhkixG+DpUCkTfgAA + +2 + +pExtra +PVOID +Kfcy4yTWhkixG+DpUCkTfgAA + + +return +pdkReturn +void +Kfcy4yTWhkixG+DpUCkTfgAA + + + +GetMaxDatagramSize +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +thoqGC8LREaKXi/aixk7xwAA + +1 + +return +pdkReturn +DWORD +thoqGC8LREaKXi/aixk7xwAA + + + +GetFreeBufferPoolSize +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +xq34nllvVkyqsRo61UQugAAA + +1 + +return +pdkReturn +DWORD +xq34nllvVkyqsRo61UQugAAA + + + +GetFreeBufferPoolHold +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +Ziy0lNNJFkyTRfVJ+A0oVwAA + +1 + +return +pdkReturn +DWORD +Ziy0lNNJFkyTRfVJ+A0oVwAA + + + +IsReuseAddress +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +Od6wQJ/Az0ixAY/Et3QXsAAA + +1 + +return +pdkReturn +BOOL +Od6wQJ/Az0ixAY/Et3QXsAAA + + + +GetBindAdddress +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +j7FzBUZ560+Ig7HaiLM1fAAA + +1 + +return +pdkReturn +LPCTSTR +j7FzBUZ560+Ig7HaiLM1fAAA + + + +GetCastMode +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +FIZHwyAcuEidT11YxBvWOQAA + +1 + +return +pdkReturn +FIZHwyAcuEidT11YxBvWOQAA +6zImDSI92UG9tawjYrSv0AAA + + + +GetMultiCastTtl +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +PF0gqTRakUGwLeMAG0waxgAA + +1 + +return +pdkReturn +int +PF0gqTRakUGwLeMAG0waxgAA + + + +IsMultiCastLoop +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +ituZO/fRNEq0SkbpGhXmCAAA + +1 + +return +pdkReturn +BOOL +ituZO/fRNEq0SkbpGhXmCAAA + + + +GetExtra +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +SjwsjJESN0euap2zwtAkHAAA + +1 + +return +pdkReturn +PVOID +SjwsjJESN0euap2zwtAkHAAA + + + +GetRemoteAddress +ukpy8IZAy0KEameLGY9mtQAA +1 + +Cpp +CppVirtual +CppVirtual +True +rGpDkEsf+kaM21gi2+CjUwAA + +4 + +lpszAddress +TCHAR +rGpDkEsf+kaM21gi2+CjUwAA + + +iAddressLen +int +rGpDkEsf+kaM21gi2+CjUwAA +1 + +Cpp +CppPointer +CppPointer +& +Xkn0TE6dck+W+g1we5IprwAA + + + +usPort +USHORT +rGpDkEsf+kaM21gi2+CjUwAA +1 + +Cpp +CppPointer +CppPointer +& +BnxFkA9j3k6jnIVqK9LMWQAA + + + +return +pdkReturn +BOOL +rGpDkEsf+kaM21gi2+CjUwAA + + + +CUdpCast +UMLStandard +create +vkPrivate +ukpy8IZAy0KEameLGY9mtQAA +1 + +psoListener +1AtPq7azIUSOBIkR8N8CGQAA +r22NFz2+L0aq+kmESgCiYAAA +1 + +Cpp +CppPointer +CppPointer +* +EyoF0ndo9kCFpkNwo8KVngAA + + + + +CUdpCast +UMLStandard +destroy +vkPrivate +ukpy8IZAy0KEameLGY9mtQAA + + + +CUdpClient +jvfBmo6uGkC61ckI99TMgAAA +4 +c825HJK3kEKsHWC48ErTtwAA +EpDVQXqw+kS1DDjafknYfAAA +klA0bERhtU+pvNTIByNKQAAA +8UpXJ0wJV0OrYQBWBniWYgAA +1 +TevsU+ekCkCxrYsp/lugswAA +25 + +Start +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +zIOyLoZDmkKv9Lcbf17k8gAA + +4 + +pszRemoteAddress +LPCTSTR +zIOyLoZDmkKv9Lcbf17k8gAA + + +usPort +USHORT +zIOyLoZDmkKv9Lcbf17k8gAA + + +bAsyncConnect +BOOL +zIOyLoZDmkKv9Lcbf17k8gAA + + +return +pdkReturn +BOOL +zIOyLoZDmkKv9Lcbf17k8gAA + + + +Stop +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +tZCHj+FpEEusNlF3kdinfgAA + +1 + +return +pdkReturn +BOOL +tZCHj+FpEEusNlF3kdinfgAA + + + +Send +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +w+sMdF9lt0qwnTiey9oImAAA + +4 + +pBuffer +BYTE +w+sMdF9lt0qwnTiey9oImAAA +2 + +Cpp +CppConst +CppConst +True +jAdLbFphm0KG0yGNqjPc3gAA + + +Cpp +CppPointer +CppPointer +* +jAdLbFphm0KG0yGNqjPc3gAA + + + +iLength +int +w+sMdF9lt0qwnTiey9oImAAA + + +iOffset +int +w+sMdF9lt0qwnTiey9oImAAA + + +return +pdkReturn +BOOL +w+sMdF9lt0qwnTiey9oImAAA + + + +SendPackets +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +p+CJ//jWcEOzgsf5TqGbCQAA + +3 + +pBuffers +WSABUF +p+CJ//jWcEOzgsf5TqGbCQAA +1 + +Cpp +CppConst +CppConst +True +iwMxJu8yJkic9L9nxSpdeAAA + + + +iCount +int +p+CJ//jWcEOzgsf5TqGbCQAA + + +return +pdkReturn +BOOL +p+CJ//jWcEOzgsf5TqGbCQAA + + + +HasStarted +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +3CKXDObB2EW5dFzW+bM8dQAA + +1 + +return +pdkReturn +BOOL +3CKXDObB2EW5dFzW+bM8dQAA + + + +GetState +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +KVpcp5EDUE6dlTijnlHiYgAA + +1 + +return +pdkReturn +KVpcp5EDUE6dlTijnlHiYgAA +3KsfqnlMb0ieGw/IAO5hFQAA + + + +GetConnectionID +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +r6e+GcFnwkS/Y/sA8VCBUgAA + +1 + +return +pdkReturn +r6e+GcFnwkS/Y/sA8VCBUgAA +G8TfQngB3UemVJWZg5KbggAA + + + +GetLocalAddress +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +2CRjxruutE6+1ML89666ewAA + +4 + +lpszAddress +TCHAR +2CRjxruutE6+1ML89666ewAA + + +iAddressLen +int +2CRjxruutE6+1ML89666ewAA +1 + +Cpp +CppPointer +CppPointer +& +6prk4FpT00aGQECslZhIwwAA + + + +usPort +USHORT +2CRjxruutE6+1ML89666ewAA +1 + +Cpp +CppPointer +CppPointer +& +IRsxMMUfr0aW1f3jLxrElwAA + + + +return +pdkReturn +BOOL +2CRjxruutE6+1ML89666ewAA + + + +GetPendingDataLength +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +92GkqRAi0EmEJIRI75uXWQAA + +2 + +iPending +int +92GkqRAi0EmEJIRI75uXWQAA +1 + +Cpp +CppPointer +CppPointer +& +9YsQZU6/4kKqr7m7dOIBSAAA + + + +return +pdkReturn +BOOL +92GkqRAi0EmEJIRI75uXWQAA + + + +GetLastError +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +l7gJX1gHeEOcRAiR/9Z1ZwAA + +1 + +return +pdkReturn +l7gJX1gHeEOcRAiR/9Z1ZwAA +R9EXi7T78E6Gt882nRMyDwAA + + + +GetLastErrorDesc +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +q6Onhue/W0azrlq9g7mSxQAA + +1 + +return +pdkReturn +LPCTSTR +q6Onhue/W0azrlq9g7mSxQAA + + + +SetMaxDatagramSize +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +4/QFkGQHzUCWxshLC9WWKwAA + +2 + +dwMaxDatagramSize +DWORD +4/QFkGQHzUCWxshLC9WWKwAA + + +return +pdkReturn +void +4/QFkGQHzUCWxshLC9WWKwAA + + + +SetDetectAttempts +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +FxCMhZYpnECCgD4xPI1RpgAA + +2 + +dwDetectAttempts +DWORD +FxCMhZYpnECCgD4xPI1RpgAA + + +return +pdkReturn +void +FxCMhZYpnECCgD4xPI1RpgAA + + + +SetDetectInterval +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +PMqAd26Oj0O0DDxvw6hKngAA + +2 + +dwDetectInterval +DWORD +PMqAd26Oj0O0DDxvw6hKngAA + + +return +pdkReturn +void +PMqAd26Oj0O0DDxvw6hKngAA + + + +SetFreeBufferPoolSize +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +jj8wNRbfAU6kkxOyHwoJIAAA + +2 + +dwFreeBufferPoolSize +DWORD +jj8wNRbfAU6kkxOyHwoJIAAA + + +return +pdkReturn +void +jj8wNRbfAU6kkxOyHwoJIAAA + + + +SetFreeBufferPoolHold +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +DRteDd5jGEuER7AFHvMcVAAA + +2 + +dwFreeBufferPoolHold +DWORD +DRteDd5jGEuER7AFHvMcVAAA + + +return +pdkReturn +void +DRteDd5jGEuER7AFHvMcVAAA + + + +SetExtra +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Ayuf+gWpdUSaJOnTAH9B2QAA + +2 + +pExtra +PVOID +Ayuf+gWpdUSaJOnTAH9B2QAA + + +return +pdkReturn +void +Ayuf+gWpdUSaJOnTAH9B2QAA + + + +GetMaxDatagramSize +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +LgVX+Em2+ke7LPUBORGrGwAA + +1 + +return +pdkReturn +DWORD +LgVX+Em2+ke7LPUBORGrGwAA + + + +GetDetectAttempts +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +gVv98hNni0y0K1VVeOPJMQAA + +1 + +return +pdkReturn +DWORD +gVv98hNni0y0K1VVeOPJMQAA + + + +GetDetectInterval +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +5xwkob5Bm0Woy6v+QzPSdwAA + +1 + +return +pdkReturn +DWORD +5xwkob5Bm0Woy6v+QzPSdwAA + + + +GetFreeBufferPoolSize +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +ICHiH/G9QEK2h9jwvl5FAgAA + +1 + +return +pdkReturn +DWORD +ICHiH/G9QEK2h9jwvl5FAgAA + + + +GetFreeBufferPoolHold +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +iRtcG/ORF0203GIJo3qzFAAA + +1 + +return +pdkReturn +DWORD +iRtcG/ORF0203GIJo3qzFAAA + + + +GetExtra +ecegk3x5sEKpNtWGALy6NAAA +1 + +Cpp +CppVirtual +CppVirtual +True +sfmmbu0NQ0K1WLLSswVHHgAA + +1 + +return +pdkReturn +PVOID +sfmmbu0NQ0K1WLLSswVHHgAA + + + +CUdpClient +UMLStandard +create +vkPrivate +ecegk3x5sEKpNtWGALy6NAAA +1 + +psoListener +TcyApNTnqk+DJWA+cSg5CgAA +/JHLRlaovkibrttO8nZPPgAA +1 + +Cpp +CppPointer +CppPointer +* +fd40Q5EVIE+le0pAEDqLewAA + + + + +CUdpClient +UMLStandard +destroy +vkPrivate +ecegk3x5sEKpNtWGALy6NAAA + + + +CUdpServer +jvfBmo6uGkC61ckI99TMgAAA +4 +bwCisxwrCEKKPJ3Eu3K44AAA +jhA06x9mmES8g/q2bBvKqwAA +EGyeYAZNvEmOFCpPS+ohJAAA +P1GnNsXQ20GUwjGbj2RuQgAA +1 +j09xKlrPNkS8/NZ3JXD5MwAA +46 + +CUdpServer +UMLStandard +create +vkPrivate +W+YbXZBJDU6NfEjOApatvwAA +1 + +psoListener +D8ifRSgqUU+ta46XJbntLwAA +ZMn2cmFZr0+GuJk5rQoyDgAA +1 + +Cpp +CppPointer +CppPointer +* +xXvRk1+KjEC2XroCTRCe9AAA + + + + +CUdpServer +UMLStandard +destroy +vkPrivate +W+YbXZBJDU6NfEjOApatvwAA + + +Start +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +V5lIUnsABkK514V2fZzY6wAA + +3 + +pszBindAddress +LPCTSTR +V5lIUnsABkK514V2fZzY6wAA + + +usPort +USHORT +V5lIUnsABkK514V2fZzY6wAA + + +return +pdkReturn +BOOL +V5lIUnsABkK514V2fZzY6wAA + + + +Stop +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +Jlw2s/Uaz0m75V4w1X+2/AAA + +1 + +return +pdkReturn +BOOL +Jlw2s/Uaz0m75V4w1X+2/AAA + + + +Send +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +no2kqiZ/5UK5S/xSHP6g8gAA + +5 + +dwConnID +no2kqiZ/5UK5S/xSHP6g8gAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffer +BYTE +no2kqiZ/5UK5S/xSHP6g8gAA +2 + +Cpp +CppConst +CppConst +True +VvNuGbd5CUioUSkCNV41+gAA + + +Cpp +CppPointer +CppPointer +* +VvNuGbd5CUioUSkCNV41+gAA + + + +iLength +int +no2kqiZ/5UK5S/xSHP6g8gAA + + +iOffset +int +no2kqiZ/5UK5S/xSHP6g8gAA + + +return +pdkReturn +BOOL +no2kqiZ/5UK5S/xSHP6g8gAA + + + +SendPackets +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +Cpu3dWcxeU2vPC0nafcrEwAA + +4 + +dwConnID +Cpu3dWcxeU2vPC0nafcrEwAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffers +WSABUF +Cpu3dWcxeU2vPC0nafcrEwAA +1 + +Cpp +CppConst +CppConst +True +yJO4PkvqBk2ck5gYDFby4QAA + + + +iCount +int +Cpu3dWcxeU2vPC0nafcrEwAA + + +return +pdkReturn +BOOL +Cpu3dWcxeU2vPC0nafcrEwAA + + + +HasStarted +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +ywlSsmVVrU2IL5R80v0WAQAA + +1 + +return +pdkReturn +BOOL +ywlSsmVVrU2IL5R80v0WAQAA + + + +GetState +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +gbgFm9Cj5UiFIRMYaFGeEQAA + +1 + +return +pdkReturn +gbgFm9Cj5UiFIRMYaFGeEQAA +3KsfqnlMb0ieGw/IAO5hFQAA + + + +Disconnect +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +hXPxs+F7aUSecehrerb89gAA + +3 + +dwConnID +hXPxs+F7aUSecehrerb89gAA +G8TfQngB3UemVJWZg5KbggAA + + +bForce +BOOL +hXPxs+F7aUSecehrerb89gAA + + +return +pdkReturn +BOOL +hXPxs+F7aUSecehrerb89gAA + + + +DisconnectLongConnections +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +7+AHi+CNBECiCONGWUOnGwAA + +3 + +dwPeriod +DWORD +7+AHi+CNBECiCONGWUOnGwAA + + +bForce +BOOL +7+AHi+CNBECiCONGWUOnGwAA + + +return +pdkReturn +BOOL +7+AHi+CNBECiCONGWUOnGwAA + + + +DisconnectSilenceConnections +W+YbXZBJDU6NfEjOApatvwAA +3 + +pdkReturn +BOOL +DwP9i6+skUaeeCQElWHsqQAA + + +dwPeriod +DWORD +DwP9i6+skUaeeCQElWHsqQAA + + +bForce +BOOL +DwP9i6+skUaeeCQElWHsqQAA + + + +GetListenAddress +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +LMId/VDCCEu9lyaMMPntpQAA + +4 + +lpszAddress +TCHAR +LMId/VDCCEu9lyaMMPntpQAA + + +iAddressLen +int +LMId/VDCCEu9lyaMMPntpQAA +1 + +Cpp +CppPointer +CppPointer +& +yUvgRjyykEaGnEaRFfQWkQAA + + + +usPort +USHORT +LMId/VDCCEu9lyaMMPntpQAA +1 + +Cpp +CppPointer +CppPointer +& +Nf/iQXbgUEWmxssUuQCDJQAA + + + +return +pdkReturn +BOOL +LMId/VDCCEu9lyaMMPntpQAA + + + +GetRemoteAddress +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +NuH1XXveUkm11bYVHQ7k9AAA + +5 + +dwConnID +NuH1XXveUkm11bYVHQ7k9AAA +G8TfQngB3UemVJWZg5KbggAA + + +lpszAddress +TCHAR +NuH1XXveUkm11bYVHQ7k9AAA + + +iAddressLen +int +NuH1XXveUkm11bYVHQ7k9AAA +1 + +Cpp +CppPointer +CppPointer +& +f9MWFcvolUCvwVErXEVSbwAA + + + +usPort +USHORT +NuH1XXveUkm11bYVHQ7k9AAA +1 + +Cpp +CppPointer +CppPointer +& +VzTHfpQacEWEHJ0SNjm7rAAA + + + +return +pdkReturn +BOOL +NuH1XXveUkm11bYVHQ7k9AAA + + + +GetPendingDataLength +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +yGn1U0J5OE2ackx8nLy47wAA + +3 + +dwConnID +yGn1U0J5OE2ackx8nLy47wAA +G8TfQngB3UemVJWZg5KbggAA + + +iPending +int +yGn1U0J5OE2ackx8nLy47wAA +1 + +Cpp +CppPointer +CppPointer +& +C3P0R3s+Bkq3xVXzc906ZAAA + + + +return +pdkReturn +BOOL +yGn1U0J5OE2ackx8nLy47wAA + + + +GetConnectionCount +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +jeArLgFBQkuAsARHVPbldAAA + +1 + +return +pdkReturn +DWORD +jeArLgFBQkuAsARHVPbldAAA + + + +GetAllConnectionIDs +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +QyTkJ1y0gkq6sdItFzUaHwAA + +3 + +pIDs +QyTkJ1y0gkq6sdItFzUaHwAA +G8TfQngB3UemVJWZg5KbggAA + + +dwCount +DWORD +QyTkJ1y0gkq6sdItFzUaHwAA +1 + +Cpp +CppPointer +CppPointer +& +h6aKqov8NE61OoApVgEBAgAA + + + +return +pdkReturn +BOOL +QyTkJ1y0gkq6sdItFzUaHwAA + + + +GetConnectPeriod +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +mQaNW2ycnEiO4gkpuBNjDAAA + +3 + +dwConnID +mQaNW2ycnEiO4gkpuBNjDAAA +G8TfQngB3UemVJWZg5KbggAA + + +dwPeriod +DWORD +mQaNW2ycnEiO4gkpuBNjDAAA +1 + +Cpp +CppPointer +CppPointer +& +h9Vlf9SWaEShtJRegwFK2gAA + + + +return +pdkReturn +BOOL +mQaNW2ycnEiO4gkpuBNjDAAA + + + +GetSilencePeriod +W+YbXZBJDU6NfEjOApatvwAA +3 + +pdkReturn +BOOL +kl+dFCyY9UaQpvgwLftQCQAA + + +dwConnID +kl+dFCyY9UaQpvgwLftQCQAA +G8TfQngB3UemVJWZg5KbggAA + + +dwPeriod +DWORD +kl+dFCyY9UaQpvgwLftQCQAA + + + +GetLastError +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +TNfshbZlfU+l5iFZEGxweAAA + +1 + +return +pdkReturn +TNfshbZlfU+l5iFZEGxweAAA +R9EXi7T78E6Gt882nRMyDwAA + + + +GetLastErrorDesc +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +2M1YnjnH60CSUcL8NjF8UgAA + +1 + +return +pdkReturn +LPCTSTR +2M1YnjnH60CSUcL8NjF8UgAA + + + +SetConnectionExtra +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +lZOxp482bUCE/wkelwniEgAA + +3 + +dwConnID +lZOxp482bUCE/wkelwniEgAA +G8TfQngB3UemVJWZg5KbggAA + + +pExtra +PVOID +lZOxp482bUCE/wkelwniEgAA + + +return +pdkReturn +BOOL +lZOxp482bUCE/wkelwniEgAA + + + +GetConnectionExtra +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +nmWJZNhXmE2NcOSdXZQulAAA + +3 + +dwConnID +nmWJZNhXmE2NcOSdXZQulAAA +G8TfQngB3UemVJWZg5KbggAA + + +ppExtra +PVOID +nmWJZNhXmE2NcOSdXZQulAAA +1 + +Cpp +CppPointer +CppPointer +* +3hbHnmGUoE2wHMGzb90XuwAA + + + +return +pdkReturn +BOOL +nmWJZNhXmE2NcOSdXZQulAAA + + + +SetSendPolicy +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +oG/E4zVa70uUS7VtaPwp2wAA + +2 + +enSendPolicy +oG/E4zVa70uUS7VtaPwp2wAA +p4RvBvwp3kOxyo/4mj2ZKwAA + + +return +pdkReturn +void +oG/E4zVa70uUS7VtaPwp2wAA + + + +SetMarkSilence +W+YbXZBJDU6NfEjOApatvwAA +2 + +pdkReturn +void +W0LICNwwH0CBJaD776pyBwAA + + +bMarkSilence +BOOL +W0LICNwwH0CBJaD776pyBwAA + + + +IsMarkSilence +W+YbXZBJDU6NfEjOApatvwAA +1 + +pdkReturn +BOOL ++GtCyW44AkyhhlJBsZqNBgAA + + + +SetWorkerThreadCount +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +356sgNben0adz63c+AptuwAA + +2 + +dwWorkerThreadCount +DWORD +356sgNben0adz63c+AptuwAA + + +return +pdkReturn +void +356sgNben0adz63c+AptuwAA + + + +SetFreeSocketObjLockTime +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +QOJXMk1ZiUqOko/3phm99gAA + +2 + +dwFreeSocketObjLockTime +DWORD +QOJXMk1ZiUqOko/3phm99gAA + + +return +pdkReturn +void +QOJXMk1ZiUqOko/3phm99gAA + + + +SetFreeSocketObjPool +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +zTnCCuODdkqUMJjRKKx4AgAA + +2 + +dwFreeSocketObjPool +DWORD +zTnCCuODdkqUMJjRKKx4AgAA + + +return +pdkReturn +void +zTnCCuODdkqUMJjRKKx4AgAA + + + +SetFreeBufferObjPool +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +pPH+7+5rUUKFKEzMEEgKAAAA + +2 + +dwFreeBufferObjPool +DWORD +pPH+7+5rUUKFKEzMEEgKAAAA + + +return +pdkReturn +void +pPH+7+5rUUKFKEzMEEgKAAAA + + + +SetFreeSocketObjHold +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +Zu2/V9cN1kG7hpd0G5at9AAA + +2 + +dwFreeSocketObjHold +DWORD +Zu2/V9cN1kG7hpd0G5at9AAA + + +return +pdkReturn +void +Zu2/V9cN1kG7hpd0G5at9AAA + + + +SetFreeBufferObjHold +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +5pFEaYktg0yhGdty6wQYygAA + +2 + +dwFreeBufferObjHold +DWORD +5pFEaYktg0yhGdty6wQYygAA + + +return +pdkReturn +void +5pFEaYktg0yhGdty6wQYygAA + + + +SetMaxDatagramSize +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +mqEkH1ShrEefLMvsOtm94QAA + +2 + +dwMaxDatagramSize +DWORD +mqEkH1ShrEefLMvsOtm94QAA + + +return +pdkReturn +void +mqEkH1ShrEefLMvsOtm94QAA + + + +SetPostReceiveCount +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +gEY7IkqHq0qt9XjFLp0w+wAA + +2 + +dwPostReceiveCount +DWORD +gEY7IkqHq0qt9XjFLp0w+wAA + + +return +pdkReturn +void +gEY7IkqHq0qt9XjFLp0w+wAA + + + +SetDetectAttempts +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +H/n8La7u6UCaEKXZPoOGLgAA + +2 + +dwDetectAttempts +DWORD +H/n8La7u6UCaEKXZPoOGLgAA + + +return +pdkReturn +void +H/n8La7u6UCaEKXZPoOGLgAA + + + +SetDetectInterval +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +ZP/6aUbFXEKzLuDralQl/QAA + +2 + +dwDetectInterval +DWORD +ZP/6aUbFXEKzLuDralQl/QAA + + +return +pdkReturn +void +ZP/6aUbFXEKzLuDralQl/QAA + + + +GetSendPolicy +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +hEMV7R4Qqk+ZXAonll6vFgAA + +1 + +return +pdkReturn +hEMV7R4Qqk+ZXAonll6vFgAA +p4RvBvwp3kOxyo/4mj2ZKwAA + + + +GetWorkerThreadCount +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +bZjMCld+OE+W8oMnZr7f4gAA + +1 + +return +pdkReturn +DWORD +bZjMCld+OE+W8oMnZr7f4gAA + + + +GetFreeSocketObjLockTime +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +tofVgud1R0GX2wIXppIKbQAA + +1 + +return +pdkReturn +DWORD +tofVgud1R0GX2wIXppIKbQAA + + + +GetFreeSocketObjPool +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +Kr/kejswmUSd298tenPZ3AAA + +1 + +return +pdkReturn +DWORD +Kr/kejswmUSd298tenPZ3AAA + + + +GetFreeBufferObjPool +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +r00rl2MKRE27YyH9h2svGAAA + +1 + +return +pdkReturn +DWORD +r00rl2MKRE27YyH9h2svGAAA + + + +GetFreeSocketObjHold +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +yDm/D0kDzkOIIK7eot1XVAAA + +1 + +return +pdkReturn +DWORD +yDm/D0kDzkOIIK7eot1XVAAA + + + +GetFreeBufferObjHold +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +zXfIjMYGVEmJxJsJbFMbxwAA + +1 + +return +pdkReturn +DWORD +zXfIjMYGVEmJxJsJbFMbxwAA + + + +GetMaxDatagramSize +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +xC8b1oS77UKHEne0jj7SzgAA + +1 + +return +pdkReturn +DWORD +xC8b1oS77UKHEne0jj7SzgAA + + + +GetPostReceiveCount +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +LjE+Lnma802EZWcL1FKEfwAA + +1 + +return +pdkReturn +DWORD +LjE+Lnma802EZWcL1FKEfwAA + + + +GetDetectAttempts +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +85mjXmu76kqaH/d89f0pfQAA + +1 + +return +pdkReturn +DWORD +85mjXmu76kqaH/d89f0pfQAA + + + +GetDetectInterval +W+YbXZBJDU6NfEjOApatvwAA +1 + +Cpp +CppVirtual +CppVirtual +True +priYIVlXUkqJpWdiYmTOkwAA + +1 + +return +pdkReturn +DWORD +priYIVlXUkqJpWdiYmTOkwAA + + + + +CONNID +Cpp +CppTypedef +jvfBmo6uGkC61ckI99TMgAAA +4 +MXVhp44nXE2Zyz2ZTeA7nAAA +UI1zHaOwb0i+koDgk989YwAA +mDpURrCz2UOaqNUVJLzTnQAA +Pec6MHGcIkeNEzaV2GiamQAA +1 + +Cpp +CppTypedef +CppTypedefDefinition +ULONG_PTR +G8TfQngB3UemVJWZg5KbggAA + +82 +Wdlbg4usN0qTDZTKnnzz/gAA +N2w5ow4KHk6m6v6crMwscwAA +C70oqA4dmUqydxL0MdYgIgAA +nSGxKnb2ik6mNllfkYJPRQAA +x9futDv2W0OYznm1lLACSwAA +qaX3MwH6qE+JLuXfT0PiSQAA +Zbj9PXnwa0CpyjR03Yo/1wAA +UdJbPNeyFUKgOIdtDRLfGwAA +zb3/+mQ3pkmVjnvOtdbXKQAA +PPJf1snCfkyrzPZxG8v5PAAA +QZoNzAXj8km7ncXj2+IFmgAA +kq7MNRJ8eUezjVOCApp/rAAA +xxVYAN+F3kmPAxyVbyDdrwAA +CTeC9mW7xky4U+BQo15oTQAA +r3xIx2J58EG3f2KedMHEqgAA +lFJkBt0bcUCs2GYIDQUIewAA +e2p/JMNuUUOUgmYKRCWUFAAA +NWMl+/HtFUiomW1KQlxfwQAA +GGyja/ZOXkqUbOk+5lhSYQAA +6y/ffQxOREesN08Iq4JkpgAA +qflysDF530ejLVS4JfugVAAA +Yum1OlPEt0S5Ak/0O2tPoAAA +PNCACarP0kqSZchxngLXXAAA +l9d06eLmGUmt8ehgftXXJQAA +fZgfPfmZ0kWFHkLtpuzOlwAA +WSJXyzwZ9EKHdnIClaS4pAAA +RAUm9vbotECXqoARKDRt4gAA +qzSAepQJjUOv5stmf5aBDwAA +TA+9YdIfyEyO22ILr7x7mQAA +a+NNlT35IkW3hP2u6nHO8wAA +oEqCBUc6r0mr7bBPzsO2DgAA +K6RisZHnIEiG9VZ3ElSTNgAA +06q418O6FEOlWfOa7XazAwAA +w2ya+IwCtUOJDbBbD+WZAgAA +6CPh/dT0NkGnyhSYKUxe4gAA +2iuz603QB0a9uPY25LQy0QAA +AAf1rZcXTkeS7fEaJKHDZgAA +51I86s1DOke3qJOgWgqVLAAA +vODfXnG5ZkmzGrpqYNUG2wAA +SncxM0JmCESwiLc8dat8cQAA +qjklpLt7nEqyg18zWQpOfAAA +hhvGUgN+XkKeKht7VmDa8AAA +PR8/vDBp6Ei24n21q0Qe/QAA +1DW1M42OnEekQHHaaHqO9wAA +eF4RBAlr6UCkWfm6uQwUaAAA +oSdysn7H9ESnkTF1DAYJbwAA +UAh7pE0ELEesQ5ThcfXGywAA +42B/4OU3EEWId/DxPeloAgAA +Emuk13E5wEiY2U4qcIPozQAA +g1nJZ0b+Tkirr6fhVP4jsQAA +7BJAhk7VMkewT16Uyq0p2QAA +VuPbvrJAOk2PrHp33sZFIQAA +Zl5BhI61+06rfnfjl62+HgAA +rBvKrEwkqkybw98VhI4gTwAA +3ewJV7UAe0GumcKUwiNSQQAA +TAerpmyu/Ei1ACCr9D3WDAAA +fm2p2iDQaEicTX/UpTmEKAAA +d9AlDlD2D0ahlv0rJcYC+wAA +ihOfWbq61U+IXRxh+s6ZewAA +7+b/W0LXPkW7BwT8KKHcDAAA +NB+z9SNhHkGKDmbeKq+uvgAA +WHQx0D9xk0C97xe/Ep8JFgAA +ZfFoJEf+O0GTU75AhYOrtQAA +4qi9+jECo06Hhot1sslYpQAA +sNBCscxV9027vg5CbNb91gAA +vHNohVZUb0ywlTxUUYZ7VAAA +B+wTGesur0SSGdNpbmTmdwAA +iW8eFBuhZkG1Dm2tbSpy5gAA +CO4GrmQdakOtDHKXAaCcDQAA +u57IlKOdzkW8rhlQuTBzWwAA +8cekXGl0GEucId2K41Cl9wAA +aDE1RwH36kafHTUy2XXdGQAA +b33D5qBDNkuWJmD5QTOjcQAA +ftD8uqizQ0W63U4pFgx7mwAA +9JsRHyLb8ki45KaRqc5w/gAA +XfUlO3vayEq5xoqsZ3WP1QAA +riSvTRwZqEyCBlrsKEXjFAAA +3QxM4aKQt0KpjtVQ+rsoFAAA +K768ob1efE6KQdpEn/n1hQAA +qGuTiizUo066hg7l4e7HUwAA +geQtoLdOK0eqVli4raUElAAA +9swYyf06XECXOjgGYBx0UQAA + + +jvfBmo6uGkC61ckI99TMgAAA +SX/KZkmsDk+r8uamHH4ZLgAA +9FsvxqZjkEyUqc9w2NDcQgAA +8 +ou+qiPZb2EWcpS5YuaAwNgAA +c38pT9MjCEWSk2UJzMhDaAAA +KZMw+i1FXkGzXXh8F7CFaAAA +JBLfVaW/40qfMN47OJAUFQAA +XBwdnbOUeUGy7Kw2Hi7UwgAA +IMSt3e4yckqn1oIeq3HFYAAA +c+RDHN9iU0CUxRQpNBd9lQAA +Ggx66EfEAkKlk2yZzolJPAAA + + +jvfBmo6uGkC61ckI99TMgAAA +h8NmVuBtVUWgcCSKCdxePgAA +SX/KZkmsDk+r8uamHH4ZLgAA +8 +goQrd740yESQtkn3nn8pxQAA +IETzQSFXh069+tMk+8NG8gAA +djwqZk3PdUuU9P4Ud7cKBQAA +Euz2bhKUV06cot782+K5vwAA +EfIZpecC8kCNpGkl/RSoIQAA +Mr8LifDa0UqZKMVYf8ErAQAA +goz0IiZTkUWgDLmFUZjdGQAA +l2mwYAdq2Uud3WNUAAgSYAAA + + +jvfBmo6uGkC61ckI99TMgAAA +nhHxAccKxEm2g0sPkFAnhwAA +h8NmVuBtVUWgcCSKCdxePgAA +4 +j7Q4Ps/iSkW6kizmnaitXgAA +PTKwj4q/I0ShpL3RnSgfCQAA +nAMenYQw5Uy+UEnB2RnwvQAA +ZQSqfFtmkE2jj946BhCgDwAA + + +jvfBmo6uGkC61ckI99TMgAAA +9yFTOYs1vEa8s69V7MjeDgAA +nhHxAccKxEm2g0sPkFAnhwAA +4 +1rNVwRf2vEGRGeC8SwdAEAAA +y/L9qKYTQ0+eWsJBoL1IgAAA +J4eXaoWhukmIYuj6knwcEwAA +sjkuz/YHykCKpS5qitI6FAAA + + +jvfBmo6uGkC61ckI99TMgAAA +ZMn2cmFZr0+GuJk5rQoyDgAA +SX/KZkmsDk+r8uamHH4ZLgAA +8 +GncN+LFplkq1zurpPaUdwgAA +9xRLTrq9IUq8AdFDvi3GuQAA +5s6HsRi2b0uwIS4LMz3DuAAA +8uZw0YHNEUmkPJCFkz8T3gAA +67vn5p+OzkersHhkDjZ4igAA +ZLFPuXcouUuSrdi0UDRJmgAA +FvElIA2yUkei3MLMoa8k2gAA +Dthe7dQ5RkyqhrSPP9XnKgAA + + +jvfBmo6uGkC61ckI99TMgAAA +Z797Ei2tSUi6O/GTUGUZfgAA +ZMn2cmFZr0+GuJk5rQoyDgAA +4 +deLw1RNzjEqsvILJ+ibF7AAA +51pyWaL0CU2frOZ5zjyI2wAA +E2rBvdl9VUWj4VqXDkaZ5gAA +sLWQNpiHvk+TWraPIbIZeAAA + + +jvfBmo6uGkC61ckI99TMgAAA +lJ5FZia7y0evV31w/xLmsAAA +9FsvxqZjkEyUqc9w2NDcQgAA +8 +zea0bPu5nk+a1o5fWOzJHwAA +xJfsE4G5lEqANAnN8ENc4QAA +4EsSVk2+2kWONvweIAFt2AAA +3bXJm+ojzEW1itRkv6lbdAAA +kiw5jSvMHEypQrYjs7EtggAA +l29NGFssr0Oph9Nmvqs75wAA +ls8Fv1dy8k2Wl7LVjx5LLQAA +NozOK6S620+qcY7JiLt/hwAA + + +jvfBmo6uGkC61ckI99TMgAAA +skl0Nm/UIUCTsqkUAIXmzAAA +lJ5FZia7y0evV31w/xLmsAAA +8 +1N+R/u7G/0uGQCTvcKagCAAA +ytrOyZ41mE2QIBwJkvlH4QAA +o7Ot+jP6IEOS76Hr++G0uAAA +bMlgO115dUWbM89joy/4GgAA +Xczg4RYGK0epoiVJPcNKBQAA +FCKhBb0jnEyEn7YexR+RlAAA +7dGi6Cz5PEOPdS8qzAGxlQAA +cQ9Yhd24Wkq4SQQtMvuB4wAA + + +jvfBmo6uGkC61ckI99TMgAAA +HjFZEYW1wEOsKFuTmPnHegAA +skl0Nm/UIUCTsqkUAIXmzAAA +4 +3NlbjHNH2ECymHRy7yzyAQAA +/BekJ/FXvkujXFx+QlPowgAA +26/YsJ6Oq0SNjxxOUi0nRQAA +k46DaLygdkSf/20Yk3JBEQAA + + +jvfBmo6uGkC61ckI99TMgAAA +hNuH1fWUHU2IT4Poty2GiwAA +HjFZEYW1wEOsKFuTmPnHegAA +4 +lWI1Zq3eQEGenqREuNOFyAAA +dRYz7D5qgUqwJ+Pe9lQWNAAA +F99tUBHNsk69EMaYgEUuoQAA +ODUhv71Ts02GVPo+m3t0fwAA + + +jvfBmo6uGkC61ckI99TMgAAA +HwLi+AyuiUa754Eutz2k5AAA +BZTI/4OA7kG+nFfsclldCgAA +8 +dgyqUNu8ck2rwaT63rOxsgAA +VS7xhkemyk6N0W+72/94AQAA +5QCQMYRtlkWhaCRpq1cVAAAA +f7kRl0rvM0WkGcfE154lGgAA +OJLWmo8NskCKPdf/f829bQAA +2fA+Ni3QEk6wzHzG0Vi23QAA +Ac129XF/7EmTSnACzkicGgAA +luSPlO7yuUmYjRD341y7TAAA + + +jvfBmo6uGkC61ckI99TMgAAA +c38EVYXmckWErbW5Cl4UwgAA +HwLi+AyuiUa754Eutz2k5AAA +4 +SS7IMtrGi0W+o/mmD4DTcQAA +dsN+JqqRnkaGxifilWIP2gAA +ygVe6QYMrU2KjM1DmzPOQwAA +MW1jdyNVj0aZonbOWJcidwAA + + +jvfBmo6uGkC61ckI99TMgAAA +4OTsa4LGqUqntun16mJ7kAAA +c38EVYXmckWErbW5Cl4UwgAA +4 +5NgNJQ+GMkWxtYcACgmvwQAA +dW8YoS7Kh0KQK694gSP8ZAAA +Zutt4UEcsEW5VhGobwz7PwAA ++YIQHLXA8k+gVyiGz0VsbgAA + + +jvfBmo6uGkC61ckI99TMgAAA +/JHLRlaovkibrttO8nZPPgAA +BZTI/4OA7kG+nFfsclldCgAA +8 +ZtlRtj7fpU+vne+4TxLP2QAA +sOHJjy6mOkG+iujo2jmtBQAA +vTkmP4tXqkqCFRzsSrA7OgAA +fqXurAuhJ0CxFMNN3Ha/kgAA +JMbhoZv7zE6YPY6DRZa03AAA +HdxilnEczUaxyL6EjpKuOQAA ++z9EeDfekEWSwMZ0by6AFwAA +PR3hmDUfqUWMblF+CaEsfAAA + + +jvfBmo6uGkC61ckI99TMgAAA +eLrcJo0DgE2AjvOF61yczQAA +/JHLRlaovkibrttO8nZPPgAA +4 +vkjSSO/iqUCY1V/2BXexKQAA +NNUZ4iWSlEKetkMV+pJNLgAA +L+t5c4ysTE6Xwu5bJDDp8QAA +XTqd6vcw6U2CEpwy+qj/YAAA + + +jvfBmo6uGkC61ckI99TMgAAA +r22NFz2+L0aq+kmESgCiYAAA +BZTI/4OA7kG+nFfsclldCgAA +8 +JWavOb3aY0mzbGXClEGqKwAA +eJkCVv9peUC9C1Xl7Qt9gQAA +ukUvh3oLakuhl003p4qpLwAA +NIYeLqF8kEOJtGwEcSq4RQAA +twCGjPyb2Ual3NJyUUi6KwAA +CHma4YTb2kyFs40oB7lTnQAA +g/nhzJ5tR0mfsnm8l+H+cAAA +xCI/ux18cUq3onQpVpKalAAA + + +jvfBmo6uGkC61ckI99TMgAAA +sJBjmKjtoEWtenBeaDLnjwAA +r22NFz2+L0aq+kmESgCiYAAA +4 +I2oTjriYG0akeelXSVfgOAAA +GHrtEAGTaEKJ02Riv2MnlwAA +ncDt+ezXM0ed89//p7QEIQAA +0Ae8agrF+E6XD53DOOKriwAA + + +jvfBmo6uGkC61ckI99TMgAAA +GoHMKPRtzES/2hlDzLtwnAAA +SqNjwMrIrEaWmScJhNPQOwAA +8 +qCBk3LUtOkKsa7q+Smy33QAA +O0ZvATMt8kKFhwKR94hgkgAA +RchnMhJQIEuIy4hStD7cMwAA +QiumQ4FlokCBbnqaRnP1PAAA +c9sExiBPSkmQeGMpookzmAAA +r4pRczKZDEqLTIa+Uv4hAwAA +Gek4/rBbQE2AhN4C2QtmHwAA +eP5PI5++WkmO2ocAZKQzaAAA + + +jvfBmo6uGkC61ckI99TMgAAA +YNdJIJRIm0SpW7CG17MtyAAA +GoHMKPRtzES/2hlDzLtwnAAA +8 +c//7pRRoQUSF81xKijSycAAA +CFnUSa0l80u7I/SUX5OqdgAA +smgqRMylXkWhpl/T9wDY9QAA +f+3U3XscTEyGDU1iTZkk3QAA +GzIRPV6QhUOs4qO7ybP5uwAA +b5Wt2k7dUUexN/g2NhNs4gAA +ChdyhRn2/U2HgOGMZ8fqNAAA +ncBurfWb10GtjNMKoxl0pwAA + + +jvfBmo6uGkC61ckI99TMgAAA +KqnhKB+uXkKxW6LqS8YzcgAA +GoHMKPRtzES/2hlDzLtwnAAA +8 +DYIGs3eF+UCxvimOqtHM+AAA +3PuxzUJqTkadJllKss6M+QAA +Ivcs17PRN0qmdMfoqmg++AAA +JqsfWjUbl0uyq3vL4pbvHQAA +zDENN75Zf0iG7KHHxpwdwAAA +AKmb+VMUfEyhnDy9QH0ltAAA +kCkw7XtCXU2PVP7mtmKBDgAA +eZvnTWEFJ0uUea9wio47qwAA + + +jvfBmo6uGkC61ckI99TMgAAA +tc20+9LmREuR1dUMSybNdQAA +SqNjwMrIrEaWmScJhNPQOwAA +8 +1Ot9CLFgT0aqcmufZU92nAAA +XiZYrR3hok2IOo9BZDKbywAA +A0/dF17oZUu3dTS5MAEQ0gAA +aAiLn8LnWUGPzt+AjAIm8gAA +4MVBssIp/ESMM6YFA1eFnQAA +lMZFWNt/sUySKYoX/1yCiAAA +HB5blXh1f0+48L/0izbNgQAA +xWTGWw3VuEiWVa4XjrHjOgAA + + +jvfBmo6uGkC61ckI99TMgAAA +ilTzVOgexUSPHrK2FSqS9wAA +tc20+9LmREuR1dUMSybNdQAA +8 +1JZtgwF9xk+gPmUzc0oJJgAA +bxIE6AfC6UytbeH5sTR2BwAA +GpWLPlBxa0GCqFyvuLdyAQAA +1j/84UXBVEOJhvz5d9FWSQAA +FdpNOlB6l02sPzaVkt78vAAA +0jqMhhUux0K75yTuQLfOxwAA +XK3zHlENckeFjMLJfXgSvgAA +9G4AEIlw6UWApHibm5CB2AAA + + +jvfBmo6uGkC61ckI99TMgAAA +CqUqbTfjd0mBGFOXrmWVDgAA +R8hLgFt1fEaSSxBO7KbEBQAA +8 +/6R5uO+otkKh3lilaF1WNAAA +K36PpLG600i+0ImA6b9RhQAA +AbJz3RGlmEWM2b6lAV3ABgAA +YhSObfexfE6PoPRtcd4r4gAA +DkHschnvwECm+DPfXBZNSAAA +reE0paYhq0SHUC5aEEQQ4gAA +yx1ldGEH8kq2wvEk/qzxxwAA +NwyCGPQGb0SGFf5dLiPM1AAA + + +jvfBmo6uGkC61ckI99TMgAAA +s/XSjWMZB0WwUzzarQOzNgAA +R8hLgFt1fEaSSxBO7KbEBQAA +8 +DnsxaGRhoUW9bJrBu99KZQAA +xosvW1bcbEqf17i1B7dmwgAA +kOhYrTLUn0Ws4OYSIL+MRQAA +7TgeFsDfnUKXZvflRDJQtQAA +oYFkVEhJqkKMEGaBuTnwAQAA +z4oGv765k0yXa5qfSekTkAAA +zT4g0D60GkOzyybPatDgOAAA +hO1LDiqrZEuFVbaR0TrvbAAA + + +jvfBmo6uGkC61ckI99TMgAAA +6HMIzI9avUGHDCpvqmkdqQAA +R8hLgFt1fEaSSxBO7KbEBQAA +8 +psIMlRQ2Dk2JbyUb+Gg0YAAA +IrmIW82wkU2E0ati90YYOwAA +XzAxQPjCPUC+SYqhvot0iwAA +Zq8hTAK2Ckmw6wm674lftQAA +CE0M/fXDXUiH1zsQOE+6fAAA +6lxfetSsrEOT7X3Evs0cWAAA +pUycG8VLzUK+8QNxofMMLAAA +dCFk/gs320GRdJ0pSBsZZQAA + + +jvfBmo6uGkC61ckI99TMgAAA +gJKazn/X+U6+FJp/F2soRAAA +BaqYQl/65Uy16GMJC7nLawAA +8 ++Yt/btzSikSosVg4o4SWKAAA +tyC1v93+2kua0TzR6a7hGgAA +mfkrDY0+QEK9Kn4Lb3xWqAAA +LFIHYizyaUajAunzCnbXJwAA +Od7nNH4/q0q+9miS+BQMQAAA +IQA3jbeMXEiqT07uVKIBwAAA +3/OF3Cm+t0i1PXp8eNNITgAA +SBPICWRItEi4WkedLHl4GwAA + + +jvfBmo6uGkC61ckI99TMgAAA +gJKazn/X+U6+FJp/F2soRAAA +YNdJIJRIm0SpW7CG17MtyAAA +8 +6S1n014H2ESngn7Aw3cgAAAA +63U/0aGAbEKcoRAQwmvDiwAA +X8x3KRlEEEy2kf6Su8vQ1gAA +cqC5G5Ie3kiuqGR05se5SgAA +lRW9X1ac10yI+fo42IJIvAAA +uvmeOGu3U0ObhRCH+N/cYgAA +bsaPOhHQ7UGDtaN/ica6gwAA +uL/mV/MeU025M9zMAgRD/AAA + + +jvfBmo6uGkC61ckI99TMgAAA +QvkeGvTpWU2SJ0MXVIx/AwAA +BaqYQl/65Uy16GMJC7nLawAA +8 +F+HzSvwj8ki7nHVW0VFcigAA +jCDdcZ6ZXU2EOsSYih6ExwAA +SmIb8/cjDkm2kX6k/b8ntAAA +DTiUSZIULUmTC4HtfeC3AAAA +t/MfWdUyF0OEhTxYbOiw7AAA +UTvgSLsazECdxl6VrGbavQAA +S6i3jl6a8E6QdB+rlPDufAAA +R8qbDPmknkOAp2O6LVl9XAAA + + +jvfBmo6uGkC61ckI99TMgAAA +QvkeGvTpWU2SJ0MXVIx/AwAA +ilTzVOgexUSPHrK2FSqS9wAA +8 +rcltMulnr0qF/qeBFloYFgAA +9hb9MkGFx0+r8kkgfseS5wAA ++Z0y+HpafUykWClO0g7bSwAA +LIPZyMH9Sk+S6LVONEva/wAA +TmGQgMctk0KObDDJHr3mHgAA +v1kqzxBAbk2IvVIzlqDO+wAA +fb9dVgo/gU+jTRGezpDpLwAA +p560ijiYxkCwEwQ0Iaef3gAA + + +jvfBmo6uGkC61ckI99TMgAAA +SjUoRiw3TUOE/FQirpeMogAA +LPfLjDLmzkKy/sn51dyX7gAA +8 +rhnnQCbHikuDeN+Oo4/FMAAA +qmNqzvGTwUu/uQ7vUhCAXwAA +fcsS2BO4EkChu1RbUUaFIQAA +Kl/PRgRaiEGYeX8Ioupo8wAA +KEO/1z0YY0SJHTZqg5v5hQAA +yYwdiA76RUGvs8LNcYb8ogAA +HW9HdRPS4E6zKir3r1LbIQAA +aw4alqX9OEe4wfd2ybEhPwAA + + +jvfBmo6uGkC61ckI99TMgAAA +SjUoRiw3TUOE/FQirpeMogAA +CqUqbTfjd0mBGFOXrmWVDgAA +8 +Qjq2UGfu1U6yEC9G7GFncAAA +EZ0R5BsS2EiNXWtJLkot/AAA +C8i3eIqe/0+28YXwhDr+fwAA +L1FrRLEd+ki2VTqIrxRm2QAA +7yaK+OouTkeaR94qcVEXVgAA +V5CgvrxyrUaDeI0bIP2/jQAA +T0/lonmG50uYTiZzyRagNwAA +URWno2ktQUGMKlEOxyq+NAAA + + +jvfBmo6uGkC61ckI99TMgAAA ++hvdtNLBPUeUmdoy9WnIywAA +ilTzVOgexUSPHrK2FSqS9wAA +4 +LXo50YVn5k6y4i7dLt9JNAAA +A6p9uYQnAUake5kt6fboOgAA +hwqG1MhHZEO6TnTm8tPYEgAA +BI4QKfy4LU+aD2bIBSLU1wAA + + +jvfBmo6uGkC61ckI99TMgAAA +rNsPUCIqcESb1NED1xr04AAA +CqUqbTfjd0mBGFOXrmWVDgAA +4 +Knkuk2do/0KUUmk1qKGJVQAA +PoNF9wqiakqi7H2sSQgFEQAA +1U+QYJuP1USrQmw6+eWPhwAA +UHcFiQyS2023I5whuRKy/gAA + + +jvfBmo6uGkC61ckI99TMgAAA +JJbEayVgmEyWvR4C1WYpsAAA +BaqYQl/65Uy16GMJC7nLawAA +4 +0rhL0gj7UkqmJd2x+BAiLgAA +yuRUENpwE0OiMB2tNJ40SQAA +blRMeSSVyk6S9Q6ktugY1AAA +c/UgcMa5IUK8gNCvhK1KcgAA + + +jvfBmo6uGkC61ckI99TMgAAA +JJbEayVgmEyWvR4C1WYpsAAA ++hvdtNLBPUeUmdoy9WnIywAA +4 +bhOoN0b4HEeSRvduzhJxPgAA +hRcyH0TnfE6fWW/bhbSFVwAA +klBeBRv3TEmxO7NFrPw7AgAA +WSuAYv/19EipFycyuvP0jwAA + + +jvfBmo6uGkC61ckI99TMgAAA +dUFVpJ56j0WxczyDxsGS+gAA +LPfLjDLmzkKy/sn51dyX7gAA +4 +JKJUz4S/4kW5nWG9k4dnrAAA ++XGMMutMLU+2sOdaGJtJKAAA +4LdLXxgofkeQljsnri1qCQAA +cjSGwgMlakG69dFL30/p3QAA + + +jvfBmo6uGkC61ckI99TMgAAA +dUFVpJ56j0WxczyDxsGS+gAA +rNsPUCIqcESb1NED1xr04AAA +4 +T52ERlC6LUShYtwcwiX3XQAA +GXUwktB+mUmMyGAe6v0nTQAA +3mYd4Qs0q0WuCqLLfsl7fgAA +K03uqu3VKki6nz/PcnPmSAAA + + +jvfBmo6uGkC61ckI99TMgAAA +5tmwPyb6D0Ki98vc8dVPhQAA +BaqYQl/65Uy16GMJC7nLawAA +4 +S76dtnBSdU2GyTzCpjqjGQAA +jE1fxhEqeEOyzCx9TigIMAAA +astHPBLQAke+cV3sm5HkgAAA +yVW2frPFcUukgF4+NIT/TwAA + + +jvfBmo6uGkC61ckI99TMgAAA +5tmwPyb6D0Ki98vc8dVPhQAA +gWn1z7ujyEu9Gf7LdRrPIAAA +4 +qtiyA4yHnEKefRjnWB5NMAAA +tMXXck5570yGI2PzqPcaXwAA +rBAKeYumSEe3qbFRoT9JzwAA +D4a01z/R0UK/G3Ua/sSzdwAA + + +jvfBmo6uGkC61ckI99TMgAAA +gWn1z7ujyEu9Gf7LdRrPIAAA +YNdJIJRIm0SpW7CG17MtyAAA +4 +Wna6ao9UaEa+LOqkRAVQJwAA +XCT77hd1uEece5kAr4VfDgAA +4slM817uV0WYVY5kD2kpBAAA +2oZ9iO7gTUiXx6WG4oqbDAAA + + +jvfBmo6uGkC61ckI99TMgAAA +ukpy8IZAy0KEameLGY9mtQAA +6HMIzI9avUGHDCpvqmkdqQAA +4 +TPDwJYaaYECgn2lLX27JzQAA +lrCmOoar4ES3Y9rZSa4YNAAA +cSXLhxOkDEOX1LQxY+CajAAA +xgbOSm+ioEGzQFghdEuD2QAA + + +jvfBmo6uGkC61ckI99TMgAAA +ecegk3x5sEKpNtWGALy6NAAA +s/XSjWMZB0WwUzzarQOzNgAA +4 +cvrjA1QmMEe6KhCf6X4QZQAA +Y1F4jb5ClEGG4w2MWXzjYAAA +Fz/CNTPOVEWGj5MDwoavUwAA +iXLoEqPOYEGdMbPt5lfkZAAA + + +jvfBmo6uGkC61ckI99TMgAAA +W+YbXZBJDU6NfEjOApatvwAA +KqnhKB+uXkKxW6LqS8YzcgAA +4 +mYiPI1jKUUy+l8TS2jnHkwAA +52eAKOALwkOwbrXOf4JhDQAA +bIpaty6YhEax7CSTvo6y1AAA +Th272KyIREaU+jNyB6ysEgAA + + +IPackSocket +jvfBmo6uGkC61ckI99TMgAAA +12 +2NPkGxsE60eclahgOjVMgAAA +qanVb+lWC0akcJOwRG/MEAAA +rhbpNUyjIEqMgrAdnnT36QAA +f3uwOOrYjUO915OhF6FxMAAA +XsluK/m59E+/IMf4Y9b0rAAA +1YlSBB09GkS+u5/rCTPOWwAA +o4LzBtp6JEySykeTk1zFmwAA +SIKdLcfuPUCDoOLG1N0MggAA +o4hWQrYZQkOmrY1zgQbErQAA +XZV5HfZFiU24ipOMLajLigAA +jOF0qC/hukiZjCcy1pQvBAAA +fyd9aLZb7UGu3D3TmXMGbQAA +5 +sgmcH4+s1Em05SzAjJdHjAAA +WUHNHDfka0O+CbvKWj/7kQAA +v+HDY4XmuEqbLAgnV9F1XgAA +x2cv/pfP+0KLEYoWHGBFVAAA +OH/WIarq+EioSJWJSZjh6AAA +5 + +SetMaxPackSize +True +Pv24uWWaqUu82r7VGD3ZNwAA +1 + +Cpp +CppVirtual +CppVirtual +True +yiu064LKGkqSPXKDvu6lEgAA + +2 + +dwMaxPackSize +DWORD +yiu064LKGkqSPXKDvu6lEgAA + + +return +pdkReturn +void +yiu064LKGkqSPXKDvu6lEgAA + + + +SetPackHeaderFlag +True +Pv24uWWaqUu82r7VGD3ZNwAA +1 + +Cpp +CppVirtual +CppVirtual +True +59gJg0Y41U6P1Uf/Ltq9bQAA + +2 + +usPackHeaderFlag +USHORT +59gJg0Y41U6P1Uf/Ltq9bQAA + + +return +pdkReturn +void +59gJg0Y41U6P1Uf/Ltq9bQAA + + + +GetMaxPackSize +True +Pv24uWWaqUu82r7VGD3ZNwAA +1 + +Cpp +CppVirtual +CppVirtual +True +KcPyYFPkLkGCbsT8q0c/swAA + +1 + +return +pdkReturn +DWORD +KcPyYFPkLkGCbsT8q0c/swAA + + + +GetPackHeaderFlag +True +Pv24uWWaqUu82r7VGD3ZNwAA +1 + +Cpp +CppVirtual +CppVirtual +True +uE1F67PHLEqLMpua/PX1bAAA + +1 + +return +pdkReturn +USHORT +uE1F67PHLEqLMpua/PX1bAAA + + + +IPackSocket +UMLStandard +destroy +vkPrivate +Pv24uWWaqUu82r7VGD3ZNwAA + +4 ++gwOOVHEKEC3d7c6ZslFKwAA +DQXPCFFri06p9vDhntrwswAA +INOu6si0U0esJ5QdnvqevgAA +Irvwq5MHbk6LOaC8nQbvzwAA + + +IPackClient +jvfBmo6uGkC61ckI99TMgAAA +8 +iW4CiDDhyEqlkb7itLSOuQAA +sqc0il9xH06nWVATGkOfuwAA +k96N8NyU60ixtqHKWEn2lAAA +8tLZHMkQgEyCa8TXoiRKRgAA +Yb89wcpcAk2cxvunkv6qmgAA +hzS+9JC6U0yyfs4CvvEskAAA +kuiez2+Yw02w897Ni7ln2wAA +s4uJ3w4uWkyKW07Th4vicAAA +2 +xly9lJtUukKwQ90VKrZR2AAA +N9PjlD8Kvk26PvXMITpM2QAA +5 + +SetMaxPackSize +True +tvyRlzR70kaEb8akK1WldwAA +1 + +Cpp +CppVirtual +CppVirtual +True +Sb2xIPoMfEmcprjhWPgyVAAA + +2 + +dwMaxPackSize +DWORD +Sb2xIPoMfEmcprjhWPgyVAAA + + +return +pdkReturn +void +Sb2xIPoMfEmcprjhWPgyVAAA + + + +SetPackHeaderFlag +True +tvyRlzR70kaEb8akK1WldwAA +1 + +Cpp +CppVirtual +CppVirtual +True +6Ya/wy/SAUiJHDk0g2jh7wAA + +2 + +usPackHeaderFlag +USHORT +6Ya/wy/SAUiJHDk0g2jh7wAA + + +return +pdkReturn +void +6Ya/wy/SAUiJHDk0g2jh7wAA + + + +GetMaxPackSize +True +tvyRlzR70kaEb8akK1WldwAA +1 + +Cpp +CppVirtual +CppVirtual +True +EkYZLhEAQkehsqPDZtU75wAA + +1 + +return +pdkReturn +DWORD +EkYZLhEAQkehsqPDZtU75wAA + + + +GetPackHeaderFlag +True +tvyRlzR70kaEb8akK1WldwAA +1 + +Cpp +CppVirtual +CppVirtual +True +/07gxRNokUOhodCzx8vihQAA + +1 + +return +pdkReturn +USHORT +/07gxRNokUOhodCzx8vihQAA + + + +IPackClient +UMLStandard +destroy +vkPrivate +tvyRlzR70kaEb8akK1WldwAA + +2 +gHDDhlJar0yV7nt2BkZnTAAA +wcXN0QyVyk+g/gkYprOV9QAA + + +ITcpPackServer +jvfBmo6uGkC61ckI99TMgAAA +8 +IxgSYDxQe0qqAConM0HORwAA +2i8a4QqJTEiBathYXQhMuwAA +bsyVrql6IkmBGTeyRmT8yAAA +vMfK2EQ7rEaMMnrRkYGyKgAA +kTpvQ8TEEkmzpYp6oZMMXwAA +GjXqyOPMfEKk3s3mFwVt+gAA +EFKVUaX3xkKVvPgpTBIuZgAA +CyiWvj/TBkOjsAeg0czdzwAA +2 +sgmcH4+s1Em05SzAjJdHjAAA +nzQ/3s2PQEG5Cz2AX+hkOgAA +2 + +ToPack +skClassifier +aDgNVKZkT029alZKzju1xAAA +1 + +Cpp +CppMemberFunction +CppInline +True +vf4CNLDVkk6wd9f0alsTGgAA + +2 + +pServer +vf4CNLDVkk6wd9f0alsTGgAA +GoHMKPRtzES/2hlDzLtwnAAA +1 + +Cpp +CppPointer +CppPointer +* +lqZIR9zpP0y49VT0gCv6swAA + + + +return +pdkReturn +vf4CNLDVkk6wd9f0alsTGgAA +Pv24uWWaqUu82r7VGD3ZNwAA +1 + +Cpp +CppPointer +CppPointer +* ++gwOOVHEKEC3d7c6ZslFKwAA + + + + +ToServer +skClassifier +aDgNVKZkT029alZKzju1xAAA +1 + +Cpp +CppMemberFunction +CppInline +True +GXbVAyywoU+PbkwWOpwriQAA + +2 + +pPackSocket +GXbVAyywoU+PbkwWOpwriQAA +Pv24uWWaqUu82r7VGD3ZNwAA +1 + +Cpp +CppPointer +CppPointer +* +DQXPCFFri06p9vDhntrwswAA + + + +return +pdkReturn +GXbVAyywoU+PbkwWOpwriQAA +YNdJIJRIm0SpW7CG17MtyAAA +1 + +Cpp +CppPointer +CppPointer +* +azDXhAug/kC0UeL/V3c2qQAA + + + + + +ITcpPackAgent +jvfBmo6uGkC61ckI99TMgAAA +8 +mDfdT1ptZk64YFRjy+qMOgAA +m6xyT3N2pkyTw61oJYXrvQAA +/dl3/5EnpUyqy2//SJ9pwwAA +7Qrfdh28q0SlebHOxi6IoQAA +kXZKbMdJjEWlFo6Q0wMKUwAA +RkCx8/mbRUatqL1bHvDz1gAA +w06vX7FbRkuTtJB+K2zTOgAA +AkDi0mVJl0ubyilvlYIgzgAA +2 +WUHNHDfka0O+CbvKWj/7kQAA +lqZ7xgrWKkewtFXoEKU2+AAA +2 + +ToPack +skClassifier +vjFkGLWb/kSPpbp9R+skbAAA +1 + +Cpp +CppMemberFunction +CppInline +True +X1JmTUypW06ys21ZeaLUowAA + +2 + +pAgent +X1JmTUypW06ys21ZeaLUowAA +tc20+9LmREuR1dUMSybNdQAA +1 + +Cpp +CppPointer +CppPointer +* +pLUAAVD3Ik2vyLatRkbfrwAA + + + +return +pdkReturn +X1JmTUypW06ys21ZeaLUowAA +Pv24uWWaqUu82r7VGD3ZNwAA +1 + +Cpp +CppPointer +CppPointer +* +INOu6si0U0esJ5QdnvqevgAA + + + + +ToAgent +skClassifier +vjFkGLWb/kSPpbp9R+skbAAA +1 + +Cpp +CppMemberFunction +CppInline +True +Lewh6Ntc10CBoT43vJIF1AAA + +2 + +pPackSocket +Lewh6Ntc10CBoT43vJIF1AAA +Pv24uWWaqUu82r7VGD3ZNwAA +1 + +Cpp +CppPointer +CppPointer +* +Irvwq5MHbk6LOaC8nQbvzwAA + + + +return +pdkReturn +Lewh6Ntc10CBoT43vJIF1AAA +ilTzVOgexUSPHrK2FSqS9wAA +1 + +Cpp +CppPointer +CppPointer +* +R2exw8R6DE6K1lw0TUkI2wAA + + + + + +ITcpPackClient +jvfBmo6uGkC61ckI99TMgAAA +8 +q5juGoWzLEGEpbKgLo4flwAA +5T8b7jFprEqa8EO1Q0kKXAAA +dBGW/2kXV0mAZJjPVCWegQAA +TYaYZa7SikKXRD+ylXtU7gAA +32lcn4ak5UeWCJbHkp/gUwAA +Ug3VKEcDvUabSaQg4iwrgwAA +JgQRxGdHTU2keN2ayiX8FgAA +XJ+BteSUJkiA2CijH1W48AAA +2 +xly9lJtUukKwQ90VKrZR2AAA +l44zgodkDEuj17c7XdoPSQAA +2 + +ToPack +skClassifier +NI0md/XcXk+UFEOqL+89owAA +1 + +Cpp +CppMemberFunction +CppInline +True +q69nbMyytESze00rpFcgHAAA + +2 + +pClient +q69nbMyytESze00rpFcgHAAA +R8hLgFt1fEaSSxBO7KbEBQAA +1 + +Cpp +CppPointer +CppPointer +* +fenI/tCbCEGzso47imi01gAA + + + +return +pdkReturn +q69nbMyytESze00rpFcgHAAA +tvyRlzR70kaEb8akK1WldwAA +1 + +Cpp +CppPointer +CppPointer +* +gHDDhlJar0yV7nt2BkZnTAAA + + + + +ToClient +skClassifier +NI0md/XcXk+UFEOqL+89owAA +1 + +Cpp +CppMemberFunction +CppInline +True +uw7CmCQv3k6APko6TVXkmwAA + +2 + +pPackClient +uw7CmCQv3k6APko6TVXkmwAA +tvyRlzR70kaEb8akK1WldwAA +1 + +Cpp +CppPointer +CppPointer +* +wcXN0QyVyk+g/gkYprOV9QAA + + + +return +pdkReturn +uw7CmCQv3k6APko6TVXkmwAA +CqUqbTfjd0mBGFOXrmWVDgAA +1 + +Cpp +CppPointer +CppPointer +* +XwIYEdJyaU+OBOCXAgFkDQAA + + + + + +CTcpPackAgent +jvfBmo6uGkC61ckI99TMgAAA +4 +D/2eg6bkTEKcTZu0rbkM1wAA +WNr3PGBfdkenuL1r1X0HoQAA +Pc0Aebt4wEaB+1vvVGI3lgAA +ys1sZKIIwUC9t3o7lIelKwAA +2 +v+HDY4XmuEqbLAgnV9F1XgAA +YVPRQLCk1keYCHnO8PWR/AAA +7 + +SendPackets +P+YM5jdCmESvfv1Fet1QqAAA +1 + +Cpp +CppVirtual +CppVirtual +True +dg/9o5UFwUuWrrQhb6d3JQAA + +4 + +dwConnID +dg/9o5UFwUuWrrQhb6d3JQAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffers +WSABUF +dg/9o5UFwUuWrrQhb6d3JQAA +1 + +Cpp +CppConst +CppConst +True +VveVPRtQVE+2Y5E9ICKkCgAA + + + +iCount +int +dg/9o5UFwUuWrrQhb6d3JQAA + + +return +pdkReturn +BOOL +dg/9o5UFwUuWrrQhb6d3JQAA + + + +SetMaxPackSize +P+YM5jdCmESvfv1Fet1QqAAA +1 + +Cpp +CppVirtual +CppVirtual +True +/VWmyO6HfUihBCSUWdukKwAA + +2 + +dwMaxPackSize +DWORD +/VWmyO6HfUihBCSUWdukKwAA + + +return +pdkReturn +void +/VWmyO6HfUihBCSUWdukKwAA + + + +SetPackHeaderFlag +P+YM5jdCmESvfv1Fet1QqAAA +1 + +Cpp +CppVirtual +CppVirtual +True ++YSjwJhn/0KSyuxGzZC3CQAA + +2 + +usPackHeaderFlag +USHORT ++YSjwJhn/0KSyuxGzZC3CQAA + + +return +pdkReturn +void ++YSjwJhn/0KSyuxGzZC3CQAA + + + +GetMaxPackSize +P+YM5jdCmESvfv1Fet1QqAAA +1 + +Cpp +CppVirtual +CppVirtual +True +Et7xVRx3DkiGnBabAiq9WAAA + +1 + +return +pdkReturn +DWORD +Et7xVRx3DkiGnBabAiq9WAAA + + + +GetPackHeaderFlag +P+YM5jdCmESvfv1Fet1QqAAA +1 + +Cpp +CppVirtual +CppVirtual +True +rbLQagIjskevp+dFtDtoqgAA + +1 + +return +pdkReturn +USHORT +rbLQagIjskevp+dFtDtoqgAA + + + +CTcpPackAgent +UMLStandard +create +vkPrivate +P+YM5jdCmESvfv1Fet1QqAAA +1 + +psoListener +COXZchxbR0aRAmZsWSDhMgAA +skl0Nm/UIUCTsqkUAIXmzAAA +1 + +Cpp +CppPointer +CppPointer +* +VbMBZfCU/0ivBlGkfv9qEwAA + + + + +CTcpPackAgent +UMLStandard +destroy +vkPrivate +P+YM5jdCmESvfv1Fet1QqAAA + + + +CTcpPackClient +jvfBmo6uGkC61ckI99TMgAAA +4 +yhdU0K3mvEeeVvCvv3kUNQAA +rme3i3CfH0K3yeiSkThSAwAA +ePo4iu/f5Eiz6KGKiV5ziwAA +VNYHDPGR80ydl9BCPX+gjwAA +3 +x2cv/pfP+0KLEYoWHGBFVAAA +PhcJjlYZKkK5/K0LejildAAA +N9PjlD8Kvk26PvXMITpM2QAA +7 + +SendPackets +L/mIC87mmUWQBG3Zhl0iGQAA +1 + +Cpp +CppVirtual +CppVirtual +True +cwQQNRSgeEiTzu5bwXNaMwAA + +3 + +pBuffers +WSABUF +cwQQNRSgeEiTzu5bwXNaMwAA +1 + +Cpp +CppConst +CppConst +True +Tpe5XywBnUSKWWMjTixRKQAA + + + +iCount +int +cwQQNRSgeEiTzu5bwXNaMwAA + + +return +pdkReturn +BOOL +cwQQNRSgeEiTzu5bwXNaMwAA + + + +SetMaxPackSize +L/mIC87mmUWQBG3Zhl0iGQAA +1 + +Cpp +CppVirtual +CppVirtual +True +G+ApphbCIEWG/fSS2s/FRwAA + +2 + +dwMaxPackSize +DWORD +G+ApphbCIEWG/fSS2s/FRwAA + + +return +pdkReturn +void +G+ApphbCIEWG/fSS2s/FRwAA + + + +SetPackHeaderFlag +L/mIC87mmUWQBG3Zhl0iGQAA +1 + +Cpp +CppVirtual +CppVirtual +True +tivsdeY9lUG+yMuJ6+rqpAAA + +2 + +usPackHeaderFlag +USHORT +tivsdeY9lUG+yMuJ6+rqpAAA + + +return +pdkReturn +void +tivsdeY9lUG+yMuJ6+rqpAAA + + + +GetMaxPackSize +L/mIC87mmUWQBG3Zhl0iGQAA +1 + +Cpp +CppVirtual +CppVirtual +True +vktlRt/yDUqwbzi7YENXiAAA + +1 + +return +pdkReturn +DWORD +vktlRt/yDUqwbzi7YENXiAAA + + + +GetPackHeaderFlag +L/mIC87mmUWQBG3Zhl0iGQAA +1 + +Cpp +CppVirtual +CppVirtual +True ++QgvovvniEmwYn9hkQOu3QAA + +1 + +return +pdkReturn +USHORT ++QgvovvniEmwYn9hkQOu3QAA + + + +CTcpPackClient +UMLStandard +create +vkPrivate +L/mIC87mmUWQBG3Zhl0iGQAA +1 + +psoListener +M4uZ5GqOl0yrNkxHQmcbtAAA +HwLi+AyuiUa754Eutz2k5AAA +1 + +Cpp +CppPointer +CppPointer +* +2htC5RYGCkmqkKaQAQy/zgAA + + + + +CTcpPackClient +UMLStandard +destroy +vkPrivate +L/mIC87mmUWQBG3Zhl0iGQAA + + + +CTcpPackServer +jvfBmo6uGkC61ckI99TMgAAA +4 +3Oc58Cgr6Uet0hJOu0xXvgAA +NDxqCLUfbkWKZemsaCefXAAA +8zkU+PhzbECwKW9TxPk6HQAA +MwnuVlrmYUarUu9Iz3bskwAA +2 +OH/WIarq+EioSJWJSZjh6AAA +aQ1uf7mN+EuF/eGcASNwmgAA +7 + +SendPackets +1ED6OCTjl0y7E7dMMSTJqgAA +1 + +Cpp +CppVirtual +CppVirtual +True +5DJim62zFkOgGKcinBl1xAAA + +4 + +dwConnID +5DJim62zFkOgGKcinBl1xAAA +G8TfQngB3UemVJWZg5KbggAA + + +pBuffers +WSABUF +5DJim62zFkOgGKcinBl1xAAA +1 + +Cpp +CppConst +CppConst +True ++BdcS2VFzUWglAaUTf3xMwAA + + + +iCount +int +5DJim62zFkOgGKcinBl1xAAA + + +return +pdkReturn +BOOL +5DJim62zFkOgGKcinBl1xAAA + + + +SetMaxPackSize +1ED6OCTjl0y7E7dMMSTJqgAA +1 + +Cpp +CppVirtual +CppVirtual +True +aX+zswQ4zE2/F1TkaAjL7AAA + +2 + +dwMaxPackSize +DWORD +aX+zswQ4zE2/F1TkaAjL7AAA + + +return +pdkReturn +void +aX+zswQ4zE2/F1TkaAjL7AAA + + + +SetPackHeaderFlag +1ED6OCTjl0y7E7dMMSTJqgAA +1 + +Cpp +CppVirtual +CppVirtual +True +VrYaob80EUSsEqOcioHnaQAA + +2 + +usPackHeaderFlag +USHORT +VrYaob80EUSsEqOcioHnaQAA + + +return +pdkReturn +void +VrYaob80EUSsEqOcioHnaQAA + + + +GetMaxPackSize +1ED6OCTjl0y7E7dMMSTJqgAA +1 + +Cpp +CppVirtual +CppVirtual +True +tsnZsahvbESscDWvIqU4AgAA + +1 + +return +pdkReturn +DWORD +tsnZsahvbESscDWvIqU4AgAA + + + +GetPackHeaderFlag +1ED6OCTjl0y7E7dMMSTJqgAA +1 + +Cpp +CppVirtual +CppVirtual +True +gw6J2BDRtEuqfM9bN4xzywAA + +1 + +return +pdkReturn +USHORT +gw6J2BDRtEuqfM9bN4xzywAA + + + +CTcpPackServer +UMLStandard +create +vkPrivate +1ED6OCTjl0y7E7dMMSTJqgAA +1 + +psoListener +MZBtGzxJrU+pckN4egygYAAA +h8NmVuBtVUWgcCSKCdxePgAA +1 + +Cpp +CppPointer +CppPointer +* +nRjXsyaRi0OblwNRuNtT6gAA + + + + +CTcpPackServer +UMLStandard +destroy +vkPrivate +1ED6OCTjl0y7E7dMMSTJqgAA + + + +jvfBmo6uGkC61ckI99TMgAAA +aDgNVKZkT029alZKzju1xAAA +Pv24uWWaqUu82r7VGD3ZNwAA +8 +6VmHYe/x/0yIaUK5+gKUPQAA +cG17rEtpik6nu0NmUwJO+QAA +PAfAjHTjFkiZ7oiA1ohkCAAA +ISoX722TrEaj3Bll5Rv8bAAA +jVWzkncwfEWSCcnGG3GRMAAA +0LBn9ifl6UehFmjLpQCmcwAA +xP/84tpMxkCTgosqEtsHtgAA +GhNYJOwNJUimKU587XOtigAA + + +jvfBmo6uGkC61ckI99TMgAAA +aDgNVKZkT029alZKzju1xAAA +YNdJIJRIm0SpW7CG17MtyAAA +8 +zkOykNrc6kiztcGJitCcewAA +aw1Skb1CS0aPF4YzfGN1BAAA +HSqp1+8nTEyJo97z66BObQAA +u3KVvzl6EEic3VwAD+X8PwAA +dWLQNpbqgUGKW9K/9gerewAA +wL9nfxmiak+wVj8gVA/5XQAA +inqtIO/kOEyV/uMEQspxBQAA +uUJIVxGUIk28m3eMme0G/QAA + + +jvfBmo6uGkC61ckI99TMgAAA +vjFkGLWb/kSPpbp9R+skbAAA +Pv24uWWaqUu82r7VGD3ZNwAA +8 +p0gU0tLurEezo3gjCu27uQAA +uRxWOxtCzkCw9/EH7JOeggAA +NH6kRHAeOUyJOfGsN2n2LQAA +y1UIsMU1skO3xdCl1lVjmwAA +cQZx6O7MQEC66fQVczNvWgAA +rBf5E1FdGkuR1lwo9uDdAwAA +PFrjVmATfES3vyAgdx+/5gAA +bL6P6lGGMki5dSB58yJtgwAA + + +jvfBmo6uGkC61ckI99TMgAAA +vjFkGLWb/kSPpbp9R+skbAAA +ilTzVOgexUSPHrK2FSqS9wAA +8 +YK6EG+gIsEiUbTkJ6ql6SgAA +xJDoCDd47UWRrLNxbRGosgAA +bpD40TTW9UGmszQ04wR4SQAA +FRbhd2c7uU+/A8ZUIZsJrAAA +yZVtVLdkT0yyLvZJq0udEwAA +NDlP8rnHIUKZMXbNCX5XwgAA +MR7xMeg0j06D94gqhhbZfAAA +4PkE+tI00UqME4XWlTeOrQAA + + +jvfBmo6uGkC61ckI99TMgAAA +NI0md/XcXk+UFEOqL+89owAA +tvyRlzR70kaEb8akK1WldwAA +8 +JoaiZS5esUKfp06TbpfY+wAA +cpoqrUMyF0uXUy9wETtiQAAA +rGnTocuvv0uJUUanQm/c1AAA +r7qbuSfZh0WeS6Mq1Lky8AAA +E7Ak0ghm1k6Lg9Jf3y031wAA +NZWEL1PlSUi0JnqVg70qngAA +pm2xIt4jYE2Sc3dYD1U9swAA +ud0FqMeUCEymi+vdZ5NTowAA + + +jvfBmo6uGkC61ckI99TMgAAA +NI0md/XcXk+UFEOqL+89owAA +CqUqbTfjd0mBGFOXrmWVDgAA +8 +Gu2GaGwEMU68V2DWzpQO5gAA +Aowdv9aj4k2o+lolIRczyQAA +YtzkgCIm2kOwGAtpbe7jWwAA +IB0hvjVG3k6jhq7QueiBPgAA +nifcgJC8Tk+EExWfjsAr/gAA +055UYWc690KVuELGF7i+5wAA +qGZ2VJKv3UyvAS117bqgzQAA +QXSSeJ5EXkq2o2GfE2leDAAA + + +jvfBmo6uGkC61ckI99TMgAAA +P+YM5jdCmESvfv1Fet1QqAAA +Pv24uWWaqUu82r7VGD3ZNwAA +4 +N3O+iMg77E2FWp6Azb67rwAA +r4Gv/ranAEqFHgYw3+PoJQAA +CWNma2B5z0OlYWkJDZT5AAAA +D5EWKjTyrEWEgR7FO23AlAAA + + +jvfBmo6uGkC61ckI99TMgAAA +P+YM5jdCmESvfv1Fet1QqAAA ++hvdtNLBPUeUmdoy9WnIywAA +4 +yiiEIOl6hEa3nbjNnPRcnwAA +8BruboB8IUGLr3Vu/XyR/AAA +a9WA4Kr1XkS5c3scC6srRgAA +ARWcj24iEEmazJoRHWs6IgAA + + +jvfBmo6uGkC61ckI99TMgAAA +L/mIC87mmUWQBG3Zhl0iGQAA +Pv24uWWaqUu82r7VGD3ZNwAA + + +jvfBmo6uGkC61ckI99TMgAAA +L/mIC87mmUWQBG3Zhl0iGQAA +rNsPUCIqcESb1NED1xr04AAA +4 +2WYqlZl+vkmYyamufjq+FQAA +Di7xP8e/NEeCzx/jnktsxgAA +9au1Gv2RpkKmo5meqhRGMwAA +qYuu2Z+SeE6Fjht0MrkL8wAA + + +jvfBmo6uGkC61ckI99TMgAAA +1ED6OCTjl0y7E7dMMSTJqgAA +Pv24uWWaqUu82r7VGD3ZNwAA +4 +HEPs/Gx6Z0qNmv6avB3TUgAA +xqPQr7tzu0mzf6Zr5tERMgAA +E4d7yAZKGkeq4UP1zfhJogAA +aIf7kv/MwUeK5gXad6vPLQAA + + +jvfBmo6uGkC61ckI99TMgAAA +1ED6OCTjl0y7E7dMMSTJqgAA +gWn1z7ujyEu9Gf7LdRrPIAAA +4 +rXnzBI5Az0iITQ+P+TYCLwAA +fpsHdHDQm0y0Lu/XAqXbhAAA +FWFo0RSgekK5B+Mee/8dCAAA +OewnzXNMrkaSNwXvWiPEkQAA + + +jvfBmo6uGkC61ckI99TMgAAA +L/mIC87mmUWQBG3Zhl0iGQAA +tvyRlzR70kaEb8akK1WldwAA +4 +fHQIM982D0Wo/Y6GIGe8rgAA +o5OAQDGZw0Wk6DXlPFZFdwAA +ePrza0QxmEqWJp/kaskLFAAA +IA8sbtaQDkejTvgMiJXKWQAA + + + +Deployment Model +UMLStandard +deploymentModel +eUBxTmzIc0q+cSu3hl5+hQAA + + +Implementation Model +UMLStandard +implementationModel +eUBxTmzIc0q+cSu3hl5+hQAA +1 + +HP-Socket Arch +J0n/XHnyekSunJdeH0mEDQAA + +9Q2G2kv+vESYu+RNI+rNZAAA +11 + +clMaroon +$00EBD6D6 +12 +764 +116 +425 +257 +ENUIjdhUOU6FAAlWIMCUjQAA + + +HP-Socket + + +False + + +False + + + + +clMaroon +$00FF5555 +10 +792 +176 +184 +49 +sdkIcon +OyfKjrwclU2EfzNdA7qZfQAA + + +1 +Component Interface + + +False + + +False + + + +False +OyfKjrwclU2EfzNdA7qZfQAA + + +False +OyfKjrwclU2EfzNdA7qZfQAA + + + +clMaroon +$00FF5555 +10 +804 +312 +157 +49 +sdkIcon +eEopxRL/jUCoAy+hw5p2AAAA + + +1 +Listener Interface + + +False + + +False + + + +False +eEopxRL/jUCoAy+hw5p2AAAA + + +False +eEopxRL/jUCoAy+hw5p2AAAA + + + +clMaroon +$00D7D7FF +10 +916 +240 +249 +49 +b7wciCk340WnIYs2OIA/WwAA + + +1 +Component Implement Class + + +False + + +False + + + +b7wciCk340WnIYs2OIA/WwAA + + +b7wciCk340WnIYs2OIA/WwAA + + +False +b7wciCk340WnIYs2OIA/WwAA + + + +clMaroon +$00B9FFFF +12 +456 +120 +272 +253 +Jet2RP8QIkiUIm6/lmhK5QAA + + +1 +My Application + + +False + + +False + + + +Jet2RP8QIkiUIm6/lmhK5QAA + + + +clMaroon +$00FFF5EC +10 +480 +312 +218 +49 +s/yNtp8VSEqjD4QJ3RgRrAAA + + +1 +Listener Implement Class + + +False + + +False + + + +s/yNtp8VSEqjD4QJ3RgRrAAA + + +s/yNtp8VSEqjD4QJ3RgRrAAA + + +False +s/yNtp8VSEqjD4QJ3RgRrAAA + + + +clMaroon +$00F1E4E4 +10 +480 +176 +189 +49 +NHJ486vDiUmN0lfkD/1ZzgAA + + +1 +Logic Controller + + +False + + +False + + + +NHJ486vDiUmN0lfkD/1ZzgAA + + +NHJ486vDiUmN0lfkD/1ZzgAA + + +False +NHJ486vDiUmN0lfkD/1ZzgAA + + + +clMaroon +$00B9FFFF +697,336;804,336 +PuM1D7vAgE2bZvp0/9TxTQAA +ABuV0aDQ80endfZcsfx3mQAA +r9gFUFTnmUqyJxGvqpK/1QAA + +False +1.5707963267949 +15 +PuM1D7vAgE2bZvp0/9TxTQAA + + +False +1.5707963267949 +30 +PuM1D7vAgE2bZvp0/9TxTQAA + + +False +-1.5707963267949 +15 +PuM1D7vAgE2bZvp0/9TxTQAA + + + +clMaroon +$00B9FFFF +1040,240;1040,200;975,200 +farC1lWXPUmwcMc4mSeSEQAA +Rx8jIENKB0ekQ4Vn7AAzZwAA +47dfeK8NE0ylzmvxrRp4JwAA + +False +1.5707963267949 +15 +farC1lWXPUmwcMc4mSeSEQAA + + +False +1.5707963267949 +30 +farC1lWXPUmwcMc4mSeSEQAA + + +False +-1.5707963267949 +15 +farC1lWXPUmwcMc4mSeSEQAA + + + +clMaroon +$00B9FFFF +1040,288;1040,336;960,336 +p+FnuqzelUKJ5KAPzXxKigAA +ABuV0aDQ80endfZcsfx3mQAA +47dfeK8NE0ylzmvxrRp4JwAA + +False +1.5707963267949 +15 +p+FnuqzelUKJ5KAPzXxKigAA + + +False +1.5707963267949 +30 +p+FnuqzelUKJ5KAPzXxKigAA + + +False +-1.5707963267949 +15 +p+FnuqzelUKJ5KAPzXxKigAA + + +False +-0.523598775598299 +30 +epHead +n9+mvVa+9kyJR31kH9f68wAA + + +False +0.523598775598299 +30 +epTail +uTb1WESP606TyWzPeyqhtwAA + + +0.523598775598299 +25 +epHead +1 +n9+mvVa+9kyJR31kH9f68wAA + + +False +-0.523598775598299 +25 +epTail +uTb1WESP606TyWzPeyqhtwAA + + +False +-0.785398163397448 +40 +epHead +n9+mvVa+9kyJR31kH9f68wAA + + +False +0.785398163397448 +40 +epTail +uTb1WESP606TyWzPeyqhtwAA + + +False +-1000 +-1000 +50 +8 +n9+mvVa+9kyJR31kH9f68wAA + + +False +-1000 +-1000 +50 +8 +uTb1WESP606TyWzPeyqhtwAA + + + +clMaroon +$00B9FFFF +668,200;792,200 +5WOr+9h2DUaYQbz6rZ7/9AAA +Rx8jIENKB0ekQ4Vn7AAzZwAA +KmlonzqrCEujowX10f1VSwAA + +False +1.5707963267949 +15 +5WOr+9h2DUaYQbz6rZ7/9AAA + + +False +1.5707963267949 +30 +5WOr+9h2DUaYQbz6rZ7/9AAA + + +False +-1.5707963267949 +15 +5WOr+9h2DUaYQbz6rZ7/9AAA + + +False +-0.523598775598299 +30 +epHead +G299coWTUUauZvajrg/XIwAA + + +False +0.523598775598299 +30 +epTail +6qXCPsrjokCkLVzSph7FmAAA + + +False +0.523598775598299 +25 +epHead +G299coWTUUauZvajrg/XIwAA + + +False +-0.523598775598299 +25 +epTail +6qXCPsrjokCkLVzSph7FmAAA + + +False +-0.785398163397448 +40 +epHead +G299coWTUUauZvajrg/XIwAA + + +False +0.785398163397448 +40 +epTail +6qXCPsrjokCkLVzSph7FmAAA + + +False +-1000 +-1000 +50 +8 +G299coWTUUauZvajrg/XIwAA + + +False +-1000 +-1000 +50 +8 +6qXCPsrjokCkLVzSph7FmAAA + + + + +11 + +My Application +J0n/XHnyekSunJdeH0mEDQAA +2 +OfLpubLykkO4+q+m7tEC5QAA +59UjRn+IeEepoL4Wj7wrhwAA + + +HP-Socket +J0n/XHnyekSunJdeH0mEDQAA +1 +JGeqKNLa9kC8OkOSSRk2iwAA + + +Component Implement Class +J0n/XHnyekSunJdeH0mEDQAA +4 +47dfeK8NE0ylzmvxrRp4JwAA +vraa/lJNMUyOKIpUAmBykQAA +T1EsI/Iaa0eBwU8SzzHNXQAA +dchkPqJzn0a8Xd0TJtILeAAA +1 +farC1lWXPUmwcMc4mSeSEQAA +1 +uTb1WESP606TyWzPeyqhtwAA + + +Listener Implement Class +J0n/XHnyekSunJdeH0mEDQAA +4 +r9gFUFTnmUqyJxGvqpK/1QAA +mzBiy0qMuEidEa0JspHd9AAA +xaEEWq+QnUuRoWAEcPFA3gAA +2mm0K11ThEWW9zv35i4BDQAA +1 +PuM1D7vAgE2bZvp0/9TxTQAA + + +Logic Controller +J0n/XHnyekSunJdeH0mEDQAA +4 +KmlonzqrCEujowX10f1VSwAA ++zF+wAT8OUCcuE+4qBPUjQAA +ohlt8kbY6U+abGvCJCPBIwAA +rIIO6Zc6S0mzOBfY57FtrQAA +1 +6qXCPsrjokCkLVzSph7FmAAA + + +Component Interface +J0n/XHnyekSunJdeH0mEDQAA +3 +Rx8jIENKB0ekQ4Vn7AAzZwAA +cFoH1oS09U2DhVhB+0wliAAA +jkSg3sBr3UmroMzKPCU06AAA +1 +farC1lWXPUmwcMc4mSeSEQAA +1 +G299coWTUUauZvajrg/XIwAA + + +Listener Interface +J0n/XHnyekSunJdeH0mEDQAA +3 +ABuV0aDQ80endfZcsfx3mQAA +TEnuxIoA7EGppCVdsEhW/QAA +QmT3h5K3GUKhyDRaCkQn4AAA +1 +PuM1D7vAgE2bZvp0/9TxTQAA +1 +n9+mvVa+9kyJR31kH9f68wAA + + +J0n/XHnyekSunJdeH0mEDQAA +s/yNtp8VSEqjD4QJ3RgRrAAA +eEopxRL/jUCoAy+hw5p2AAAA +4 +52tvZpwt7ke7SLh7Wu8+dAAA +H4j8vTBOc0eXpDbcQy6XKgAA +1T+A4D1Dlk6oc92ipaYHTAAA +//d5rYX00kSadIjZATXLkQAA + + +J0n/XHnyekSunJdeH0mEDQAA +b7wciCk340WnIYs2OIA/WwAA +OyfKjrwclU2EfzNdA7qZfQAA +4 +0FPOcrOAAEyTHaBjqHuJWwAA +6dMenPZ7Jk2dKLDRE+G+fwAA +dJl8YShJE0eVerGFHladpQAA +dTS7LeSZREK6sywABVTcKgAA + + +J0n/XHnyekSunJdeH0mEDQAA +4 +DtIC50CGKUW19UVlPVJ/rQAA +P+a9iueZMkSHeED9uGwq3QAA +dhDEx3OZ10qUrgOXluzaSAAA +H5eUuW6oU02vmED1UIByHAAA +2 + +p+FnuqzelUKJ5KAPzXxKigAA +b7wciCk340WnIYs2OIA/WwAA +4 +IQP5Slkz20u7Y4z8G/twqgAA +rK1AqbIIZU6ylHKld05Y1AAA +NIsz9ES0HUKNoSqEdYPWvQAA +HTsR7hBYFkyR5xKfnkaVSQAA + + +akAggregate +1 +p+FnuqzelUKJ5KAPzXxKigAA +eEopxRL/jUCoAy+hw5p2AAAA +4 +/Ggfu2JynUyhL8ly60GPaAAA +ndwr+XRf1k+jaUNhCtSv+AAA +QVd3RrZ6/UWFhEDn2tk36wAA +lBKTBzvT3E+LTo1rmN3XWgAA + + + +J0n/XHnyekSunJdeH0mEDQAA +4 +wdXPTguwBE2HA/jL7Jls9gAA +b3bHmMWkl0WWSUMFtKLztAAA +ONiO/3uMXUGe7qmsVpNwwwAA +NoZe9o+qQ0indXOU+GJFBQAA +2 + +False +5WOr+9h2DUaYQbz6rZ7/9AAA +NHJ486vDiUmN0lfkD/1ZzgAA +4 +xruw2YIaT0W+MNniDQdOmwAA +u2WOJawdw0WdlXNXdZ92uQAA +UYjd65Bl5kipsWrx+gZALwAA +pU4+gOG4RUuAFodY9yWbZQAA + + +5WOr+9h2DUaYQbz6rZ7/9AAA +OyfKjrwclU2EfzNdA7qZfQAA +4 +wt6n3n10JkGMur/0XAd2vwAA +6wK5U7X1rE+OIBhWTP/2sAAA +Xno1BIQ2Rk6nMMup+xJLeAAA +xcepG51jT06ZPhVaW0nW7gAA + + +1 + +Work Flow +J0n/XHnyekSunJdeH0mEDQAA +2 + +Sample-1 +5Xea+2Ha3kuZqH6rjIWf7AAA +1 + +Sample +False +mskNameAndType +1QTFfJIkv0Oe+uLEcmTfCQAA + +Ss3Zh8ovG0K0+mzviNMvoQAA +83 + +clMaroon +$00B9FFFF +88 +120 +119 +1057 +wQGBjVheXk6JUG6UyHLOLQAA + + +4 +My Logic Controller + + +False + + +False + + + +wQGBjVheXk6JUG6UyHLOLQAA + + + +clMaroon +$00B9FFFF +320 +120 +139 +1057 +Amawaz/I9kSR3ZRprOaA0QAA + + +4 +My TCP Agent Listener + + +False + + +False + + + +Amawaz/I9kSR3ZRprOaA0QAA + + + +clMaroon +$00E3C8C8 +592 +120 +70 +1061 +U2Za99rIrEi8z93FLSAjUAAA + + +4 +TCP Agent + + +False + + +False + + + +U2Za99rIrEi8z93FLSAjUAAA + + + +$00F0E1FF +900 +116 +114 +869 +j+NgCUOjNE2kmFd3hYSIegAA + + +4 +Server Application + + +False + + +False + + + +j+NgCUOjNE2kmFd3hYSIegAA + + + +clMaroon +$00E6CCCC +1148 +116 +117 +869 +ychpc6mSzUOyFf7vQMlVXAAA + + +4 +Server Component + + +False + + +False + + + +ychpc6mSzUOyFf7vQMlVXAAA + + + +clMaroon +$00B9FFFF +1404 +116 +108 +869 +Ta3rZIdU6E2pIcWjSM7HXgAA + + +4 +Client Application + + +False + + +False + + + +Ta3rZIdU6E2pIcWjSM7HXgAA + + + +clMaroon +$00FFD7FF +1648 +120 +108 +917 +rscStAuJEkiUAz9WikX0hQAA + + +4 +Client Application + + +False + + +False + + + +rscStAuJEkiUAz9WikX0hQAA + + + +clMaroon +$00E6CCCC +1884 +120 +112 +917 +lvD/j4YgmkG/Ov+o+mJZPQAA + + +4 +Client Component + + +False + + +False + + + +lvD/j4YgmkG/Ov+o+mJZPQAA + + + +clMaroon +$00B9FFFF +2116 +120 +114 +913 +HdPN0QWbYUq0xPzVpVWOdwAA + + +4 +Server Application + + +False + + +False + + + +HdPN0QWbYUq0xPzVpVWOdwAA + + + +clMaroon +$00B9FFFF +lsRectilinear +957,209;1199,209 +GKqHK7uaTEeoZL1eXATu1QAA +dpffqY3360GzYdj7w2urkQAA +Of+EE4bQSk2dMrxBCuhmVwAA + +1.5707963267949 +10 +IServer := new(listener) +GKqHK7uaTEeoZL1eXATu1QAA +zj0gLe4XtU2J2bVhHsjKoQAA + + +1.5707963267949 +25 +<<create>> +GKqHK7uaTEeoZL1eXATu1QAA +zj0gLe4XtU2J2bVhHsjKoQAA + + +False +-1.5707963267949 +10 +GKqHK7uaTEeoZL1eXATu1QAA +zj0gLe4XtU2J2bVhHsjKoQAA + + +1199 +209 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +1702,216;1933,216 +twaVQAbQn0SQxSav8hKGygAA ++wCnW3yutEeNI63TdKQpkAAA +TbZv4vmixEauqpXIdyVNdgAA + +1.5707963267949 +10 +IAgent := new(listener) +twaVQAbQn0SQxSav8hKGygAA +cCyZUo+qL02sb4GGEh3gwgAA + + +1.5707963267949 +25 +<<create>> +twaVQAbQn0SQxSav8hKGygAA +cCyZUo+qL02sb4GGEh3gwgAA + + +False +-1.5707963267949 +10 +twaVQAbQn0SQxSav8hKGygAA +cCyZUo+qL02sb4GGEh3gwgAA + + +1933 +216 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +147,224;382,224 +UVJZlx7WuUW8BWRWnTMKVwAA +yexABU1UCEy5R/KkGohcEQAA +bgjtXzPElEqJn9pi84tImgAA + +1.5707963267949 +10 +ITcpAgentListener := new() +UVJZlx7WuUW8BWRWnTMKVwAA +9LSfj24cFU+rp+nfIoeHUwAA + + +1.5707963267949 +25 +<<create>> +UVJZlx7WuUW8BWRWnTMKVwAA +9LSfj24cFU+rp+nfIoeHUwAA + + +False +-1.5707963267949 +10 +UVJZlx7WuUW8BWRWnTMKVwAA +9LSfj24cFU+rp+nfIoeHUwAA + + +382 +224 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +1199,236;957,236 +waLdiSPvU0aqFpb250AZIwAA +Of+EE4bQSk2dMrxBCuhmVwAA +dpffqY3360GzYdj7w2urkQAA + +1.5707963267949 +10 +server +waLdiSPvU0aqFpb250AZIwAA +aEtdljySnk+Jnw8H2MyfBAAA + + +False +1.5707963267949 +25 +waLdiSPvU0aqFpb250AZIwAA +aEtdljySnk+Jnw8H2MyfBAAA + + +False +-1.5707963267949 +10 +waLdiSPvU0aqFpb250AZIwAA +aEtdljySnk+Jnw8H2MyfBAAA + + +False +957 +236 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +1933,242;1702,242 +RjOELc899E24BqUs1P8w2gAA +TbZv4vmixEauqpXIdyVNdgAA ++wCnW3yutEeNI63TdKQpkAAA + +1.5707963267949 +10 +agent +RjOELc899E24BqUs1P8w2gAA +hM4zK3J2M0qTbiDJg6DftgAA + + +False +1.5707963267949 +25 +RjOELc899E24BqUs1P8w2gAA +hM4zK3J2M0qTbiDJg6DftgAA + + +False +-1.5707963267949 +10 +RjOELc899E24BqUs1P8w2gAA +hM4zK3J2M0qTbiDJg6DftgAA + + +False +1702 +242 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +382,251;147,251 +mpQYN0pghkiv6UDJsnfuWwAA +bgjtXzPElEqJn9pi84tImgAA +yexABU1UCEy5R/KkGohcEQAA + +1.5707963267949 +10 +listener +mpQYN0pghkiv6UDJsnfuWwAA +YzPwOBpQpU2JgPIxj5MjdgAA + + +False +1.5707963267949 +25 +mpQYN0pghkiv6UDJsnfuWwAA +YzPwOBpQpU2JgPIxj5MjdgAA + + +False +-1.5707963267949 +10 +mpQYN0pghkiv6UDJsnfuWwAA +YzPwOBpQpU2JgPIxj5MjdgAA + + +False +147 +251 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +957,290;1199,290 +u/hYdn97j0e2w7qGm8lrPQAA +dpffqY3360GzYdj7w2urkQAA +Of+EE4bQSk2dMrxBCuhmVwAA + +clBlue +1.5707963267949 +10 +Start() +u/hYdn97j0e2w7qGm8lrPQAA +81Znj6ipLE+uQJdj3I3BjAAA + + +False +1.5707963267949 +25 +u/hYdn97j0e2w7qGm8lrPQAA +81Znj6ipLE+uQJdj3I3BjAAA + + +False +-1.5707963267949 +10 +u/hYdn97j0e2w7qGm8lrPQAA +81Znj6ipLE+uQJdj3I3BjAAA + + +1199 +290 +14 +29 + + + +clMaroon +$00E6FFE6 +440 +228 +157 +26 +Create Agent & Listener + + + +clMaroon +$00B9FFFF +395,238;440,239 +0Vfln1pKf0uQ0mhZitJAzgAA +v2rXGeEJu0GEcQH90sDU+wAA + + +clMaroon +$00E6FFE6 +468 +384 +85 +26 +Start Agent + + + +clMaroon +$00B9FFFF +620,328;533,253 +0Vfln1pKf0uQ0mhZitJAzgAA +/og21wPYTEaycNPMQZkZUQAA + + +clMaroon +$00B9FFFF +620,441;542,409 +Qv2CPimlhkSTXPkCIxPjLgAA +0a1wOUQz2UiUyr3e9Bb0SwAA + + +clMaroon +$00E6FFE6 +188 +524 +126 +26 +Connect Operation + + + +clMaroon +$00B9FFFF +620,509;313,531 +gkqUvj6zm0SHCoIe2SKckAAA +kaymAvXvsEafxUejw5yotgAA + + +clMaroon +$00B9FFFF +382,569;365,568 +7ttclFeTnUmkkMMP9dw/bAAA +F7ir4qnZcEaW6UwtUzgylQAA + + +clMaroon +$00B9FFFF +382,628;300,605 +WNyldfqfh0+nnq5wwL3X4AAA +tvHHENZLZ0qJm4tOe/b3qQAA + + +clMaroon +$00E6FFE6 +188 +692 +109 +26 +Send Operation + + + +clMaroon +$00B9FFFF +620,690;296,702 +FVocQtL3gkaQluADo0iwUQAA +9lS2iW92REyTOFXx6oFvYAAA + + +clMaroon +$00E6FFE6 +188 +552 +178 +26 +OnPrepareConnect Callback + + + +clMaroon +$00E6FFE6 +188 +580 +133 +26 +OnConnect Callback + + + +clMaroon +$00E6FFE6 +188 +720 +116 +26 +OnSend Callback + + + +clMaroon +$00B9FFFF +382,745;303,738 +L52zCnvp3UuZnci4sRI0lwAA +knnNYW35b0Cy/WKm0z8H/QAA + + +clMaroon +$00E6FFE6 +188 +816 +131 +26 +OnReceive Callback + + + +clMaroon +$00B9FFFF +382,842;318,835 +Idabkcv/ikmqAFmb6MUaOgAA ++49T4AyPL0W3AJZ/WaYk+wAA + + +clMaroon +$00E6FFE6 +188 +912 +120 +26 +OnClose Callback + + + +clMaroon +$00E6FFE6 +188 +1044 +117 +26 +Stop Operation + + + +clMaroon +$00E6FFE6 +188 +1084 +177 +26 +OnShutdown Callback + + + +clMaroon +$00B9FFFF +382,941;307,932 +bNeTVtkO80is01lUjD9v/AAA +3uAxv167jUuuqqe+9BSGmwAA + + +clMaroon +$00B9FFFF +620,1042;304,1054 +b0nSfzl8Z0uD21Wmmjt/LAAA +bJKMlTAo7U6yXpGRa1cWcgAA + + +clMaroon +$00B9FFFF +382,1109;364,1107 +4KlPgeWRsUiAN23Tqg8/QgAA +FFFK0l7+EkirZYOB3oJ25gAA + + +clBlue +$00B9FFFF +lsRectilinear +1702,312;1933,312 +ge2n5wRT306cnabk/HU2IgAA ++wCnW3yutEeNI63TdKQpkAAA +TbZv4vmixEauqpXIdyVNdgAA + +clBlue +1.5707963267949 +10 +Start() +ge2n5wRT306cnabk/HU2IgAA +ONHfDMi2cE6eUYVGDXwgGwAA + + +False +1.5707963267949 +25 +ge2n5wRT306cnabk/HU2IgAA +ONHfDMi2cE6eUYVGDXwgGwAA + + +False +-1.5707963267949 +10 +ge2n5wRT306cnabk/HU2IgAA +ONHfDMi2cE6eUYVGDXwgGwAA + + +1933 +312 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1199,314;957,314 +KjbQrlapxE2xRsUF2q8bDwAA +Of+EE4bQSk2dMrxBCuhmVwAA +dpffqY3360GzYdj7w2urkQAA + +clPurple +1.5707963267949 +10 +OnPrepareListen +KjbQrlapxE2xRsUF2q8bDwAA +gHBXKkyxe0K1OBNbZXeV3wAA + + +False +1.5707963267949 +25 +KjbQrlapxE2xRsUF2q8bDwAA +gHBXKkyxe0K1OBNbZXeV3wAA + + +False +-1.5707963267949 +10 +KjbQrlapxE2xRsUF2q8bDwAA +gHBXKkyxe0K1OBNbZXeV3wAA + + +False +957 +314 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +147,319;620,319 +eiRtiRQwQU+VjHaN3rVhqAAA +mNvSnPlpGUa+X6DT/4CU0gAA +bgjtXzPElEqJn9pi84tImgAA + +1.5707963267949 +10 +ITcpAgent := new(listener) +eiRtiRQwQU+VjHaN3rVhqAAA +TvRznbBpRE+w6+5JbXI1MQAA + + +1.5707963267949 +25 +<<create>> +eiRtiRQwQU+VjHaN3rVhqAAA +TvRznbBpRE+w6+5JbXI1MQAA + + +False +-1.5707963267949 +10 +eiRtiRQwQU+VjHaN3rVhqAAA +TvRznbBpRE+w6+5JbXI1MQAA + + +620 +319 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +620,346;147,346 +gc1T6rnMnUylWpF5/By8ZAAA +bgjtXzPElEqJn9pi84tImgAA +mNvSnPlpGUa+X6DT/4CU0gAA + +1.5707963267949 +10 +agent +gc1T6rnMnUylWpF5/By8ZAAA +Mwl65WlBAkWLprLAGAE5rwAA + + +False +1.5707963267949 +25 +gc1T6rnMnUylWpF5/By8ZAAA +Mwl65WlBAkWLprLAGAE5rwAA + + +False +-1.5707963267949 +10 +gc1T6rnMnUylWpF5/By8ZAAA +Mwl65WlBAkWLprLAGAE5rwAA + + +False +147 +346 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1206,395;957,395 +q1qjKctdRE2v7HKXDklokQAA +Of+EE4bQSk2dMrxBCuhmVwAA +dpffqY3360GzYdj7w2urkQAA + +clPurple +1.5707963267949 +10 +OnAccept +q1qjKctdRE2v7HKXDklokQAA +aeW3gGFMI0i5mnoP8rzsewAA + + +False +1.5707963267949 +25 +q1qjKctdRE2v7HKXDklokQAA +aeW3gGFMI0i5mnoP8rzsewAA + + +False +-1.5707963267949 +10 +q1qjKctdRE2v7HKXDklokQAA +aeW3gGFMI0i5mnoP8rzsewAA + + +False +957 +395 +14 +29 + + + +$00B9FFFF +lsRectilinear +1458,395;1206,395 +hhg1h6MW70ylqCivIbWRXQAA +dpffqY3360GzYdj7w2urkQAA +DKt3hU+zzUSpte7zoVHRzQAA + +1.5707963267949 +10 +Connect +hhg1h6MW70ylqCivIbWRXQAA +CAh9vY3mukOvRlolvYiXeQAA + + +False +1.5707963267949 +25 +hhg1h6MW70ylqCivIbWRXQAA +CAh9vY3mukOvRlolvYiXeQAA + + +False +-1.5707963267949 +10 +hhg1h6MW70ylqCivIbWRXQAA +CAh9vY3mukOvRlolvYiXeQAA + + +False +1206 +395 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +1702,404;1933,404 +UiC+SdjuLkO6xrRIGFh2PAAA ++wCnW3yutEeNI63TdKQpkAAA +TbZv4vmixEauqpXIdyVNdgAA + +clBlue +1.5707963267949 +10 +Connect() +UiC+SdjuLkO6xrRIGFh2PAAA +x12y5MX61kSU8UEZBCKBzAAA + + +False +1.5707963267949 +25 +UiC+SdjuLkO6xrRIGFh2PAAA +x12y5MX61kSU8UEZBCKBzAAA + + +False +-1.5707963267949 +10 +UiC+SdjuLkO6xrRIGFh2PAAA +x12y5MX61kSU8UEZBCKBzAAA + + +1933 +404 +14 +57 + + + +clBlue +$00B9FFFF +lsRectilinear +147,429;620,429 +3ll2HhKX0kq8L2WoIISIqQAA +mNvSnPlpGUa+X6DT/4CU0gAA +bgjtXzPElEqJn9pi84tImgAA + +clNavy +1.5707963267949 +10 +Start() +3ll2HhKX0kq8L2WoIISIqQAA +HnK/vetZsE2Zoo9YLGV1KgAA + + +False +1.5707963267949 +25 +3ll2HhKX0kq8L2WoIISIqQAA +HnK/vetZsE2Zoo9YLGV1KgAA + + +False +-1.5707963267949 +10 +3ll2HhKX0kq8L2WoIISIqQAA +HnK/vetZsE2Zoo9YLGV1KgAA + + +620 +429 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,430;1702,430 +FYipeeoMCUm19jcfhm3biAAA +TbZv4vmixEauqpXIdyVNdgAA ++wCnW3yutEeNI63TdKQpkAAA + +clPurple +clPurple +1.5707963267949 +10 +OnPrepareConnect +FYipeeoMCUm19jcfhm3biAAA +PMbi1EVd7kmNs8rUg0gpgwAA + + +False +1.5707963267949 +25 +FYipeeoMCUm19jcfhm3biAAA +PMbi1EVd7kmNs8rUg0gpgwAA + + +False +-1.5707963267949 +10 +FYipeeoMCUm19jcfhm3biAAA +PMbi1EVd7kmNs8rUg0gpgwAA + + +False +1702 +430 +14 +56 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,457;1702,457 +/bHgYzIBqECI2mdaGkoJMwAA +TbZv4vmixEauqpXIdyVNdgAA ++wCnW3yutEeNI63TdKQpkAAA + +clPurple +clPurple +1.5707963267949 +10 +OnConnect +/bHgYzIBqECI2mdaGkoJMwAA +K1jfKNg6hUSMEfA71rVwswAA + + +False +1.5707963267949 +25 +/bHgYzIBqECI2mdaGkoJMwAA +K1jfKNg6hUSMEfA71rVwswAA + + +False +-1.5707963267949 +10 +/bHgYzIBqECI2mdaGkoJMwAA +K1jfKNg6hUSMEfA71rVwswAA + + +False +1702 +457 +14 +29 + + + +$00B9FFFF +lsRectilinear +1946,457;2173,457 +NUW8ZK/ERk2X3umbnhegzwAA +W7BRFi1ZrESz7J7YQP9lKAAA ++wCnW3yutEeNI63TdKQpkAAA + +1.5707963267949 +10 +Connect +NUW8ZK/ERk2X3umbnhegzwAA +Uva/yeEJ00eMzNPCIyuWZAAA + + +False +1.5707963267949 +25 +NUW8ZK/ERk2X3umbnhegzwAA +Uva/yeEJ00eMzNPCIyuWZAAA + + +False +-1.5707963267949 +10 +NUW8ZK/ERk2X3umbnhegzwAA +Uva/yeEJ00eMzNPCIyuWZAAA + + +False +2173 +457 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +147,495;620,495 +qxo3boab2UKQT7Y0WGaO5wAA +mNvSnPlpGUa+X6DT/4CU0gAA +bgjtXzPElEqJn9pi84tImgAA + +clNavy +1.5707963267949 +10 +Connect(address, port) +qxo3boab2UKQT7Y0WGaO5wAA +eYJrYhPCEUS7T6jsSTfTGAAA + + +False +1.5707963267949 +25 +qxo3boab2UKQT7Y0WGaO5wAA +eYJrYhPCEUS7T6jsSTfTGAAA + + +False +-1.5707963267949 +10 +qxo3boab2UKQT7Y0WGaO5wAA +eYJrYhPCEUS7T6jsSTfTGAAA + + +620 +495 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1206,503;957,503 +xbH85UKQlESFWJculb723gAA +Of+EE4bQSk2dMrxBCuhmVwAA +dpffqY3360GzYdj7w2urkQAA + +clPurple +1.5707963267949 +10 +OnReceive +xbH85UKQlESFWJculb723gAA +OLadb8YV2kW2/OneXcT5fAAA + + +False +1.5707963267949 +25 +xbH85UKQlESFWJculb723gAA +OLadb8YV2kW2/OneXcT5fAAA + + +False +-1.5707963267949 +10 +xbH85UKQlESFWJculb723gAA +OLadb8YV2kW2/OneXcT5fAAA + + +False +957 +503 +14 +29 + + + +$00B9FFFF +lsRectilinear +1458,503;1206,503 +/VRCJTy/oEur+ilCjeW2XgAA +dpffqY3360GzYdj7w2urkQAA +DKt3hU+zzUSpte7zoVHRzQAA + +1.5707963267949 +10 +Send +/VRCJTy/oEur+ilCjeW2XgAA +k+k1sVK/4kCTCrxJp3KZmAAA + + +False +1.5707963267949 +25 +/VRCJTy/oEur+ilCjeW2XgAA +k+k1sVK/4kCTCrxJp3KZmAAA + + +False +-1.5707963267949 +10 +/VRCJTy/oEur+ilCjeW2XgAA +k+k1sVK/4kCTCrxJp3KZmAAA + + +False +1206 +503 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +1702,548;1933,548 +3BL7NFdLw0yo7RLubFSFzQAA ++wCnW3yutEeNI63TdKQpkAAA +TbZv4vmixEauqpXIdyVNdgAA + +clBlue +1.5707963267949 +10 +Send() +3BL7NFdLw0yo7RLubFSFzQAA +fRP4qNvR302+2rcIff42YQAA + + +False +1.5707963267949 +25 +3BL7NFdLw0yo7RLubFSFzQAA +fRP4qNvR302+2rcIff42YQAA + + +False +-1.5707963267949 +10 +3BL7NFdLw0yo7RLubFSFzQAA +fRP4qNvR302+2rcIff42YQAA + + +1933 +548 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,555;395,555 +Wjv7v/0JW0SsHdI2VbWR+AAA +yexABU1UCEy5R/KkGohcEQAA +mNvSnPlpGUa+X6DT/4CU0gAA + +clMaroon +1.5707963267949 +10 +OnPrepareConnect(connid) +Wjv7v/0JW0SsHdI2VbWR+AAA +jEQTYK+V2062OgAJI9+KJgAA + + +False +1.5707963267949 +25 +Wjv7v/0JW0SsHdI2VbWR+AAA +jEQTYK+V2062OgAJI9+KJgAA + + +False +-1.5707963267949 +10 +Wjv7v/0JW0SsHdI2VbWR+AAA +jEQTYK+V2062OgAJI9+KJgAA + + +382 +555 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,572;1702,572 +oF/LEA7hx0qNduBcIVAMJQAA +TbZv4vmixEauqpXIdyVNdgAA ++wCnW3yutEeNI63TdKQpkAAA + +clPurple +clPurple +1.5707963267949 +10 +OnSend +oF/LEA7hx0qNduBcIVAMJQAA ++vTGrF2zx0OWj4eXWblGowAA + + +False +1.5707963267949 +25 +oF/LEA7hx0qNduBcIVAMJQAA ++vTGrF2zx0OWj4eXWblGowAA + + +False +-1.5707963267949 +10 +oF/LEA7hx0qNduBcIVAMJQAA ++vTGrF2zx0OWj4eXWblGowAA + + +False +1702 +572 +14 +29 + + + +$00B9FFFF +lsRectilinear +1946,572;2173,572 +1vb2mQKxZ0+r/MA4zbJgbwAA +W7BRFi1ZrESz7J7YQP9lKAAA ++wCnW3yutEeNI63TdKQpkAAA + +1.5707963267949 +10 +Send +1vb2mQKxZ0+r/MA4zbJgbwAA +QO8N1X6VLky4cZtNH/bVqQAA + + +False +1.5707963267949 +25 +1vb2mQKxZ0+r/MA4zbJgbwAA +QO8N1X6VLky4cZtNH/bVqQAA + + +False +-1.5707963267949 +10 +1vb2mQKxZ0+r/MA4zbJgbwAA +QO8N1X6VLky4cZtNH/bVqQAA + + +False +2173 +572 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,616;395,616 +8p8OEDcPcEqcPclkWC6twgAA +yexABU1UCEy5R/KkGohcEQAA +mNvSnPlpGUa+X6DT/4CU0gAA + +clMaroon +1.5707963267949 +10 +OnConnect(connid) +8p8OEDcPcEqcPclkWC6twgAA +H7uvq6t59UCNEZljpwH1GAAA + + +False +1.5707963267949 +25 +8p8OEDcPcEqcPclkWC6twgAA +H7uvq6t59UCNEZljpwH1GAAA + + +False +-1.5707963267949 +10 +8p8OEDcPcEqcPclkWC6twgAA +H7uvq6t59UCNEZljpwH1GAAA + + +382 +616 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +957,616;1199,616 +kAJ6OYlT5kSWgt6Y8JB6KQAA +dpffqY3360GzYdj7w2urkQAA +Of+EE4bQSk2dMrxBCuhmVwAA + +clBlue +1.5707963267949 +10 +Send() +kAJ6OYlT5kSWgt6Y8JB6KQAA +/VoO4MkQoUqEWr+dUv9R5AAA + + +False +1.5707963267949 +25 +kAJ6OYlT5kSWgt6Y8JB6KQAA +/VoO4MkQoUqEWr+dUv9R5AAA + + +False +-1.5707963267949 +10 +kAJ6OYlT5kSWgt6Y8JB6KQAA +/VoO4MkQoUqEWr+dUv9R5AAA + + +1199 +616 +14 +33 + + + +clPurple +$00B9FFFF +lsRectilinear +1199,644;957,644 +0exvc+RmxE++FLqQZ+YzawAA +Of+EE4bQSk2dMrxBCuhmVwAA +dpffqY3360GzYdj7w2urkQAA + +clPurple +1.5707963267949 +10 +OnSend +0exvc+RmxE++FLqQZ+YzawAA +9lFefDL9EkGWx+GRTnrIZgAA + + +False +1.5707963267949 +25 +0exvc+RmxE++FLqQZ+YzawAA +9lFefDL9EkGWx+GRTnrIZgAA + + +False +-1.5707963267949 +10 +0exvc+RmxE++FLqQZ+YzawAA +9lFefDL9EkGWx+GRTnrIZgAA + + +False +957 +644 +14 +29 + + + +$00B9FFFF +lsRectilinear +1212,644;1458,644 +9Ol7xVDHfk+aOrYlU/XxDAAA +DKt3hU+zzUSpte7zoVHRzQAA +dpffqY3360GzYdj7w2urkQAA + +1.5707963267949 +10 +Send +9Ol7xVDHfk+aOrYlU/XxDAAA +s2d3Z0E0+kKI8W+SNgARXAAA + + +False +1.5707963267949 +25 +9Ol7xVDHfk+aOrYlU/XxDAAA +s2d3Z0E0+kKI8W+SNgARXAAA + + +False +-1.5707963267949 +10 +9Ol7xVDHfk+aOrYlU/XxDAAA +s2d3Z0E0+kKI8W+SNgARXAAA + + +False +1458 +644 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +147,676;620,676 +0gQj+YWF1kWUYfNhSvBRRgAA +mNvSnPlpGUa+X6DT/4CU0gAA +bgjtXzPElEqJn9pi84tImgAA + +clNavy +1.5707963267949 +10 +Send(connid, data, length) +0gQj+YWF1kWUYfNhSvBRRgAA +niqU3lxUj06wxkIb2xcgfwAA + + +False +1.5707963267949 +25 +0gQj+YWF1kWUYfNhSvBRRgAA +niqU3lxUj06wxkIb2xcgfwAA + + +False +-1.5707963267949 +10 +0gQj+YWF1kWUYfNhSvBRRgAA +niqU3lxUj06wxkIb2xcgfwAA + + +620 +676 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1940,676;1702,676 +mErn0SwL4kWgwh37KhxrOwAA +TbZv4vmixEauqpXIdyVNdgAA ++wCnW3yutEeNI63TdKQpkAAA + +clPurple +clPurple +1.5707963267949 +10 +OnReceive +mErn0SwL4kWgwh37KhxrOwAA +YkEmXAqy9EevsUZJVhd0hwAA + + +False +1.5707963267949 +25 +mErn0SwL4kWgwh37KhxrOwAA +YkEmXAqy9EevsUZJVhd0hwAA + + +False +-1.5707963267949 +10 +mErn0SwL4kWgwh37KhxrOwAA +YkEmXAqy9EevsUZJVhd0hwAA + + +False +1702 +676 +14 +29 + + + +$00B9FFFF +lsRectilinear +2173,676;1940,676 +PSWE8W0TEU+2XvyhDfkDzgAA ++wCnW3yutEeNI63TdKQpkAAA +W7BRFi1ZrESz7J7YQP9lKAAA + +1.5707963267949 +10 +Send +PSWE8W0TEU+2XvyhDfkDzgAA +CWRCDraG50e3xZDvX5vLpQAA + + +False +1.5707963267949 +25 +PSWE8W0TEU+2XvyhDfkDzgAA +CWRCDraG50e3xZDvX5vLpQAA + + +False +-1.5707963267949 +10 +PSWE8W0TEU+2XvyhDfkDzgAA +CWRCDraG50e3xZDvX5vLpQAA + + +False +1940 +676 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1206,724;957,724 +1hZ1Ivgi7UWnVEcQGQ9xdwAA +Of+EE4bQSk2dMrxBCuhmVwAA +dpffqY3360GzYdj7w2urkQAA + +clPurple +1.5707963267949 +10 +OnClose +1hZ1Ivgi7UWnVEcQGQ9xdwAA +KbnvIzhjfEWFVgq1gekqXAAA + + +False +1.5707963267949 +25 +1hZ1Ivgi7UWnVEcQGQ9xdwAA +KbnvIzhjfEWFVgq1gekqXAAA + + +False +-1.5707963267949 +10 +1hZ1Ivgi7UWnVEcQGQ9xdwAA +KbnvIzhjfEWFVgq1gekqXAAA + + +False +957 +724 +14 +29 + + + +$00B9FFFF +lsRectilinear +1458,724;1206,724 +aXyZYOKcl0mBOwUqTqobmgAA +dpffqY3360GzYdj7w2urkQAA +DKt3hU+zzUSpte7zoVHRzQAA + +1.5707963267949 +10 +Disconnect +aXyZYOKcl0mBOwUqTqobmgAA +zMOiSN3GsEiMtDJA5EV00wAA + + +False +1.5707963267949 +25 +aXyZYOKcl0mBOwUqTqobmgAA +zMOiSN3GsEiMtDJA5EV00wAA + + +False +-1.5707963267949 +10 +aXyZYOKcl0mBOwUqTqobmgAA +zMOiSN3GsEiMtDJA5EV00wAA + + +False +1206 +724 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,732;395,732 +5CQCgkQMiEa8EdVYKZGhowAA +yexABU1UCEy5R/KkGohcEQAA +mNvSnPlpGUa+X6DT/4CU0gAA + +clMaroon +1.5707963267949 +10 +OnSend(connid, data, length) +5CQCgkQMiEa8EdVYKZGhowAA +YpPwITXi7ESS5zzS/nJtdgAA + + +False +1.5707963267949 +25 +5CQCgkQMiEa8EdVYKZGhowAA +YpPwITXi7ESS5zzS/nJtdgAA + + +False +-1.5707963267949 +10 +5CQCgkQMiEa8EdVYKZGhowAA +YpPwITXi7ESS5zzS/nJtdgAA + + +382 +732 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1940,764;1702,764 +9lUxZSoXvkOOzpV4doFFPwAA +TbZv4vmixEauqpXIdyVNdgAA ++wCnW3yutEeNI63TdKQpkAAA + +clPurple +clPurple +1.5707963267949 +10 +OnClose +9lUxZSoXvkOOzpV4doFFPwAA +YfuBDr8+XEGC/f0KAwYlMwAA + + +False +1.5707963267949 +25 +9lUxZSoXvkOOzpV4doFFPwAA +YfuBDr8+XEGC/f0KAwYlMwAA + + +False +-1.5707963267949 +10 +9lUxZSoXvkOOzpV4doFFPwAA +YfuBDr8+XEGC/f0KAwYlMwAA + + +False +1702 +764 +14 +29 + + + +$00B9FFFF +lsRectilinear +2173,764;1940,764 +79YTw4PBt0qttSuIpUL7HQAA ++wCnW3yutEeNI63TdKQpkAAA +W7BRFi1ZrESz7J7YQP9lKAAA + +1.5707963267949 +10 +Disconnect +79YTw4PBt0qttSuIpUL7HQAA +y1T7PceGOk+3n0Ql8l12UgAA + + +False +1.5707963267949 +25 +79YTw4PBt0qttSuIpUL7HQAA +y1T7PceGOk+3n0Ql8l12UgAA + + +False +-1.5707963267949 +10 +79YTw4PBt0qttSuIpUL7HQAA +y1T7PceGOk+3n0Ql8l12UgAA + + +False +1940 +764 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +957,812;1199,812 +RakUMYixx0eokaMaO8399AAA +dpffqY3360GzYdj7w2urkQAA +Of+EE4bQSk2dMrxBCuhmVwAA + +clBlue +1.5707963267949 +10 +Disconnect() +RakUMYixx0eokaMaO8399AAA +H0hhU481MUSlr+PpVelBqwAA + + +False +1.5707963267949 +25 +RakUMYixx0eokaMaO8399AAA +H0hhU481MUSlr+PpVelBqwAA + + +False +-1.5707963267949 +10 +RakUMYixx0eokaMaO8399AAA +H0hhU481MUSlr+PpVelBqwAA + + +1199 +812 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,829;395,829 +OtUn1tUnHUiiI6GLtYamBwAA +yexABU1UCEy5R/KkGohcEQAA +mNvSnPlpGUa+X6DT/4CU0gAA + +clMaroon +1.5707963267949 +10 +OnReceive(connid, data, length) +OtUn1tUnHUiiI6GLtYamBwAA +vPOw9w4yJE+eo3dYsSWrBAAA + + +False +1.5707963267949 +25 +OtUn1tUnHUiiI6GLtYamBwAA +vPOw9w4yJE+eo3dYsSWrBAAA + + +False +-1.5707963267949 +10 +OtUn1tUnHUiiI6GLtYamBwAA +vPOw9w4yJE+eo3dYsSWrBAAA + + +382 +829 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1199,836;957,836 +qB+snL4IlEeGy2CTYMy/zAAA +Of+EE4bQSk2dMrxBCuhmVwAA +dpffqY3360GzYdj7w2urkQAA + +clPurple +1.5707963267949 +10 +OnClose +qB+snL4IlEeGy2CTYMy/zAAA +mYJo9K+KDEi+F3GgmHC8MAAA + + +False +1.5707963267949 +25 +qB+snL4IlEeGy2CTYMy/zAAA +mYJo9K+KDEi+F3GgmHC8MAAA + + +False +-1.5707963267949 +10 +qB+snL4IlEeGy2CTYMy/zAAA +mYJo9K+KDEi+F3GgmHC8MAAA + + +False +957 +836 +14 +29 + + + +$00B9FFFF +lsRectilinear +1212,836;1458,836 +Mj5U0wte/Ui52pM+Nh0WIgAA +DKt3hU+zzUSpte7zoVHRzQAA +dpffqY3360GzYdj7w2urkQAA + +1.5707963267949 +10 +Disconnect +Mj5U0wte/Ui52pM+Nh0WIgAA +vmvOU5NFGkOJH7BYW+rfLQAA + + +False +1.5707963267949 +25 +Mj5U0wte/Ui52pM+Nh0WIgAA +vmvOU5NFGkOJH7BYW+rfLQAA + + +False +-1.5707963267949 +10 +Mj5U0wte/Ui52pM+Nh0WIgAA +vmvOU5NFGkOJH7BYW+rfLQAA + + +False +1458 +836 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +1702,864;1933,864 +pvIA8HpUU0eAf/CRON6ISQAA ++wCnW3yutEeNI63TdKQpkAAA +TbZv4vmixEauqpXIdyVNdgAA + +clBlue +1.5707963267949 +10 +Disconnect() +pvIA8HpUU0eAf/CRON6ISQAA +iS+1y0N6I0eiK+0IWQQe2gAA + + +False +1.5707963267949 +25 +pvIA8HpUU0eAf/CRON6ISQAA +iS+1y0N6I0eiK+0IWQQe2gAA + + +False +-1.5707963267949 +10 +pvIA8HpUU0eAf/CRON6ISQAA +iS+1y0N6I0eiK+0IWQQe2gAA + + +1933 +864 +14 +29 + + + +$00B9FFFF +lsRectilinear +1946,888;2173,888 +bylpP6WP+0+xDkDWbCho6AAA +W7BRFi1ZrESz7J7YQP9lKAAA ++wCnW3yutEeNI63TdKQpkAAA + +1.5707963267949 +10 +Disconnect +bylpP6WP+0+xDkDWbCho6AAA +yP78nj+bZk+75vsYWcgXGwAA + + +False +1.5707963267949 +25 +bylpP6WP+0+xDkDWbCho6AAA +yP78nj+bZk+75vsYWcgXGwAA + + +False +-1.5707963267949 +10 +bylpP6WP+0+xDkDWbCho6AAA +yP78nj+bZk+75vsYWcgXGwAA + + +False +2173 +888 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,889;1702,889 +yCsrGZ0ZX0eRnh7MrDJ8fwAA +TbZv4vmixEauqpXIdyVNdgAA ++wCnW3yutEeNI63TdKQpkAAA + +clPurple +clPurple +1.5707963267949 +10 +OnClose +yCsrGZ0ZX0eRnh7MrDJ8fwAA +GW3/+fr0HEewn0AavM5PHQAA + + +False +1.5707963267949 +25 +yCsrGZ0ZX0eRnh7MrDJ8fwAA +GW3/+fr0HEewn0AavM5PHQAA + + +False +-1.5707963267949 +10 +yCsrGZ0ZX0eRnh7MrDJ8fwAA +GW3/+fr0HEewn0AavM5PHQAA + + +False +1702 +889 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +957,904;1199,904 +PT5rHARWmkS/g4IqVuPQbwAA +dpffqY3360GzYdj7w2urkQAA +Of+EE4bQSk2dMrxBCuhmVwAA + +clBlue +1.5707963267949 +10 +Stop() +PT5rHARWmkS/g4IqVuPQbwAA +WfhIgUdxekSnY02eBkGaEgAA + + +False +1.5707963267949 +25 +PT5rHARWmkS/g4IqVuPQbwAA +WfhIgUdxekSnY02eBkGaEgAA + + +False +-1.5707963267949 +10 +PT5rHARWmkS/g4IqVuPQbwAA +WfhIgUdxekSnY02eBkGaEgAA + + +1199 +904 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,928;395,928 +/HUsBl+/S0CY4MtM5ABl2AAA +yexABU1UCEy5R/KkGohcEQAA +mNvSnPlpGUa+X6DT/4CU0gAA + +clMaroon +1.5707963267949 +10 +OnClose(connid, operation, code) +/HUsBl+/S0CY4MtM5ABl2AAA +WTcgBUL5lk60yTAJ6+Ym8QAA + + +False +1.5707963267949 +25 +/HUsBl+/S0CY4MtM5ABl2AAA +WTcgBUL5lk60yTAJ6+Ym8QAA + + +False +-1.5707963267949 +10 +/HUsBl+/S0CY4MtM5ABl2AAA +WTcgBUL5lk60yTAJ6+Ym8QAA + + +382 +928 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1199,928;957,928 +yyMM+2gkDEehAYP+raNxDQAA +Of+EE4bQSk2dMrxBCuhmVwAA +dpffqY3360GzYdj7w2urkQAA + +clPurple +1.5707963267949 +10 +OnShutdown +yyMM+2gkDEehAYP+raNxDQAA +ElAEbekWtEO22kTeSu21VgAA + + +False +1.5707963267949 +25 +yyMM+2gkDEehAYP+raNxDQAA +ElAEbekWtEO22kTeSu21VgAA + + +False +-1.5707963267949 +10 +yyMM+2gkDEehAYP+raNxDQAA +ElAEbekWtEO22kTeSu21VgAA + + +False +957 +928 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +1702,968;1933,968 +czN9bfI5G0KZ0agADz5LWAAA ++wCnW3yutEeNI63TdKQpkAAA +TbZv4vmixEauqpXIdyVNdgAA + +clBlue +1.5707963267949 +10 +Stop() +czN9bfI5G0KZ0agADz5LWAAA +ho/lDUk1MEiX91DNXOY2JAAA + + +False +1.5707963267949 +25 +czN9bfI5G0KZ0agADz5LWAAA +ho/lDUk1MEiX91DNXOY2JAAA + + +False +-1.5707963267949 +10 +czN9bfI5G0KZ0agADz5LWAAA +ho/lDUk1MEiX91DNXOY2JAAA + + +1933 +968 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,991;1702,991 +5yig2AFjOEajXi3fbrN7VwAA +TbZv4vmixEauqpXIdyVNdgAA ++wCnW3yutEeNI63TdKQpkAAA + +clPurple +clPurple +1.5707963267949 +10 +OnShutdown +5yig2AFjOEajXi3fbrN7VwAA +6rc5yZyIPke1iL7nJLrUwQAA + + +False +1.5707963267949 +25 +5yig2AFjOEajXi3fbrN7VwAA +6rc5yZyIPke1iL7nJLrUwQAA + + +False +-1.5707963267949 +10 +5yig2AFjOEajXi3fbrN7VwAA +6rc5yZyIPke1iL7nJLrUwQAA + + +False +1702 +991 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +147,1028;620,1028 +z1QNUA0z7UCZuLoDVY19rgAA +mNvSnPlpGUa+X6DT/4CU0gAA +bgjtXzPElEqJn9pi84tImgAA + +clNavy +1.5707963267949 +10 +Stop() +z1QNUA0z7UCZuLoDVY19rgAA +22wrc8LEUkiANLhHOdNHUAAA + + +False +1.5707963267949 +25 +z1QNUA0z7UCZuLoDVY19rgAA +22wrc8LEUkiANLhHOdNHUAAA + + +False +-1.5707963267949 +10 +z1QNUA0z7UCZuLoDVY19rgAA +22wrc8LEUkiANLhHOdNHUAAA + + +620 +1028 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,1096;395,1096 +Wd9H4IjL3USBGC0pH5hlUQAA +yexABU1UCEy5R/KkGohcEQAA +mNvSnPlpGUa+X6DT/4CU0gAA + +clMaroon +1.5707963267949 +10 +OnShutdown() +Wd9H4IjL3USBGC0pH5hlUQAA +yZwXCIlw0UqzEEVqe995JgAA + + +False +1.5707963267949 +25 +Wd9H4IjL3USBGC0pH5hlUQAA +yZwXCIlw0UqzEEVqe995JgAA + + +False +-1.5707963267949 +10 +Wd9H4IjL3USBGC0pH5hlUQAA +yZwXCIlw0UqzEEVqe995JgAA + + +382 +1096 +14 +29 + + + + +51 + +new +listener +IServer +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +GKqHK7uaTEeoZL1eXATu1QAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +zj0gLe4XtU2J2bVhHsjKoQAA +JPS6dsyJR0S0TETjcdDPzQAA +ZqanKXSj20qoGWz9XhC9VQAA +Je5Rr6ZcME+IRLz17kornAAA + + +new +listener +IAgent +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +twaVQAbQn0SQxSav8hKGygAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +cCyZUo+qL02sb4GGEh3gwgAA +5BDr2UxqLE2GGjbTc+azDgAA +4WkxemYG00WYV5++zENhUgAA +Dl6jjpeXM0SMqkUGPmPexQAA + + +new +ITcpAgentListener +wQGBjVheXk6JUG6UyHLOLQAA +Amawaz/I9kSR3ZRprOaA0QAA + +UVJZlx7WuUW8BWRWnTMKVwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +9LSfj24cFU+rp+nfIoeHUwAA +adH2FYKfrkyalgzcHRESxwAA +HYjly1YVRUSu/I5FiSQYagAA +tfT8pva9kk6PQjxG1SFXLwAA + + +server +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +waLdiSPvU0aqFpb250AZIwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +aEtdljySnk+Jnw8H2MyfBAAA +rs+xJB8kQU2FIQspU4MfWgAA +16D6Hqt0VUyFa/bIyaOf/AAA +zEZdkaqUbUeUTwGXgtT3lQAA + + +agent +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +RjOELc899E24BqUs1P8w2gAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +hM4zK3J2M0qTbiDJg6DftgAA +rVafn85Q0UuQ8CT3kM8omgAA +fPZCy0QkUEuunewcn0EgMAAA +7jaNfsa5aUeweVVoMZEPoQAA + + +listener +Amawaz/I9kSR3ZRprOaA0QAA +wQGBjVheXk6JUG6UyHLOLQAA + +mpQYN0pghkiv6UDJsnfuWwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +YzPwOBpQpU2JgPIxj5MjdgAA +YSsHkmv/TEKDGOd/Agr68gAA +sSLq0Qpa8Uy9SdJwtifvYQAA +wVZ1QsXVuUWge/szkcqrKwAA + + +Start +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +u/hYdn97j0e2w7qGm8lrPQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +81Znj6ipLE+uQJdj3I3BjAAA +/myrcBq6xEmtPLopTIxvPQAA +tiLG7fP0K0Sei2XNjqspmgAA +lHRXGq0+iEyMcve/cNwqZQAA + + +Start +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +ge2n5wRT306cnabk/HU2IgAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +ONHfDMi2cE6eUYVGDXwgGwAA +7kaHO4BY+02bLmXX33d0MwAA +bm8tEGiHRk+kIwUDKneKFgAA +MyOXiblw7UuKuKCE1BW1bQAA + + +OnPrepareListen +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +KjbQrlapxE2xRsUF2q8bDwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +gHBXKkyxe0K1OBNbZXeV3wAA +tmtNQw9rKEyZzwwsb6nUFgAA ++mhVJ1ufakO4Io6g0KALRQAA +hsv35g4f2E+POf/gq4cfGQAA + + +new +True +listener +ITcpAgent +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +eiRtiRQwQU+VjHaN3rVhqAAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +TvRznbBpRE+w6+5JbXI1MQAA +XADN74LqR0yL0MGs32m/CwAA +Yq3P8NDISkWbBpzIALuaNAAA +Sw1pCgW9yUetluMmS7gJDQAA + + +agent +U2Za99rIrEi8z93FLSAjUAAA +wQGBjVheXk6JUG6UyHLOLQAA + +gc1T6rnMnUylWpF5/By8ZAAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +Mwl65WlBAkWLprLAGAE5rwAA +nFx0rlGSaESIT2wsAYwrPQAA +2whExSQQeUuKrz6NLE118wAA +SzfCPTfD2E6h57QE/gJ7RwAA + + +OnAccept +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +q1qjKctdRE2v7HKXDklokQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +aeW3gGFMI0i5mnoP8rzsewAA +IIBHLWCwIUiM6wuvyLWTmAAA +m0jDDCoTiEq8NwAytW11RQAA +QwmWvJMhaU6ewMykRWR9fAAA + + +Connect +Ta3rZIdU6E2pIcWjSM7HXgAA +ychpc6mSzUOyFf7vQMlVXAAA + +hhg1h6MW70ylqCivIbWRXQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +CAh9vY3mukOvRlolvYiXeQAA +JditL6P5Ik2/PtBBqUhmIQAA +MjulBGij+U+E5JpzHIJMEQAA +1a+zJ1XMukC/JACU+aBHpwAA + + +Connect +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +UiC+SdjuLkO6xrRIGFh2PAAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +x12y5MX61kSU8UEZBCKBzAAA +VAqAXQcyTEODbem67Ii8fQAA +oSni4e7TvEifqVqMkG8SIQAA +6lTcAQt1v0u6iPpCYWefkwAA + + +Start +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +3ll2HhKX0kq8L2WoIISIqQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +HnK/vetZsE2Zoo9YLGV1KgAA +Gnu7K7y05Ua+fA2/QxU5IgAA +KIsC249fQkanOGfrxCf1oQAA +sKtOLiHU8EyqnH3HBGyYoAAA + + +OnPrepareConnect +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +FYipeeoMCUm19jcfhm3biAAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +PMbi1EVd7kmNs8rUg0gpgwAA +HBvIQwHTJ0uhglpkMgdLZwAA +QO897OzHzUmfzk9SzWRNsAAA +xJSpv2Wxp029oO8YA4kxsgAA + + +OnConnect +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +/bHgYzIBqECI2mdaGkoJMwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +K1jfKNg6hUSMEfA71rVwswAA +oCuVcNdbjE+NevEDYO0iuAAA +aveAsSq3cEyTyKNgdNh0EQAA +7hRALDgv0UuWoSd7q9lcMQAA + + +Connect +lvD/j4YgmkG/Ov+o+mJZPQAA +HdPN0QWbYUq0xPzVpVWOdwAA + +NUW8ZK/ERk2X3umbnhegzwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +Uva/yeEJ00eMzNPCIyuWZAAA +o2Jo085TaU+VCg83m1yWjQAA +w/6FVGnluk6k+nxlAftAZQAA +9PYcNtOxfE63ie6AXXjTXAAA + + +Connect +address, port +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +qxo3boab2UKQT7Y0WGaO5wAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +eYJrYhPCEUS7T6jsSTfTGAAA +J/7B/bplR0mvdF2z/39NKQAA ++BQImtFl5EatTspYweostgAA +YaQ6jqrvlkGnm9TobP6zFgAA + + +OnReceive +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +xbH85UKQlESFWJculb723gAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +OLadb8YV2kW2/OneXcT5fAAA +pFjZq1ZbMESH4F1X0n00WgAA +eaKTRn/wnki9Mww6L7VskwAA +nyDC18c9sUGBz8ALFTYbkgAA + + +Send +Ta3rZIdU6E2pIcWjSM7HXgAA +ychpc6mSzUOyFf7vQMlVXAAA + +/VRCJTy/oEur+ilCjeW2XgAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +k+k1sVK/4kCTCrxJp3KZmAAA +vvS+hIfiFUm6pV7syiA4rQAA +XdA4bINjukiRzFUWcIGLowAA +1Lt0eShNTUOlP3C/pdWUTgAA + + +Send +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +3BL7NFdLw0yo7RLubFSFzQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +fRP4qNvR302+2rcIff42YQAA +TJCZs0i5lk2QArLRdXMFTAAA +4L0bDC+B/0quYVP/OUBkKgAA +bdgWKPJ1ZU2ukkIYbuZ6nQAA + + +OnPrepareConnect +connid +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +Wjv7v/0JW0SsHdI2VbWR+AAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +jEQTYK+V2062OgAJI9+KJgAA +2GVDb1w55kK7Kt9QHjl+GgAA +ZBiAeBth30mcnxI4RyM3UwAA +mtELRVGaxkinEIIebcCMXQAA + + +OnSend +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +oF/LEA7hx0qNduBcIVAMJQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 ++vTGrF2zx0OWj4eXWblGowAA +UsLKaDn/rUGVeWg1C7PYGQAA +1sjX7N6DF0WjS/QD9X7klAAA ++GEqcbO4pUKGYA3Uj/mD3QAA + + +Send +lvD/j4YgmkG/Ov+o+mJZPQAA +HdPN0QWbYUq0xPzVpVWOdwAA + +1vb2mQKxZ0+r/MA4zbJgbwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +QO8N1X6VLky4cZtNH/bVqQAA +zkJB78q7jkqBrdF/ry/wBAAA +GNk3vPcGuUuUSwZa/fZFpgAA +qgdZ0W1woUWyjYnM4VnhPQAA + + +OnConnect +connid +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +8p8OEDcPcEqcPclkWC6twgAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +H7uvq6t59UCNEZljpwH1GAAA +yyo4rDEn9UaB9eUEd8vL+gAA +9yN+sJlAXUaiAVf+v1bolwAA +VvhqIlxoyEGpkMlfcdG7gwAA + + +Send +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +kAJ6OYlT5kSWgt6Y8JB6KQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +/VoO4MkQoUqEWr+dUv9R5AAA +LJJLuZaXzEeLvU3XHUrhRQAA +B9hleoGfzECx9CLckvq+pQAA +6NyJKCu7Kk6h1SB0oTjcZwAA + + +OnSend +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +0exvc+RmxE++FLqQZ+YzawAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +9lFefDL9EkGWx+GRTnrIZgAA +jHCDw9k5Xk+hiM0YqiH1rQAA +AKsxD1v0bEmrSHsp1AbdeAAA +tpbUDxCgIUu9Z6vKJx46gAAA + + +Send +ychpc6mSzUOyFf7vQMlVXAAA +Ta3rZIdU6E2pIcWjSM7HXgAA + +9Ol7xVDHfk+aOrYlU/XxDAAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +s2d3Z0E0+kKI8W+SNgARXAAA +z6hiLqsAU0qBnwR7Kwix4gAA +i8Gf/qjfe06+Y0Kpv0nKHwAA +ld3ZSL54xUqFQKEv+ME5HwAA + + +Send +connid, data, length +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +0gQj+YWF1kWUYfNhSvBRRgAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +niqU3lxUj06wxkIb2xcgfwAA +dDj9hguQmkCxZuYWFRvM7AAA +tzhYB0FLd0GBlk2f5puN3wAA ++2CLfHE+0UOCiArnLrpPuQAA + + +OnReceive +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +mErn0SwL4kWgwh37KhxrOwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +YkEmXAqy9EevsUZJVhd0hwAA +SrnbMXO510mGYeFjYmesgAAA +jR+Zo152ukOhmQUFHgu1bgAA +nLknQDEGmEiWRkv3ssdsjAAA + + +Send +HdPN0QWbYUq0xPzVpVWOdwAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +PSWE8W0TEU+2XvyhDfkDzgAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +CWRCDraG50e3xZDvX5vLpQAA +O/BpHz9Gb0Odl8wHkJCIvwAA +w9Put6+2Tkqjc28U1Q1U/gAA +36FP6B4zL0acXLrWYxWStAAA + + +OnClose +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +1hZ1Ivgi7UWnVEcQGQ9xdwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +KbnvIzhjfEWFVgq1gekqXAAA +lXWksQSw0kyHBODybSFoQQAA +lpCc05pDQEqW+QI1AVMyQQAA +qW/5pdGBq0yaWXDi91oiJwAA + + +Disconnect +Ta3rZIdU6E2pIcWjSM7HXgAA +ychpc6mSzUOyFf7vQMlVXAAA + +aXyZYOKcl0mBOwUqTqobmgAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +zMOiSN3GsEiMtDJA5EV00wAA +MTlv1P/9w0+CRwN8hRfcQwAA +qh85j/NI0EKdrEp/rr24KgAA +WWihkitawUC7one9xWDNYwAA + + +OnSend +connid, data, length +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +5CQCgkQMiEa8EdVYKZGhowAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +YpPwITXi7ESS5zzS/nJtdgAA +kHAC5hzRrUWpsmuF50Yu6wAA +bvOfd5kqi0ifMT1kybOjtgAA +9NpUk7LdMEKMEPy2NsKO7wAA + + +OnClose +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +9lUxZSoXvkOOzpV4doFFPwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +YfuBDr8+XEGC/f0KAwYlMwAA +xdjIVxNnmkyM2UQnq4FysQAA +FU0yH1z+Dku67wjOJAcXbQAA +sY5Mfi7IN0aIVe6G6gdJFgAA + + +Disconnect +HdPN0QWbYUq0xPzVpVWOdwAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +79YTw4PBt0qttSuIpUL7HQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +y1T7PceGOk+3n0Ql8l12UgAA +lr7f5rkS4U28S5RNBnv7hwAA +zVFuIqPvgUyYw6O2DF6MvAAA +5gwHY3cWVU66igOu25UWSwAA + + +Disconnect +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +RakUMYixx0eokaMaO8399AAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +H0hhU481MUSlr+PpVelBqwAA +xGz+ImSquUKDQSaxXLQKVwAA +7mm2IIo0TkWCevHiDB4JmgAA +qAgFncPmQE2ZWPpG8HddIAAA + + +OnReceive +connid, data, length +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +OtUn1tUnHUiiI6GLtYamBwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +vPOw9w4yJE+eo3dYsSWrBAAA +DbKDs8tc+kKuuhKhjZW/VgAA +DEtQNtRXKk+nduo9seSpKgAA +7i3FK2/b7kywkAScUyygZQAA + + +OnClose +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +qB+snL4IlEeGy2CTYMy/zAAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +mYJo9K+KDEi+F3GgmHC8MAAA +n9vn/+4SEkG6P0KUCdO7XAAA +D+KSu7v3vUWfMW/oraC5DwAA +JBJGrWtRyEqg1dvtwSi8VAAA + + +Disconnect +ychpc6mSzUOyFf7vQMlVXAAA +Ta3rZIdU6E2pIcWjSM7HXgAA + +Mj5U0wte/Ui52pM+Nh0WIgAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +vmvOU5NFGkOJH7BYW+rfLQAA +rb7nJ3k3N0SXzGhWpmEMFAAA +Zsn/hmLJZEaoH26Ro+LfWAAA +HdXCZ5ftBU6J6HpOmUbdpgAA + + +Disconnect +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +pvIA8HpUU0eAf/CRON6ISQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +iS+1y0N6I0eiK+0IWQQe2gAA +svQBVOXNmEuD5KRG0KfnuQAA +2noN6gwumkSSmO6oQe/r7AAA +4xM4qcc3lEaq5sMZ0CDFRAAA + + +Disconnect +lvD/j4YgmkG/Ov+o+mJZPQAA +HdPN0QWbYUq0xPzVpVWOdwAA + +bylpP6WP+0+xDkDWbCho6AAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +yP78nj+bZk+75vsYWcgXGwAA +oqjFX/ItXUCjjNXrUKrPiwAA +ZwD+4FwZ2E6Jy/y3iJ3sEAAA +Eup3YayPyk6JbQ01HJtm9QAA + + +OnClose +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +yCsrGZ0ZX0eRnh7MrDJ8fwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +GW3/+fr0HEewn0AavM5PHQAA +FdUsqHDQ8kqufHHLTEbmcQAA +++Lj7iGzyUadL57vltYqvQAA +nKKtrvfqY0WlxSB5hyveDAAA + + +Stop +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +PT5rHARWmkS/g4IqVuPQbwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +WfhIgUdxekSnY02eBkGaEgAA +RYmf2kDuTEK2Xn1L9ajTAQAA +qeYAD1I22Eyim9QV76lhNQAA +UMWLm9bYhUG5dUTM3d5qjgAA + + +OnClose +connid, operation, code +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +/HUsBl+/S0CY4MtM5ABl2AAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +WTcgBUL5lk60yTAJ6+Ym8QAA +J6I+dWrx7Ua2SbtCjs3YFgAA +j+iLrvCC5k2UrJ6sQ7n8ZQAA +o0ElvhM91UWXyVUooJcBQwAA + + +OnShutdown +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +yyMM+2gkDEehAYP+raNxDQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +ElAEbekWtEO22kTeSu21VgAA +WR7n+diPW0i8OU/W1dOqZAAA +GKseBx4vKUaINOg0C13ktQAA +h8YqzT7w2keY+iSJ3Jr8pwAA + + +Stop +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +czN9bfI5G0KZ0agADz5LWAAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +ho/lDUk1MEiX91DNXOY2JAAA +kj3VrllJ+kWD5hBi6m4/wwAA +0AOGfRQZSUaa//8NgIkn9gAA +a3BDEmT6Yk6WsyJh6e0cyAAA + + +OnShutdown +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +5yig2AFjOEajXi3fbrN7VwAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +6rc5yZyIPke1iL7nJLrUwQAA ++KLaCxqQNk+yGrn6BMdRNwAA +qwOZUUArg06rrUzTZQqcpQAA +hw2mGCmZy02gVtzw4rXkSQAA + + +Stop +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +z1QNUA0z7UCZuLoDVY19rgAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +22wrc8LEUkiANLhHOdNHUAAA +1+kFroMKOkWnsfw9YjaasAAA +eG1Nd5Qda0aIwLI+KVJd5AAA +riOjVPDKCUCNJ5sCvbehqAAA + + +OnShutdown +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +Wd9H4IjL3USBGC0pH5hlUQAA + +1QTFfJIkv0Oe+uLEcmTfCQAA +4 +yZwXCIlw0UqzEEVqe995JgAA +Up9ZIRzyykG/r3XiA56qxAAA +VVrFXPo2DES5ogdhhTDaxwAA +lkgWgMB0oEaX1HYmp2yiiQAA + +3 + +Listener & Agent +Create +1QTFfJIkv0Oe+uLEcmTfCQAA + + +Frame1 +sd +1QTFfJIkv0Oe+uLEcmTfCQAA + + +Frame2 +sd +1QTFfJIkv0Oe+uLEcmTfCQAA + + + +Sample-2 +5Xea+2Ha3kuZqH6rjIWf7AAA +1 + +Sample +False +mskNameAndType +0VTzN8sts0yg55EvvKzPQAAA + +1eO85Ua7aE+CmBmmIDDxDAAA +80 + +clMaroon +$00B9FFFF +88 +120 +119 +1069 +wQGBjVheXk6JUG6UyHLOLQAA + + +4 +My Logic Controller + + +False + + +False + + + +wQGBjVheXk6JUG6UyHLOLQAA + + + +clMaroon +$00B9FFFF +320 +120 +139 +1073 +Amawaz/I9kSR3ZRprOaA0QAA + + +4 +My TCP Agent Listener + + +False + + +False + + + +Amawaz/I9kSR3ZRprOaA0QAA + + + +clMaroon +$00E3C8C8 +592 +120 +70 +1073 +U2Za99rIrEi8z93FLSAjUAAA + + +4 +TCP Agent + + +False + + +False + + + +U2Za99rIrEi8z93FLSAjUAAA + + + +$00F0E1FF +900 +120 +114 +869 +j+NgCUOjNE2kmFd3hYSIegAA + + +4 +Server Application + + +False + + +False + + + +j+NgCUOjNE2kmFd3hYSIegAA + + + +clMaroon +$00E6CCCC +1148 +120 +117 +869 +ychpc6mSzUOyFf7vQMlVXAAA + + +4 +Server Component + + +False + + +False + + + +ychpc6mSzUOyFf7vQMlVXAAA + + + +clMaroon +$00B9FFFF +1404 +120 +108 +869 +Ta3rZIdU6E2pIcWjSM7HXgAA + + +4 +Client Application + + +False + + +False + + + +Ta3rZIdU6E2pIcWjSM7HXgAA + + + +clMaroon +$00FFD7FF +1648 +116 +108 +721 +rscStAuJEkiUAz9WikX0hQAA + + +4 +Client Application + + +False + + +False + + + +rscStAuJEkiUAz9WikX0hQAA + + + +clMaroon +$00E6CCCC +1884 +116 +112 +721 +lvD/j4YgmkG/Ov+o+mJZPQAA + + +4 +Client Component + + +False + + +False + + + +lvD/j4YgmkG/Ov+o+mJZPQAA + + + +clMaroon +$00B9FFFF +2116 +116 +114 +721 +HdPN0QWbYUq0xPzVpVWOdwAA + + +4 +Server Application + + +False + + +False + + + +HdPN0QWbYUq0xPzVpVWOdwAA + + + +clMaroon +$00B9FFFF +lsRectilinear +1702,212;1933,212 +tmMPWz926keOYRK7CfB+ogAA +LtIPm701qEiKOEIQzsRsigAA +yRcxWVCafEypCOzoqyZd9wAA + +1.5707963267949 +10 +IClient := new(listener) +tmMPWz926keOYRK7CfB+ogAA +zn6D2ECw+Eu8AUGWOyBeGwAA + + +1.5707963267949 +25 +<<create>> +tmMPWz926keOYRK7CfB+ogAA +zn6D2ECw+Eu8AUGWOyBeGwAA + + +False +-1.5707963267949 +10 +tmMPWz926keOYRK7CfB+ogAA +zn6D2ECw+Eu8AUGWOyBeGwAA + + +1933 +212 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +957,213;1199,213 +gAVKOFcG5Uy+DJqh3e+rmQAA +SGclKA1c/EeIKpRjr6adVAAA +fB7Q+DVBWE6rQM2gSNHKZAAA + +1.5707963267949 +10 +IServer := new(listener) +gAVKOFcG5Uy+DJqh3e+rmQAA +Ao9U+ysX4kSHNAEgs/GP6QAA + + +1.5707963267949 +25 +<<create>> +gAVKOFcG5Uy+DJqh3e+rmQAA +Ao9U+ysX4kSHNAEgs/GP6QAA + + +False +-1.5707963267949 +10 +gAVKOFcG5Uy+DJqh3e+rmQAA +Ao9U+ysX4kSHNAEgs/GP6QAA + + +1199 +213 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +147,224;382,224 +u0t7NrBh2EmsnM1kDsHdBwAA +enASZyLbhUip3579An5eRwAA +gtOTyYM9IUenocj7Nq/rCQAA + +1.5707963267949 +10 +ITcpAgentListener := new() +u0t7NrBh2EmsnM1kDsHdBwAA +1lwIUuEn1UievyHx8P6L4wAA + + +1.5707963267949 +25 +<<create>> +u0t7NrBh2EmsnM1kDsHdBwAA +1lwIUuEn1UievyHx8P6L4wAA + + +False +-1.5707963267949 +10 +u0t7NrBh2EmsnM1kDsHdBwAA +1lwIUuEn1UievyHx8P6L4wAA + + +382 +224 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +1933,238;1702,238 +qdFUCd8ppUytkbv1kQ22KAAA +yRcxWVCafEypCOzoqyZd9wAA +LtIPm701qEiKOEIQzsRsigAA + +1.5707963267949 +10 +client +qdFUCd8ppUytkbv1kQ22KAAA +BRZi89k2FkSJZxAOYzWP1wAA + + +False +1.5707963267949 +25 +qdFUCd8ppUytkbv1kQ22KAAA +BRZi89k2FkSJZxAOYzWP1wAA + + +False +-1.5707963267949 +10 +qdFUCd8ppUytkbv1kQ22KAAA +BRZi89k2FkSJZxAOYzWP1wAA + + +False +1702 +238 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +1199,240;957,240 +pPAAy86kd0iPjz3jRkE7GQAA +fB7Q+DVBWE6rQM2gSNHKZAAA +SGclKA1c/EeIKpRjr6adVAAA + +1.5707963267949 +10 +server +pPAAy86kd0iPjz3jRkE7GQAA +WM1BZGw83E6VMbBt8/T9sQAA + + +False +1.5707963267949 +25 +pPAAy86kd0iPjz3jRkE7GQAA +WM1BZGw83E6VMbBt8/T9sQAA + + +False +-1.5707963267949 +10 +pPAAy86kd0iPjz3jRkE7GQAA +WM1BZGw83E6VMbBt8/T9sQAA + + +False +957 +240 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +382,251;147,251 +zvjkh/olMkKz8fshUqs1/gAA +gtOTyYM9IUenocj7Nq/rCQAA +enASZyLbhUip3579An5eRwAA + +1.5707963267949 +10 +listener +zvjkh/olMkKz8fshUqs1/gAA +DYmXwHQZ1EmVy87fdA6qaAAA + + +False +1.5707963267949 +25 +zvjkh/olMkKz8fshUqs1/gAA +DYmXwHQZ1EmVy87fdA6qaAAA + + +False +-1.5707963267949 +10 +zvjkh/olMkKz8fshUqs1/gAA +DYmXwHQZ1EmVy87fdA6qaAAA + + +False +147 +251 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +957,294;1199,294 +X5T4GSZ++0CHKCiad7lJUQAA +SGclKA1c/EeIKpRjr6adVAAA +fB7Q+DVBWE6rQM2gSNHKZAAA + +clBlue +1.5707963267949 +10 +Start() +X5T4GSZ++0CHKCiad7lJUQAA ++k4sIdNc60iYAznNneRuzAAA + + +False +1.5707963267949 +25 +X5T4GSZ++0CHKCiad7lJUQAA ++k4sIdNc60iYAznNneRuzAAA + + +False +-1.5707963267949 +10 +X5T4GSZ++0CHKCiad7lJUQAA ++k4sIdNc60iYAznNneRuzAAA + + +1199 +294 +14 +29 + + + +clMaroon +$00E6FFE6 +456 +220 +157 +26 +Create Agent & Listener + + + +clMaroon +$00B9FFFF +395,238;456,235 +bCJ1ECd090uoeesdImvAtwAA +n8Oamnaks0SQAmULrnFbtwAA + + +clMaroon +$00E6FFE6 +468 +384 +85 +26 +Start Agent + + + +clMaroon +$00B9FFFF +620,326;546,245 +bCJ1ECd090uoeesdImvAtwAA +1J2E71dFJU6aD0fXxGzREQAA + + +clMaroon +$00B9FFFF +620,441;542,409 +r1SWHJiuP0itPzuWN37uqgAA +9m6ILnZ8Z0S9Ff0U96FlaQAA + + +clMaroon +$00E6FFE6 +188 +524 +126 +26 +Connect Operation + + + +clMaroon +$00B9FFFF +620,509;313,531 +A916pNDvKEGTFZHx/Ck4dgAA +7D9JKOoLAESLpIhVa53E3wAA + + +clMaroon +$00B9FFFF +382,569;365,568 +Kr0N0BpfW0Cg11vT+gcZsgAA +i2f7IUfB0UWsx3DkfV+l8QAA + + +clMaroon +$00B9FFFF +382,628;300,605 +9gXroG5q0k2cucuDVv5AXwAA +hAerel7D8U+RjQwj6HfIYgAA + + +clMaroon +$00E6FFE6 +188 +692 +109 +26 +Send Operation + + + +clMaroon +$00B9FFFF +620,690;296,702 +yGbmL5jJH0+N9AUwam7DAgAA +fcOyNWhlxkmyd/5Q+wTqzQAA + + +clMaroon +$00E6FFE6 +188 +552 +178 +26 +OnPrepareConnect Callback + + + +clMaroon +$00E6FFE6 +188 +580 +133 +26 +OnConnect Callback + + + +clMaroon +$00E6FFE6 +188 +720 +116 +26 +OnSend Callback + + + +clMaroon +$00B9FFFF +382,745;303,738 +5Clgm8hWj06fWrFNpgvqiwAA +Q2jStGS9pkWxKk+UAfZlQwAA + + +clMaroon +$00E6FFE6 +188 +816 +131 +26 +OnReceive Callback + + + +clMaroon +$00B9FFFF +382,842;318,835 +wRqkAPk8PUmO+Wi8C5ajEgAA +TRn4IjU5Gka2jzbvlUZITwAA + + +clMaroon +$00E6FFE6 +188 +912 +120 +26 +OnClose Callback + + + +clMaroon +$00E6FFE6 +188 +1044 +117 +26 +Stop Operation + + + +clMaroon +$00E6FFE6 +188 +1084 +177 +26 +OnShutdown Callback + + + +clMaroon +$00B9FFFF +382,941;307,932 +Dh/cbggyFUyNBo/dwEzONQAA +JvJxpBl0rE2BbyPdNUO/7AAA + + +clMaroon +$00B9FFFF +620,1042;304,1054 +a5JimTSJfke4sOm54DQZiAAA +RejPp2NOp0WsoSvmo1IUVAAA + + +clMaroon +$00B9FFFF +382,1109;364,1107 +xKg65AOpQUaq+6kouozyZQAA +s4gyVY5Z1kayHLiVL7C2OwAA + + +clBlue +$00B9FFFF +lsRectilinear +1702,296;1933,296 +i0okbOG+V0Wy21SEhlS3YQAA +LtIPm701qEiKOEIQzsRsigAA +yRcxWVCafEypCOzoqyZd9wAA + +clBlue +1.5707963267949 +10 +Start() +i0okbOG+V0Wy21SEhlS3YQAA +XwaiI/v6qkC56jzj/IhW6gAA + + +False +1.5707963267949 +25 +i0okbOG+V0Wy21SEhlS3YQAA +XwaiI/v6qkC56jzj/IhW6gAA + + +False +-1.5707963267949 +10 +i0okbOG+V0Wy21SEhlS3YQAA +XwaiI/v6qkC56jzj/IhW6gAA + + +1933 +296 +14 +57 + + + +clPurple +$00B9FFFF +lsRectilinear +1199,318;957,318 +zinYWd6ATEavjMBO+/H28wAA +fB7Q+DVBWE6rQM2gSNHKZAAA +SGclKA1c/EeIKpRjr6adVAAA + +clPurple +1.5707963267949 +10 +OnPrepareListen +zinYWd6ATEavjMBO+/H28wAA +rJ5GoZYRJEyEcqM/vzPmHQAA + + +False +1.5707963267949 +25 +zinYWd6ATEavjMBO+/H28wAA +rJ5GoZYRJEyEcqM/vzPmHQAA + + +False +-1.5707963267949 +10 +zinYWd6ATEavjMBO+/H28wAA +rJ5GoZYRJEyEcqM/vzPmHQAA + + +False +957 +318 +14 +29 + + + +clMaroon +$00B9FFFF +lsRectilinear +147,319;620,319 +IGSCEi76fECYOq9TAgfycAAA +BexDoaFUEkCBpmk29zrEggAA +gtOTyYM9IUenocj7Nq/rCQAA + +1.5707963267949 +10 +ITcpAgent := new(listener) +IGSCEi76fECYOq9TAgfycAAA +gswhi/yQlEyni0BQeCu9YAAA + + +1.5707963267949 +25 +<<create>> +IGSCEi76fECYOq9TAgfycAAA +gswhi/yQlEyni0BQeCu9YAAA + + +False +-1.5707963267949 +10 +IGSCEi76fECYOq9TAgfycAAA +gswhi/yQlEyni0BQeCu9YAAA + + +620 +319 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,322;1702,322 +cMDdajmI+EqZX7e2IJLW2AAA +yRcxWVCafEypCOzoqyZd9wAA +LtIPm701qEiKOEIQzsRsigAA + +clPurple +clPurple +1.5707963267949 +10 +OnPrepareConnect +cMDdajmI+EqZX7e2IJLW2AAA +HhmcyDgFYkeEUyKoPJYJawAA + + +False +1.5707963267949 +25 +cMDdajmI+EqZX7e2IJLW2AAA +HhmcyDgFYkeEUyKoPJYJawAA + + +False +-1.5707963267949 +10 +cMDdajmI+EqZX7e2IJLW2AAA +HhmcyDgFYkeEUyKoPJYJawAA + + +False +1702 +322 +14 +56 + + + +clMaroon +$00B9FFFF +lsRectilinear +620,346;147,346 +YB6eaJtPCk2AGSgtffbdcAAA +gtOTyYM9IUenocj7Nq/rCQAA +BexDoaFUEkCBpmk29zrEggAA + +1.5707963267949 +10 +agent +YB6eaJtPCk2AGSgtffbdcAAA +pJ8aa9482EKLz1EwjSpJ2wAA + + +False +1.5707963267949 +25 +YB6eaJtPCk2AGSgtffbdcAAA +pJ8aa9482EKLz1EwjSpJ2wAA + + +False +-1.5707963267949 +10 +YB6eaJtPCk2AGSgtffbdcAAA +pJ8aa9482EKLz1EwjSpJ2wAA + + +False +147 +346 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,349;1702,349 +oz9VGOLnCUChZ5znyjLuEAAA +yRcxWVCafEypCOzoqyZd9wAA +LtIPm701qEiKOEIQzsRsigAA + +clPurple +clPurple +1.5707963267949 +10 +OnConnect +oz9VGOLnCUChZ5znyjLuEAAA +KBRuOTWQb0Kxs3sxGmlxTQAA + + +False +1.5707963267949 +25 +oz9VGOLnCUChZ5znyjLuEAAA +KBRuOTWQb0Kxs3sxGmlxTQAA + + +False +-1.5707963267949 +10 +oz9VGOLnCUChZ5znyjLuEAAA +KBRuOTWQb0Kxs3sxGmlxTQAA + + +False +1702 +349 +14 +29 + + + +$00B9FFFF +lsRectilinear +1946,349;2173,349 +qOZhBu7iv0295TZDqlzApwAA +mw7/rLkCOEGcLiEDsPSp6QAA +LtIPm701qEiKOEIQzsRsigAA + +1.5707963267949 +10 +Connect +qOZhBu7iv0295TZDqlzApwAA ++UbCYBTI3kar1x77pEFNtgAA + + +False +1.5707963267949 +25 +qOZhBu7iv0295TZDqlzApwAA ++UbCYBTI3kar1x77pEFNtgAA + + +False +-1.5707963267949 +10 +qOZhBu7iv0295TZDqlzApwAA ++UbCYBTI3kar1x77pEFNtgAA + + +False +2173 +349 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1206,399;957,399 +R2zIGFrlCEKaKzyvT7GYSQAA +fB7Q+DVBWE6rQM2gSNHKZAAA +SGclKA1c/EeIKpRjr6adVAAA + +clPurple +1.5707963267949 +10 +OnAccept +R2zIGFrlCEKaKzyvT7GYSQAA +7Khq9w8CGEqNyK9jPATR7wAA + + +False +1.5707963267949 +25 +R2zIGFrlCEKaKzyvT7GYSQAA +7Khq9w8CGEqNyK9jPATR7wAA + + +False +-1.5707963267949 +10 +R2zIGFrlCEKaKzyvT7GYSQAA +7Khq9w8CGEqNyK9jPATR7wAA + + +False +957 +399 +14 +29 + + + +$00B9FFFF +lsRectilinear +1458,399;1206,399 +1zvjlDg+4kCIQVSgL1zDcQAA +SGclKA1c/EeIKpRjr6adVAAA +04EYjXxjXESV7JyM0501yQAA + +1.5707963267949 +10 +Connect +1zvjlDg+4kCIQVSgL1zDcQAA +F51H4/s89UGOD6UgisZ6rQAA + + +False +1.5707963267949 +25 +1zvjlDg+4kCIQVSgL1zDcQAA +F51H4/s89UGOD6UgisZ6rQAA + + +False +-1.5707963267949 +10 +1zvjlDg+4kCIQVSgL1zDcQAA +F51H4/s89UGOD6UgisZ6rQAA + + +False +1206 +399 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +147,429;620,429 +4hoSWcXUfke9LteCU5kIwwAA +BexDoaFUEkCBpmk29zrEggAA +gtOTyYM9IUenocj7Nq/rCQAA + +clNavy +1.5707963267949 +10 +Start() +4hoSWcXUfke9LteCU5kIwwAA +6Uog5bXZhUiHM0gZRpNlmgAA + + +False +1.5707963267949 +25 +4hoSWcXUfke9LteCU5kIwwAA +6Uog5bXZhUiHM0gZRpNlmgAA + + +False +-1.5707963267949 +10 +4hoSWcXUfke9LteCU5kIwwAA +6Uog5bXZhUiHM0gZRpNlmgAA + + +620 +429 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +1702,440;1933,440 +wjXK0j1It0OH0yUKkwb+BQAA +LtIPm701qEiKOEIQzsRsigAA +yRcxWVCafEypCOzoqyZd9wAA + +clBlue +1.5707963267949 +10 +Send() +wjXK0j1It0OH0yUKkwb+BQAA +ZTNKB8pelUiJllAFqF5yvgAA + + +False +1.5707963267949 +25 +wjXK0j1It0OH0yUKkwb+BQAA +ZTNKB8pelUiJllAFqF5yvgAA + + +False +-1.5707963267949 +10 +wjXK0j1It0OH0yUKkwb+BQAA +ZTNKB8pelUiJllAFqF5yvgAA + + +1933 +440 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,464;1702,464 +hJJRrn7qSU+4yKjjptTojAAA +yRcxWVCafEypCOzoqyZd9wAA +LtIPm701qEiKOEIQzsRsigAA + +clPurple +clPurple +1.5707963267949 +10 +OnSend +hJJRrn7qSU+4yKjjptTojAAA +7j6N8nOtAEmB8NfiHrmbIQAA + + +False +1.5707963267949 +25 +hJJRrn7qSU+4yKjjptTojAAA +7j6N8nOtAEmB8NfiHrmbIQAA + + +False +-1.5707963267949 +10 +hJJRrn7qSU+4yKjjptTojAAA +7j6N8nOtAEmB8NfiHrmbIQAA + + +False +1702 +464 +14 +29 + + + +$00B9FFFF +lsRectilinear +1946,464;2173,464 +Eg1/ELcHik2Up68uZHh8yQAA +mw7/rLkCOEGcLiEDsPSp6QAA +LtIPm701qEiKOEIQzsRsigAA + +1.5707963267949 +10 +Send +Eg1/ELcHik2Up68uZHh8yQAA +ATDOv2t9gEOu+eLMb9R4UAAA + + +False +1.5707963267949 +25 +Eg1/ELcHik2Up68uZHh8yQAA +ATDOv2t9gEOu+eLMb9R4UAAA + + +False +-1.5707963267949 +10 +Eg1/ELcHik2Up68uZHh8yQAA +ATDOv2t9gEOu+eLMb9R4UAAA + + +False +2173 +464 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +147,495;620,495 +Dd01nPPtvUmZGMmaii+l8AAA +BexDoaFUEkCBpmk29zrEggAA +gtOTyYM9IUenocj7Nq/rCQAA + +clNavy +1.5707963267949 +10 +Connect(address, port) +Dd01nPPtvUmZGMmaii+l8AAA +6z8juZwgW0+ApkebzIIVqwAA + + +False +1.5707963267949 +25 +Dd01nPPtvUmZGMmaii+l8AAA +6z8juZwgW0+ApkebzIIVqwAA + + +False +-1.5707963267949 +10 +Dd01nPPtvUmZGMmaii+l8AAA +6z8juZwgW0+ApkebzIIVqwAA + + +620 +495 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1206,507;957,507 +yEyx+76l70agEtERTC8A3gAA +fB7Q+DVBWE6rQM2gSNHKZAAA +SGclKA1c/EeIKpRjr6adVAAA + +clPurple +1.5707963267949 +10 +OnReceive +yEyx+76l70agEtERTC8A3gAA +dHhE0pvmZ02JicuvK5SN+gAA + + +False +1.5707963267949 +25 +yEyx+76l70agEtERTC8A3gAA +dHhE0pvmZ02JicuvK5SN+gAA + + +False +-1.5707963267949 +10 +yEyx+76l70agEtERTC8A3gAA +dHhE0pvmZ02JicuvK5SN+gAA + + +False +957 +507 +14 +29 + + + +$00B9FFFF +lsRectilinear +1458,507;1206,507 +wb7PgcS43U24SfLIi+31YQAA +SGclKA1c/EeIKpRjr6adVAAA +04EYjXxjXESV7JyM0501yQAA + +1.5707963267949 +10 +Send +wb7PgcS43U24SfLIi+31YQAA +smpZhVwRukGySgvtPqsUxAAA + + +False +1.5707963267949 +25 +wb7PgcS43U24SfLIi+31YQAA +smpZhVwRukGySgvtPqsUxAAA + + +False +-1.5707963267949 +10 +wb7PgcS43U24SfLIi+31YQAA +smpZhVwRukGySgvtPqsUxAAA + + +False +1206 +507 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,555;395,555 +jQfI7z+Tv0umyvJ5ac6g1wAA +enASZyLbhUip3579An5eRwAA +BexDoaFUEkCBpmk29zrEggAA + +clMaroon +1.5707963267949 +10 +OnPrepareConnect(connid) +jQfI7z+Tv0umyvJ5ac6g1wAA +tfIWfLElhUuRVt22cXDBeAAA + + +False +1.5707963267949 +25 +jQfI7z+Tv0umyvJ5ac6g1wAA +tfIWfLElhUuRVt22cXDBeAAA + + +False +-1.5707963267949 +10 +jQfI7z+Tv0umyvJ5ac6g1wAA +tfIWfLElhUuRVt22cXDBeAAA + + +382 +555 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1940,568;1702,568 +N9pXJsZRlUmaybf6IJQ4mgAA +yRcxWVCafEypCOzoqyZd9wAA +LtIPm701qEiKOEIQzsRsigAA + +clPurple +clPurple +1.5707963267949 +10 +OnReceive +N9pXJsZRlUmaybf6IJQ4mgAA +dDCiuxW8s0y6Luz8hDGRlAAA + + +False +1.5707963267949 +25 +N9pXJsZRlUmaybf6IJQ4mgAA +dDCiuxW8s0y6Luz8hDGRlAAA + + +False +-1.5707963267949 +10 +N9pXJsZRlUmaybf6IJQ4mgAA +dDCiuxW8s0y6Luz8hDGRlAAA + + +False +1702 +568 +14 +29 + + + +$00B9FFFF +lsRectilinear +2173,568;1940,568 +Z5SRL0VyAk2BAVlOyee2QwAA +LtIPm701qEiKOEIQzsRsigAA +mw7/rLkCOEGcLiEDsPSp6QAA + +1.5707963267949 +10 +Send +Z5SRL0VyAk2BAVlOyee2QwAA +/JeU3JlGDEeacIe+5aDr1AAA + + +False +1.5707963267949 +25 +Z5SRL0VyAk2BAVlOyee2QwAA +/JeU3JlGDEeacIe+5aDr1AAA + + +False +-1.5707963267949 +10 +Z5SRL0VyAk2BAVlOyee2QwAA +/JeU3JlGDEeacIe+5aDr1AAA + + +False +1940 +568 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,616;395,616 +JunGTRMAMEuAy1IqCOHccQAA +enASZyLbhUip3579An5eRwAA +BexDoaFUEkCBpmk29zrEggAA + +clMaroon +1.5707963267949 +10 +OnConnect(connid) +JunGTRMAMEuAy1IqCOHccQAA +PPhh4IC3sku4vCK4K8qUbQAA + + +False +1.5707963267949 +25 +JunGTRMAMEuAy1IqCOHccQAA +PPhh4IC3sku4vCK4K8qUbQAA + + +False +-1.5707963267949 +10 +JunGTRMAMEuAy1IqCOHccQAA +PPhh4IC3sku4vCK4K8qUbQAA + + +382 +616 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +957,620;1199,620 +02A3b3ioX0qlnvJtx6cIagAA +SGclKA1c/EeIKpRjr6adVAAA +fB7Q+DVBWE6rQM2gSNHKZAAA + +clBlue +1.5707963267949 +10 +Send() +02A3b3ioX0qlnvJtx6cIagAA +S1Kxo90uOEePeIXzh9h+ZwAA + + +False +1.5707963267949 +25 +02A3b3ioX0qlnvJtx6cIagAA +S1Kxo90uOEePeIXzh9h+ZwAA + + +False +-1.5707963267949 +10 +02A3b3ioX0qlnvJtx6cIagAA +S1Kxo90uOEePeIXzh9h+ZwAA + + +1199 +620 +14 +33 + + + +clPurple +$00B9FFFF +lsRectilinear +1199,648;957,648 +gEtk/cB3KEOiz2OMHIXtXQAA +fB7Q+DVBWE6rQM2gSNHKZAAA +SGclKA1c/EeIKpRjr6adVAAA + +clPurple +1.5707963267949 +10 +OnSend +gEtk/cB3KEOiz2OMHIXtXQAA +q6ROVMPvT06hHZhtrvcFGQAA + + +False +1.5707963267949 +25 +gEtk/cB3KEOiz2OMHIXtXQAA +q6ROVMPvT06hHZhtrvcFGQAA + + +False +-1.5707963267949 +10 +gEtk/cB3KEOiz2OMHIXtXQAA +q6ROVMPvT06hHZhtrvcFGQAA + + +False +957 +648 +14 +29 + + + +$00B9FFFF +lsRectilinear +1212,648;1458,648 +jfHJN6N3Q0mtnffCkx/XNAAA +04EYjXxjXESV7JyM0501yQAA +SGclKA1c/EeIKpRjr6adVAAA + +1.5707963267949 +10 +Send +jfHJN6N3Q0mtnffCkx/XNAAA +coQmEVUSeEa7og7ZhhbDBwAA + + +False +1.5707963267949 +25 +jfHJN6N3Q0mtnffCkx/XNAAA +coQmEVUSeEa7og7ZhhbDBwAA + + +False +-1.5707963267949 +10 +jfHJN6N3Q0mtnffCkx/XNAAA +coQmEVUSeEa7og7ZhhbDBwAA + + +False +1458 +648 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1940,656;1702,656 +XhOJgHKLNE+7Q4KPQbSulAAA +yRcxWVCafEypCOzoqyZd9wAA +LtIPm701qEiKOEIQzsRsigAA + +clPurple +clPurple +1.5707963267949 +10 +OnClose +XhOJgHKLNE+7Q4KPQbSulAAA +MY04krdOgUy47GAbt0NDFAAA + + +False +1.5707963267949 +25 +XhOJgHKLNE+7Q4KPQbSulAAA +MY04krdOgUy47GAbt0NDFAAA + + +False +-1.5707963267949 +10 +XhOJgHKLNE+7Q4KPQbSulAAA +MY04krdOgUy47GAbt0NDFAAA + + +False +1702 +656 +14 +29 + + + +$00B9FFFF +lsRectilinear +2173,656;1940,656 +M2ziWA1eJUGke3Uslc7kMwAA +LtIPm701qEiKOEIQzsRsigAA +mw7/rLkCOEGcLiEDsPSp6QAA + +1.5707963267949 +10 +Disconnect +M2ziWA1eJUGke3Uslc7kMwAA +SjVH++WOwEynnRt6joGZJQAA + + +False +1.5707963267949 +25 +M2ziWA1eJUGke3Uslc7kMwAA +SjVH++WOwEynnRt6joGZJQAA + + +False +-1.5707963267949 +10 +M2ziWA1eJUGke3Uslc7kMwAA +SjVH++WOwEynnRt6joGZJQAA + + +False +1940 +656 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +147,676;620,676 +JjTzmv8xZkyzSk5L/26mAAAA +BexDoaFUEkCBpmk29zrEggAA +gtOTyYM9IUenocj7Nq/rCQAA + +clNavy +1.5707963267949 +10 +Send(connid, data, length) +JjTzmv8xZkyzSk5L/26mAAAA +m/wbvETGy0yBNNBC3y+LcgAA + + +False +1.5707963267949 +25 +JjTzmv8xZkyzSk5L/26mAAAA +m/wbvETGy0yBNNBC3y+LcgAA + + +False +-1.5707963267949 +10 +JjTzmv8xZkyzSk5L/26mAAAA +m/wbvETGy0yBNNBC3y+LcgAA + + +620 +676 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1206,728;957,728 +0hr2j6uSRkiDwGZUmx4uigAA +fB7Q+DVBWE6rQM2gSNHKZAAA +SGclKA1c/EeIKpRjr6adVAAA + +clPurple +1.5707963267949 +10 +OnClose +0hr2j6uSRkiDwGZUmx4uigAA +SbIpBJS4mUWStRZ1eWLzJwAA + + +False +1.5707963267949 +25 +0hr2j6uSRkiDwGZUmx4uigAA +SbIpBJS4mUWStRZ1eWLzJwAA + + +False +-1.5707963267949 +10 +0hr2j6uSRkiDwGZUmx4uigAA +SbIpBJS4mUWStRZ1eWLzJwAA + + +False +957 +728 +14 +29 + + + +$00B9FFFF +lsRectilinear +1458,728;1206,728 +fEaX7prSFk6ZtUpnQCErOgAA +SGclKA1c/EeIKpRjr6adVAAA +04EYjXxjXESV7JyM0501yQAA + +1.5707963267949 +10 +Disconnect +fEaX7prSFk6ZtUpnQCErOgAA +rE0KjgQ/y0aUQ421QvI9MQAA + + +False +1.5707963267949 +25 +fEaX7prSFk6ZtUpnQCErOgAA +rE0KjgQ/y0aUQ421QvI9MQAA + + +False +-1.5707963267949 +10 +fEaX7prSFk6ZtUpnQCErOgAA +rE0KjgQ/y0aUQ421QvI9MQAA + + +False +1206 +728 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,732;395,732 +K5Yx1sRrakeMEdhgvbU6BwAA +enASZyLbhUip3579An5eRwAA +BexDoaFUEkCBpmk29zrEggAA + +clMaroon +1.5707963267949 +10 +OnSend(connid, data, length) +K5Yx1sRrakeMEdhgvbU6BwAA +nNaRZXTwN0205YVILz8JdgAA + + +False +1.5707963267949 +25 +K5Yx1sRrakeMEdhgvbU6BwAA +nNaRZXTwN0205YVILz8JdgAA + + +False +-1.5707963267949 +10 +K5Yx1sRrakeMEdhgvbU6BwAA +nNaRZXTwN0205YVILz8JdgAA + + +382 +732 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +1702,756;1933,756 +OVurhNbPjE23+XwihCOnFQAA +LtIPm701qEiKOEIQzsRsigAA +yRcxWVCafEypCOzoqyZd9wAA + +clBlue +1.5707963267949 +10 +Stop() +OVurhNbPjE23+XwihCOnFQAA +lXG+rFjJOk64gnsWL44HegAA + + +False +1.5707963267949 +25 +OVurhNbPjE23+XwihCOnFQAA +lXG+rFjJOk64gnsWL44HegAA + + +False +-1.5707963267949 +10 +OVurhNbPjE23+XwihCOnFQAA +lXG+rFjJOk64gnsWL44HegAA + + +1933 +756 +14 +29 + + + +$00B9FFFF +lsRectilinear +1946,780;2173,780 +4nCUuj5zWkyD5QM1T7mWoAAA +mw7/rLkCOEGcLiEDsPSp6QAA +LtIPm701qEiKOEIQzsRsigAA + +1.5707963267949 +10 +Disconnect +4nCUuj5zWkyD5QM1T7mWoAAA +6UPro7leY0O1DYOm4gvoCQAA + + +False +1.5707963267949 +25 +4nCUuj5zWkyD5QM1T7mWoAAA +6UPro7leY0O1DYOm4gvoCQAA + + +False +-1.5707963267949 +10 +4nCUuj5zWkyD5QM1T7mWoAAA +6UPro7leY0O1DYOm4gvoCQAA + + +False +2173 +780 +14 +29 + + + +clPurple +$00B9FFFF +clPurple +lsRectilinear +1933,781;1702,781 +Fz8nASWwCE6JmU5bZSWDjAAA +yRcxWVCafEypCOzoqyZd9wAA +LtIPm701qEiKOEIQzsRsigAA + +clPurple +clPurple +1.5707963267949 +10 +OnClose +Fz8nASWwCE6JmU5bZSWDjAAA +PmJ8Hi7oT0mfzr2wIKif6wAA + + +False +1.5707963267949 +25 +Fz8nASWwCE6JmU5bZSWDjAAA +PmJ8Hi7oT0mfzr2wIKif6wAA + + +False +-1.5707963267949 +10 +Fz8nASWwCE6JmU5bZSWDjAAA +PmJ8Hi7oT0mfzr2wIKif6wAA + + +False +1702 +781 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +957,816;1199,816 +MwEkpjxhMEmwSm9iWOGPMAAA +SGclKA1c/EeIKpRjr6adVAAA +fB7Q+DVBWE6rQM2gSNHKZAAA + +clBlue +1.5707963267949 +10 +Disconnect() +MwEkpjxhMEmwSm9iWOGPMAAA +Up/UudcwsEyJGWHcu8B1oQAA + + +False +1.5707963267949 +25 +MwEkpjxhMEmwSm9iWOGPMAAA +Up/UudcwsEyJGWHcu8B1oQAA + + +False +-1.5707963267949 +10 +MwEkpjxhMEmwSm9iWOGPMAAA +Up/UudcwsEyJGWHcu8B1oQAA + + +1199 +816 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,829;395,829 +QcAX8dFF2kyeKSVNYAQyGAAA +enASZyLbhUip3579An5eRwAA +BexDoaFUEkCBpmk29zrEggAA + +clMaroon +1.5707963267949 +10 +OnReceive(connid, data, length) +QcAX8dFF2kyeKSVNYAQyGAAA ++cchD3UcdkSIFdn3Geou7wAA + + +False +1.5707963267949 +25 +QcAX8dFF2kyeKSVNYAQyGAAA ++cchD3UcdkSIFdn3Geou7wAA + + +False +-1.5707963267949 +10 +QcAX8dFF2kyeKSVNYAQyGAAA ++cchD3UcdkSIFdn3Geou7wAA + + +382 +829 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1199,840;957,840 +QHwYoSSQtESypYaOH9iHjwAA +fB7Q+DVBWE6rQM2gSNHKZAAA +SGclKA1c/EeIKpRjr6adVAAA + +clPurple +1.5707963267949 +10 +OnClose +QHwYoSSQtESypYaOH9iHjwAA +xx+bHdVdikeFEEdZRpUAewAA + + +False +1.5707963267949 +25 +QHwYoSSQtESypYaOH9iHjwAA +xx+bHdVdikeFEEdZRpUAewAA + + +False +-1.5707963267949 +10 +QHwYoSSQtESypYaOH9iHjwAA +xx+bHdVdikeFEEdZRpUAewAA + + +False +957 +840 +14 +29 + + + +$00B9FFFF +lsRectilinear +1212,840;1458,840 +0tMhx9FGokewzBdSGlA2ygAA +04EYjXxjXESV7JyM0501yQAA +SGclKA1c/EeIKpRjr6adVAAA + +1.5707963267949 +10 +Disconnect +0tMhx9FGokewzBdSGlA2ygAA +b2G/gJEzcEW5tix0y/s0xQAA + + +False +1.5707963267949 +25 +0tMhx9FGokewzBdSGlA2ygAA +b2G/gJEzcEW5tix0y/s0xQAA + + +False +-1.5707963267949 +10 +0tMhx9FGokewzBdSGlA2ygAA +b2G/gJEzcEW5tix0y/s0xQAA + + +False +1458 +840 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +957,908;1199,908 +F0p8CwFIxE6A+uFqsVdypwAA +SGclKA1c/EeIKpRjr6adVAAA +fB7Q+DVBWE6rQM2gSNHKZAAA + +clBlue +1.5707963267949 +10 +Stop() +F0p8CwFIxE6A+uFqsVdypwAA +UNWvYjoToE6l/0jU2PyghwAA + + +False +1.5707963267949 +25 +F0p8CwFIxE6A+uFqsVdypwAA +UNWvYjoToE6l/0jU2PyghwAA + + +False +-1.5707963267949 +10 +F0p8CwFIxE6A+uFqsVdypwAA +UNWvYjoToE6l/0jU2PyghwAA + + +1199 +908 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,928;395,928 +QJhSCFnA0Ei2roB4lPLNhgAA +enASZyLbhUip3579An5eRwAA +BexDoaFUEkCBpmk29zrEggAA + +clMaroon +1.5707963267949 +10 +OnClose(connid, operation, code) +QJhSCFnA0Ei2roB4lPLNhgAA +955086JJSEGzOBHG63RjTwAA + + +False +1.5707963267949 +25 +QJhSCFnA0Ei2roB4lPLNhgAA +955086JJSEGzOBHG63RjTwAA + + +False +-1.5707963267949 +10 +QJhSCFnA0Ei2roB4lPLNhgAA +955086JJSEGzOBHG63RjTwAA + + +382 +928 +14 +29 + + + +clPurple +$00B9FFFF +lsRectilinear +1199,932;957,932 +FjbPFNpo106+r3RZ67ZnFwAA +fB7Q+DVBWE6rQM2gSNHKZAAA +SGclKA1c/EeIKpRjr6adVAAA + +clPurple +1.5707963267949 +10 +OnShutdown +FjbPFNpo106+r3RZ67ZnFwAA +095qm2doBU2w6jghi0CZlgAA + + +False +1.5707963267949 +25 +FjbPFNpo106+r3RZ67ZnFwAA +095qm2doBU2w6jghi0CZlgAA + + +False +-1.5707963267949 +10 +FjbPFNpo106+r3RZ67ZnFwAA +095qm2doBU2w6jghi0CZlgAA + + +False +957 +932 +14 +29 + + + +clBlue +$00B9FFFF +lsRectilinear +147,1028;620,1028 +yXKHIjR8gkG5PTWkHsolYwAA +BexDoaFUEkCBpmk29zrEggAA +gtOTyYM9IUenocj7Nq/rCQAA + +clNavy +1.5707963267949 +10 +Stop() +yXKHIjR8gkG5PTWkHsolYwAA +tKJbUizZ0Eez+ToWvvvHTAAA + + +False +1.5707963267949 +25 +yXKHIjR8gkG5PTWkHsolYwAA +tKJbUizZ0Eez+ToWvvvHTAAA + + +False +-1.5707963267949 +10 +yXKHIjR8gkG5PTWkHsolYwAA +tKJbUizZ0Eez+ToWvvvHTAAA + + +620 +1028 +14 +29 + + + +$00A703B4 +$00B9FFFF +lsRectilinear +627,1096;395,1096 +0c9hLinu20uJNJm9U5CPyAAA +enASZyLbhUip3579An5eRwAA +BexDoaFUEkCBpmk29zrEggAA + +clMaroon +1.5707963267949 +10 +OnShutdown() +0c9hLinu20uJNJm9U5CPyAAA +bDYJaJ+Kb06dtPzUvKpOOQAA + + +False +1.5707963267949 +25 +0c9hLinu20uJNJm9U5CPyAAA +bDYJaJ+Kb06dtPzUvKpOOQAA + + +False +-1.5707963267949 +10 +0c9hLinu20uJNJm9U5CPyAAA +bDYJaJ+Kb06dtPzUvKpOOQAA + + +382 +1096 +14 +29 + + + + +48 + +new +listener +IClient +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +tmMPWz926keOYRK7CfB+ogAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +zn6D2ECw+Eu8AUGWOyBeGwAA +xfv0zr6rnkm5TK3b06vEwwAA +f+a6lSTIlUmKsnDRas5bqgAA +LugiIgdH9UKlbkDROnnA2gAA + + +new +listener +IServer +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +gAVKOFcG5Uy+DJqh3e+rmQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +Ao9U+ysX4kSHNAEgs/GP6QAA +w4rc2loRAUa80WaA7rYUDAAA ++cj0GJzkFU2rgru6n11tRwAA +FQ/zJ+WvCEiRzaR37ea2LQAA + + +new +ITcpAgentListener +wQGBjVheXk6JUG6UyHLOLQAA +Amawaz/I9kSR3ZRprOaA0QAA + +u0t7NrBh2EmsnM1kDsHdBwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +1lwIUuEn1UievyHx8P6L4wAA +p0y8z97QckqGuNv6LxlH0AAA +tRifWe6/TUaqX+BanyQGzwAA +AIUVT++MVEu0ECFwH+9GIQAA + + +client +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +qdFUCd8ppUytkbv1kQ22KAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +BRZi89k2FkSJZxAOYzWP1wAA +pvPxh5bfl0WRhBYQoUhrTAAA +oSbPqpsoRU2uoJc3ASyKPAAA +/g3lckro6kmKWUJk5TBEuAAA + + +server +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +pPAAy86kd0iPjz3jRkE7GQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +WM1BZGw83E6VMbBt8/T9sQAA ++xnMfusA90OhNi+UUPeLVQAA +MSx0gLWyiky9hhkepyM9FQAA +RW5we4NKmEq7s+qefls0zgAA + + +listener +Amawaz/I9kSR3ZRprOaA0QAA +wQGBjVheXk6JUG6UyHLOLQAA + +zvjkh/olMkKz8fshUqs1/gAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +DYmXwHQZ1EmVy87fdA6qaAAA +X81cwuPsgk+KAWMq1YOCMQAA +rGAi9je/QEWjQ7asjxBsLgAA +UACZU1moXEqx6xEgO5z9fgAA + + +Start +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +X5T4GSZ++0CHKCiad7lJUQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 ++k4sIdNc60iYAznNneRuzAAA +Bg2EWkCZF06lcSowbntWugAA +uKIBGZNQbk6SDM1HFYtyFwAA +El2opIvE5k6n5ifKYimoKwAA + + +Start +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +i0okbOG+V0Wy21SEhlS3YQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +XwaiI/v6qkC56jzj/IhW6gAA +ecOU55F1MECtQMjpOvHU9AAA +F6zA2RmeBEeghYGTwqfaRAAA +6LAQlXh9wkyfa0rVIrVkdgAA + + +OnPrepareListen +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +zinYWd6ATEavjMBO+/H28wAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +rJ5GoZYRJEyEcqM/vzPmHQAA +Kaez2YSIiE+TTARh+vQZcAAA +WPqh4nY5ykaepmCFfzImyAAA +2IfyPo+bW0qRd6ScP32DNwAA + + +new +True +listener +ITcpAgent +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +IGSCEi76fECYOq9TAgfycAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +gswhi/yQlEyni0BQeCu9YAAA +BQYOtXZnHUCs5ggsV96l7wAA +9PNqWxktFEy/o/ppt3n5gAAA +YCa1mPCRO0G5LOjp9s6g4AAA + + +OnPrepareConnect +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +cMDdajmI+EqZX7e2IJLW2AAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +HhmcyDgFYkeEUyKoPJYJawAA +bFiEmUyfhUm3jrQW2TQduwAA +ZEPj09i3QUOxDaJ6v1vNTQAA +jvFw0qcHJkqdZD+H87HlZgAA + + +agent +U2Za99rIrEi8z93FLSAjUAAA +wQGBjVheXk6JUG6UyHLOLQAA + +YB6eaJtPCk2AGSgtffbdcAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +pJ8aa9482EKLz1EwjSpJ2wAA +XFSqaGi1F0anw7TZXNFZ3gAA +MZ06AEJL+EqPw5Qo7q0nLAAA +mvPRwpfcYU2UjxYdKYfsWgAA + + +OnConnect +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +oz9VGOLnCUChZ5znyjLuEAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +KBRuOTWQb0Kxs3sxGmlxTQAA +WkAcnSHO/EukHfG2S7ZP6AAA +0b0yc5BrqUewNMyOjR+1fgAA +fastR8O0IkmZ8Ed1ehqGEQAA + + +Connect +lvD/j4YgmkG/Ov+o+mJZPQAA +HdPN0QWbYUq0xPzVpVWOdwAA + +qOZhBu7iv0295TZDqlzApwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 ++UbCYBTI3kar1x77pEFNtgAA +66cxWvnpmkKS01S8lsn03wAA +vPx1leRrCUeaH5DaRz5VmgAA +fueosi4t/0ifaR9hi4p+DgAA + + +OnAccept +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +R2zIGFrlCEKaKzyvT7GYSQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +7Khq9w8CGEqNyK9jPATR7wAA +JyrWiLZqEkSBuLIjbv9FOwAA +z42TRVagJkmA3Fqm1Q40bgAA +BWxn2N+paEWuVxxq+eyxXgAA + + +Connect +Ta3rZIdU6E2pIcWjSM7HXgAA +ychpc6mSzUOyFf7vQMlVXAAA + +1zvjlDg+4kCIQVSgL1zDcQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +F51H4/s89UGOD6UgisZ6rQAA +px9WMnVSQE+z24Jd/HCZbAAA +TzZCTaBxj0u43IOOEv7TUQAA +wDijN4iHlUaktQrU/bYzwAAA + + +Start +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +4hoSWcXUfke9LteCU5kIwwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +6Uog5bXZhUiHM0gZRpNlmgAA +nMYEtcPmRE6bNqYuqHVILgAA +F3xZoXvxtUGwxQ5gJWH+zAAA +CnBztEHcMUaSalEaqB7c/QAA + + +Send +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +wjXK0j1It0OH0yUKkwb+BQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +ZTNKB8pelUiJllAFqF5yvgAA +PO6oqwwjZkiVNCxeHDomZQAA +XCfX/ApgskucByRDF7PufAAA +N5JbtkOyBUKfpU2cS/OJ0gAA + + +OnSend +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +hJJRrn7qSU+4yKjjptTojAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +7j6N8nOtAEmB8NfiHrmbIQAA +Qxno9bKL6U2/YPbZKsdSIAAA +VpPXxmUkbUm/UA2qIZcKagAA +QuUgR8WQOUeTETBJgCyhHwAA + + +Send +lvD/j4YgmkG/Ov+o+mJZPQAA +HdPN0QWbYUq0xPzVpVWOdwAA + +Eg1/ELcHik2Up68uZHh8yQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +ATDOv2t9gEOu+eLMb9R4UAAA +SEjOXbCTDkOtIhUhwOc1HgAA +i+6xvqQHT0WGLLmZUikFZAAA +53mBG/8a2k264ymFrSqRoQAA + + +Connect +address, port +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +Dd01nPPtvUmZGMmaii+l8AAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +6z8juZwgW0+ApkebzIIVqwAA +61gYtskbEUK3DYRW65mM8QAA +E4nKaE/4nEigh57FbzlOlwAA +b01pMFnaQ0KUEtM/uItBdAAA + + +OnReceive +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +yEyx+76l70agEtERTC8A3gAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +dHhE0pvmZ02JicuvK5SN+gAA +/xy87rY/ckqGog20YR8jDgAA +GqQg6oc8NE2B/kgYnMHN0gAA +yE5dyPxqA0a72ksNLmdJ8AAA + + +Send +Ta3rZIdU6E2pIcWjSM7HXgAA +ychpc6mSzUOyFf7vQMlVXAAA + +wb7PgcS43U24SfLIi+31YQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +smpZhVwRukGySgvtPqsUxAAA +uMrgrUe6PEWutqKsCFe7AQAA +LLWy3t49sUK4jrVCmHzvFAAA +kth0aKdptk2gLZUnlQseigAA + + +OnPrepareConnect +connid +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +jQfI7z+Tv0umyvJ5ac6g1wAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +tfIWfLElhUuRVt22cXDBeAAA +NCCvYNtv50akw5jcwNR0YAAA +QK53Dobw8EysjBMdHeMq8QAA +qzGWy+bk8ECIFi8nd0MzwAAA + + +OnReceive +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +N9pXJsZRlUmaybf6IJQ4mgAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +dDCiuxW8s0y6Luz8hDGRlAAA +JsigzOXmIUitHGsr8AF5SAAA +HoTOD5y18EmI6uCYXDAolwAA +mj6/dJFOvkqy1DfH4DhwqQAA + + +Send +HdPN0QWbYUq0xPzVpVWOdwAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +Z5SRL0VyAk2BAVlOyee2QwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +/JeU3JlGDEeacIe+5aDr1AAA +XZbDJCJjiEeFxdlu+sI0cQAA +3lWLLDFh+0yBN9CG/fUSjgAA +JwwtGZ4Pk06V2Tj1A6qcuwAA + + +OnConnect +connid +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +JunGTRMAMEuAy1IqCOHccQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +PPhh4IC3sku4vCK4K8qUbQAA +NAc38wISukaNnf/8www6FQAA +PYxwFq5jl0mzROqr2CyyGQAA +objh1EFCmES1H/VwJesupQAA + + +Send +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +02A3b3ioX0qlnvJtx6cIagAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +S1Kxo90uOEePeIXzh9h+ZwAA +tWhZddtdzEWywiuAoC8c8gAA +Fga3/CQ2BkKu7njM8XQn4QAA +5stbLcs140Kun1PGx4Ak/QAA + + +OnSend +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +gEtk/cB3KEOiz2OMHIXtXQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +q6ROVMPvT06hHZhtrvcFGQAA +bGERDMyxMEa6CW9qKBX+1wAA +TMskV16980eQsEyZNynlWwAA +IVZWn1v//kuUTHzAR8Y4JAAA + + +Send +ychpc6mSzUOyFf7vQMlVXAAA +Ta3rZIdU6E2pIcWjSM7HXgAA + +jfHJN6N3Q0mtnffCkx/XNAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +coQmEVUSeEa7og7ZhhbDBwAA +L0UJtA7FfkmQkbmXX/jEiAAA +2iZtuyG2AEyNn7rBU0SUNgAA +6zKFlCujT0WpFevsOSC85gAA + + +OnClose +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +XhOJgHKLNE+7Q4KPQbSulAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +MY04krdOgUy47GAbt0NDFAAA +MQqABXJYrk+k9d7zfFlN8AAA +l5UXhnDmB0WogcVpc2M4rgAA +rsh82z+sNUi6cSYk5yYC7wAA + + +Disconnect +HdPN0QWbYUq0xPzVpVWOdwAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +M2ziWA1eJUGke3Uslc7kMwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +SjVH++WOwEynnRt6joGZJQAA +b/oqJ+rxEU2fnvZVXgH+nAAA +/m1pUbUroE2iitUeU8JX7wAA +CSztBO+hBkec4+FndMKfvQAA + + +Send +connid, data, length +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +JjTzmv8xZkyzSk5L/26mAAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +m/wbvETGy0yBNNBC3y+LcgAA +xj7vLwvzCUGhy9isZA0aLgAA +ZsPa88BVZkW5bJMcVDmQmQAA +imunYXyTJEaYxo2oE3rO8QAA + + +OnClose +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +0hr2j6uSRkiDwGZUmx4uigAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +SbIpBJS4mUWStRZ1eWLzJwAA +DYKrOjKO90uJWIXbDTcuxAAA +NkaArdl1tEe5WDfEILo9vwAA +2vMTGccSG0qulaKXfmxJOQAA + + +Disconnect +Ta3rZIdU6E2pIcWjSM7HXgAA +ychpc6mSzUOyFf7vQMlVXAAA + +fEaX7prSFk6ZtUpnQCErOgAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +rE0KjgQ/y0aUQ421QvI9MQAA +aCSWUC1P4kWuqsFsZzEWXwAA +JYoqYPBPmUagKDUMjijnDAAA +uPcqBpCTJUuTBrGnpIPl8wAA + + +OnSend +connid, data, length +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +K5Yx1sRrakeMEdhgvbU6BwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +nNaRZXTwN0205YVILz8JdgAA +dVHaT6Oj5k6+vZMeEoG7CAAA +A2L6ylQ4rk6NNju+jcWmwQAA +Yu9QG3liv0eCvJ81Te0GhgAA + + +Stop +rscStAuJEkiUAz9WikX0hQAA +lvD/j4YgmkG/Ov+o+mJZPQAA + +OVurhNbPjE23+XwihCOnFQAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +lXG+rFjJOk64gnsWL44HegAA +rmlye/89SEmq7jZxEta5EgAA +nargtOdxOkms2XIcdCbGpQAA +oVTOcCKb4Ea7ZY+QCGJ6kgAA + + +Disconnect +lvD/j4YgmkG/Ov+o+mJZPQAA +HdPN0QWbYUq0xPzVpVWOdwAA + +4nCUuj5zWkyD5QM1T7mWoAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +6UPro7leY0O1DYOm4gvoCQAA +WSK9nqCtX0Ocg+BqcJW2egAA +Q21MrcGRXE69jo3PPiIs3gAA +IETSI6TbCUiBDkuAAHLnMwAA + + +OnClose +lvD/j4YgmkG/Ov+o+mJZPQAA +rscStAuJEkiUAz9WikX0hQAA + +Fz8nASWwCE6JmU5bZSWDjAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +PmJ8Hi7oT0mfzr2wIKif6wAA +VM+rb+kH+Ue3S/J2ZCjRrwAA +7vEjz7SLlEy6ZrDvf+dUwAAA +5LWhxnHUIkCSK1bwqZrXGgAA + + +Disconnect +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +MwEkpjxhMEmwSm9iWOGPMAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +Up/UudcwsEyJGWHcu8B1oQAA +1l/tFba2wUC4n9f098qCdwAA +roKbMUiApEGs6m4YdM5MKgAA +cq5rOtn5QUO9sNP33BFtjAAA + + +OnReceive +connid, data, length +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +QcAX8dFF2kyeKSVNYAQyGAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 ++cchD3UcdkSIFdn3Geou7wAA +j1aaoqxTZUSIsf1F6UeWUQAA +y2KvAReGuUWYtTo2fXfyQwAA +yFUxll7wz0y1kQ9REt/BgAAA + + +OnClose +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +QHwYoSSQtESypYaOH9iHjwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +xx+bHdVdikeFEEdZRpUAewAA +dfVqd0sfBE2hH5rmjdwGWAAA +pye+9M/B/Ui+KdBZI2OngAAA +k1vxzQkMrkaMKktmGzhg6AAA + + +Disconnect +ychpc6mSzUOyFf7vQMlVXAAA +Ta3rZIdU6E2pIcWjSM7HXgAA + +0tMhx9FGokewzBdSGlA2ygAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +b2G/gJEzcEW5tix0y/s0xQAA +kn00Pmo480e5RQNFO3SaVQAA +b7yhyUUMe0K+1ctblbL45wAA +mp/wApNCTE6ypYEsa9v4igAA + + +Stop +j+NgCUOjNE2kmFd3hYSIegAA +ychpc6mSzUOyFf7vQMlVXAAA + +F0p8CwFIxE6A+uFqsVdypwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +UNWvYjoToE6l/0jU2PyghwAA +zWxSevr/IUOajqRARJ1l1AAA +Yp0xifbDI0WQPg2vD/G0fAAA ++2vfYZ56s0CyiXoJ8R7iJgAA + + +OnClose +connid, operation, code +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +QJhSCFnA0Ei2roB4lPLNhgAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +955086JJSEGzOBHG63RjTwAA +BFyw4OXcT06YrEqacLGKXwAA +cDWgkn6r2UOMKQhK6hQcxAAA +tHnz7M3NPE+/2OEzfK1dWQAA + + +OnShutdown +ychpc6mSzUOyFf7vQMlVXAAA +j+NgCUOjNE2kmFd3hYSIegAA + +FjbPFNpo106+r3RZ67ZnFwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +095qm2doBU2w6jghi0CZlgAA +Zp1voyU25E61seke08J0QwAA +Rj5w5zVwUUGx7E5cQcB1AgAA +RGk3C3ZpuUiup+bk6reIvQAA + + +Stop +wQGBjVheXk6JUG6UyHLOLQAA +U2Za99rIrEi8z93FLSAjUAAA + +yXKHIjR8gkG5PTWkHsolYwAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +tKJbUizZ0Eez+ToWvvvHTAAA +ZS6aJbCFSEiHJ5du+sv0WgAA +UAtND7maHEmdHp22WWu9PAAA +JrCfG8BVq0mpTb1pF1DOhgAA + + +OnShutdown +U2Za99rIrEi8z93FLSAjUAAA +Amawaz/I9kSR3ZRprOaA0QAA + +0c9hLinu20uJNJm9U5CPyAAA + +0VTzN8sts0yg55EvvKzPQAAA +4 +bDYJaJ+Kb06dtPzUvKpOOQAA +VZMSVA1tZUuzkUJALomXGgAA +ufQZhorP/UyYWr+g8Wx6WgAA +34tdzCVMxUmHXv6nThGzEwAA + +3 + +Listener & Agent +Create +0VTzN8sts0yg55EvvKzPQAAA + + +Frame1 +sd +0VTzN8sts0yg55EvvKzPQAAA + + +Frame2 +sd +0VTzN8sts0yg55EvvKzPQAAA + + +9 + +My Logic Controller +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +EZHLxNt+aUejK04sc+0EUQAA +bgjtXzPElEqJn9pi84tImgAA +wfcNrZq7tka+YsApMmB1GQAA +gtOTyYM9IUenocj7Nq/rCQAA +12 +UVJZlx7WuUW8BWRWnTMKVwAA +eiRtiRQwQU+VjHaN3rVhqAAA +3ll2HhKX0kq8L2WoIISIqQAA +qxo3boab2UKQT7Y0WGaO5wAA +0gQj+YWF1kWUYfNhSvBRRgAA +z1QNUA0z7UCZuLoDVY19rgAA +u0t7NrBh2EmsnM1kDsHdBwAA +IGSCEi76fECYOq9TAgfycAAA +4hoSWcXUfke9LteCU5kIwwAA +Dd01nPPtvUmZGMmaii+l8AAA +JjTzmv8xZkyzSk5L/26mAAAA +yXKHIjR8gkG5PTWkHsolYwAA +4 +mpQYN0pghkiv6UDJsnfuWwAA +gc1T6rnMnUylWpF5/By8ZAAA +zvjkh/olMkKz8fshUqs1/gAA +YB6eaJtPCk2AGSgtffbdcAAA + + +My TCP Agent Listener +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +swyQ21smL0awb2XAlPy5mgAA +yexABU1UCEy5R/KkGohcEQAA +iRb1QxsXIEirQ0i5vx5lMAAA +enASZyLbhUip3579An5eRwAA +2 +mpQYN0pghkiv6UDJsnfuWwAA +zvjkh/olMkKz8fshUqs1/gAA +14 +UVJZlx7WuUW8BWRWnTMKVwAA +Wjv7v/0JW0SsHdI2VbWR+AAA +8p8OEDcPcEqcPclkWC6twgAA +5CQCgkQMiEa8EdVYKZGhowAA +OtUn1tUnHUiiI6GLtYamBwAA +/HUsBl+/S0CY4MtM5ABl2AAA +Wd9H4IjL3USBGC0pH5hlUQAA +u0t7NrBh2EmsnM1kDsHdBwAA +jQfI7z+Tv0umyvJ5ac6g1wAA +JunGTRMAMEuAy1IqCOHccQAA +K5Yx1sRrakeMEdhgvbU6BwAA +QcAX8dFF2kyeKSVNYAQyGAAA +QJhSCFnA0Ei2roB4lPLNhgAA +0c9hLinu20uJNJm9U5CPyAAA + + +TCP Agent +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +zlV9NJZWG02GGPAxyuQehAAA +mNvSnPlpGUa+X6DT/4CU0gAA +K/WqY2T7hECp3eSoc+cc9QAA +BexDoaFUEkCBpmk29zrEggAA +14 +gc1T6rnMnUylWpF5/By8ZAAA +Wjv7v/0JW0SsHdI2VbWR+AAA +8p8OEDcPcEqcPclkWC6twgAA +5CQCgkQMiEa8EdVYKZGhowAA +OtUn1tUnHUiiI6GLtYamBwAA +/HUsBl+/S0CY4MtM5ABl2AAA +Wd9H4IjL3USBGC0pH5hlUQAA +YB6eaJtPCk2AGSgtffbdcAAA +jQfI7z+Tv0umyvJ5ac6g1wAA +JunGTRMAMEuAy1IqCOHccQAA +K5Yx1sRrakeMEdhgvbU6BwAA +QcAX8dFF2kyeKSVNYAQyGAAA +QJhSCFnA0Ei2roB4lPLNhgAA +0c9hLinu20uJNJm9U5CPyAAA +10 +eiRtiRQwQU+VjHaN3rVhqAAA +3ll2HhKX0kq8L2WoIISIqQAA +qxo3boab2UKQT7Y0WGaO5wAA +0gQj+YWF1kWUYfNhSvBRRgAA +z1QNUA0z7UCZuLoDVY19rgAA +IGSCEi76fECYOq9TAgfycAAA +4hoSWcXUfke9LteCU5kIwwAA +Dd01nPPtvUmZGMmaii+l8AAA +JjTzmv8xZkyzSk5L/26mAAAA +yXKHIjR8gkG5PTWkHsolYwAA + + +Server Application +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +YLHSMhGZSUK678eHArh3vAAA +Of+EE4bQSk2dMrxBCuhmVwAA +Vp06qjJ4m0i7DMRtTHJxNAAA +fB7Q+DVBWE6rQM2gSNHKZAAA +10 +GKqHK7uaTEeoZL1eXATu1QAA +u/hYdn97j0e2w7qGm8lrPQAA +kAJ6OYlT5kSWgt6Y8JB6KQAA +RakUMYixx0eokaMaO8399AAA +PT5rHARWmkS/g4IqVuPQbwAA +gAVKOFcG5Uy+DJqh3e+rmQAA +X5T4GSZ++0CHKCiad7lJUQAA +02A3b3ioX0qlnvJtx6cIagAA +MwEkpjxhMEmwSm9iWOGPMAAA +F0p8CwFIxE6A+uFqsVdypwAA +16 +waLdiSPvU0aqFpb250AZIwAA +KjbQrlapxE2xRsUF2q8bDwAA +q1qjKctdRE2v7HKXDklokQAA +xbH85UKQlESFWJculb723gAA +0exvc+RmxE++FLqQZ+YzawAA +1hZ1Ivgi7UWnVEcQGQ9xdwAA +qB+snL4IlEeGy2CTYMy/zAAA +yyMM+2gkDEehAYP+raNxDQAA +pPAAy86kd0iPjz3jRkE7GQAA +zinYWd6ATEavjMBO+/H28wAA +R2zIGFrlCEKaKzyvT7GYSQAA +yEyx+76l70agEtERTC8A3gAA +gEtk/cB3KEOiz2OMHIXtXQAA +0hr2j6uSRkiDwGZUmx4uigAA +QHwYoSSQtESypYaOH9iHjwAA +FjbPFNpo106+r3RZ67ZnFwAA + + +Server Component +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +UgB5yC40g0yVEXFrzc9dqwAA +dpffqY3360GzYdj7w2urkQAA +Yog9jWlodUOwZiyEZFHuOQAA +SGclKA1c/EeIKpRjr6adVAAA +20 +waLdiSPvU0aqFpb250AZIwAA +KjbQrlapxE2xRsUF2q8bDwAA +q1qjKctdRE2v7HKXDklokQAA +xbH85UKQlESFWJculb723gAA +0exvc+RmxE++FLqQZ+YzawAA +9Ol7xVDHfk+aOrYlU/XxDAAA +1hZ1Ivgi7UWnVEcQGQ9xdwAA +qB+snL4IlEeGy2CTYMy/zAAA +Mj5U0wte/Ui52pM+Nh0WIgAA +yyMM+2gkDEehAYP+raNxDQAA +pPAAy86kd0iPjz3jRkE7GQAA +zinYWd6ATEavjMBO+/H28wAA +R2zIGFrlCEKaKzyvT7GYSQAA +yEyx+76l70agEtERTC8A3gAA +gEtk/cB3KEOiz2OMHIXtXQAA +jfHJN6N3Q0mtnffCkx/XNAAA +0hr2j6uSRkiDwGZUmx4uigAA +QHwYoSSQtESypYaOH9iHjwAA +0tMhx9FGokewzBdSGlA2ygAA +FjbPFNpo106+r3RZ67ZnFwAA +16 +GKqHK7uaTEeoZL1eXATu1QAA +u/hYdn97j0e2w7qGm8lrPQAA +hhg1h6MW70ylqCivIbWRXQAA +/VRCJTy/oEur+ilCjeW2XgAA +kAJ6OYlT5kSWgt6Y8JB6KQAA +aXyZYOKcl0mBOwUqTqobmgAA +RakUMYixx0eokaMaO8399AAA +PT5rHARWmkS/g4IqVuPQbwAA +gAVKOFcG5Uy+DJqh3e+rmQAA +X5T4GSZ++0CHKCiad7lJUQAA +1zvjlDg+4kCIQVSgL1zDcQAA +wb7PgcS43U24SfLIi+31YQAA +02A3b3ioX0qlnvJtx6cIagAA +fEaX7prSFk6ZtUpnQCErOgAA +MwEkpjxhMEmwSm9iWOGPMAAA +F0p8CwFIxE6A+uFqsVdypwAA + + +Client Application +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +vCbJ1MWtek+az88C5aAL/gAA +DKt3hU+zzUSpte7zoVHRzQAA +zX8HV7Zftk28YPxHFmPixwAA +04EYjXxjXESV7JyM0501yQAA +6 +hhg1h6MW70ylqCivIbWRXQAA +/VRCJTy/oEur+ilCjeW2XgAA +aXyZYOKcl0mBOwUqTqobmgAA +1zvjlDg+4kCIQVSgL1zDcQAA +wb7PgcS43U24SfLIi+31YQAA +fEaX7prSFk6ZtUpnQCErOgAA +4 +9Ol7xVDHfk+aOrYlU/XxDAAA +Mj5U0wte/Ui52pM+Nh0WIgAA +jfHJN6N3Q0mtnffCkx/XNAAA +0tMhx9FGokewzBdSGlA2ygAA + + +Client Application +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +UR8Vq2YtJk+4TYHcsBQoVQAA +TbZv4vmixEauqpXIdyVNdgAA +7zOz+Vns2kiiJ6vTPfJz/gAA +yRcxWVCafEypCOzoqyZd9wAA +10 +twaVQAbQn0SQxSav8hKGygAA +ge2n5wRT306cnabk/HU2IgAA +UiC+SdjuLkO6xrRIGFh2PAAA +3BL7NFdLw0yo7RLubFSFzQAA +pvIA8HpUU0eAf/CRON6ISQAA +czN9bfI5G0KZ0agADz5LWAAA +tmMPWz926keOYRK7CfB+ogAA +i0okbOG+V0Wy21SEhlS3YQAA +wjXK0j1It0OH0yUKkwb+BQAA +OVurhNbPjE23+XwihCOnFQAA +15 +RjOELc899E24BqUs1P8w2gAA +FYipeeoMCUm19jcfhm3biAAA +/bHgYzIBqECI2mdaGkoJMwAA +oF/LEA7hx0qNduBcIVAMJQAA +mErn0SwL4kWgwh37KhxrOwAA +9lUxZSoXvkOOzpV4doFFPwAA +yCsrGZ0ZX0eRnh7MrDJ8fwAA +5yig2AFjOEajXi3fbrN7VwAA +qdFUCd8ppUytkbv1kQ22KAAA +cMDdajmI+EqZX7e2IJLW2AAA +oz9VGOLnCUChZ5znyjLuEAAA +hJJRrn7qSU+4yKjjptTojAAA +N9pXJsZRlUmaybf6IJQ4mgAA +XhOJgHKLNE+7Q4KPQbSulAAA +Fz8nASWwCE6JmU5bZSWDjAAA + + +Client Component +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +fXhPXMHvXEemH7KkbHH2pgAA ++wCnW3yutEeNI63TdKQpkAAA +Aw2Cil4vrUSblzvM5Ifx+gAA +LtIPm701qEiKOEIQzsRsigAA +21 +RjOELc899E24BqUs1P8w2gAA +FYipeeoMCUm19jcfhm3biAAA +/bHgYzIBqECI2mdaGkoJMwAA +NUW8ZK/ERk2X3umbnhegzwAA +oF/LEA7hx0qNduBcIVAMJQAA +1vb2mQKxZ0+r/MA4zbJgbwAA +mErn0SwL4kWgwh37KhxrOwAA +9lUxZSoXvkOOzpV4doFFPwAA +bylpP6WP+0+xDkDWbCho6AAA +yCsrGZ0ZX0eRnh7MrDJ8fwAA +5yig2AFjOEajXi3fbrN7VwAA +qdFUCd8ppUytkbv1kQ22KAAA +cMDdajmI+EqZX7e2IJLW2AAA +oz9VGOLnCUChZ5znyjLuEAAA +qOZhBu7iv0295TZDqlzApwAA +hJJRrn7qSU+4yKjjptTojAAA +Eg1/ELcHik2Up68uZHh8yQAA +N9pXJsZRlUmaybf6IJQ4mgAA +XhOJgHKLNE+7Q4KPQbSulAAA +4nCUuj5zWkyD5QM1T7mWoAAA +Fz8nASWwCE6JmU5bZSWDjAAA +14 +twaVQAbQn0SQxSav8hKGygAA +ge2n5wRT306cnabk/HU2IgAA +UiC+SdjuLkO6xrRIGFh2PAAA +3BL7NFdLw0yo7RLubFSFzQAA +PSWE8W0TEU+2XvyhDfkDzgAA +79YTw4PBt0qttSuIpUL7HQAA +pvIA8HpUU0eAf/CRON6ISQAA +czN9bfI5G0KZ0agADz5LWAAA +tmMPWz926keOYRK7CfB+ogAA +i0okbOG+V0Wy21SEhlS3YQAA +wjXK0j1It0OH0yUKkwb+BQAA +Z5SRL0VyAk2BAVlOyee2QwAA +M2ziWA1eJUGke3Uslc7kMwAA +OVurhNbPjE23+XwihCOnFQAA + + +Server Application +5Xea+2Ha3kuZqH6rjIWf7AAA +4 +N3zJh2w4fk2XjEXUNCt9gwAA +W7BRFi1ZrESz7J7YQP9lKAAA ++NvHRq1YeEGH+78N+bmeBgAA +mw7/rLkCOEGcLiEDsPSp6QAA +4 +PSWE8W0TEU+2XvyhDfkDzgAA +79YTw4PBt0qttSuIpUL7HQAA +Z5SRL0VyAk2BAVlOyee2QwAA +M2ziWA1eJUGke3Uslc7kMwAA +6 +NUW8ZK/ERk2X3umbnhegzwAA +1vb2mQKxZ0+r/MA4zbJgbwAA +bylpP6WP+0+xDkDWbCho6AAA +qOZhBu7iv0295TZDqlzApwAA +Eg1/ELcHik2Up68uZHh8yQAA +4nCUuj5zWkyD5QM1T7mWoAAA + + + + + + diff --git "a/Doc/HP-Socket TCP & UDP \351\200\232\344\277\241\346\241\206\346\236\266\345\274\200\345\217\221\346\214\207\345\215\227 (v3.4-20160325).pdf" "b/Doc/HP-Socket TCP & UDP \351\200\232\344\277\241\346\241\206\346\236\266\345\274\200\345\217\221\346\214\207\345\215\227 (v3.4-20160325).pdf" new file mode 100644 index 000000000..1e9a485ce Binary files /dev/null and "b/Doc/HP-Socket TCP & UDP \351\200\232\344\277\241\346\241\206\346\236\266\345\274\200\345\217\221\346\214\207\345\215\227 (v3.4-20160325).pdf" differ diff --git a/HP-Socket/Bin/HPSocket/HPSocket.h b/HP-Socket/Bin/HPSocket/HPSocket.h new file mode 100644 index 000000000..d72376f87 --- /dev/null +++ b/HP-Socket/Bin/HPSocket/HPSocket.h @@ -0,0 +1,385 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: HPSocket DLL + +Usage: + һ + -------------------------------------------------------------------------------------- + 0. Ӧó SocketInterface.h HPSocket.h ͷļ + 1. HP_Create_Xxx() HPSocket + 2. ʹϺ HP_Destroy_Xxx() HPSocket + + + -------------------------------------------------------------------------------------- + 0. Ӧó SocketInterface.h HPSocket.h ͷļ + 1. CXxxPtr ָ룬ָͨʹ HPSocket + +Release: + 1. x86/HPSocket.dll - (32λ/MBCS/Release) + 2. x86/HPSocket_D.dll - (32λ/MBCS/DeBug) + 3. x86/HPSocket_U.dll - (32λ/UNICODE/Release) + 4. x86/HPSocket_UD.dll - (32λ/UNICODE/DeBug) + 5. x64/HPSocket.dll - (64λ/MBCS/Release) + 6. x64/HPSocket_D.dll - (64λ/MBCS/DeBug) + 7. x64/HPSocket_U.dll - (64λ/UNICODE/Release) + 8. x64/HPSocket_UD.dll - (64λ/UNICODE/DeBug) + +******************************************************************************/ + +#pragma once + +/**************************************************/ +/********* imports / exports HPSocket.dll *********/ + +#ifdef HPSOCKET_EXPORTS + #define HPSOCKET_API EXTERN_C __declspec(dllexport) +#else + #define HPSOCKET_API EXTERN_C __declspec(dllimport) +#endif + +#include "SocketInterface.h" + +/**************************************************/ +/************** HPSocket.dll **************/ + +// ITcpServer +HPSOCKET_API ITcpServer* HP_Create_TcpServer(ITcpServerListener* pListener); +// ITcpAgent +HPSOCKET_API ITcpAgent* HP_Create_TcpAgent(ITcpAgentListener* pListener); +// ITcpClient +HPSOCKET_API ITcpClient* HP_Create_TcpClient(ITcpClientListener* pListener); +// ITcpPullServer +HPSOCKET_API ITcpPullServer* HP_Create_TcpPullServer(ITcpServerListener* pListener); +// ITcpPullAgent +HPSOCKET_API ITcpPullAgent* HP_Create_TcpPullAgent(ITcpAgentListener* pListener); +// ITcpPullClient +HPSOCKET_API ITcpPullClient* HP_Create_TcpPullClient(ITcpClientListener* pListener); +// ITcpPackServer +HPSOCKET_API ITcpPackServer* HP_Create_TcpPackServer(ITcpServerListener* pListener); +// ITcpPackAgent +HPSOCKET_API ITcpPackAgent* HP_Create_TcpPackAgent(ITcpAgentListener* pListener); +// ITcpPackClient +HPSOCKET_API ITcpPackClient* HP_Create_TcpPackClient(ITcpClientListener* pListener); +// IUdpServer +HPSOCKET_API IUdpServer* HP_Create_UdpServer(IUdpServerListener* pListener); +// IUdpClient +HPSOCKET_API IUdpClient* HP_Create_UdpClient(IUdpClientListener* pListener); +// IUdpCast +HPSOCKET_API IUdpCast* HP_Create_UdpCast(IUdpCastListener* pListener); + +// ITcpServer +HPSOCKET_API void HP_Destroy_TcpServer(ITcpServer* pServer); +// ITcpAgent +HPSOCKET_API void HP_Destroy_TcpAgent(ITcpAgent* pAgent); +// ITcpClient +HPSOCKET_API void HP_Destroy_TcpClient(ITcpClient* pClient); +// ITcpPullServer +HPSOCKET_API void HP_Destroy_TcpPullServer(ITcpPullServer* pServer); +// ITcpPullAgent +HPSOCKET_API void HP_Destroy_TcpPullAgent(ITcpPullAgent* pAgent); +// ITcpPullClient +HPSOCKET_API void HP_Destroy_TcpPullClient(ITcpPullClient* pClient); +// ITcpPackServer +HPSOCKET_API void HP_Destroy_TcpPackServer(ITcpPackServer* pServer); +// ITcpPackAgent +HPSOCKET_API void HP_Destroy_TcpPackAgent(ITcpPackAgent* pAgent); +// ITcpPackClient +HPSOCKET_API void HP_Destroy_TcpPackClient(ITcpPackClient* pClient); +// IUdpServer +HPSOCKET_API void HP_Destroy_UdpServer(IUdpServer* pServer); +// IUdpClient +HPSOCKET_API void HP_Destroy_UdpClient(IUdpClient* pClient); +// IUdpCast +HPSOCKET_API void HP_Destroy_UdpCast(IUdpCast* pCast); + +// ȡı +HPSOCKET_API LPCTSTR HP_GetSocketErrorDesc(EnSocketError enCode); +// ϵͳ ::GetLastError() ȡϵͳ +HPSOCKET_API DWORD SYS_GetLastError (); +// ϵͳ ::WSAGetLastError() ȡͨŴ +HPSOCKET_API int SYS_WSAGetLastError(); +// ϵͳ setsockopt() +HPSOCKET_API int SYS_SetSocketOption(SOCKET sock, int level, int name, LPVOID val, int len); +// ϵͳ getsockopt() +HPSOCKET_API int SYS_GetSocketOption(SOCKET sock, int level, int name, LPVOID val, int* len); +// ϵͳ ioctlsocket() +HPSOCKET_API int SYS_IoctlSocket(SOCKET sock, long cmd, u_long* arg); +// ϵͳ ::WSAIoctl() +HPSOCKET_API int SYS_WSAIoctl(SOCKET sock, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned); + +// ITcpServer 󴴽 +struct TcpServer_Creator +{ + static ITcpServer* Create(ITcpServerListener* pListener) + { + return HP_Create_TcpServer(pListener); + } + + static void Destroy(ITcpServer* pServer) + { + HP_Destroy_TcpServer(pServer); + } +}; + +// ITcpAgent 󴴽 +struct TcpAgent_Creator +{ + static ITcpAgent* Create(ITcpAgentListener* pListener) + { + return HP_Create_TcpAgent(pListener); + } + + static void Destroy(ITcpAgent* pAgent) + { + HP_Destroy_TcpAgent(pAgent); + } +}; + +// ITcpClient 󴴽 +struct TcpClient_Creator +{ + static ITcpClient* Create(ITcpClientListener* pListener) + { + return HP_Create_TcpClient(pListener); + } + + static void Destroy(ITcpClient* pClient) + { + HP_Destroy_TcpClient(pClient); + } +}; + +// ITcpPullServer 󴴽 +struct TcpPullServer_Creator +{ + static ITcpPullServer* Create(ITcpServerListener* pListener) + { + return HP_Create_TcpPullServer(pListener); + } + + static void Destroy(ITcpPullServer* pServer) + { + HP_Destroy_TcpPullServer(pServer); + } +}; + +// ITcpPullAgent 󴴽 +struct TcpPullAgent_Creator +{ + static ITcpPullAgent* Create(ITcpAgentListener* pListener) + { + return HP_Create_TcpPullAgent(pListener); + } + + static void Destroy(ITcpPullAgent* pAgent) + { + HP_Destroy_TcpPullAgent(pAgent); + } +}; + +// ITcpPullClient 󴴽 +struct TcpPullClient_Creator +{ + static ITcpPullClient* Create(ITcpClientListener* pListener) + { + return HP_Create_TcpPullClient(pListener); + } + + static void Destroy(ITcpPullClient* pClient) + { + HP_Destroy_TcpPullClient(pClient); + } +}; + +// ITcpPackServer 󴴽 +struct TcpPackServer_Creator +{ + static ITcpPackServer* Create(ITcpServerListener* pListener) + { + return HP_Create_TcpPackServer(pListener); + } + + static void Destroy(ITcpPackServer* pServer) + { + HP_Destroy_TcpPackServer(pServer); + } +}; + +// ITcpPackAgent 󴴽 +struct TcpPackAgent_Creator +{ + static ITcpPackAgent* Create(ITcpAgentListener* pListener) + { + return HP_Create_TcpPackAgent(pListener); + } + + static void Destroy(ITcpPackAgent* pAgent) + { + HP_Destroy_TcpPackAgent(pAgent); + } +}; + +// ITcpPackClient 󴴽 +struct TcpPackClient_Creator +{ + static ITcpPackClient* Create(ITcpClientListener* pListener) + { + return HP_Create_TcpPackClient(pListener); + } + + static void Destroy(ITcpPackClient* pClient) + { + HP_Destroy_TcpPackClient(pClient); + } +}; + +// IUdpServer 󴴽 +struct UdpServer_Creator +{ + static IUdpServer* Create(IUdpServerListener* pListener) + { + return HP_Create_UdpServer(pListener); + } + + static void Destroy(IUdpServer* pServer) + { + HP_Destroy_UdpServer(pServer); + } +}; + +// IUdpClient 󴴽 +struct UdpClient_Creator +{ + static IUdpClient* Create(IUdpClientListener* pListener) + { + return HP_Create_UdpClient(pListener); + } + + static void Destroy(IUdpClient* pClient) + { + HP_Destroy_UdpClient(pClient); + } +}; + +// IUdpClient 󴴽 +struct UdpCast_Creator +{ + static IUdpCast* Create(IUdpCastListener* pListener) + { + return HP_Create_UdpCast(pListener); + } + + static void Destroy(IUdpCast* pCast) + { + HP_Destroy_UdpCast(pCast); + } +}; + +/**************************************************/ +/************** HPSocket ָ **************/ + +template class CHPSocketPtr +{ +public: + CHPSocketPtr(_Listener* pListener = nullptr) + { + if(pListener) + m_pObj = _Creator::Create(pListener); + else + m_pObj = nullptr; + } + + ~CHPSocketPtr() + { + Reset(); + } + +public: + CHPSocketPtr& Reset(T* pObj = nullptr) + { + if(pObj != m_pObj) + { + if(m_pObj) + _Creator::Destroy(m_pObj); + + m_pObj = pObj; + } + + return *this; + } + + CHPSocketPtr& Attach(T* pObj) + { + return Reset(pObj); + } + + T* Detach() + { + T* pObj = m_pObj; + m_pObj = nullptr; + + return pObj; + } + + BOOL IsValid () const {return m_pObj != nullptr ;} + T* Get () const {return m_pObj ;} + T* operator -> () const {return m_pObj ;} + operator T* () const {return m_pObj ;} + + CHPSocketPtr& operator = (T* pObj) {return Reset(pObj) ;} + +private: + CHPSocketPtr(const CHPSocketPtr&); + CHPSocketPtr& operator = (const CHPSocketPtr&); + +private: + T* m_pObj; +}; + +// ITcpServer ָ +typedef CHPSocketPtr CTcpServerPtr; +// ITcpAgent ָ +typedef CHPSocketPtr CTcpAgentPtr; +// ITcpClient ָ +typedef CHPSocketPtr CTcpClientPtr; +// ITcpPullServer ָ +typedef CHPSocketPtr CTcpPullServerPtr; +// ITcpPullAgent ָ +typedef CHPSocketPtr CTcpPullAgentPtr; +// ITcpPullClient ָ +typedef CHPSocketPtr CTcpPullClientPtr; +// ITcpPackServer ָ +typedef CHPSocketPtr CTcpPackServerPtr; +// ITcpPackAgent ָ +typedef CHPSocketPtr CTcpPackAgentPtr; +// ITcpPackClient ָ +typedef CHPSocketPtr CTcpPackClientPtr; +// IUdpServer ָ +typedef CHPSocketPtr CUdpServerPtr; +// IUdpClient ָ +typedef CHPSocketPtr CUdpClientPtr; +// IUdpCast ָ +typedef CHPSocketPtr CUdpCastPtr; diff --git a/HP-Socket/Bin/HPSocket/SocketInterface.h b/HP-Socket/Bin/HPSocket/SocketInterface.h new file mode 100644 index 000000000..d332c2dba --- /dev/null +++ b/HP-Socket/Bin/HPSocket/SocketInterface.h @@ -0,0 +1,1360 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +/************************************************************************ +ƣ ID +Ӧó԰ CONNID ΪҪͣ磺ULONG / ULONGLONG +************************************************************************/ +typedef ULONG_PTR CONNID; + +/*****************************************************************************************************/ +/******************************************** ࡢӿ ********************************************/ +/*****************************************************************************************************/ + +/************************************************************************ +ƣͨ״̬ +Ӧóͨͨ GetState() ȡǰ״̬ +************************************************************************/ +enum EnServiceState +{ + SS_STARTING = 0, // + SS_STARTED = 1, // Ѿ + SS_STOPPING = 2, // ֹͣ + SS_STOPPED = 3, // Ѿֹͣ +}; + +/************************************************************************ +ƣSocket +Ӧó OnClose() ¼ͨòʶֲµĴ +************************************************************************/ +enum EnSocketOperation +{ + SO_UNKNOWN = 0, // Unknown + SO_ACCEPT = 1, // Acccept + SO_CONNECT = 2, // Connect + SO_SEND = 3, // Send + SO_RECEIVE = 4, // Receive + SO_CLOSE = 5, // Close +}; + +/************************************************************************ +ƣ¼ +¼ķֵͬķֵӰͨĺΪ +************************************************************************/ +enum EnHandleResult +{ + HR_OK = 0, // ɹ + HR_IGNORE = 1, // + HR_ERROR = 2, // +}; + +/************************************************************************ +ƣץȡ +ץȡķֵ +************************************************************************/ +enum EnFetchResult +{ + FR_OK = 0, // ɹ + FR_LENGTH_TOO_LONG = 1, // ץȡȹ + FR_DATA_NOT_FOUND = 2, // Ҳ ConnID Ӧ +}; + +/************************************************************************ +ƣݷͲ +Server Agent ݷͲ + +* ģʽĬϣ ѶͲһͣӴЧ +* ȫģʽ ѶͲһͣƴٶȣ⻺ +* ֱģʽ ÿһͲֱͶݣڸزߵҪʵʱԽϸߵij + +************************************************************************/ +enum EnSendPolicy +{ + SP_PACK = 0, // ģʽĬϣ + SP_SAFE = 1, // ȫģʽ + SP_DIRECT = 2, // ֱģʽ +}; + +/************************************************************************ +ƣ + Start() / Stop() ִʧʱͨ GetLastError() ȡ +************************************************************************/ +enum EnSocketError +{ + SE_OK = NO_ERROR, // ɹ + SE_ILLEGAL_STATE = 1, // ǰ״̬ + SE_INVALID_PARAM = 2, // Ƿ + SE_SOCKET_CREATE = 3, // SOCKET ʧ + SE_SOCKET_BIND = 4, // SOCKET ʧ + SE_SOCKET_PREPARE = 5, // SOCKET ʧ + SE_SOCKET_LISTEN = 6, // SOCKET ʧ + SE_CP_CREATE = 7, // ɶ˿ʧ + SE_WORKER_THREAD_CREATE = 8, // ߳ʧ + SE_DETECT_THREAD_CREATE = 9, // ߳ʧ + SE_SOCKE_ATTACH_TO_CP = 10, // ɶ˿ʧ + SE_CONNECT_SERVER = 11, // ӷʧ + SE_NETWORK = 12, // + SE_DATA_PROC = 13, // ݴ + SE_DATA_SEND = 14, // ݷʧ +}; + +/************************************************************************ +ƣģʽ +UDP IJģʽ鲥㲥 +************************************************************************/ +enum EnCastMode +{ + CM_MULTICAST = 0, // 鲥 + CM_BROADCAST = 1, // 㲥 +}; + +/************************************************************************ +ƣSocket ӿ +˺Ϳͻ Socket ĹϢ +************************************************************************/ +class IComplexSocketListener +{ +public: + + /* + * ƣѷ֪ͨ + * ɹݺSocket յ֪ͨ + * + * dwConnID -- ID + * pData -- ѷݻ + * iLength -- ѷݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֪ͨ HR_ERRORģʽԴ + */ + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) = 0; + + /* + * ƣݵ֪ͨPUSH ģͣ + * PUSH ģ͵ Socket ͨɹݺ Socket ͸֪ͨ + * + * dwConnID -- ID + * pData -- ѽݻ + * iLength -- ѽݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- OnClose() ¼ʱ䲢ر + */ + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) = 0; + + /* + * ƣݵ֪ͨPULL ģͣ + * PULL ģ͵ Socket ͨɹݺ Socket ͸֪ͨ + * + * dwConnID -- ID + * iLength -- ѽݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- OnClose() ¼ʱ䲢ر + */ + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) = 0; + + /* + * ƣͨŴ֪ͨ + * ͨŷSocket յ֪ͨر + * + * dwConnID -- ID + * enOperation -- Socket + * iErrorCode -- + * ֵ Էֵ + */ + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) = 0; + + /* + * ƣر֪ͨͨ + * ͨرʱSocket յ֪ͨ + * + * + * ֵԷֵ + */ + virtual EnHandleResult OnShutdown() = 0; + +public: + virtual ~IComplexSocketListener() {} +}; + +/************************************************************************ +ƣ Socket ӿ + Socket ¼ +************************************************************************/ +class IServerListener : public IComplexSocketListener +{ +public: + + /* + * ƣ׼֪ͨ + * ͨŷʱڼ Socket ɲʼִмǰSocket + * յִ֪֪ͨͨ Socket ѡõȶ⹤ + * + * soListen -- Socket + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֹͨŷ + */ + virtual EnHandleResult OnPrepareListen(SOCKET soListen) = 0; +}; + +/************************************************************************ +ƣTCP Socket ӿ + TCP Socket ¼ +************************************************************************/ +class ITcpServerListener : public IServerListener +{ +public: + + /* + * ƣ֪ͨ + * յͻʱSocket յ֪֪ͨͨ + * ִ Socket ѡûܾͻӵȶ⹤ + * + * dwConnID -- ID + * soClient -- ͻ Socket + * ֵ HR_OK / HR_IGNORE -- + * HR_ERROR -- ܾ + */ + virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient) = 0; +}; + +/************************************************************************ +ƣPUSH ģͷ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpServerListener : public ITcpServerListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareListen(SOCKET soListen) {return HR_IGNORE;} + virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient) {return HR_IGNORE;} + virtual EnHandleResult OnShutdown() {return HR_IGNORE;} +}; + +/************************************************************************ +ƣPULL ģͷ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpPullServerListener : public CTcpServerListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) = 0; + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣUDP Socket ӿ + UDP Socket ¼ +************************************************************************/ +class IUdpServerListener : public IServerListener +{ +public: + + /* + * ƣ֪ͨ + * յͻʱSocket յ֪֪ͨͨ + * ִ Socket ѡûܾͻӵȶ⹤ + * + * dwConnID -- ID + * soClient -- ͻ Socket + * ֵ HR_OK / HR_IGNORE -- + * HR_ERROR -- ܾ + */ + virtual EnHandleResult OnAccept(CONNID dwConnID, const SOCKADDR_IN* pSockAddr) = 0; +}; + +/************************************************************************ +ƣUDP Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CUdpServerListener : public IUdpServerListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareListen(SOCKET soListen) {return HR_IGNORE;} + virtual EnHandleResult OnAccept(CONNID dwConnID, const SOCKADDR_IN* pSockAddr) {return HR_IGNORE;} + virtual EnHandleResult OnShutdown() {return HR_IGNORE;} +}; + +/************************************************************************ +ƣͨŴ Socket ӿ + ͨŴ Socket ¼ +************************************************************************/ +class IAgentListener : public IComplexSocketListener +{ +public: + + /* + * ƣ׼֪ͨ + * ͨſͻʱڿͻ Socket ɲʼִǰSocket + * յִ֪֪ͨͨ Socket ѡõȶ⹤ + * + * dwConnID -- ID + * socket -- ͻ Socket + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֹͨſͻ + */ + virtual EnHandleResult OnPrepareConnect(CONNID dwConnID, SOCKET socket) = 0; + + /* + * ƣ֪ͨ + * ˳ɹʱSocket յ֪ͨ + * + * dwConnID -- ID + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ͬӣֹͨſͻ + * 첽ӣر + */ + virtual EnHandleResult OnConnect(CONNID dwConnID) = 0; +}; + +/************************************************************************ +ƣTCP ͨŴ Socket ӿ + TCP ͨŴ Socket ¼ +************************************************************************/ +class ITcpAgentListener : public IAgentListener +{ +}; + +/************************************************************************ +ƣPUSH ģͨŴ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpAgentListener : public ITcpAgentListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(CONNID dwConnID, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(CONNID dwConnID) {return HR_IGNORE;} + virtual EnHandleResult OnShutdown() {return HR_IGNORE;} +}; + +/************************************************************************ +ƣPULL ͨŴ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpPullAgentListener : public CTcpAgentListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) = 0; + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} +}; + +class IClient; + +/************************************************************************ +ƣͻ Socket ӿ +ͻ Socket ¼ +************************************************************************/ +class IClientListener +{ +public: + + /* + * ƣ׼֪ͨ + * ͨſͻʱڿͻ Socket ɲʼִǰSocket + * յִ֪֪ͨͨ Socket ѡõȶ⹤ + * + * pClient -- Ӷ + * socket -- ͻ Socket + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֹͨſͻ + */ + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket) = 0; + + /* + * ƣ֪ͨ + * ˳ɹʱSocket յ֪ͨ + * + * pClient -- Ӷ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ͬӣֹͨſͻ + * 첽ӣر + */ + virtual EnHandleResult OnConnect(IClient* pClient) = 0; + + /* + * ƣѷ֪ͨ + * ɹݺSocket յ֪ͨ + * + * pClient -- Ӷ + * pData -- ѷݻ + * iLength -- ѷݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֪ͨ HR_ERRORģʽԴ + */ + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) = 0; + + /* + * ƣݵ֪ͨPUSH ģͣ + * PUSH ģ͵ Socket ͨɹݺ Socket ͸֪ͨ + * + * pClient -- Ӷ + * pData -- ѽݻ + * iLength -- ѽݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- OnClose() ¼ʱ䲢ر + */ + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength) = 0; + + /* + * ƣݵ֪ͨPULL ģͣ + * PULL ģ͵ Socket ͨɹݺ Socket ͸֪ͨ + * + * pClient -- Ӷ + * iLength -- ѽݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- OnClose() ¼ʱ䲢ر + */ + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) = 0; + + /* + * ƣͨŴ֪ͨ + * ͨŷSocket յ֪ͨر + * + * pClient -- Ӷ + * enOperation -- Socket + * iErrorCode -- + * ֵ Էֵ + */ + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) = 0; + +public: + virtual ~IClientListener() {} +}; + +/************************************************************************ +ƣTCP ͻ Socket ӿ + TCP ͻ Socket ¼ +************************************************************************/ +class ITcpClientListener : public IClientListener +{ +}; + +/************************************************************************ +ƣPUSH ģͿͻ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpClientListener : public ITcpClientListener +{ +public: + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(IClient* pClient) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣPULL ͻ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpPullClientListener : public CTcpClientListener +{ +public: + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) = 0; + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣUDP ͻ Socket ӿ + UDP ͻ Socket ¼ +************************************************************************/ +class IUdpClientListener : public IClientListener +{ +}; + +/************************************************************************ +ƣUDP Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CUdpClientListener : public IUdpClientListener +{ +public: + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(IClient* pClient) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣUDP Socket ӿ + UDP Socket ¼ +************************************************************************/ +class IUdpCastListener : public IClientListener +{ +}; + +/************************************************************************ +ƣUDP Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CUdpCastListener : public IUdpCastListener +{ +public: + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(IClient* pClient) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣ Socket ӿ +帴 Socket вԷʷ Socket ͬʱ Socket +************************************************************************/ +class IComplexSocket +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣرͨ + * رͨرɺϿӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Stop () = 0; + + /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL Send (CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0) = 0; + + /* + * ƣͶ + * ָӷͶ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * dwConnID -- ID + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount) = 0; + + /* + * ƣϿ + * Ͽij + * + * dwConnID -- ID + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ + virtual BOOL Disconnect(CONNID dwConnID, BOOL bForce = TRUE) = 0; + + /* + * ƣϿʱ + * Ͽָʱ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ + virtual BOOL DisconnectLongConnections(DWORD dwPeriod, BOOL bForce = TRUE) = 0; + + /* + * ƣϿĬ + * ϿָʱľĬ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ + virtual BOOL DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce = TRUE) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* + * ƣӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦó + * + * dwConnID -- ID + * pv -- + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ + virtual BOOL SetConnectionExtra (CONNID dwConnID, PVOID pExtra) = 0; + + /* + * ƣȡӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦó + * + * dwConnID -- ID + * ppv -- ָ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ + virtual BOOL GetConnectionExtra (CONNID dwConnID, PVOID* ppExtra) = 0; + + /* ͨǷ */ + virtual BOOL HasStarted () = 0; + /* 鿴ͨǰ״̬ */ + virtual EnServiceState GetState () = 0; + /* ȡ */ + virtual DWORD GetConnectionCount () = 0; + /* ȡӵ CONNID */ + virtual BOOL GetAllConnectionIDs (CONNID pIDs[], DWORD& dwCount) = 0; + /* ȡijʱ룩 */ + virtual BOOL GetConnectPeriod (CONNID dwConnID, DWORD& dwPeriod) = 0; + /* ȡijӾĬʱ䣨룩 */ + virtual BOOL GetSilencePeriod (CONNID dwConnID, DWORD& dwPeriod) = 0; + /* ȡijӵԶ̵ַϢ */ + virtual BOOL GetRemoteAddress (CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; + /* ȡһʧܲĴ */ + virtual EnSocketError GetLastError () = 0; + /* ȡһʧܲĴ */ + virtual LPCTSTR GetLastErrorDesc () = 0; + /* ȡδݵij */ + virtual BOOL GetPendingDataLength (CONNID dwConnID, int& iPending) = 0; + + /* ݷͲ */ + virtual void SetSendPolicy (EnSendPolicy enSendPolicy) = 0; + /* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ + virtual void SetFreeSocketObjLockTime (DWORD dwFreeSocketObjLockTime) = 0; + /* Socket شСͨΪƽ 1/3 - 1/2 */ + virtual void SetFreeSocketObjPool (DWORD dwFreeSocketObjPool) = 0; + /* ڴ黺شСͨΪ Socket شС 2 - 3 */ + virtual void SetFreeBufferObjPool (DWORD dwFreeBufferObjPool) = 0; + /* Socket ػշֵͨΪ Socket شС 3 */ + virtual void SetFreeSocketObjHold (DWORD dwFreeSocketObjHold) = 0; + /* ڴ黺ػշֵͨΪڴ黺شС 3 */ + virtual void SetFreeBufferObjHold (DWORD dwFreeBufferObjHold) = 0; + /* ù߳ͨΪ 2 * CPU + 2 */ + virtual void SetWorkerThreadCount (DWORD dwWorkerThreadCount) = 0; + /* ǷǾĬʱ䣨Ϊ TRUE ʱ DisconnectSilenceConnections() GetSilencePeriod() ЧĬϣFALSE */ + virtual void SetMarkSilence (BOOL bMarkSilence) = 0; + + /* ȡݷͲ */ + virtual EnSendPolicy GetSendPolicy () = 0; + /* ȡ Socket ʱ */ + virtual DWORD GetFreeSocketObjLockTime () = 0; + /* ȡ Socket شС */ + virtual DWORD GetFreeSocketObjPool () = 0; + /* ȡڴ黺شС */ + virtual DWORD GetFreeBufferObjPool () = 0; + /* ȡ Socket ػշֵ */ + virtual DWORD GetFreeSocketObjHold () = 0; + /* ȡڴ黺ػշֵ */ + virtual DWORD GetFreeBufferObjHold () = 0; + /* ȡ߳ */ + virtual DWORD GetWorkerThreadCount () = 0; + /* ǷǾĬʱ */ + virtual BOOL IsMarkSilence () = 0; + +public: + virtual ~IComplexSocket() {} +}; + +/************************************************************************ +ƣͨŷӿ +ͨŷвԷʷ +************************************************************************/ +class IServer : public IComplexSocket +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣͨ + * ͨɺɿʼտͻӲշ + * + * pszBindAddress -- ַ + * usPort -- ˿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Start (LPCTSTR pszBindAddress, USHORT usPort) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ȡ Socket ĵַϢ */ + virtual BOOL GetListenAddress(TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; +}; + +/************************************************************************ +ƣTCP ͨŷӿ + TCP ͨŷвԷʷ +************************************************************************/ +class ITcpServer : public IServer +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendSmallFile (CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* Accept ԤͶݸصãAccept ԤͶԽֵ֧IJԽࣩ */ + virtual void SetAcceptSocketCount (DWORD dwAcceptSocketCount) = 0; + /* ͨݻСƽͨݰСãͨΪ 1024 ı */ + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) = 0; + /* ü Socket ĵȺдСݲã */ + virtual void SetSocketListenQueue (DWORD dwSocketListenQueue) = 0; + /* 룬0 򲻷Ĭϣ30 * 1000 */ + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) = 0; + /* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) = 0; + + /* ȡ Accept ԤͶ */ + virtual DWORD GetAcceptSocketCount () = 0; + /* ȡͨݻС */ + virtual DWORD GetSocketBufferSize () = 0; + /* ȡ Socket ĵȺдС */ + virtual DWORD GetSocketListenQueue () = 0; + /* ȡ */ + virtual DWORD GetKeepAliveTime () = 0; + /* ȡ쳣 */ + virtual DWORD GetKeepAliveInterval () = 0; +}; + +/************************************************************************ +ƣUDP ͨŷӿ + UDP ͨŷвԷʷ +************************************************************************/ +class IUdpServer : public IServer +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) = 0; + /* ȡݱ󳤶 */ + virtual DWORD GetMaxDatagramSize () = 0; + + /* Receive ԤͶݸصãReceive ԤͶԽ򶪰ԽС */ + virtual void SetPostReceiveCount (DWORD dwPostReceiveCount) = 0; + /* ȡ Receive ԤͶ */ + virtual DWORD GetPostReceiveCount () = 0; + + /* üԴ0 򲻷ͼԴΪѶߣ */ + virtual void SetDetectAttempts (DWORD dwDetectAttempts) = 0; + /* üͼ룬0 ͼ */ + virtual void SetDetectInterval (DWORD dwDetectInterval) = 0; + /* ȡ */ + virtual DWORD GetDetectAttempts () = 0; + /* ȡ */ + virtual DWORD GetDetectInterval () = 0; +}; + +/************************************************************************ +ƣͨŴӿ +ͨŴвԷʷһͬʱӶĿͻ +************************************************************************/ +class IAgent : public IComplexSocket +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣͨ + * ͨŴɺɿʼԶ̷ + * + * pszBindAddress -- ַ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Start (LPCTSTR pszBindAddress = nullptr, BOOL bAsyncConnect = TRUE) = 0; + + /* + * ƣӷ + * ӷӳɹ IAgentListener յ OnConnect() ¼ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * pdwConnID -- IDĬϣnullptrȡ ID + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID = nullptr) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ȡijӵıصַϢ */ + virtual BOOL GetLocalAddress(CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; +}; + +/************************************************************************ +ƣTCP ͨŴӿ + TCP ͨŴвԷʷ +************************************************************************/ +class ITcpAgent : public IAgent +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendSmallFile (CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ǷõַûƣĬϣã */ + virtual void SetReuseAddress (BOOL bReuseAddress) = 0; + /* Ƿõַû */ + virtual BOOL IsReuseAddress () = 0; + + /* ͨݻСƽͨݰСãͨΪ 1024 ı */ + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) = 0; + /* 룬0 򲻷Ĭϣ30 * 1000 */ + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) = 0; + /* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) = 0; + + /* ȡͨݻС */ + virtual DWORD GetSocketBufferSize () = 0; + /* ȡ */ + virtual DWORD GetKeepAliveTime () = 0; + /* ȡ쳣 */ + virtual DWORD GetKeepAliveInterval () = 0; +}; + +/************************************************************************ +ƣͨſͻӿ +ͨſͻвԷʷ +************************************************************************/ +class IClient +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣͨ + * ͻͨӷˣɺɿʼշ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Start (LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect = FALSE) = 0; + + /* + * ƣرͨ + * رտͻͨرɺϿ˵ӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Stop () = 0; + + /* + * ƣ + * ˷ + * + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL Send (const BYTE* pBuffer, int iLength, int iOffset = 0) = 0; + + /* + * ƣͶ + * ˷Ͷ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendPackets(const WSABUF pBuffers[], int iCount) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ӵĸ */ + virtual void SetExtra (PVOID pExtra) = 0; + + /* ȡӵĸ */ + virtual PVOID GetExtra () = 0; + + /* ͨǷ */ + virtual BOOL HasStarted () = 0; + /* 鿴ͨǰ״̬ */ + virtual EnServiceState GetState () = 0; + /* ȡһʧܲĴ */ + virtual EnSocketError GetLastError () = 0; + /* ȡһʧܲĴ */ + virtual LPCTSTR GetLastErrorDesc() = 0; + /* ȡ ID */ + virtual CONNID GetConnectionID () = 0; + /* ȡ Client Socket ĵַϢ */ + virtual BOOL GetLocalAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; + /* ȡδݵij */ + virtual BOOL GetPendingDataLength (int& iPending) = 0; + + /* ڴ黺شСͨΪ -> PUSH ģͣ5 - 10PULL ģͣ10 - 20 */ + virtual void SetFreeBufferPoolSize (DWORD dwFreeBufferPoolSize) = 0; + /* ڴ黺ػշֵͨΪڴ黺شС 3 */ + virtual void SetFreeBufferPoolHold (DWORD dwFreeBufferPoolHold) = 0; + + /* ȡڴ黺شС */ + virtual DWORD GetFreeBufferPoolSize () = 0; + /* ȡڴ黺ػշֵ */ + virtual DWORD GetFreeBufferPoolHold () = 0; + +public: + virtual ~IClient() {} +}; + +/************************************************************************ +ƣTCP ͨſͻӿ + TCP ͨſͻвԷʷ +************************************************************************/ +class ITcpClient : public IClient +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣСļ + * ˷ 4096 KB µСļ + * + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendSmallFile (LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ͨݻСƽͨݰСãͨΪ(N * 1024) - sizeof(TBufferObj) */ + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) = 0; + /* 룬0 򲻷Ĭϣ30 * 1000 */ + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) = 0; + /* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) = 0; + + /* ȡͨݻС */ + virtual DWORD GetSocketBufferSize () = 0; + /* ȡ */ + virtual DWORD GetKeepAliveTime () = 0; + /* ȡ쳣 */ + virtual DWORD GetKeepAliveInterval () = 0; +}; + +/************************************************************************ +ƣUDP ͨſͻӿ + UDP ͨſͻвԷʷ +************************************************************************/ +class IUdpClient : public IClient +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) = 0; + /* ȡݱ󳤶 */ + virtual DWORD GetMaxDatagramSize() = 0; + + /* üԴ0 򲻷ͼԴΪѶߣ */ + virtual void SetDetectAttempts (DWORD dwDetectAttempts) = 0; + /* üͼ룬0 ͼ */ + virtual void SetDetectInterval (DWORD dwDetectInterval) = 0; + /* ȡ */ + virtual DWORD GetDetectAttempts () = 0; + /* ȡ */ + virtual DWORD GetDetectInterval () = 0; +}; + +/************************************************************************ +ƣUDP ӿ + UDP 鲥㲥вԷʷ +************************************************************************/ +class IUdpCast : public IClient +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ð󶨵ַ */ + virtual void SetBindAdddress (LPCTSTR pszBindAddress) = 0; + /* ȡ󶨵ַ */ + virtual LPCTSTR GetBindAdddress () = 0; + + /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) = 0; + /* ȡݱ󳤶 */ + virtual DWORD GetMaxDatagramSize() = 0; + + /* ǷõַûƣĬϣã */ + virtual void SetReuseAddress (BOOL bReuseAddress) = 0; + /* Ƿõַû */ + virtual BOOL IsReuseAddress () = 0; + + /* ôģʽ鲥㲥 */ + virtual void SetCastMode (EnCastMode enCastMode) = 0; + /* ȡģʽ */ + virtual EnCastMode GetCastMode () = 0; + + /* 鲥ĵ TTL0 - 255 */ + virtual void SetMultiCastTtl (int iMCTtl) = 0; + /* ȡ鲥ĵ TTL */ + virtual int GetMultiCastTtl () = 0; + + /* Ƿ鲥·TRUE or FALSE */ + virtual void SetMultiCastLoop (BOOL bMCLoop) = 0; + /* Ƿ鲥· */ + virtual BOOL IsMultiCastLoop () = 0; + + /* ȡǰݱԶ̵ַϢͨ OnReceive ¼еã */ + virtual BOOL GetRemoteAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; +}; + +/************************************************************************ +ƣServer/Agent PULL ģӿ + Server/Agent PULL ģв +************************************************************************/ +class IPullSocket +{ +public: + + /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pData -- ץȡ + * iLength -- ץȡݳ + * ֵ EnFetchResult + */ + virtual EnFetchResult Fetch (CONNID dwConnID, BYTE* pData, int iLength) = 0; + + /* + * ƣ̽ݣƳݣ + * ûͨ÷ Socket п̽ + * + * dwConnID -- ID + * pData -- ̽ + * iLength -- ̽ݳ + * ֵ EnFetchResult + */ + virtual EnFetchResult Peek (CONNID dwConnID, BYTE* pData, int iLength) = 0; + +public: + virtual ~IPullSocket() {} +}; + +/************************************************************************ +ƣClient PULL ģӿ + Client PULL ģв +************************************************************************/ +class IPullClient +{ +public: + + /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * pData -- ץȡ + * iLength -- ץȡݳ + * ֵ EnFetchResult + */ + virtual EnFetchResult Fetch (BYTE* pData, int iLength) = 0; + + /* + * ƣ̽ݣƳݣ + * ûͨ÷ Socket п̽ + * + * pData -- ̽ + * iLength -- ̽ݳ + * ֵ EnFetchResult + */ + virtual EnFetchResult Peek (BYTE* pData, int iLength) = 0; + +public: + virtual ~IPullClient() {} +}; + +/************************************************************************ +ƣTCP Server PULL ģӿ +̳ ITcpServer IPullSocket +************************************************************************/ +class ITcpPullServer : public IPullSocket, public ITcpServer +{ +public: + /* IServer* תΪ IPullSocket* */ + inline static IPullSocket* ToPull(IServer* pServer) + { + return (IPullSocket*)((char*)pServer - sizeof(IPullSocket)); + } + + /* IPullSocket* תΪ ITcpServer* */ + inline static ITcpServer* ToServer(IPullSocket* pPullSocket) + { + return (ITcpServer*)((char*)pPullSocket + sizeof(IPullSocket)); + } +}; + +/************************************************************************ +ƣTCP Agent PULL ģӿ +̳ ITcpAgent IPullSocket +************************************************************************/ +class ITcpPullAgent : public IPullSocket, public ITcpAgent +{ +public: + /* IAgent* תΪ IPullSocket* */ + inline static IPullSocket* ToPull(IAgent* pAgent) + { + return (IPullSocket*)((char*)pAgent - sizeof(IPullSocket)); + } + + /* IPullSocket* תΪ ITcpAgent* */ + inline static ITcpAgent* ToAgent(IPullSocket* pPullSocket) + { + return (ITcpAgent*)((char*)pPullSocket + sizeof(IPullSocket)); + } +}; + +/************************************************************************ +ƣTCP Client PULL ģӿ +̳ ITcpClient IPullClient +************************************************************************/ +class ITcpPullClient : public IPullClient, public ITcpClient +{ +public: + /* IClient* תΪ IPullClient* */ + inline static IPullClient* ToPull(IClient* pClient) + { + return (IPullClient*)((char*)pClient - sizeof(IPullClient)); + } + + /* IPullClient* תΪ ITcpClient* */ + inline static ITcpClient* ToClient(IPullClient* pPullClient) + { + return (ITcpClient*)((char*)pPullClient + sizeof(IPullClient)); + } +}; + +/************************************************************************ +ƣServer/Agent PACK ģӿ + Server/Agent PACK ģв +************************************************************************/ +class IPackSocket +{ +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ + virtual void SetMaxPackSize (DWORD dwMaxPackSize) = 0; + /* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ + virtual void SetPackHeaderFlag (USHORT usPackHeaderFlag) = 0; + + /* ȡݰ󳤶 */ + virtual DWORD GetMaxPackSize () = 0; + /* ȡͷʶ */ + virtual USHORT GetPackHeaderFlag() = 0; + +public: + virtual ~IPackSocket() {} +}; + +/************************************************************************ +ƣClient PACK ģӿ + Client PACK ģв +************************************************************************/ +class IPackClient +{ +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ + virtual void SetMaxPackSize (DWORD dwMaxPackSize) = 0; + /* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ + virtual void SetPackHeaderFlag (USHORT usPackHeaderFlag) = 0; + + /* ȡݰ󳤶 */ + virtual DWORD GetMaxPackSize () = 0; + /* ȡͷʶ */ + virtual USHORT GetPackHeaderFlag() = 0; + +public: + virtual ~IPackClient() {} +}; + +/************************************************************************ +ƣTCP Server PACK ģӿ +̳ ITcpServer IPackSocket +************************************************************************/ +class ITcpPackServer : public IPackSocket, public ITcpServer +{ +public: + /* IServer* תΪ IPackSocket* */ + inline static IPackSocket* ToPack(IServer* pServer) + { + return (IPackSocket*)((char*)pServer - sizeof(IPackSocket)); + } + + /* IPackSocket* תΪ ITcpServer* */ + inline static ITcpServer* ToServer(IPackSocket* pPackSocket) + { + return (ITcpServer*)((char*)pPackSocket + sizeof(IPackSocket)); + } +}; + +/************************************************************************ +ƣTCP Agent PACK ģӿ +̳ ITcpAgent IPackSocket +************************************************************************/ +class ITcpPackAgent : public IPackSocket, public ITcpAgent +{ +public: + /* IAgent* תΪ IPackSocket* */ + inline static IPackSocket* ToPack(IAgent* pAgent) + { + return (IPackSocket*)((char*)pAgent - sizeof(IPackSocket)); + } + + /* IPackSocket* תΪ ITcpAgent* */ + inline static ITcpAgent* ToAgent(IPackSocket* pPackSocket) + { + return (ITcpAgent*)((char*)pPackSocket + sizeof(IPackSocket)); + } +}; + +/************************************************************************ +ƣTCP Client PACK ģӿ +̳ ITcpClient IPackClient +************************************************************************/ +class ITcpPackClient : public IPackClient, public ITcpClient +{ +public: + /* IClient* תΪ IPackClient* */ + inline static IPackClient* ToPack(IClient* pClient) + { + return (IPackClient*)((char*)pClient - sizeof(IPackClient)); + } + + /* IPackClient* תΪ ITcpClient* */ + inline static ITcpClient* ToClient(IPackClient* pPackClient) + { + return (ITcpClient*)((char*)pPackClient + sizeof(IPackClient)); + } +}; diff --git a/HP-Socket/Bin/HPSocket/x64/HPSocket.dll b/HP-Socket/Bin/HPSocket/x64/HPSocket.dll new file mode 100644 index 000000000..fdc937181 Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x64/HPSocket.dll differ diff --git a/HP-Socket/Bin/HPSocket/x64/HPSocket.lib b/HP-Socket/Bin/HPSocket/x64/HPSocket.lib new file mode 100644 index 000000000..9c42665d4 Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x64/HPSocket.lib differ diff --git a/HP-Socket/Bin/HPSocket/x64/HPSocket_D.dll b/HP-Socket/Bin/HPSocket/x64/HPSocket_D.dll new file mode 100644 index 000000000..5293e78cd Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x64/HPSocket_D.dll differ diff --git a/HP-Socket/Bin/HPSocket/x64/HPSocket_D.lib b/HP-Socket/Bin/HPSocket/x64/HPSocket_D.lib new file mode 100644 index 000000000..c1e9009fd Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x64/HPSocket_D.lib differ diff --git a/HP-Socket/Bin/HPSocket/x64/HPSocket_U.dll b/HP-Socket/Bin/HPSocket/x64/HPSocket_U.dll new file mode 100644 index 000000000..f04f0c4d4 Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x64/HPSocket_U.dll differ diff --git a/HP-Socket/Bin/HPSocket/x64/HPSocket_U.lib b/HP-Socket/Bin/HPSocket/x64/HPSocket_U.lib new file mode 100644 index 000000000..293f5cd42 Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x64/HPSocket_U.lib differ diff --git a/HP-Socket/Bin/HPSocket/x64/HPSocket_UD.dll b/HP-Socket/Bin/HPSocket/x64/HPSocket_UD.dll new file mode 100644 index 000000000..3842406f1 Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x64/HPSocket_UD.dll differ diff --git a/HP-Socket/Bin/HPSocket/x64/HPSocket_UD.lib b/HP-Socket/Bin/HPSocket/x64/HPSocket_UD.lib new file mode 100644 index 000000000..e6f813e6e Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x64/HPSocket_UD.lib differ diff --git a/HP-Socket/Bin/HPSocket/x86/HPSocket.dll b/HP-Socket/Bin/HPSocket/x86/HPSocket.dll new file mode 100644 index 000000000..8af936e1e Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x86/HPSocket.dll differ diff --git a/HP-Socket/Bin/HPSocket/x86/HPSocket.lib b/HP-Socket/Bin/HPSocket/x86/HPSocket.lib new file mode 100644 index 000000000..fcf95bb78 Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x86/HPSocket.lib differ diff --git a/HP-Socket/Bin/HPSocket/x86/HPSocket_D.dll b/HP-Socket/Bin/HPSocket/x86/HPSocket_D.dll new file mode 100644 index 000000000..b2fba5394 Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x86/HPSocket_D.dll differ diff --git a/HP-Socket/Bin/HPSocket/x86/HPSocket_D.lib b/HP-Socket/Bin/HPSocket/x86/HPSocket_D.lib new file mode 100644 index 000000000..15025930e Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x86/HPSocket_D.lib differ diff --git a/HP-Socket/Bin/HPSocket/x86/HPSocket_U.dll b/HP-Socket/Bin/HPSocket/x86/HPSocket_U.dll new file mode 100644 index 000000000..7ee68eb59 Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x86/HPSocket_U.dll differ diff --git a/HP-Socket/Bin/HPSocket/x86/HPSocket_U.lib b/HP-Socket/Bin/HPSocket/x86/HPSocket_U.lib new file mode 100644 index 000000000..f22f844cc Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x86/HPSocket_U.lib differ diff --git a/HP-Socket/Bin/HPSocket/x86/HPSocket_UD.dll b/HP-Socket/Bin/HPSocket/x86/HPSocket_UD.dll new file mode 100644 index 000000000..eb1bd836f Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x86/HPSocket_UD.dll differ diff --git a/HP-Socket/Bin/HPSocket/x86/HPSocket_UD.lib b/HP-Socket/Bin/HPSocket/x86/HPSocket_UD.lib new file mode 100644 index 000000000..512a2ca1c Binary files /dev/null and b/HP-Socket/Bin/HPSocket/x86/HPSocket_UD.lib differ diff --git a/HP-Socket/Bin/HPSocket4C/HPSocket4C.h b/HP-Socket/Bin/HPSocket4C/HPSocket4C.h new file mode 100644 index 000000000..44a7ed11a --- /dev/null +++ b/HP-Socket/Bin/HPSocket4C/HPSocket4C.h @@ -0,0 +1,1163 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: HPSocket for C DLL + +Desc: C ԣ磺C / C# / Delphi ȣܷʹ HPSocket + +Usage: + һ + -------------------------------------------------------------------------------------- + 0. C/C++ 򣩰 HPSocket4C.h ͷļ + 1. ::Create_HP_XxxListener() + 2. ::Create_HP_Xxx(pListener) HPSocket + 3. ::HP_Set_FN_Xxx_OnYyy(pListener, ...) üĻص + 4. ص HPSocket + 5. ...... ...... + 6. ::Destroy_HP_Xxx(pSocket) HPSocket + 7. ::Destroy_HP_XxxListener(pListener) ټ + + + -------------------------------------------------------------------------------------- + 1. ӦóҪõĵװضԵİװ + 2. ͨװװķʽʹ HPSocket + +Release: + 1. x86/HPSocket4C.dll - (32λ/MBCS/Release) + 2. x86/HPSocket4C_D.dll - (32λ/MBCS/DeBug) + 3. x86/HPSocket4C_U.dll - (32λ/UNICODE/Release) + 4. x86/HPSocket4C_UD.dll - (32λ/UNICODE/DeBug) + 5. x64/HPSocket4C.dll - (64λ/MBCS/Release) + 6. x64/HPSocket4C_D.dll - (64λ/MBCS/DeBug) + 7. x64/HPSocket4C_U.dll - (64λ/UNICODE/Release) + 8. x64/HPSocket4C_UD.dll - (64λ/UNICODE/DeBug) + +******************************************************************************/ + +#pragma once + +#include + +/**************************************************/ +/********* imports / exports HPSocket.dll *********/ + +#ifdef HPSOCKET_EXPORTS + #define HPSOCKET_API extern "C" __declspec(dllexport) +#else + #define HPSOCKET_API extern "C" __declspec(dllimport) +#endif + +/************************************************************************ +ƣ ID + ID +************************************************************************/ +typedef ULONG_PTR HP_CONNID; + +/************************************************************************ +ƣ Socket ָͱ + Socket ָ붨Ϊֱ۵ı +************************************************************************/ + +typedef PVOID HP_Object; + +typedef HP_Object HP_Server; +typedef HP_Object HP_Agent; +typedef HP_Object HP_Client; +typedef HP_Object HP_TcpServer; +typedef HP_Object HP_TcpAgent; +typedef HP_Object HP_TcpClient; +typedef HP_Object HP_PullSocket; +typedef HP_Object HP_PullClient; +typedef HP_Object HP_TcpPullServer; +typedef HP_Object HP_TcpPullAgent; +typedef HP_Object HP_TcpPullClient; +typedef HP_Object HP_PackSocket; +typedef HP_Object HP_PackClient; +typedef HP_Object HP_TcpPackServer; +typedef HP_Object HP_TcpPackAgent; +typedef HP_Object HP_TcpPackClient; +typedef HP_Object HP_UdpServer; +typedef HP_Object HP_UdpClient; +typedef HP_Object HP_UdpCast; + +typedef HP_Object HP_Listener; +typedef HP_Object HP_ServerListener; +typedef HP_Object HP_AgentListener; +typedef HP_Object HP_ClientListener; +typedef HP_Object HP_TcpServerListener; +typedef HP_Object HP_TcpAgentListener; +typedef HP_Object HP_TcpClientListener; +typedef HP_Object HP_PullSocketListener; +typedef HP_Object HP_PullClientListener; +typedef HP_Object HP_TcpPullServerListener; +typedef HP_Object HP_TcpPullAgentListener; +typedef HP_Object HP_TcpPullClientListener; +typedef HP_Object HP_UdpServerListener; +typedef HP_Object HP_UdpClientListener; +typedef HP_Object HP_UdpCastListener; + +/*****************************************************************************************************/ +/******************************************** ࡢӿ ********************************************/ +/*****************************************************************************************************/ + +/************************************************************************ +ƣͨ״̬ +Ӧóͨͨ GetState() ȡǰ״̬ +************************************************************************/ +enum En_HP_ServiceState +{ + HP_SS_STARTING = 0, // + HP_SS_STARTED = 1, // Ѿ + HP_SS_STOPPING = 2, // ֹͣ + HP_SS_STOPPED = 3, // Ѿֹͣ +}; + +/************************************************************************ +ƣSocket +Ӧó OnErrror() ¼ͨòʶֲµĴ +************************************************************************/ +enum En_HP_SocketOperation +{ + HP_SO_UNKNOWN = 0, // Unknown + HP_SO_ACCEPT = 1, // Acccept + HP_SO_CONNECT = 2, // Connect + HP_SO_SEND = 3, // Send + HP_SO_RECEIVE = 4, // Receive + HP_SO_CLOSE = 5, // Close +}; + +/************************************************************************ +ƣ¼֪ͨ +¼֪ͨķֵͬķֵӰͨĺΪ +************************************************************************/ +enum En_HP_HandleResult +{ + HP_HR_OK = 0, // ɹ + HP_HR_IGNORE = 1, // + HP_HR_ERROR = 2, // +}; + +/************************************************************************ +ƣץȡ +ץȡķֵ +************************************************************************/ +enum En_HP_FetchResult +{ + HP_FR_OK = 0, // ɹ + HP_FR_LENGTH_TOO_LONG = 1, // ץȡȹ + HP_FR_DATA_NOT_FOUND = 2, // Ҳ ConnID Ӧ +}; + +/************************************************************************ +ƣݷͲ +Server Agent ݷͲ + +* ģʽĬϣ ѶͲһͣӴЧ +* ȫģʽ ѶͲһͣƴٶȣ⻺ +* ֱģʽ ÿһͲֱͶݣڸزߵҪʵʱԽϸߵij + +************************************************************************/ +enum En_HP_SendPolicy +{ + HP_SP_PACK = 0, // ģʽĬϣ + HP_SP_SAFE = 1, // ȫģʽ + HP_SP_DIRECT = 2, // ֱģʽ +}; + +/************************************************************************ +ƣ + Start() / Stop() ִʧʱͨ GetLastError() ȡ +************************************************************************/ +enum En_HP_SocketError +{ + HP_SE_OK = NO_ERROR, // ɹ + HP_SE_ILLEGAL_STATE = 1, // ǰ״̬ + HP_SE_INVALID_PARAM = 2, // Ƿ + HP_SE_SOCKET_CREATE = 3, // SOCKET ʧ + HP_SE_SOCKET_BIND = 4, // SOCKET ʧ + HP_SE_SOCKET_PREPARE = 5, // SOCKET ʧ + HP_SE_SOCKET_LISTEN = 6, // SOCKET ʧ + HP_SE_CP_CREATE = 7, // ɶ˿ʧ + HP_SE_WORKER_THREAD_CREATE = 8, // ߳ʧ + HP_SE_DETECT_THREAD_CREATE = 9, // ߳ʧ + HP_SE_SOCKE_ATTACH_TO_CP = 10, // ɶ˿ʧ + HP_SE_CONNECT_SERVER = 11, // ӷʧ + HP_SE_NETWORK = 12, // + HP_SE_DATA_PROC = 13, // ݴ + HP_SE_DATA_SEND = 14, // ݷʧ +}; + +/************************************************************************ +ƣģʽ +UDP IJģʽ鲥㲥 +************************************************************************/ +enum En_HP_CastMode +{ + HP_CM_MULTICAST = 0, // 鲥 + HP_CM_BROADCAST = 1, // 㲥 +}; + +/****************************************************/ +/************** HPSocket4C.dll ص **************/ + +/* Server ص */ +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnPrepareListen) (UINT_PTR soListen); +// Ϊ TCP ӣpClientΪ SOCKET Ϊ UDP ӣpClientΪ SOCKADDR_IN ָ룻 +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnAccept) (HP_CONNID dwConnID, UINT_PTR pClient); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnSend) (HP_CONNID dwConnID, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnReceive) (HP_CONNID dwConnID, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnPullReceive) (HP_CONNID dwConnID, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnClose) (HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnShutdown) (); + +/* Agent ص */ +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnPrepareConnect) (HP_CONNID dwConnID, UINT_PTR socket); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnConnect) (HP_CONNID dwConnID); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnSend) (HP_CONNID dwConnID, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnReceive) (HP_CONNID dwConnID, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnPullReceive) (HP_CONNID dwConnID, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnClose) (HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnShutdown) (); + +/* Client ص */ +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnPrepareConnect) (HP_Client pClient, UINT_PTR socket); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnConnect) (HP_Client pClient); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnSend) (HP_Client pClient, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnReceive) (HP_Client pClient, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnPullReceive) (HP_Client pClient, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnClose) (HP_Client pClient, En_HP_SocketOperation enOperation, int iErrorCode); + +/****************************************************/ +/************** HPSocket4C.dll **************/ + +// HP_TcpServer +HPSOCKET_API HP_TcpServer __stdcall Create_HP_TcpServer(HP_TcpServerListener pListener); +// HP_TcpAgent +HPSOCKET_API HP_TcpAgent __stdcall Create_HP_TcpAgent(HP_TcpAgentListener pListener); +// HP_TcpClient +HPSOCKET_API HP_TcpClient __stdcall Create_HP_TcpClient(HP_TcpClientListener pListener); +// HP_TcpPullServer +HPSOCKET_API HP_TcpPullServer __stdcall Create_HP_TcpPullServer(HP_TcpPullServerListener pListener); +// HP_TcpPullAgent +HPSOCKET_API HP_TcpPullAgent __stdcall Create_HP_TcpPullAgent(HP_TcpPullAgentListener pListener); +// HP_TcpPullClient +HPSOCKET_API HP_TcpPullClient __stdcall Create_HP_TcpPullClient(HP_TcpPullClientListener pListener); +// HP_TcpPackServer +HPSOCKET_API HP_TcpPackServer __stdcall Create_HP_TcpPackServer(HP_TcpServerListener pListener); +// HP_TcpPackAgent +HPSOCKET_API HP_TcpPackAgent __stdcall Create_HP_TcpPackAgent(HP_TcpAgentListener pListener); +// HP_TcpPackClient +HPSOCKET_API HP_TcpPackClient __stdcall Create_HP_TcpPackClient(HP_TcpClientListener pListener); +// HP_UdpServer +HPSOCKET_API HP_UdpServer __stdcall Create_HP_UdpServer(HP_UdpServerListener pListener); +// HP_UdpClient +HPSOCKET_API HP_UdpClient __stdcall Create_HP_UdpClient(HP_UdpClientListener pListener); +// HP_UdpCast +HPSOCKET_API HP_UdpCast __stdcall Create_HP_UdpCast(HP_UdpCastListener pListener); + +// HP_TcpServer +HPSOCKET_API void __stdcall Destroy_HP_TcpServer(HP_TcpServer pServer); +// HP_TcpAgent +HPSOCKET_API void __stdcall Destroy_HP_TcpAgent(HP_TcpAgent pAgent); +// HP_TcpClient +HPSOCKET_API void __stdcall Destroy_HP_TcpClient(HP_TcpClient pClient); +// HP_TcpPullServer +HPSOCKET_API void __stdcall Destroy_HP_TcpPullServer(HP_TcpPullServer pServer); +// HP_TcpPullAgent +HPSOCKET_API void __stdcall Destroy_HP_TcpPullAgent(HP_TcpPullAgent pAgent); +// HP_TcpPullClient +HPSOCKET_API void __stdcall Destroy_HP_TcpPullClient(HP_TcpPullClient pClient); +// HP_TcpPackServer +HPSOCKET_API void __stdcall Destroy_HP_TcpPackServer(HP_TcpPackServer pServer); +// HP_TcpPackAgent +HPSOCKET_API void __stdcall Destroy_HP_TcpPackAgent(HP_TcpPackAgent pAgent); +// HP_TcpPackClient +HPSOCKET_API void __stdcall Destroy_HP_TcpPackClient(HP_TcpPackClient pClient); +// HP_UdpServer +HPSOCKET_API void __stdcall Destroy_HP_UdpServer(HP_UdpServer pServer); +// HP_UdpClient +HPSOCKET_API void __stdcall Destroy_HP_UdpClient(HP_UdpClient pClient); +// HP_UdpCast +HPSOCKET_API void __stdcall Destroy_HP_UdpCast(HP_UdpCast pCast); + +// HP_TcpServerListener +HPSOCKET_API HP_TcpServerListener __stdcall Create_HP_TcpServerListener(); +// HP_TcpAgentListener +HPSOCKET_API HP_TcpAgentListener __stdcall Create_HP_TcpAgentListener(); +// HP_TcpClientListener +HPSOCKET_API HP_TcpClientListener __stdcall Create_HP_TcpClientListener(); +// HP_TcpPullServerListener +HPSOCKET_API HP_TcpPullServerListener __stdcall Create_HP_TcpPullServerListener(); +// HP_TcpPullAgentListener +HPSOCKET_API HP_TcpPullAgentListener __stdcall Create_HP_TcpPullAgentListener(); +// HP_TcpPullClientListener +HPSOCKET_API HP_TcpPullClientListener __stdcall Create_HP_TcpPullClientListener(); +// HP_UdpServerListener +HPSOCKET_API HP_UdpServerListener __stdcall Create_HP_UdpServerListener(); +// HP_UdpClientListener +HPSOCKET_API HP_UdpClientListener __stdcall Create_HP_UdpClientListener(); +// HP_UdpCastListener +HPSOCKET_API HP_UdpCastListener __stdcall Create_HP_UdpCastListener(); + +// HP_TcpServerListener +HPSOCKET_API void __stdcall Destroy_HP_TcpServerListener(HP_TcpServerListener pListener); +// HP_TcpAgentListener +HPSOCKET_API void __stdcall Destroy_HP_TcpAgentListener(HP_TcpAgentListener pListener); +// HP_TcpClientListener +HPSOCKET_API void __stdcall Destroy_HP_TcpClientListener(HP_TcpClientListener pListener); +// HP_TcpPullServerListener +HPSOCKET_API void __stdcall Destroy_HP_TcpPullServerListener(HP_TcpPullServerListener pListener); +// HP_TcpPullAgentListener +HPSOCKET_API void __stdcall Destroy_HP_TcpPullAgentListener(HP_TcpPullAgentListener pListener); +// HP_TcpPullClientListener +HPSOCKET_API void __stdcall Destroy_HP_TcpPullClientListener(HP_TcpPullClientListener pListener); +// HP_UdpServerListener +HPSOCKET_API void __stdcall Destroy_HP_UdpServerListener(HP_UdpServerListener pListener); +// HP_UdpClientListener +HPSOCKET_API void __stdcall Destroy_HP_UdpClientListener(HP_UdpClientListener pListener); +// HP_UdpCastListener +HPSOCKET_API void __stdcall Destroy_HP_UdpCastListener(HP_UdpCastListener pListener); + +/**********************************************************************************/ +/***************************** Server ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnPrepareListen(HP_ServerListener pListener , HP_FN_Server_OnPrepareListen fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnAccept(HP_ServerListener pListener , HP_FN_Server_OnAccept fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnSend(HP_ServerListener pListener , HP_FN_Server_OnSend fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnReceive(HP_ServerListener pListener , HP_FN_Server_OnReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnPullReceive(HP_ServerListener pListener , HP_FN_Server_OnPullReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnClose(HP_ServerListener pListener , HP_FN_Server_OnClose fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnShutdown(HP_ServerListener pListener , HP_FN_Server_OnShutdown fn); + +/**********************************************************************************/ +/****************************** Agent ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnPrepareConnect(HP_AgentListener pListener , HP_FN_Agent_OnPrepareConnect fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnConnect(HP_AgentListener pListener , HP_FN_Agent_OnConnect fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnSend(HP_AgentListener pListener , HP_FN_Agent_OnSend fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnReceive(HP_AgentListener pListener , HP_FN_Agent_OnReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnPullReceive(HP_AgentListener pListener , HP_FN_Agent_OnPullReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnClose(HP_AgentListener pListener , HP_FN_Agent_OnClose fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnShutdown(HP_AgentListener pListener , HP_FN_Agent_OnShutdown fn); + +/**********************************************************************************/ +/***************************** Client ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnPrepareConnect(HP_ClientListener pListener , HP_FN_Client_OnPrepareConnect fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnConnect(HP_ClientListener pListener , HP_FN_Client_OnConnect fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnSend(HP_ClientListener pListener , HP_FN_Client_OnSend fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnReceive(HP_ClientListener pListener , HP_FN_Client_OnReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnPullReceive(HP_ClientListener pListener , HP_FN_Client_OnPullReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnClose(HP_ClientListener pListener , HP_FN_Client_OnClose fn); + +/**************************************************************************/ +/***************************** Server *****************************/ + +/* +* ƣͨ +* ͨɺɿʼտͻӲշ +* +* pszBindAddress -- ַ +* usPort -- ˿ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_Start(HP_Server pServer, LPCTSTR pszBindAddress, USHORT usPort); + +/* +* ƣرͨ +* رշͨرɺϿпͻӲͷԴ +* +* +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_Stop(HP_Server pServer); + +/* +* ƣ +* ָӷ +* +* dwConnID -- ID +* pBuffer -- ͻ +* iLength -- ͻ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Server_Send(HP_Server pServer, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength); + +/* +* ƣ +* ָӷ +* +* dwConnID -- ID +* pBuffer -- ͻ +* iLength -- ͻ +* iOffset -- ͻָƫ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Server_SendPart(HP_Server pServer, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset); + +/* +* ƣͶ +* ָӷͶ +* TCP - ˳ݰ +* UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ +* +* dwConnID -- ID +* pBuffers -- ͻ +* iCount -- ͻĿ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Server_SendPackets(HP_Server pServer, HP_CONNID dwConnID, const WSABUF pBuffers[], int iCount); + +/* +* ƣϿ +* Ͽijͻ˵ +* +* dwConnID -- ID +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_Disconnect(HP_Server pServer, HP_CONNID dwConnID, BOOL bForce); + +/* +* ƣϿʱ +* Ͽָʱ +* +* dwPeriod -- ʱ룩 +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_DisconnectLongConnections(HP_Server pServer, DWORD dwPeriod, BOOL bForce); + +/* +* ƣϿĬ +* ϿָʱľĬ +* +* dwPeriod -- ʱ룩 +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_DisconnectSilenceConnections(HP_Server pServer, DWORD dwPeriod, BOOL bForce); + +/******************************************************************************/ +/***************************** Server Էʷ *****************************/ + +/* +* ƣӵĸ +* ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ +* +* dwConnID -- ID +* pv -- +* ֵ TRUE -- ɹ +* FALSE -- ʧܣЧ ID +*/ +HPSOCKET_API BOOL __stdcall HP_Server_SetConnectionExtra(HP_Server pServer, HP_CONNID dwConnID, PVOID pExtra); + +/* +* ƣȡӵĸ +* ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ +* +* dwConnID -- ID +* ppv -- ָ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣЧ ID +*/ +HPSOCKET_API BOOL __stdcall HP_Server_GetConnectionExtra(HP_Server pServer, HP_CONNID dwConnID, PVOID* ppExtra); + +/* ͨǷ */ +HPSOCKET_API BOOL __stdcall HP_Server_HasStarted(HP_Server pServer); +/* 鿴ͨǰ״̬ */ +HPSOCKET_API En_HP_ServiceState __stdcall HP_Server_GetState(HP_Server pServer); +/* ȡһʧܲĴ */ +HPSOCKET_API En_HP_SocketError __stdcall HP_Server_GetLastError(HP_Server pServer); +/* ȡһʧܲĴ */ +HPSOCKET_API LPCTSTR __stdcall HP_Server_GetLastErrorDesc(HP_Server pServer); +/* ȡδݵij */ +HPSOCKET_API BOOL __stdcall HP_Server_GetPendingDataLength(HP_Server pServer, HP_CONNID dwConnID, int* piPending); +/* ȡͻ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetConnectionCount(HP_Server pServer); +/* ȡӵ CONNID */ +HPSOCKET_API BOOL __stdcall HP_Server_GetAllConnectionIDs(HP_Server pServer, HP_CONNID pIDs[], DWORD* pdwCount); +/* ȡijͻʱ룩 */ +HPSOCKET_API BOOL __stdcall HP_Server_GetConnectPeriod(HP_Server pServer, HP_CONNID dwConnID, DWORD* pdwPeriod); +/* ȡijӾĬʱ䣨룩 */ +HPSOCKET_API BOOL __stdcall HP_Server_GetSilencePeriod(HP_Server pServer, HP_CONNID dwConnID, DWORD* pdwPeriod); +/* ȡ Socket ĵַϢ */ +HPSOCKET_API BOOL __stdcall HP_Server_GetListenAddress(HP_Server pServer, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ȡijӵԶ̵ַϢ */ +HPSOCKET_API BOOL __stdcall HP_Server_GetRemoteAddress(HP_Server pServer, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); + +/* ݷͲ */ +HPSOCKET_API void __stdcall HP_Server_SetSendPolicy(HP_Server pServer, En_HP_SendPolicy enSendPolicy); +/* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjLockTime(HP_Server pServer, DWORD dwFreeSocketObjLockTime); +/* Socket شСͨΪƽ 1/3 - 1/2 */ +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjPool(HP_Server pServer, DWORD dwFreeSocketObjPool); +/* ڴ黺شСͨΪ Socket شС 2 - 3 */ +HPSOCKET_API void __stdcall HP_Server_SetFreeBufferObjPool(HP_Server pServer, DWORD dwFreeBufferObjPool); +/* Socket ػշֵͨΪ Socket شС 3 */ +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjHold(HP_Server pServer, DWORD dwFreeSocketObjHold); +/* ڴ黺ػշֵͨΪڴ黺شС 3 */ +HPSOCKET_API void __stdcall HP_Server_SetFreeBufferObjHold(HP_Server pServer, DWORD dwFreeBufferObjHold); +/* ù߳ͨΪ 2 * CPU + 2 */ +HPSOCKET_API void __stdcall HP_Server_SetWorkerThreadCount(HP_Server pServer, DWORD dwWorkerThreadCount); +/* ǷǾĬʱ䣨Ϊ TRUE ʱ DisconnectSilenceConnections() GetSilencePeriod() ЧĬϣFALSE */ +HPSOCKET_API void __stdcall HP_Server_SetMarkSilence(HP_Server pServer, BOOL bMarkSilence); + +/* ȡݷͲ */ +HPSOCKET_API En_HP_SendPolicy __stdcall HP_Server_GetSendPolicy(HP_Server pServer); +/* ȡ Socket ʱ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjLockTime(HP_Server pServer); +/* ȡ Socket شС */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjPool(HP_Server pServer); +/* ȡڴ黺شС */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeBufferObjPool(HP_Server pServer); +/* ȡ Socket ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjHold(HP_Server pServer); +/* ȡڴ黺ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeBufferObjHold(HP_Server pServer); +/* ȡ߳ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetWorkerThreadCount(HP_Server pServer); +/* ǷǾĬʱ */ +HPSOCKET_API BOOL __stdcall HP_Server_IsMarkSilence(HP_Server pServer); + +/**********************************************************************************/ +/******************************* TCP Server *******************************/ + +/* +* ƣСļ +* ָӷ 4096 KB µСļ +* +* dwConnID -- ID +* lpszFileName -- ļ· +* pHead -- ͷ +* pTail -- β +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_TcpServer_SendSmallFile(HP_Server pServer, HP_CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail); + +/**********************************************************************************/ +/***************************** TCP Server Էʷ *****************************/ + +/* ü Socket ĵȺдСݲã */ +HPSOCKET_API void __stdcall HP_TcpServer_SetSocketListenQueue(HP_TcpServer pServer, DWORD dwSocketListenQueue); +/* Accept ԤͶݸصãAccept ԤͶԽֵ֧IJԽࣩ */ +HPSOCKET_API void __stdcall HP_TcpServer_SetAcceptSocketCount(HP_TcpServer pServer, DWORD dwAcceptSocketCount); +/* ͨݻСƽͨݰСãͨΪ 1024 ı */ +HPSOCKET_API void __stdcall HP_TcpServer_SetSocketBufferSize(HP_TcpServer pServer, DWORD dwSocketBufferSize); +/* 룬0 򲻷Ĭϣ30 * 1000 */ +HPSOCKET_API void __stdcall HP_TcpServer_SetKeepAliveTime(HP_TcpServer pServer, DWORD dwKeepAliveTime); +/* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ +HPSOCKET_API void __stdcall HP_TcpServer_SetKeepAliveInterval(HP_TcpServer pServer, DWORD dwKeepAliveInterval); + +/* ȡ Accept ԤͶ */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetAcceptSocketCount(HP_TcpServer pServer); +/* ȡͨݻС */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetSocketBufferSize(HP_TcpServer pServer); +/* ȡ Socket ĵȺдС */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetSocketListenQueue(HP_TcpServer pServer); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetKeepAliveTime(HP_TcpServer pServer); +/* ȡ쳣 */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetKeepAliveInterval(HP_TcpServer pServer); + +/**********************************************************************************/ +/***************************** UDP Server Էʷ *****************************/ + +/* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ +HPSOCKET_API void __stdcall HP_UdpServer_SetMaxDatagramSize(HP_UdpServer pServer, DWORD dwMaxDatagramSize); +/* ȡݱ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetMaxDatagramSize(HP_UdpServer pServer); + +/* Receive ԤͶݸصãReceive ԤͶԽ򶪰ԽС */ +HPSOCKET_API void __stdcall HP_UdpServer_SetPostReceiveCount(HP_UdpServer pServer, DWORD dwPostReceiveCount); +/* ȡ Receive ԤͶ */ +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetPostReceiveCount(HP_UdpServer pServer); + +/* üԴ0 򲻷ͼԴΪѶߣ */ +HPSOCKET_API void __stdcall HP_UdpServer_SetDetectAttempts(HP_UdpServer pServer, DWORD dwDetectAttempts); +/* üͼ룬0 ͼ */ +HPSOCKET_API void __stdcall HP_UdpServer_SetDetectInterval(HP_UdpServer pServer, DWORD dwDetectInterval); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetDetectAttempts(HP_UdpServer pServer); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetDetectInterval(HP_UdpServer pServer); + +/**************************************************************************/ +/***************************** Agent *****************************/ + +/* +* ƣͨ +* ͨŴɺɿʼԶ̷ +* +* pszBindAddress -- ַ +* bAsyncConnect -- Ƿ첽 Connect +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Start(HP_Agent pAgent, LPCTSTR pszBindAddress, BOOL bAsyncConnect); + +/* +* ƣرͨ +* رͨرɺϿӲͷԴ +* +* +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Stop(HP_Agent pAgent); + +/* +* ƣӷ +* ӷӳɹ IAgentListener յ OnConnect() ¼ +* +* pszRemoteAddress -- ˵ַ +* usPort -- ˶˿ +* pdwConnID -- IDĬϣnullptrȡ ID +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ SYS_GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Connect(HP_Agent pAgent, LPCTSTR pszRemoteAddress, USHORT usPort, HP_CONNID* pdwConnID); + +/* +* ƣ +* ָӷ +* +* dwConnID -- ID +* pBuffer -- ͻ +* iLength -- ͻ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Send(HP_Agent pAgent, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength); + +/* +* ƣ +* ָӷ +* +* dwConnID -- ID +* pBuffer -- ͻ +* iLength -- ͻ +* iOffset -- ͻָƫ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_SendPart(HP_Agent pAgent, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset); + +/* +* ƣͶ +* ָӷͶ +* TCP - ˳ݰ +* UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ +* +* dwConnID -- ID +* pBuffers -- ͻ +* iCount -- ͻĿ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_SendPackets(HP_Agent pAgent, HP_CONNID dwConnID, const WSABUF pBuffers[], int iCount); + +/* +* ƣϿ +* Ͽij +* +* dwConnID -- ID +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Disconnect(HP_Agent pAgent, HP_CONNID dwConnID, BOOL bForce); + +/* +* ƣϿʱ +* Ͽָʱ +* +* dwPeriod -- ʱ룩 +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_DisconnectLongConnections(HP_Agent pAgent, DWORD dwPeriod, BOOL bForce); + +/* +* ƣϿĬ +* ϿָʱľĬ +* +* dwPeriod -- ʱ룩 +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_DisconnectSilenceConnections(HP_Agent pAgent, DWORD dwPeriod, BOOL bForce); + +/******************************************************************************/ +/***************************** Agent Էʷ *****************************/ + +/* +* ƣӵĸ +* ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ +* +* dwConnID -- ID +* pv -- +* ֵ TRUE -- ɹ +* FALSE -- ʧܣЧ ID +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_SetConnectionExtra(HP_Agent pAgent, HP_CONNID dwConnID, PVOID pExtra); + +/* +* ƣȡӵĸ +* ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ +* +* dwConnID -- ID +* ppv -- ָ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣЧ ID +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_GetConnectionExtra(HP_Agent pAgent, HP_CONNID dwConnID, PVOID* ppExtra); + +/* ͨǷ */ +HPSOCKET_API BOOL __stdcall HP_Agent_HasStarted(HP_Agent pAgent); +/* 鿴ͨǰ״̬ */ +HPSOCKET_API En_HP_ServiceState __stdcall HP_Agent_GetState(HP_Agent pAgent); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetConnectionCount(HP_Agent pAgent); +/* ȡӵ CONNID */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetAllConnectionIDs(HP_Agent pAgent, HP_CONNID pIDs[], DWORD* pdwCount); +/* ȡijʱ룩 */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetConnectPeriod(HP_Agent pAgent, HP_CONNID dwConnID, DWORD* pdwPeriod); +/* ȡijӾĬʱ䣨룩 */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetSilencePeriod(HP_Agent pAgent, HP_CONNID dwConnID, DWORD* pdwPeriod); +/* ȡijӵıصַϢ */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetLocalAddress(HP_Agent pAgent, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ȡijӵԶ̵ַϢ */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetRemoteAddress(HP_Agent pAgent, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ȡһʧܲĴ */ +HPSOCKET_API En_HP_SocketError __stdcall HP_Agent_GetLastError(HP_Agent pAgent); +/* ȡһʧܲĴ */ +HPSOCKET_API LPCTSTR __stdcall HP_Agent_GetLastErrorDesc(HP_Agent pAgent); +/* ȡδݵij */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetPendingDataLength(HP_Agent pAgent, HP_CONNID dwConnID, int* piPending); + +/* ݷͲ */ +HPSOCKET_API void __stdcall HP_Agent_SetSendPolicy(HP_Agent pAgent, En_HP_SendPolicy enSendPolicy); +/* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjLockTime(HP_Agent pAgent, DWORD dwFreeSocketObjLockTime); +/* Socket شСͨΪƽ 1/3 - 1/2 */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjPool(HP_Agent pAgent, DWORD dwFreeSocketObjPool); +/* ڴ黺شСͨΪ Socket شС 2 - 3 */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeBufferObjPool(HP_Agent pAgent, DWORD dwFreeBufferObjPool); +/* Socket ػշֵͨΪ Socket شС 3 */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjHold(HP_Agent pAgent, DWORD dwFreeSocketObjHold); +/* ڴ黺ػշֵͨΪڴ黺شС 3 */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeBufferObjHold(HP_Agent pAgent, DWORD dwFreeBufferObjHold); +/* ù߳ͨΪ 2 * CPU + 2 */ +HPSOCKET_API void __stdcall HP_Agent_SetWorkerThreadCount(HP_Agent pAgent, DWORD dwWorkerThreadCount); +/* ǷǾĬʱ䣨Ϊ TRUE ʱ DisconnectSilenceConnections() GetSilencePeriod() ЧĬϣFALSE */ +HPSOCKET_API void __stdcall HP_Agent_SetMarkSilence(HP_Agent pAgent, BOOL bMarkSilence); + +/* ȡݷͲ */ +HPSOCKET_API En_HP_SendPolicy __stdcall HP_Agent_GetSendPolicy(HP_Agent pAgent); +/* ȡ Socket ʱ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjLockTime(HP_Agent pAgent); +/* ȡ Socket شС */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjPool(HP_Agent pAgent); +/* ȡڴ黺شС */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeBufferObjPool(HP_Agent pAgent); +/* ȡ Socket ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjHold(HP_Agent pAgent); +/* ȡڴ黺ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeBufferObjHold(HP_Agent pAgent); +/* ȡ߳ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetWorkerThreadCount(HP_Agent pAgent); +/* ǷǾĬʱ */ +HPSOCKET_API BOOL __stdcall HP_Agent_IsMarkSilence(HP_Agent pAgent); + +/**********************************************************************************/ +/******************************* TCP Agent *******************************/ + +/* +* ƣСļ +* ָӷ 4096 KB µСļ +* +* dwConnID -- ID +* lpszFileName -- ļ· +* pHead -- ͷ +* pTail -- β +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_TcpAgent_SendSmallFile(HP_Agent pAgent, HP_CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail); + +/**********************************************************************************/ +/***************************** TCP Agent Էʷ *****************************/ + +/* ǷõַûƣĬϣã */ +HPSOCKET_API void __stdcall HP_TcpAgent_SetReuseAddress(HP_TcpAgent pAgent, BOOL bReuseAddress); +/* Ƿõַû */ +HPSOCKET_API BOOL __stdcall HP_TcpAgent_IsReuseAddress(HP_TcpAgent pAgent); + +/* ͨݻСƽͨݰСãͨΪ 1024 ı */ +HPSOCKET_API void __stdcall HP_TcpAgent_SetSocketBufferSize(HP_TcpAgent pAgent, DWORD dwSocketBufferSize); +/* 룬0 򲻷Ĭϣ30 * 1000 */ +HPSOCKET_API void __stdcall HP_TcpAgent_SetKeepAliveTime(HP_TcpAgent pAgent, DWORD dwKeepAliveTime); +/* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ +HPSOCKET_API void __stdcall HP_TcpAgent_SetKeepAliveInterval(HP_TcpAgent pAgent, DWORD dwKeepAliveInterval); + +/* ȡͨݻС */ +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetSocketBufferSize(HP_TcpAgent pAgent); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetKeepAliveTime(HP_TcpAgent pAgent); +/* ȡ쳣 */ +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetKeepAliveInterval(HP_TcpAgent pAgent); + +/******************************************************************************/ +/***************************** Client *****************************/ + +/* +* ƣͨ +* ͻͨӷˣɺɿʼշ +* +* pszRemoteAddress -- ˵ַ +* usPort -- ˶˿ +* bAsyncConnect -- Ƿ첽 Connect +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Client_Start(HP_Client pClient, LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect); + +/* +* ƣرͨ +* رտͻͨرɺϿ˵ӲͷԴ +* +* +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Client_Stop(HP_Client pClient); + +/* +* ƣ +* ˷ +* +* pBuffer -- ͻ +* iLength -- ͻ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Client_Send(HP_Client pClient, const BYTE* pBuffer, int iLength); + +/* +* ƣ +* ˷ +* +* pBuffer -- ͻ +* iLength -- ͻ +* iOffset -- ͻָƫ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Client_SendPart(HP_Client pClient, const BYTE* pBuffer, int iLength, int iOffset); + +/* +* ƣͶ +* ˷Ͷ +* TCP - ˳ݰ +* UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ +* +* pBuffers -- ͻ +* iCount -- ͻĿ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Client_SendPackets(HP_Client pClient, const WSABUF pBuffers[], int iCount); + +/******************************************************************************/ +/***************************** Client Էʷ *****************************/ + +/* ӵĸ */ +HPSOCKET_API void __stdcall HP_Client_SetExtra(HP_Client pClient, PVOID pExtra); +/* ȡӵĸ */ +HPSOCKET_API PVOID __stdcall HP_Client_GetExtra(HP_Client pClient); + +/* ͨǷ */ +HPSOCKET_API BOOL __stdcall HP_Client_HasStarted(HP_Client pClient); +/* 鿴ͨǰ״̬ */ +HPSOCKET_API En_HP_ServiceState __stdcall HP_Client_GetState(HP_Client pClient); +/* ȡһʧܲĴ */ +HPSOCKET_API En_HP_SocketError __stdcall HP_Client_GetLastError(HP_Client pClient); +/* ȡһʧܲĴ */ +HPSOCKET_API LPCTSTR __stdcall HP_Client_GetLastErrorDesc(HP_Client pClient); +/* ȡ ID */ +HPSOCKET_API HP_CONNID __stdcall HP_Client_GetConnectionID(HP_Client pClient); +/* ȡ Client Socket ĵַϢ */ +HPSOCKET_API BOOL __stdcall HP_Client_GetLocalAddress(HP_Client pClient, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ȡδݵij */ +HPSOCKET_API BOOL __stdcall HP_Client_GetPendingDataLength(HP_Client pClient, int* piPending); +/* ڴ黺شСͨΪ -> PUSH ģͣ5 - 10PULL ģͣ10 - 20 */ +HPSOCKET_API void __stdcall HP_Client_SetFreeBufferPoolSize(HP_Client pClient, DWORD dwFreeBufferPoolSize); +/* ڴ黺ػշֵͨΪڴ黺شС 3 */ +HPSOCKET_API void __stdcall HP_Client_SetFreeBufferPoolHold(HP_Client pClient, DWORD dwFreeBufferPoolHold); +/* ȡڴ黺شС */ +HPSOCKET_API DWORD __stdcall HP_Client_GetFreeBufferPoolSize(HP_Client pClient); +/* ȡڴ黺ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Client_GetFreeBufferPoolHold(HP_Client pClient); + +/**********************************************************************************/ +/******************************* TCP Client *******************************/ + +/* +* ƣСļ +* ˷ 4096 KB µСļ +* +* lpszFileName -- ļ· +* pHead -- ͷ +* pTail -- β +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_TcpClient_SendSmallFile(HP_Client pClient, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail); + +/**********************************************************************************/ +/***************************** TCP Client Էʷ *****************************/ + +/* ͨݻСƽͨݰСãͨΪ(N * 1024) - sizeof(TBufferObj) */ +HPSOCKET_API void __stdcall HP_TcpClient_SetSocketBufferSize(HP_TcpClient pClient, DWORD dwSocketBufferSize); +/* 룬0 򲻷Ĭϣ30 * 1000 */ +HPSOCKET_API void __stdcall HP_TcpClient_SetKeepAliveTime(HP_TcpClient pClient, DWORD dwKeepAliveTime); +/* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ +HPSOCKET_API void __stdcall HP_TcpClient_SetKeepAliveInterval(HP_TcpClient pClient, DWORD dwKeepAliveInterval); + +/* ȡͨݻС */ +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetSocketBufferSize(HP_TcpClient pClient); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetKeepAliveTime(HP_TcpClient pClient); +/* ȡ쳣 */ +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetKeepAliveInterval(HP_TcpClient pClient); + +/**********************************************************************************/ +/***************************** UDP Client Էʷ *****************************/ + +/* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ +HPSOCKET_API void __stdcall HP_UdpClient_SetMaxDatagramSize(HP_UdpClient pClient, DWORD dwMaxDatagramSize); +/* ȡݱ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetMaxDatagramSize(HP_UdpClient pClient); + +/* üԴ0 򲻷ͼԴΪѶߣ */ +HPSOCKET_API void __stdcall HP_UdpClient_SetDetectAttempts(HP_UdpClient pClient, DWORD dwDetectAttempts); +/* üͼ룬0 ͼ */ +HPSOCKET_API void __stdcall HP_UdpClient_SetDetectInterval(HP_UdpClient pClient, DWORD dwDetectInterval); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetDetectAttempts(HP_UdpClient pClient); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetDetectInterval(HP_UdpClient pClient); + +/**********************************************************************************/ +/****************************** UDP Cast Էʷ ******************************/ + +/* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ +HPSOCKET_API void __stdcall HP_UdpCast_SetMaxDatagramSize(HP_UdpCast pCast, DWORD dwMaxDatagramSize); +/* ȡݱ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_UdpCast_GetMaxDatagramSize(HP_UdpCast pCast); +/* ȡǰݱԶ̵ַϢͨ OnReceive ¼еã */ +HPSOCKET_API BOOL __stdcall HP_UdpCast_GetRemoteAddress(HP_UdpCast pCast, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ð󶨵ַ */ +HPSOCKET_API void __stdcall HP_UdpCast_SetBindAdddress(HP_UdpCast pCast, LPCTSTR pszBindAddress); +/* ȡ󶨵ַ */ +HPSOCKET_API LPCTSTR __stdcall HP_UdpCast_GetBindAdddress(HP_UdpCast pCast); +/* ǷõַûƣĬϣã */ +HPSOCKET_API void __stdcall HP_UdpCast_SetReuseAddress(HP_UdpCast pCast, BOOL bReuseAddress); +/* Ƿõַû */ +HPSOCKET_API BOOL __stdcall HP_UdpCast_IsReuseAddress(HP_UdpCast pCast); +/* ôģʽ鲥㲥 */ +HPSOCKET_API void __stdcall HP_UdpCast_SetCastMode(HP_UdpCast pCast, En_HP_CastMode enCastMode); +/* ȡģʽ */ +HPSOCKET_API En_HP_CastMode __stdcall HP_UdpCast_GetCastMode(HP_UdpCast pCast); +/* 鲥ĵ TTL0 - 255 */ +HPSOCKET_API void __stdcall HP_UdpCast_SetMultiCastTtl(HP_UdpCast pCast, int iMCTtl); +/* ȡ鲥ĵ TTL */ +HPSOCKET_API int __stdcall HP_UdpCast_GetMultiCastTtl(HP_UdpCast pCast); +/* Ƿ鲥·TRUE or FALSE */ +HPSOCKET_API void __stdcall HP_UdpCast_SetMultiCastLoop(HP_UdpCast pCast, BOOL bMCLoop); +/* Ƿ鲥· */ +HPSOCKET_API BOOL __stdcall HP_UdpCast_IsMultiCastLoop(HP_UdpCast pCast); + +/***************************************************************************************/ +/***************************** TCP Pull Server *****************************/ + +/* +* ƣץȡ +* ûͨ÷ Socket ץȡ +* +* dwConnID -- ID +* pData -- ץȡ +* iLength -- ץȡݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullServer_Fetch(HP_TcpPullServer pServer, HP_CONNID dwConnID, BYTE* pData, int iLength); + +/* +* ƣ̽ݣƳݣ +* ûͨ÷ Socket п̽ +* +* dwConnID -- ID +* pData -- ̽ +* iLength -- ̽ݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullServer_Peek(HP_TcpPullServer pServer, HP_CONNID dwConnID, BYTE* pData, int iLength); + +/***************************************************************************************/ +/***************************** TCP Pull Server Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pull Agent *****************************/ + +/* +* ƣץȡ +* ûͨ÷ Socket ץȡ +* +* dwConnID -- ID +* pData -- ץȡ +* iLength -- ץȡݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullAgent_Fetch(HP_TcpPullAgent pAgent, HP_CONNID dwConnID, BYTE* pData, int iLength); + +/* +* ƣ̽ݣƳݣ +* ûͨ÷ Socket п̽ +* +* dwConnID -- ID +* pData -- ̽ +* iLength -- ̽ݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullAgent_Peek(HP_TcpPullAgent pAgent, HP_CONNID dwConnID, BYTE* pData, int iLength); + +/***************************************************************************************/ +/***************************** TCP Pull Agent Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pull Client *****************************/ + +/* +* ƣץȡ +* ûͨ÷ Socket ץȡ +* +* dwConnID -- ID +* pData -- ץȡ +* iLength -- ץȡݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullClient_Fetch(HP_TcpPullClient pClient, BYTE* pData, int iLength); + +/* +* ƣ̽ݣƳݣ +* ûͨ÷ Socket п̽ +* +* dwConnID -- ID +* pData -- ̽ +* iLength -- ̽ݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullClient_Peek(HP_TcpPullClient pClient, BYTE* pData, int iLength); + +/***************************************************************************************/ +/***************************** TCP Pull Client Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Server *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Server Էʷ *****************************/ + +/* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ +HPSOCKET_API void __stdcall HP_TcpPackServer_SetMaxPackSize(HP_TcpPackServer pServer, DWORD dwMaxPackSize); +/* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ +HPSOCKET_API void __stdcall HP_TcpPackServer_SetPackHeaderFlag(HP_TcpPackServer pServer, USHORT usPackHeaderFlag); + +/* ȡݰ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_TcpPackServer_GetMaxPackSize(HP_TcpPackServer pServer); +/* ȡͷʶ */ +HPSOCKET_API USHORT __stdcall HP_TcpPackServer_GetPackHeaderFlag(HP_TcpPackServer pServer); + +/***************************************************************************************/ +/***************************** TCP Pack Agent *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Agent Էʷ *****************************/ + +/* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ +HPSOCKET_API void __stdcall HP_TcpPackAgent_SetMaxPackSize(HP_TcpPackAgent pAgent, DWORD dwMaxPackSize); +/* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ +HPSOCKET_API void __stdcall HP_TcpPackAgent_SetPackHeaderFlag(HP_TcpPackAgent pAgent, USHORT usPackHeaderFlag); + +/* ȡݰ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_TcpPackAgent_GetMaxPackSize(HP_TcpPackAgent pAgent); +/* ȡͷʶ */ +HPSOCKET_API USHORT __stdcall HP_TcpPackAgent_GetPackHeaderFlag(HP_TcpPackAgent pAgent); + +/***************************************************************************************/ +/***************************** TCP Pack Client *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Client Էʷ *****************************/ + +/* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ +HPSOCKET_API void __stdcall HP_TcpPackClient_SetMaxPackSize(HP_TcpPackClient pClient, DWORD dwMaxPackSize); +/* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ +HPSOCKET_API void __stdcall HP_TcpPackClient_SetPackHeaderFlag(HP_TcpPackClient pClient, USHORT usPackHeaderFlag); + +/* ȡݰ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_TcpPackClient_GetMaxPackSize(HP_TcpPackClient pClient); +/* ȡͷʶ */ +HPSOCKET_API USHORT __stdcall HP_TcpPackClient_GetPackHeaderFlag(HP_TcpPackClient pClient); + +/***************************************************************************************/ +/*************************************** ***************************************/ + +/* ȡı */ +HPSOCKET_API LPCTSTR __stdcall HP_GetSocketErrorDesc(En_HP_SocketError enCode); +/* ϵͳ ::GetLastError() ȡϵͳ */ +HPSOCKET_API DWORD __stdcall SYS_GetLastError(); +// ϵͳ ::WSAGetLastError() ȡͨŴ +HPSOCKET_API int __stdcall SYS_WSAGetLastError(); +// ϵͳ setsockopt() +HPSOCKET_API int __stdcall SYS_SetSocketOption(SOCKET sock, int level, int name, LPVOID val, int len); +// ϵͳ getsockopt() +HPSOCKET_API int __stdcall SYS_GetSocketOption(SOCKET sock, int level, int name, LPVOID val, int* len); +// ϵͳ ioctlsocket() +HPSOCKET_API int __stdcall SYS_IoctlSocket(SOCKET sock, long cmd, u_long* arg); +// ϵͳ ::WSAIoctl() +HPSOCKET_API int __stdcall SYS_WSAIoctl(SOCKET sock, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned); diff --git a/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C.dll b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C.dll new file mode 100644 index 000000000..e8bffb0b5 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C.dll differ diff --git a/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C.lib b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C.lib new file mode 100644 index 000000000..32bd59776 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C.lib differ diff --git a/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_D.dll b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_D.dll new file mode 100644 index 000000000..36b1879a0 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_D.dll differ diff --git a/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_D.lib b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_D.lib new file mode 100644 index 000000000..dcc043adb Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_D.lib differ diff --git a/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_U.dll b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_U.dll new file mode 100644 index 000000000..e95307766 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_U.dll differ diff --git a/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_U.lib b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_U.lib new file mode 100644 index 000000000..04abe9c1b Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_U.lib differ diff --git a/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_UD.dll b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_UD.dll new file mode 100644 index 000000000..5b55ca8f9 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_UD.dll differ diff --git a/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_UD.lib b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_UD.lib new file mode 100644 index 000000000..0902cf0fa Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x64/HPSocket4C_UD.lib differ diff --git a/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C.dll b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C.dll new file mode 100644 index 000000000..3e83509a4 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C.dll differ diff --git a/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C.lib b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C.lib new file mode 100644 index 000000000..82a2263a1 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C.lib differ diff --git a/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_D.dll b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_D.dll new file mode 100644 index 000000000..d08361817 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_D.dll differ diff --git a/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_D.lib b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_D.lib new file mode 100644 index 000000000..1f736a706 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_D.lib differ diff --git a/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_U.dll b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_U.dll new file mode 100644 index 000000000..e88c968ee Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_U.dll differ diff --git a/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_U.lib b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_U.lib new file mode 100644 index 000000000..097becd25 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_U.lib differ diff --git a/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_UD.dll b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_UD.dll new file mode 100644 index 000000000..f842db29e Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_UD.dll differ diff --git a/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_UD.lib b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_UD.lib new file mode 100644 index 000000000..6816650c9 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4C/x86/HPSocket4C_UD.lib differ diff --git a/HP-Socket/Bin/HPSocket4CS/x64/HPSocket4C_U.dll b/HP-Socket/Bin/HPSocket4CS/x64/HPSocket4C_U.dll new file mode 100644 index 000000000..e95307766 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4CS/x64/HPSocket4C_U.dll differ diff --git a/HP-Socket/Bin/HPSocket4CS/x64/HPSocketCS.dll b/HP-Socket/Bin/HPSocket4CS/x64/HPSocketCS.dll new file mode 100644 index 000000000..e41af7e05 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4CS/x64/HPSocketCS.dll differ diff --git a/HP-Socket/Bin/HPSocket4CS/x86/HPSocket4C_U.dll b/HP-Socket/Bin/HPSocket4CS/x86/HPSocket4C_U.dll new file mode 100644 index 000000000..e88c968ee Binary files /dev/null and b/HP-Socket/Bin/HPSocket4CS/x86/HPSocket4C_U.dll differ diff --git a/HP-Socket/Bin/HPSocket4CS/x86/HPSocketCS.dll b/HP-Socket/Bin/HPSocket4CS/x86/HPSocketCS.dll new file mode 100644 index 000000000..e41af7e05 Binary files /dev/null and b/HP-Socket/Bin/HPSocket4CS/x86/HPSocketCS.dll differ diff --git "a/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/HPSocket_4C.lib" "b/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/HPSocket_4C.lib" new file mode 100644 index 000000000..f41d995ec Binary files /dev/null and "b/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/HPSocket_4C.lib" differ diff --git "a/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/Hp_Socket.fne" "b/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/Hp_Socket.fne" new file mode 100644 index 000000000..c183324e4 Binary files /dev/null and "b/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/Hp_Socket.fne" differ diff --git "a/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/Hp_Socket_static.lib" "b/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/Hp_Socket_static.lib" new file mode 100644 index 000000000..181706fee Binary files /dev/null and "b/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/Hp_Socket_static.lib" differ diff --git "a/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/\344\275\277\347\224\250\346\226\271\346\263\225.txt" "b/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/\344\275\277\347\224\250\346\226\271\346\263\225.txt" new file mode 100644 index 000000000..536faad5d --- /dev/null +++ "b/HP-Socket/Bin/HPSocket4E/\346\224\257\346\214\201\345\272\223/\344\275\277\347\224\250\346\226\271\346\263\225.txt" @@ -0,0 +1,6 @@ +Hp_Socket.fne 放入易语言Lib目录 +Hp_Socket_static.lib、HPSocket_4C.lib 放入static_Lib目录 + +本支持库需要易语言vs2010链接器(链接: http://pan.baidu.com/s/1i3ydamT 密码: baka) + +点击链接加入群【怪兽乐园】:http://jq.qq.com/?_wv=1027&k=2Ia8fHv \ No newline at end of file diff --git "a/HP-Socket/Bin/HPSocket4E/\346\250\241\345\235\227/HPSocket.ec" "b/HP-Socket/Bin/HPSocket4E/\346\250\241\345\235\227/HPSocket.ec" new file mode 100644 index 000000000..5c6f5066f Binary files /dev/null and "b/HP-Socket/Bin/HPSocket4E/\346\250\241\345\235\227/HPSocket.ec" differ diff --git "a/HP-Socket/Bin/HPSocket4E/\346\250\241\345\235\227/HPSocket4C.ec" "b/HP-Socket/Bin/HPSocket4E/\346\250\241\345\235\227/HPSocket4C.ec" new file mode 100644 index 000000000..f2d99d836 Binary files /dev/null and "b/HP-Socket/Bin/HPSocket4E/\346\250\241\345\235\227/HPSocket4C.ec" differ diff --git a/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.cpp b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.cpp new file mode 100644 index 000000000..0a93c85d1 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.cpp @@ -0,0 +1,25 @@ +/* + * Copyright Bruce Liang (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Porject : https://code.google.com/p/ldcsaa + * Bolg : http://www.cnblogs.com/ldcsaa + * WeiBo : http://weibo.com/u/1402935851 + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" diff --git a/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.rc b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.rc new file mode 100644 index 000000000..2a88864e8 Binary files /dev/null and b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.rc differ diff --git a/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.sln b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.sln new file mode 100644 index 000000000..fc2fdd68a --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HPSocketDLL", "HPSocketDLL.vcxproj", "{79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + uDebug|Win32 = uDebug|Win32 + uDebug|x64 = uDebug|x64 + uRelease|Win32 = uRelease|Win32 + uRelease|x64 = uRelease|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Debug|Win32.ActiveCfg = Debug|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Debug|Win32.Build.0 = Debug|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Debug|x64.ActiveCfg = Debug|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Debug|x64.Build.0 = Debug|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Release|Win32.ActiveCfg = Release|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Release|Win32.Build.0 = Release|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Release|x64.ActiveCfg = Release|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Release|x64.Build.0 = Release|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uDebug|Win32.ActiveCfg = uDebug|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uDebug|Win32.Build.0 = uDebug|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uDebug|x64.ActiveCfg = uDebug|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uDebug|x64.Build.0 = uDebug|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uRelease|Win32.ActiveCfg = uRelease|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uRelease|Win32.Build.0 = uRelease|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uRelease|x64.ActiveCfg = uRelease|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uRelease|x64.Build.0 = uRelease|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.suo b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.suo new file mode 100644 index 000000000..6c9295fae Binary files /dev/null and b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.suo differ diff --git a/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj new file mode 100644 index 000000000..3cd3a7d07 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj @@ -0,0 +1,410 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + uDebug + Win32 + + + uDebug + x64 + + + uRelease + Win32 + + + uRelease + x64 + + + + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F} + Win32Proj + HPSocketDLL + + + + DynamicLibrary + true + MultiByte + + + DynamicLibrary + true + MultiByte + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + false + true + MultiByte + + + DynamicLibrary + false + true + MultiByte + + + DynamicLibrary + false + true + Unicode + + + DynamicLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + ..\..\Bin\HPSocket\x86\ + $(OutDir)obj\$(Configuration)\ + HPSocket_D + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + true + ..\..\Bin\HPSocket\x64\ + $(OutDir)obj\$(Configuration)\ + HPSocket_D + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + true + ..\..\Bin\HPSocket\x86\ + $(OutDir)obj\$(Configuration)\ + HPSocket_UD + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + true + ..\..\Bin\HPSocket\x64\ + $(OutDir)obj\$(Configuration)\ + HPSocket_UD + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + false + ..\..\Bin\HPSocket\x86\ + $(OutDir)obj\$(Configuration)\ + HPSocket + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + false + ..\..\Bin\HPSocket\x64\ + $(OutDir)obj\$(Configuration)\ + HPSocket + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + false + ..\..\Bin\HPSocket\x86\ + $(OutDir)obj\$(Configuration)\ + HPSocket_U + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + false + ..\..\Bin\HPSocket\x64\ + $(OutDir)obj\$(Configuration)\ + HPSocket_U + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + + Use + Level3 + Disabled + HPSOCKET_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Use + Level3 + Disabled + HPSOCKET_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Use + Level3 + Disabled + HPSOCKET_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Use + Level3 + Disabled + HPSOCKET_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Level3 + Use + MaxSpeed + true + true + HPSOCKET_EXPORTS;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Level3 + Use + MaxSpeed + true + true + HPSOCKET_EXPORTS;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Level3 + Use + MaxSpeed + true + true + HPSOCKET_EXPORTS;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Level3 + Use + MaxSpeed + true + true + HPSOCKET_EXPORTS;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + false + false + false + + + + + + + + + false + false + false + false + + + + + + + + + + + + Create + Create + Create + Create + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj.filters b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj.filters new file mode 100644 index 000000000..deaad3437 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj.filters @@ -0,0 +1,203 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {039b40b4-14cf-45b3-bca5-65a981c86518} + + + {c1cdb45b-7c34-4b60-83c3-a6f06ec55fbe} + + + + + + + + Header Files + + + Header Files + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + Common + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj.user b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj.user new file mode 100644 index 000000000..d458a4334 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/HPSocketDLL.vcxproj.user @@ -0,0 +1,19 @@ + + + + E:\MyWork\Cpp\HP-Socket\Bin\HPSocket\x86\TestEcho-Pack-Client.exe + WindowsLocalDebugger + + + E:\MyWork\Cpp\HP-Socket\Bin\HPSocket\x86\TestEcho-Pack-Client.exe + WindowsLocalDebugger + + + D:\MyWork\Cpp\TestSocket\TestEcho-PFM\Release\Server.exe + WindowsLocalDebugger + + + D:\MyWork\Cpp\HP-Socket\Bin\HPSocket\x64\HttpProxy-Server.exe + WindowsLocalDebugger + + \ No newline at end of file diff --git a/HP-Socket/DLL/HPSocketDLL/ReadMe.txt b/HP-Socket/DLL/HPSocketDLL/ReadMe.txt new file mode 100644 index 000000000..62b838ce0 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/ReadMe.txt @@ -0,0 +1,50 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: HPSocket DLL + +Usage: + һ + -------------------------------------------------------------------------------------- + 0. Ӧó SocketInterface.h HPSocket.h ͷļ + 1. HP_Create_Xxx() HPSocket + 2. ʹϺ HP_Create_Xxx() HPSocket + + + -------------------------------------------------------------------------------------- + 0. Ӧó SocketInterface.h HPSocket.h ͷļ + 1. CXxxWrapper װͨװָʹ HPSocket + +Release: + 1. Bin/x86/HPSocket.dll - (32λ/MBCS/Release) + 2. Bin/x86/HPSocket_D.dll - (32λ/MBCS/DeBug) + 3. Bin/x86/HPSocket_U.dll - (32λ/UNICODE/Release) + 4. Bin/x6/HPSocket_UD.dll - (32λ/UNICODE/DeBug) + 5. Bin/x64/HPSocket.dll - (64λ/MBCS/Release) + 6. Bin/x64/HPSocket_D.dll - (64λ/MBCS/DeBug) + 7. Bin/x64/HPSocket_U.dll - (64λ/UNICODE/Release) + 8. Bin/x64/HPSocket_UD.dll - (64λ/UNICODE/DeBug) + +******************************************************************************/ diff --git a/HP-Socket/DLL/HPSocketDLL/dllmain.cpp b/HP-Socket/DLL/HPSocketDLL/dllmain.cpp new file mode 100644 index 000000000..7225a216d --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/dllmain.cpp @@ -0,0 +1,33 @@ +/* + * Copyright Bruce Liang (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Porject : https://code.google.com/p/ldcsaa + * Bolg : http://www.cnblogs.com/ldcsaa + * WeiBo : http://weibo.com/u/1402935851 + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + return TRUE; +} diff --git a/HP-Socket/DLL/HPSocketDLL/resource.h b/HP-Socket/DLL/HPSocketDLL/resource.h new file mode 100644 index 000000000..bf12e2fc1 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by HPSocketDLL.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/HP-Socket/DLL/HPSocketDLL/stdafx.cpp b/HP-Socket/DLL/HPSocketDLL/stdafx.cpp new file mode 100644 index 000000000..0a93c85d1 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/stdafx.cpp @@ -0,0 +1,25 @@ +/* + * Copyright Bruce Liang (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Porject : https://code.google.com/p/ldcsaa + * Bolg : http://www.cnblogs.com/ldcsaa + * WeiBo : http://weibo.com/u/1402935851 + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" diff --git a/HP-Socket/DLL/HPSocketDLL/stdafx.h b/HP-Socket/DLL/HPSocketDLL/stdafx.h new file mode 100644 index 000000000..5e3eae678 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL/stdafx.h @@ -0,0 +1,29 @@ +/* + * Copyright Bruce Liang (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Porject : https://code.google.com/p/ldcsaa + * Bolg : http://www.cnblogs.com/ldcsaa + * WeiBo : http://weibo.com/u/1402935851 + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#define _DETECT_MEMORY_LEAK + +#include "../../../Common/Src/GeneralHelper.h" diff --git a/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.cpp b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.cpp new file mode 100644 index 000000000..0a93c85d1 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.cpp @@ -0,0 +1,25 @@ +/* + * Copyright Bruce Liang (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Porject : https://code.google.com/p/ldcsaa + * Bolg : http://www.cnblogs.com/ldcsaa + * WeiBo : http://weibo.com/u/1402935851 + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" diff --git a/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.rc b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.rc new file mode 100644 index 000000000..d67a505ca Binary files /dev/null and b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.rc differ diff --git a/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj new file mode 100644 index 000000000..e2aa9c3b9 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj @@ -0,0 +1,411 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + uDebug + Win32 + + + uDebug + x64 + + + uRelease + Win32 + + + uRelease + x64 + + + + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F} + Win32Proj + HPSocketDLL + HPSocketDLL4C + + + + DynamicLibrary + true + MultiByte + + + DynamicLibrary + true + MultiByte + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + false + true + MultiByte + + + DynamicLibrary + false + true + MultiByte + + + DynamicLibrary + false + true + Unicode + + + DynamicLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + ..\..\Bin\HPSocket4C\x86\ + $(OutDir)obj\$(Configuration)\ + HPSocket4C_D + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + true + ..\..\Bin\HPSocket4C\x64\ + $(OutDir)obj\$(Configuration)\ + HPSocket4C_D + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + true + ..\..\Bin\HPSocket4C\x86\ + $(OutDir)obj\$(Configuration)\ + HPSocket4C_UD + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + true + ..\..\Bin\HPSocket4C\x64\ + $(OutDir)obj\$(Configuration)\ + HPSocket4C_UD + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + false + ..\..\Bin\HPSocket4C\x86\ + $(OutDir)obj\$(Configuration)\ + HPSocket4C + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + false + ..\..\Bin\HPSocket4C\x64\ + $(OutDir)obj\$(Configuration)\ + HPSocket4C + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + false + ..\..\Bin\HPSocket4C\x86\ + $(OutDir)obj\$(Configuration)\ + HPSocket4C_U + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + false + ..\..\Bin\HPSocket4C\x64\ + $(OutDir)obj\$(Configuration)\ + HPSocket4C_U + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.metagen;*.bi;$(TargetPath) + + + + Use + Level3 + Disabled + HPSOCKET_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Use + Level3 + Disabled + HPSOCKET_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Use + Level3 + Disabled + HPSOCKET_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Use + Level3 + Disabled + HPSOCKET_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Level3 + Use + MaxSpeed + true + true + HPSOCKET_EXPORTS;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Level3 + Use + MaxSpeed + true + true + HPSOCKET_EXPORTS;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Level3 + Use + MaxSpeed + true + true + HPSOCKET_EXPORTS;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + Level3 + Use + MaxSpeed + true + true + HPSOCKET_EXPORTS;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + $(OutDir)$(TargetName).pdb + $(OutDir)$(TargetName).lib + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + false + false + false + + + + + + + + + false + false + false + false + + + + + + + + + + + + Create + Create + Create + Create + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj.filters b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj.filters new file mode 100644 index 000000000..b6e3ef486 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj.filters @@ -0,0 +1,203 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {039b40b4-14cf-45b3-bca5-65a981c86518} + + + {c1cdb45b-7c34-4b60-83c3-a6f06ec55fbe} + + + + + + + + Header Files + + + Header Files + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + Common + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + HPSocket + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj.user b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj.user new file mode 100644 index 000000000..adc5c1265 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL.vcxproj.user @@ -0,0 +1,7 @@ + + + + E:\MyWork\Cpp\HP-Socket\Bin\HPSocket4C\x86\TestEcho-Pack-Server.exe + WindowsLocalDebugger + + \ No newline at end of file diff --git a/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL4C.sln b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL4C.sln new file mode 100644 index 000000000..1d6dc58d6 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL4C.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HPSocketDLL4C", "HPSocketDLL.vcxproj", "{79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + uDebug|Win32 = uDebug|Win32 + uDebug|x64 = uDebug|x64 + uRelease|Win32 = uRelease|Win32 + uRelease|x64 = uRelease|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Debug|Win32.ActiveCfg = Debug|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Debug|Win32.Build.0 = Debug|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Debug|x64.ActiveCfg = Debug|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Debug|x64.Build.0 = Debug|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Release|Win32.ActiveCfg = Release|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Release|Win32.Build.0 = Release|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Release|x64.ActiveCfg = Release|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.Release|x64.Build.0 = Release|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uDebug|Win32.ActiveCfg = uDebug|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uDebug|Win32.Build.0 = uDebug|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uDebug|x64.ActiveCfg = uDebug|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uDebug|x64.Build.0 = uDebug|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uRelease|Win32.ActiveCfg = uRelease|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uRelease|Win32.Build.0 = uRelease|Win32 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uRelease|x64.ActiveCfg = uRelease|x64 + {79A7B2E5-6F5A-4DE3-B954-5EBA1858793F}.uRelease|x64.Build.0 = uRelease|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL4C.suo b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL4C.suo new file mode 100644 index 000000000..c5d8f923a Binary files /dev/null and b/HP-Socket/DLL/HPSocketDLL4C/HPSocketDLL4C.suo differ diff --git a/HP-Socket/DLL/HPSocketDLL4C/ReadMe.txt b/HP-Socket/DLL/HPSocketDLL4C/ReadMe.txt new file mode 100644 index 000000000..ee5da435b --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/ReadMe.txt @@ -0,0 +1,57 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: HPSocket for C DLL + +Desc: C ԣ磺C / C# / Delphi ȣܷʹ HPSocket + +Usage: + һ + -------------------------------------------------------------------------------------- + 0. C/C++ 򣩰 HPSocket4C.h ͷļ + 1. ::Create_HP_XxxListener() + 2. ::Create_HP_Xxx(pListener) HPSocket + 3. ::HP_Set_FN_Xxx_OnYyy(pListener, ...) üĻص + 4. ص HPSocket + 5. ...... ...... + 6. ::Destroy_HP_Xxx(pSocket) HPSocket + 7. ::Destroy_HP_XxxListener(pListener) ټ + + + -------------------------------------------------------------------------------------- + 1. ӦóҪõĵװضԵİװ + 2. ͨװװķʽʹ HPSocket + +Release: + 1. Bin/x86/HPSocket4C.dll - (32λ/MBCS/Release) + 2. Bin/x86/HPSocket4C_D.dll - (32λ/MBCS/DeBug) + 3. Bin/x86/HPSocket4C_U.dll - (32λ/UNICODE/Release) + 4. Bin/x86/HPSocket4C_UD.dll - (32λ/UNICODE/DeBug) + 5. Bin/x64/HPSocket4C.dll - (64λ/MBCS/Release) + 6. Bin/x64/HPSocket4C_D.dll - (64λ/MBCS/DeBug) + 7. Bin/x64/HPSocket4C_U.dll - (64λ/UNICODE/Release) + 8. Bin/x64/HPSocket4C_UD.dll - (64λ/UNICODE/DeBug) + +******************************************************************************/ diff --git a/HP-Socket/DLL/HPSocketDLL4C/dllmain.cpp b/HP-Socket/DLL/HPSocketDLL4C/dllmain.cpp new file mode 100644 index 000000000..7225a216d --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/dllmain.cpp @@ -0,0 +1,33 @@ +/* + * Copyright Bruce Liang (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Porject : https://code.google.com/p/ldcsaa + * Bolg : http://www.cnblogs.com/ldcsaa + * WeiBo : http://weibo.com/u/1402935851 + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + return TRUE; +} diff --git a/HP-Socket/DLL/HPSocketDLL4C/resource.h b/HP-Socket/DLL/HPSocketDLL4C/resource.h new file mode 100644 index 000000000..bf12e2fc1 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by HPSocketDLL.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/HP-Socket/DLL/HPSocketDLL4C/stdafx.cpp b/HP-Socket/DLL/HPSocketDLL4C/stdafx.cpp new file mode 100644 index 000000000..0a93c85d1 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/stdafx.cpp @@ -0,0 +1,25 @@ +/* + * Copyright Bruce Liang (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Porject : https://code.google.com/p/ldcsaa + * Bolg : http://www.cnblogs.com/ldcsaa + * WeiBo : http://weibo.com/u/1402935851 + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" diff --git a/HP-Socket/DLL/HPSocketDLL4C/stdafx.h b/HP-Socket/DLL/HPSocketDLL4C/stdafx.h new file mode 100644 index 000000000..5e3eae678 --- /dev/null +++ b/HP-Socket/DLL/HPSocketDLL4C/stdafx.h @@ -0,0 +1,29 @@ +/* + * Copyright Bruce Liang (ldcsaa@gmail.com) + * + * Version : 3.4.2 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Porject : https://code.google.com/p/ldcsaa + * Bolg : http://www.cnblogs.com/ldcsaa + * WeiBo : http://weibo.com/u/1402935851 + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#define _DETECT_MEMORY_LEAK + +#include "../../../Common/Src/GeneralHelper.h" diff --git a/HP-Socket/Demo/Global/helper.cpp b/HP-Socket/Demo/Global/helper.cpp new file mode 100644 index 000000000..d09791efc --- /dev/null +++ b/HP-Socket/Demo/Global/helper.cpp @@ -0,0 +1,405 @@ +#include "stdafx.h" +#include "helper.h" + +CWnd* g_pMainWnd; +CListBox* g_pInfoList; + +info_msg* info_msg::Construct(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength, LPCTSTR lpszContent) +{ + return new info_msg(dwConnID, lpszEvent, iContentLength, lpszContent); +} + +void info_msg::Destruct(info_msg* pMsg) +{ + delete pMsg; +} + +info_msg::info_msg(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength, LPCTSTR lpszContent) + : connID(dwConnID), evt(lpszEvent), contentLength(iContentLength), content(lpszContent) +{ + +} + +info_msg::~info_msg() +{ + if(contentLength > 0) + delete[] content; +} + +void SetMainWnd(CWnd* pWnd) +{ + g_pMainWnd = pWnd; +} + +void SetInfoList(CListBox* pInfoList) +{ + g_pInfoList = pInfoList; +} + +void LogServerStart(LPCTSTR lpszAddress, USHORT port) +{ + CString msg; + msg.Format(_T("$ Server Start OK --> (%s : %d)"), lpszAddress, port); + LogMsg(msg); +} + +void LogServerStartFail(DWORD code, LPCTSTR lpszDesc) +{ + CString msg; + msg.Format(_T("$ Server Start Fail --> %s (%d)"), lpszDesc, code); + LogMsg(msg); +} + +void LogServerStop() +{ + CString msg = _T("$ Server Stop"); + LogMsg(msg); +} + +void LogServerStopFail(DWORD code, LPCTSTR lpszDesc) +{ + CString msg; + msg.Format(_T("$ Server Stop Fail --> %s (%d)"), lpszDesc, code); + LogMsg(msg); +} + +void LogClientStart(LPCTSTR lpszAddress, USHORT port) +{ + CString msg; + msg.Format(_T("$ Client Start OK --> (%s : %d)"), lpszAddress, port); + LogMsg(msg); +} + +void LogClientStarting(LPCTSTR lpszAddress, USHORT port) +{ + CString msg; + msg.Format(_T("$ Client Starting ... --> (%s : %d)"), lpszAddress, port); + LogMsg(msg); +} + +void LogClientStartFail(DWORD code, LPCTSTR lpszDesc) +{ + CString msg; + msg.Format(_T("$ Client Start Fail --> %s (%d)"), lpszDesc, code); + LogMsg(msg); +} + +void LogClientStopping(CONNID dwConnID) +{ + CString msg; + msg.Format(_T("$ Client Stopping ... --> (%Iu)"), dwConnID); + LogMsg(msg); +} + +void LogClientStopFail(DWORD code, LPCTSTR lpszDesc) +{ + CString msg; + msg.Format(_T("$ Client Stop Fail --> %s (%d)"), lpszDesc, code); + LogMsg(msg); +} + +void LogClientSendFail(int iSequence, int iSocketIndex, DWORD code, LPCTSTR lpszDesc) +{ + CString msg; + msg.Format(_T("$ Client Send Fail [SOCK: %d, SEQ: %d] --> %s (%d)"), iSocketIndex, iSequence, lpszDesc, code); + LogMsg(msg); +} + +void LogSend(CONNID dwConnID, LPCTSTR lpszContent) +{ + CString msg; + msg.Format(_T("$ (%Iu) Send OK --> %s"), dwConnID, lpszContent); + LogMsg(msg); +} + +void LogSendFail(CONNID dwConnID, DWORD code, LPCTSTR lpszDesc) +{ + CString msg; + msg.Format(_T("$ (%Iu) Send Fail --> %s (%d)"), dwConnID, lpszDesc, code); + LogMsg(msg); +} + +void LogDisconnect(CONNID dwConnID) +{ + CString msg; + msg.Format(_T("$ (%Iu) Disconnect OK"), dwConnID); + LogMsg(msg); +} + +void LogDisconnectFail(CONNID dwConnID) +{ + CString msg; + msg.Format(_T("$ (%Iu) Disconnect Fail"), dwConnID); + LogMsg(msg); +} + +void LogDetect(CONNID dwConnID) +{ + CString msg; + msg.Format(_T("$ (%Iu) Detect Connection OK"), dwConnID); + LogMsg(msg); +} + +void LogDetectFail(CONNID dwConnID) +{ + CString msg; + msg.Format(_T("$ (%Iu) Detect Connection Fail"), dwConnID); + LogMsg(msg); +} + +void LogOnConnect(CONNID dwConnID, const CString& strAddress, USHORT usPort) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T("local address: %s:%d"), strAddress, usPort); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CONNECT, content_len, lpszContent); + + LogInfoMsg(msg); +} + +void LogOnConnect2(CONNID dwConnID) +{ + CString msg; + msg.Format(_T(" > [ %Iu, %s ]"), dwConnID, EVT_ON_CONNECT); + LogMsg(msg); +} + +void PostOnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ + /* + LPTSTR lpszContent = nullptr; + int content_len = ::BytesToHex(pData, iLength, &lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_SEND, content_len, lpszContent); + */ + + LPTSTR lpszContent = new TCHAR[20]; + wsprintf(lpszContent, _T("(%d bytes)"), iLength); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_SEND, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostOnReceive(CONNID dwConnID, const BYTE* pData, int iLength) +{ + /* + LPTSTR lpszContent = nullptr; + int content_len = ::BytesToHex(pData, iLength, &lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_RECEIVE, content_len, lpszContent); + */ + + LPTSTR lpszContent = new TCHAR[20]; + wsprintf(lpszContent, _T("(%d bytes)"), iLength); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_RECEIVE, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostOnReceiveCast(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, const BYTE* pData, int iLength) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T("<%s:%d> (%d bytes)"), lpszAddress, usPort, iLength); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_RECEIVE, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostOnClose(CONNID dwConnID) +{ + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CLOSE, 0, nullptr); + + PostInfoMsg(msg); +} + +void PostOnError(CONNID dwConnID, int enOperation, int iErrorCode) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T("OP: %d, CODE: %d"), enOperation, iErrorCode); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_ERROR, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostOnAccept(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, BOOL bPass) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T("%s (%s:%d)"), bPass ? _T("PASS") : _T("REJECT"), lpszAddress, usPort); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_ACCEPT, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostOnAccept2(CONNID dwConnID) +{ + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_ACCEPT, 0, nullptr); + + PostInfoMsg(msg); +} + +void PostOnPrepareListen(LPCTSTR lpszAddress, USHORT usPort) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T("bind address: %s:%d"), lpszAddress, usPort); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(0, EVT_ON_PREPARE_LISTEN, content_len, lpszContent); + + LogInfoMsg(msg); +} + +void PostOnPrepareConnect(CONNID dwConnID) +{ + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_PREPARE_CONNECT, 0, nullptr); + + LogInfoMsg(msg); +} + +void PostOnConnect(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T("local address: %s:%d"), lpszAddress, usPort); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CONNECT, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostOnConnect2(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T("remote address: %s:%d"), lpszAddress, usPort); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(dwConnID, EVT_ON_CONNECT, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostOnShutdown() +{ + info_msg* msg = info_msg::Construct(0, EVT_ON_SHUTDOWN, 0, nullptr); + + PostInfoMsg(msg); +} + +void PostServerStatics(const LONGLONG& llTotalSent, const LONGLONG& llTotalReceived) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T(" *** Summary: send - %I64d, recv - %I64d"), llTotalSent, llTotalReceived); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(0, EVT_ON_END_TEST, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostTimeConsuming(DWORD dwTickCount) +{ + LPTSTR lpszContent = new TCHAR[100]; + wsprintf(lpszContent, _T("Total Time Consuming: %u"), dwTickCount); + int content_len = lstrlen(lpszContent); + info_msg* msg = info_msg::Construct(0, EVT_ON_END_TEST, content_len, lpszContent); + + PostInfoMsg(msg); +} + +void PostInfoMsg(info_msg* msg) +{ + if( g_pMainWnd == nullptr || + g_pMainWnd->GetSafeHwnd() == nullptr || + !g_pMainWnd->PostMessage(USER_INFO_MSG, (WPARAM)msg )) + info_msg::Destruct(msg); +} + +void LogInfoMsg(info_msg* pInfoMsg) +{ + CString msg; + + if(pInfoMsg->connID > 0) + { + if(pInfoMsg->contentLength > 0) + msg.Format(_T(" > [ %Iu, %s ] -> %s"), pInfoMsg->connID, pInfoMsg->evt, pInfoMsg->content); + else + msg.Format(_T(" > [ %Iu, %s ]"), pInfoMsg->connID, pInfoMsg->evt); + } + else + { + if(pInfoMsg->contentLength > 0) + msg.Format(_T(" > [ %s ] -> %s"), pInfoMsg->evt, pInfoMsg->content); + else + msg.Format(_T(" > [ %s ]"), pInfoMsg->evt); + } + + LogMsg(msg); + + info_msg::Destruct(pInfoMsg); +} + +void LogMsg(const CString& msg) +{ + if(!g_pInfoList || !g_pInfoList->GetSafeHwnd()) + return; + + int iCurIndex = g_pInfoList->GetCurSel(); + int iCount = g_pInfoList->GetCount(); + BOOL bCurLast = (iCurIndex != LB_ERR && iCurIndex == iCount - 1); + + g_pInfoList->SetRedraw(FALSE); + + if(iCount > MAX_LOG_RECORD_LENGTH) + g_pInfoList->DeleteString(0); + + g_pInfoList->AddString(msg); + + iCount = g_pInfoList->GetCount(); + + if(bCurLast) + g_pInfoList->SetCurSel(iCount - 1); + + iCurIndex = g_pInfoList->GetCurSel(); + if(iCurIndex == LB_ERR) + { + iCurIndex = 0; + g_pInfoList->SetCurSel(iCurIndex); + } + + g_pInfoList->SetAnchorIndex(iCurIndex); + g_pInfoList->SetRedraw(TRUE); +} + +CBufferPtr* GeneratePkgBuffer(DWORD seq, LPCTSTR lpszName, short age, LPCTSTR lpszDesc) +{ + USES_CONVERSION; + + LPCSTR name = T2A((LPTSTR)lpszName); + LPCSTR desc = T2A((LPTSTR)lpszDesc); + int desc_len = (int)strlen(desc) + 1; + int body_len = offsetof(TPkgBody, desc) + desc_len; + + TPkgBody* pBody = (TPkgBody*)_alloca(body_len); + memset(pBody, 0, body_len); + + pBody->age = age; + strcpy(pBody->name, name); + strcpy(pBody->desc, desc); + + TPkgHeader header; + header.seq = seq; + header.body_len = body_len; + + return GeneratePkgBuffer(header, *pBody); +} + +CBufferPtr* GeneratePkgBuffer(const TPkgHeader& header, const TPkgBody& body) +{ + int header_len = sizeof(TPkgHeader); + int body_len = header.body_len; + + CBufferPtr* pBuffer = new CBufferPtr(header_len + body_len); + + memcpy(pBuffer->Ptr(), (BYTE*)&header, header_len); + memcpy(pBuffer->Ptr() + header_len, (BYTE*)&body, body_len); + + return pBuffer; +} diff --git a/HP-Socket/Demo/Global/helper.h b/HP-Socket/Demo/Global/helper.h new file mode 100644 index 000000000..106f15503 --- /dev/null +++ b/HP-Socket/Demo/Global/helper.h @@ -0,0 +1,101 @@ +#pragma once + +#include "../../Src/SocketInterface.h" + +#define USER_INFO_MSG (WM_USER + 100) +#define MAX_LOG_RECORD_LENGTH 1000 + +#define EVT_ON_SEND _T("OnSend") +#define EVT_ON_RECEIVE _T("OnReceive") +#define EVT_ON_CLOSE _T("OnClose") +#define EVT_ON_ERROR _T("OnError") +#define EVT_ON_PREPARE_CONNECT _T("OnPrepareConnect") +#define EVT_ON_PREPARE_LISTEN _T("OnPrepareListen") +#define EVT_ON_ACCEPT _T("OnAccept") +#define EVT_ON_CONNECT _T("OnConnect") +#define EVT_ON_SHUTDOWN _T("OnShutdown") +#define EVT_ON_END_TEST _T("END TEST") + +enum EnAppState +{ + ST_STARTING, ST_STARTED, ST_CONNECTING, ST_CONNECTED, ST_STOPPING, ST_STOPPED +}; + +struct info_msg +{ + CONNID connID; + LPCTSTR evt; + int contentLength; + LPCTSTR content; + + static info_msg* Construct(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength, LPCTSTR lpszContent); + static void Destruct(info_msg* pMsg); + +private: + info_msg(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength, LPCTSTR lpszContent); + ~info_msg(); +}; + +struct TPkgHeader +{ + DWORD seq; + int body_len; +}; + +struct TPkgBody +{ + char name[30]; + short age; + char desc[1]; +}; + +struct TPkgInfo +{ + bool is_header; + int length; + + TPkgInfo(bool header = true, int len = sizeof(TPkgHeader)) : is_header(header), length(len) {} + void Reset() {is_header = true, length = sizeof(TPkgHeader);} + ~TPkgInfo() {} +}; + +CBufferPtr* GeneratePkgBuffer(DWORD seq, LPCTSTR lpszName, short age, LPCTSTR lpszDesc); +CBufferPtr* GeneratePkgBuffer(const TPkgHeader& header, const TPkgBody& body); + +void SetMainWnd(CWnd* pWnd); +void SetInfoList(CListBox* pInfoList); +void LogServerStart(LPCTSTR lpszAddress, USHORT port); +void LogServerStartFail(DWORD code, LPCTSTR lpszDesc); +void LogServerStop(); +void LogServerStopFail(DWORD code, LPCTSTR lpszDesc); +void LogClientStart(LPCTSTR lpszAddress, USHORT port); +void LogClientStarting(LPCTSTR lpszAddress, USHORT port); +void LogClientStartFail(DWORD code, LPCTSTR lpszDesc); +void LogClientStopping(CONNID dwConnID); +void LogClientStopFail(DWORD code, LPCTSTR lpszDesc); +void LogSend(CONNID dwConnID, LPCTSTR lpszContent); +void LogClientSendFail(int iSequence, int iSocketIndex, DWORD code, LPCTSTR lpszDesc); +void LogSendFail(CONNID dwConnID, DWORD code, LPCTSTR lpszDesc); +void LogDisconnect(CONNID dwConnID); +void LogDisconnectFail(CONNID dwConnID); +void LogDetect(CONNID dwConnID); +void LogDetectFail(CONNID dwConnID); +void LogOnConnect(CONNID dwConnID, const CString& strAddress, USHORT usPort); +void LogOnConnect2(CONNID dwConnID); +void LogMsg(const CString& msg); +void PostOnSend(CONNID dwConnID, const BYTE* pData, int iLength); +void PostOnReceive(CONNID dwConnID, const BYTE* pData, int iLength); +void PostOnReceiveCast(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, const BYTE* pData, int iLength); +void PostOnClose(CONNID dwConnID); +void PostOnError(CONNID dwConnID, int enOperation, int iErrorCode); +void PostOnAccept(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, BOOL bPass); +void PostOnAccept2(CONNID dwConnID); +void PostOnPrepareListen(LPCTSTR lpszAddress, USHORT usPort); +void PostOnPrepareConnect(CONNID dwConnID); +void PostOnConnect(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort); +void PostOnConnect2(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort); +void PostOnShutdown(); +void PostServerStatics(const LONGLONG& llTotalSent, const LONGLONG& llTotalReceived); +void PostTimeConsuming(DWORD dwTickCount); +void PostInfoMsg(info_msg* msg); +void LogInfoMsg(info_msg* pInfoMsg); diff --git a/HP-Socket/Demo/HttpProxy/HttpProxy.sln b/HP-Socket/Demo/HttpProxy/HttpProxy.sln new file mode 100644 index 000000000..4d75da829 --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/HttpProxy.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C878}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.Build.0 = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.Build.0 = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.Build.0 = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.ActiveCfg = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/HttpProxy/HttpProxy.suo b/HP-Socket/Demo/HttpProxy/HttpProxy.suo new file mode 100644 index 000000000..1105f5346 Binary files /dev/null and b/HP-Socket/Demo/HttpProxy/HttpProxy.suo differ diff --git a/HP-Socket/Demo/HttpProxy/Server/ReadMe.txt b/HP-Socket/Demo/HttpProxy/Server/ReadMe.txt new file mode 100644 index 000000000..d97be25bf --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Server Project Overview +=============================================================================== + +The application wizard has created this Server application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Server application. + +Server.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Server.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CServerApp application class. + +Server.cpp + This is the main application source file that contains the application + class CServerApp. + +Server.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Server.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Server.rc. + +res\Server.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ServerDlg.h, ServerDlg.cpp - the dialog + These files contain your CServerDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Server.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Server.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Server.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/HttpProxy/Server/Server.cpp b/HP-Socket/Demo/HttpProxy/Server/Server.cpp new file mode 100644 index 000000000..417b91c90 --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/Server.cpp @@ -0,0 +1,87 @@ + +// Server.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" + + +// CServerApp + +BEGIN_MESSAGE_MAP(CServerApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CServerApp construction + +CServerApp::CServerApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CServerApp object + +CServerApp theApp; + + +// CServerApp initialization + +BOOL CServerApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CServerDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != nullptr) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/HttpProxy/Server/Server.h b/HP-Socket/Demo/HttpProxy/Server/Server.h new file mode 100644 index 000000000..df6a5f075 --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/Server.h @@ -0,0 +1,32 @@ + +// Server.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CServerApp: +// See Server.cpp for the implementation of this class +// + +class CServerApp : public CWinApp +{ +public: + CServerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CServerApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/HttpProxy/Server/Server.rc b/HP-Socket/Demo/HttpProxy/Server/Server.rc new file mode 100644 index 000000000..0726326a6 Binary files /dev/null and b/HP-Socket/Demo/HttpProxy/Server/Server.rc differ diff --git a/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj b/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj new file mode 100644 index 000000000..16650fb03 --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj @@ -0,0 +1,237 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5A2EE763-53B1-462E-AE9F-7CC58436C878} + Server + MFCProj + Server + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + + + Windows + true + + + + + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + + + Windows + true + + + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + MultiThreadedDLL + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + MultiThreadedDLL + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj.filters b/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj.filters new file mode 100644 index 000000000..d18a36eab --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj.filters @@ -0,0 +1,86 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {48c55559-451a-4f0d-9cb2-884503406307} + + + {f57bc1d3-66f4-49c0-b1c8-c7e5d163de15} + + + {849bedeb-2d4e-4965-8c3a-c8ace1a89f27} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket + + + HPSocket + + + Common + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj.user b/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/Server.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/HttpProxy/Server/ServerDlg.cpp b/HP-Socket/Demo/HttpProxy/Server/ServerDlg.cpp new file mode 100644 index 000000000..aad150e65 --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/ServerDlg.cpp @@ -0,0 +1,617 @@ + +// ServerDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" +#include "afxdialogex.h" +#include "../../../../Common/Src/WaitFor.h" + +#ifdef _WIN64 + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_U.lib") + #endif +#else + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_U.lib") + #endif +#endif + +// CServerDlg dialog + +#define DEFAULT_ADDRESS _T("0.0.0.0") +#define DEFAULT_PORT _T("5555") + +#ifdef _DEBUG + #define DEF_SHOW_LOG BST_CHECKED +#else + #define DEF_SHOW_LOG BST_UNCHECKED +#endif + +#define DEF_HTTP_PORT 80 +#define DEF_HTTPS_PORT 443 +#define HTTPS_FLAG "CONNECT" +#define HTTP_SCHEME "http://" +#define HTTP_1_1 "HTTP/1.1" +#define HEAD_CONN "Connection:" +#define HEAD_PROXY_CONN "Proxy-Connection:" +#define HTTPS_RESP "HTTP/1.1 200 Connection Established\r\n\r\n" +#define IE_OPT_DIALOG "rundll32.exe shell32.dll, Control_RunDLL inetcpl.cpl, , 4" + +static int HTTP_SCHEME_LEN = (int)strlen(HTTP_SCHEME); +static int HEAD_CONN_LEN = (int)strlen(HEAD_CONN); +static int HEAD_PROXY_CONN_LEN = (int)strlen(HEAD_PROXY_CONN); +static int HTTPS_RESP_LEN = (int)strlen(HTTPS_RESP); + +CServerDlg::CServerDlg(CWnd* pParent /*=nullptr*/) + : CDialogEx(CServerDlg::IDD, pParent) + , m_pServerListener(new CTcpServerListenerImpl(this)) + , m_pAgentListener(new CTcpAgentListenerImpl(this)) + , m_Server(m_pServerListener) + , m_Agent(m_pAgentListener) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CServerDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_OPTIONS, m_Options); + DDX_Control(pDX, IDC_SHOWLOG, m_ShowLog); +} + +BEGIN_MESSAGE_MAP(CServerDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CServerDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CServerDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() + ON_WM_CLOSE() + ON_BN_CLICKED(IDC_OPTIONS, &CServerDlg::OnBnClickedOptions) +END_MESSAGE_MAP() + + +// CServerDlg message handlers + +BOOL CServerDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + CString strTitle; + CString strOriginTitle; + m_Port.SetWindowText(DEFAULT_PORT); + m_ShowLog.SetCheck(DEF_SHOW_LOG); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CServerDlg::OnClose() +{ + /* + if(m_Server->GetState() != SS_STOPED) + { + this->MessageBox(_T("stop IOCP Server first, pls !"), _T("forbiddden")); + return; + } + */ + + ::SetMainWnd(nullptr); + __super::OnClose(); + + if(m_Server->HasStarted()) + m_Server->Stop(); + + if(m_Agent->HasStarted()) + m_Agent->Stop(); +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CServerDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CServerDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CServerDlg::SetAppState(EnAppState state) +{ + if(m_enState == state) + return; + + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Port.EnableWindow(m_enState == ST_STOPPED); + //m_Options.EnableWindow(m_enState == ST_STOPPED); + m_ShowLog.EnableWindow(m_enState == ST_STOPPED); +} + +void CServerDlg::OnBnClickedStart() +{ + CString strPort; + m_Port.GetWindowText(strPort); + USHORT usPort = (USHORT)_ttoi(strPort); + + if(usPort == 0) + { + MessageBox(_T("Listen Port invalid, pls check!"), _T("Params Error"), MB_OK); + m_Port.SetFocus(); + return; + } + + m_bLog = (m_ShowLog.GetCheck() == BST_CHECKED); + + SetAppState(ST_STARTING); + + //m_Server->SetFreeSocketObjPool(500); + //m_Server->SetFreeSocketObjHold(1500); + //m_Server->SetFreeBufferObjPool(2000); + //m_Server->SetFreeBufferObjHold(6000); + //m_Server->SetAcceptSocketCount(50); + + m_Server->SetSendPolicy(SP_DIRECT); + m_Agent->SetSendPolicy(SP_DIRECT); + + if(m_Server->Start(DEFAULT_ADDRESS, usPort)) + { + VERIFY(m_Agent->Start(nullptr, FALSE)); + + ::LogServerStart(DEFAULT_ADDRESS, usPort); + SetAppState(ST_STARTED); + } + else + { + ::LogServerStartFail(m_Server->GetLastError(), m_Server->GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + +void CServerDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + VERIFY(m_Server->Stop()); + VERIFY(m_Agent->Stop()); + + ::LogServerStop(); + SetAppState(ST_STOPPED); +} + +void CServerDlg::OnBnClickedOptions() +{ + ::WinExec(IE_OPT_DIALOG, 0); +} + +int CServerDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CTcpServerListenerImpl::OnPrepareListen(SOCKET soListen) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_pDlg->m_Server->GetListenAddress(szAddress, iAddressLen, usPort); + ::PostOnPrepareListen(szAddress, usPort); + + return HR_OK; +} + +EnHandleResult CTcpServerListenerImpl::OnAccept(CONNID dwConnID, SOCKET soClient) +{ + //if(m_pDlg->m_bLog) ::PostOnAccept2(dwConnID); + + return HR_OK; +} + +EnHandleResult CTcpServerListenerImpl::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ + //if(m_pDlg->m_bLog) ::PostOnSend(dwConnID, pData, iLength); + + return HR_OK; +} + +EnHandleResult CTcpServerListenerImpl::OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) +{ + //if(m_pDlg->m_bLog) ::PostOnReceive(dwConnID, pData, iLength); + + CONNID dwAgentID = 0; + + if(!m_pDlg->m_Server->GetConnectionExtra(dwConnID, (PVOID*)&dwAgentID)) + return HR_IGNORE; + + EnHandleResult rs = HR_ERROR; + BYTE* pData2 = (BYTE*)pData; + int iLength2 = iLength; + + BOOL isHttps; + CString strAddr; + USHORT usPort; + + if(dwAgentID == 0) + { + if(ParseRequestHeader(pData2, iLength2, isHttps, strAddr, usPort)) + { + if(m_pDlg->m_Agent->Connect(strAddr, usPort, &dwAgentID)) + { + m_pDlg->m_Agent->SetConnectionExtra(dwAgentID, (PVOID)dwConnID); + m_pDlg->m_Server->SetConnectionExtra(dwConnID, (PVOID)dwAgentID); + + if(isHttps) + { + if(m_pDlg->m_Server->Send(dwConnID, (BYTE*)HTTPS_RESP, HTTPS_RESP_LEN)) + rs = HR_OK; + } + else + { + if(m_pDlg->m_Agent->Send(dwAgentID, pData2, iLength2)) + rs = HR_OK; + } + } + } + } + else + { + BOOL isOK = TRUE; + + if(CheckIfHttp(pData2, iLength2)) + isOK = ParseRequestHeader(pData2, iLength2, isHttps, strAddr, usPort); + + if(isOK && m_pDlg->m_Agent->Send(dwAgentID, pData2, iLength2)) + rs = HR_OK; + } + + return rs; +} + +EnHandleResult CTcpServerListenerImpl::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + /* + if(m_pDlg->m_bLog) + { + iErrorCode == SE_OK ? ::PostOnClose(dwConnID) : + ::PostOnError(dwConnID, enOperation, iErrorCode); + } + */ + + DetachConnInfo(dwConnID); + + return HR_OK; +} + +EnHandleResult CTcpServerListenerImpl::OnShutdown() +{ + return HR_OK; +} + +void CTcpServerListenerImpl::DetachConnInfo(CONNID dwConnID) +{ + CONNID dwAgentID = 0; + BOOL bExist = m_pDlg->m_Server->GetConnectionExtra(dwConnID, (PVOID*)&dwAgentID); + + if(bExist && dwAgentID != 0) + { + m_pDlg->m_Agent->SetConnectionExtra(dwAgentID, (PVOID)0); + m_pDlg->m_Agent->Disconnect(dwAgentID); + } +} + +BOOL CTcpServerListenerImpl::ParseRequestHeader(BYTE*& pData, int& iLength, BOOL& isHttps, CString& strAddr, USHORT& usPort) +{ + usPort = 0; + isHttps = FALSE; + strAddr.Empty(); + + BYTE* pTemp = pData; + int i = 0; + + for(; i < iLength; ++i, ++pTemp) + { + if(*pTemp == '\r') + break; + } + + if(i == iLength) + return FALSE; + + CStringA strContent; + + int iBufferLen = (int)(pTemp - pData); + LPSTR lpstr = strContent.GetBufferSetLength(iBufferLen); + memcpy(lpstr, pData, iBufferLen); + + int iPos = 0; + int iPos1 = 0; + int iSchemePos = 0; + BOOL bHttp11 = FALSE; + + CStringA strHost; + CStringA strToken = strContent.Tokenize(" ", iPos); + + for(int i = 0; !strToken.IsEmpty() && i < 3; i++) + { + if(i == 0) + { + if(strToken.CompareNoCase(HTTPS_FLAG) == 0) + isHttps = TRUE; + else + iPos1 = iPos; + + strToken = strContent.Tokenize(" ", iPos); + } + else if(i == 1) + { + if(isHttps) + strHost = strToken; + else + { + if(strToken.Find(HTTP_SCHEME) != 0) + return FALSE; + + int iPos2 = 0; + iSchemePos = iPos1; + + strToken.Replace(HTTP_SCHEME, ""); + strHost = strToken.Tokenize("/", iPos2); + } + + strToken = strContent.Tokenize(" ", iPos); + } + else if(i == 2) + { + if(strToken.CompareNoCase(HTTP_1_1) == 0) + bHttp11 = TRUE; + } + } + + if(strHost.IsEmpty()) + return FALSE; + + iPos = 0; + strToken = strHost.Tokenize(":", iPos); + + for(int i = 0; !strToken.IsEmpty() && i < 2; i++) + { + if(i == 0) + { + strAddr = strToken; + strToken = strHost.Tokenize(":", iPos); + } + else if(i == 1) + { + usPort = atoi(strToken); + } + } + + if(usPort == 0) + usPort = isHttps ? DEF_HTTPS_PORT : DEF_HTTP_PORT; + + if(!isHttps && bHttp11) + { + int iMoveLen = strHost.GetLength() + HTTP_SCHEME_LEN; + memcpy(pData + iMoveLen, pData, iSchemePos); + + pData += iMoveLen; + iLength -= iMoveLen; + } + + ++pTemp; + BYTE* pHead = pTemp; + int iRange = iLength - (int)(pHead - pData); + + for(i = 0; i < iRange; ++i, ++pTemp) + { + if(*pTemp == '\r') + { + if(_strnicmp((char*)pHead, HEAD_PROXY_CONN, HEAD_PROXY_CONN_LEN) == 0) + { + int iMoveLen = HEAD_PROXY_CONN_LEN - HEAD_CONN_LEN; + memcpy(pHead + iMoveLen, HEAD_CONN, HEAD_CONN_LEN); + + int iCopyLen = (int)(pHead - pData); + memcpy(pData + iMoveLen, pData, iCopyLen); + + pData += iMoveLen; + iLength -= iMoveLen; + + break; + } + else if(*(pTemp - 1) == '\r' || *(pTemp - 2) == '\r') + break; + } + else if(*pTemp == '\n') + { + ++pTemp; + pHead = pTemp; + } + } + + return TRUE; +} + +BOOL CTcpServerListenerImpl::CheckIfHttp(const BYTE* pData, int iLength) +{ + BYTE c = *pData; + + if(c < 'A' || (c > 'Z' && c < 'a') || c > 'z') + return FALSE; + + LPCSTR lpszData = (LPCSTR)pData; + + if(_strnicmp(lpszData, "GET " , 4) == 0) + return TRUE; + if(_strnicmp(lpszData, "POST " , 5) == 0) + return TRUE; + if(_strnicmp(lpszData, "HEAD " , 5) == 0) + return TRUE; + if(_strnicmp(lpszData, "PUT " , 4) == 0) + return TRUE; + if(_strnicmp(lpszData, "DELETE " , 7) == 0) + return TRUE; + if(_strnicmp(lpszData, "TRACE " , 6) == 0) + return TRUE; + if(_strnicmp(lpszData, "OPTIONS " , 8) == 0) + return TRUE; + + return FALSE; +} + +EnHandleResult CTcpAgentListenerImpl::OnConnect(CONNID dwConnID) +{ + if(m_pDlg->m_bLog) + { + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_pDlg->m_Agent->GetRemoteAddress(dwConnID, szAddress, iAddressLen, usPort); + + ::PostOnConnect2(dwConnID, szAddress, usPort); + } + + return HR_OK; +} + +EnHandleResult CTcpAgentListenerImpl::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ + if(m_pDlg->m_bLog) ::PostOnSend(dwConnID, pData, iLength); + + return HR_OK; +} + +EnHandleResult CTcpAgentListenerImpl::OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) +{ + if(m_pDlg->m_bLog) ::PostOnReceive(dwConnID, pData, iLength); + + CONNID dwServerID = 0; + BOOL bExist = TRUE; + + while(TRUE) + { + bExist = m_pDlg->m_Agent->GetConnectionExtra(dwConnID, (PVOID*)&dwServerID); + + if(bExist && dwServerID == 0) + ::WaitWithMessageLoop(10); + else + break; + } + + if(!bExist) + return HR_IGNORE; + if(!m_pDlg->m_Server->Send(dwServerID, pData, iLength)) + return HR_ERROR; + + return HR_OK; +} + +EnHandleResult CTcpAgentListenerImpl::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + if(m_pDlg->m_bLog) + { + iErrorCode == SE_OK ? ::PostOnClose(dwConnID) : + ::PostOnError(dwConnID, enOperation, iErrorCode); + } + + DetachConnInfo(dwConnID); + + return HR_OK; +} + +EnHandleResult CTcpAgentListenerImpl::OnShutdown() +{ + ::PostOnShutdown(); + + return HR_OK; +} + +void CTcpAgentListenerImpl::DetachConnInfo(CONNID dwConnID) +{ + CONNID dwServerID = 0; + BOOL bExist = m_pDlg->m_Agent->GetConnectionExtra(dwConnID, (PVOID*)&dwServerID); + + if(bExist && dwServerID != 0) + { + m_pDlg->m_Server->SetConnectionExtra(dwServerID, (PVOID)0); + m_pDlg->m_Server->Disconnect(dwServerID); + } +} diff --git a/HP-Socket/Demo/HttpProxy/Server/ServerDlg.h b/HP-Socket/Demo/HttpProxy/Server/ServerDlg.h new file mode 100644 index 000000000..25c8d06ba --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/ServerDlg.h @@ -0,0 +1,110 @@ + +// ServerDlg.h : header file +// + +#pragma once +#include "afxwin.h" + +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + +class CServerDlg; + +class CTcpServerListenerImpl : public CTcpServerListener +{ +public: + CTcpServerListenerImpl(CServerDlg* pDlg) : m_pDlg(pDlg) + { + + } + +private: + virtual EnHandleResult OnPrepareListen(SOCKET soListen); + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient); + virtual EnHandleResult OnShutdown(); + +private: + void DetachConnInfo(CONNID dwConnID); + BOOL ParseRequestHeader(BYTE*& pData, int& iLength, BOOL& isHttps, CString& strAddr, USHORT& usPort); + BOOL CheckIfHttp(const BYTE* pData, int iLength); + +public: + CServerDlg* m_pDlg; +}; + +class CTcpAgentListenerImpl : public CTcpAgentListener +{ +public: + CTcpAgentListenerImpl(CServerDlg* pDlg) : m_pDlg(pDlg) + { + + } + +private: + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(CONNID dwConnID); + virtual EnHandleResult OnShutdown(); + +private: + void DetachConnInfo(CONNID dwConnID); + +public: + CServerDlg* m_pDlg; +}; + +// CServerDlg dialog +class CServerDlg : public CDialogEx +{ +// Construction +public: + CServerDlg(CWnd* pParent = nullptr); // standard constructor + +// Dialog Data + enum { IDD = IDD_SERVER_DIALOG }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + afx_msg void OnBnClickedOptions(); + afx_msg void OnClose(); + + DECLARE_MESSAGE_MAP() + +public: + void SetAppState(EnAppState state); + +private: + CListBox m_Info; + CEdit m_Port; + CButton m_Start; + CButton m_Stop; + CButton m_Options; + CButton m_ShowLog; + EnAppState m_enState; + +public: + smart_simple_ptr m_pServerListener; + smart_simple_ptr m_pAgentListener; + CTcpServerPtr m_Server; + CTcpAgentPtr m_Agent; + + BOOL m_bLog; +}; diff --git a/HP-Socket/Demo/HttpProxy/Server/res/Server.ico b/HP-Socket/Demo/HttpProxy/Server/res/Server.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/HttpProxy/Server/res/Server.ico differ diff --git a/HP-Socket/Demo/HttpProxy/Server/res/Server.rc2 b/HP-Socket/Demo/HttpProxy/Server/res/Server.rc2 new file mode 100644 index 000000000..b77c9d1c1 Binary files /dev/null and b/HP-Socket/Demo/HttpProxy/Server/res/Server.rc2 differ diff --git a/HP-Socket/Demo/HttpProxy/Server/resource.h b/HP-Socket/Demo/HttpProxy/Server/resource.h new file mode 100644 index 000000000..406eefc53 Binary files /dev/null and b/HP-Socket/Demo/HttpProxy/Server/resource.h differ diff --git a/HP-Socket/Demo/HttpProxy/Server/stdafx.cpp b/HP-Socket/Demo/HttpProxy/Server/stdafx.cpp new file mode 100644 index 000000000..22d19927c --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/HttpProxy/Server/stdafx.h b/HP-Socket/Demo/HttpProxy/Server/stdafx.h new file mode 100644 index 000000000..dc0a47732 --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/stdafx.h @@ -0,0 +1,14 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" diff --git a/HP-Socket/Demo/HttpProxy/Server/targetver.h b/HP-Socket/Demo/HttpProxy/Server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/HttpProxy/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/Other Languages Demos/Authors.txt b/HP-Socket/Demo/Other Languages Demos/Authors.txt new file mode 100644 index 000000000..b1035d5a9 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Authors.txt @@ -0,0 +1,7 @@ +* C# SDK ߣ int 2e +* ֿ֧ ߣ Yecate +* ģ ߣ ׿ԽάС + +1C# Demo ߣ int 2e +2Delphi Demo ߣ int 2e +3 Demo ߣ Yecate׿ԽάС \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/CSharpTestEcho-4C.sln b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/CSharpTestEcho-4C.sln new file mode 100644 index 000000000..c7f6f8730 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/CSharpTestEcho-4C.sln @@ -0,0 +1,182 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HPSocketCS", "HPSocketCS\HPSocketCS.csproj", "{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpPullClient", "TcpPullClient\TcpPullClient.csproj", "{B9965E66-853A-47CC-B0C9-197B5A29ABFC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpPullServer", "TcpPullServer\TcpPullServer.csproj", "{B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpClient", "TcpClient\TcpClient.csproj", "{B6E43918-236A-4EA7-84C8-ED4A98049907}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpServer", "TcpServer\TcpServer.csproj", "{9A3339BC-37F0-4D03-9ACE-51CC4CF75277}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpProxyServer", "TcpProxyServer\TcpProxyServer.csproj", "{5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpServer-PFM", "TcpServer-PFM\TcpServer-PFM.csproj", "{10426A79-A3B3-4CD2-BD84-02AAEE27FB75}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpClient-PFM", "TcpClient-PFM\TcpClient-PFM.csproj", "{9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpPackServer", "TcpPackServer\TcpPackServer.csproj", "{2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpPackClient", "TcpPackClient\TcpPackClient.csproj", "{36D05914-1A8A-484C-9FB7-8BE4582A665A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|x64.ActiveCfg = Debug|x64 + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|x64.Build.0 = Debug|x64 + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|x86.ActiveCfg = Debug|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|x86.Build.0 = Debug|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|Any CPU.Build.0 = Release|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|x64.ActiveCfg = Release|x64 + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|x64.Build.0 = Release|x64 + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|x86.ActiveCfg = Release|Any CPU + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|x86.Build.0 = Release|Any CPU + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Debug|Any CPU.ActiveCfg = Debug|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Debug|x64.ActiveCfg = Debug|x64 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Debug|x64.Build.0 = Debug|x64 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Debug|x86.ActiveCfg = Debug|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Debug|x86.Build.0 = Debug|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Release|Any CPU.ActiveCfg = Release|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Release|Mixed Platforms.Build.0 = Release|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Release|x64.ActiveCfg = Release|x64 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Release|x64.Build.0 = Release|x64 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Release|x86.ActiveCfg = Release|x86 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC}.Release|x86.Build.0 = Release|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Debug|Any CPU.ActiveCfg = Debug|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Debug|x64.ActiveCfg = Debug|x64 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Debug|x64.Build.0 = Debug|x64 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Debug|x86.ActiveCfg = Debug|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Debug|x86.Build.0 = Debug|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Release|Any CPU.ActiveCfg = Release|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Release|Mixed Platforms.Build.0 = Release|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Release|x64.ActiveCfg = Release|x64 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Release|x64.Build.0 = Release|x64 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Release|x86.ActiveCfg = Release|x86 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA}.Release|x86.Build.0 = Release|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Debug|Any CPU.ActiveCfg = Debug|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Debug|x64.ActiveCfg = Debug|x64 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Debug|x64.Build.0 = Debug|x64 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Debug|x86.ActiveCfg = Debug|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Debug|x86.Build.0 = Debug|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Release|Any CPU.ActiveCfg = Release|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Release|Mixed Platforms.Build.0 = Release|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Release|x64.ActiveCfg = Release|x64 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Release|x64.Build.0 = Release|x64 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Release|x86.ActiveCfg = Release|x86 + {B6E43918-236A-4EA7-84C8-ED4A98049907}.Release|x86.Build.0 = Release|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Debug|Any CPU.ActiveCfg = Debug|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Debug|x64.ActiveCfg = Debug|x64 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Debug|x64.Build.0 = Debug|x64 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Debug|x86.ActiveCfg = Debug|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Debug|x86.Build.0 = Debug|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Release|Any CPU.ActiveCfg = Release|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Release|Mixed Platforms.Build.0 = Release|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Release|x64.ActiveCfg = Release|x64 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Release|x64.Build.0 = Release|x64 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Release|x86.ActiveCfg = Release|x86 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277}.Release|x86.Build.0 = Release|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Debug|Any CPU.ActiveCfg = Debug|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Debug|x64.ActiveCfg = Debug|x64 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Debug|x64.Build.0 = Debug|x64 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Debug|x86.ActiveCfg = Debug|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Debug|x86.Build.0 = Debug|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Release|Any CPU.ActiveCfg = Release|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Release|Mixed Platforms.Build.0 = Release|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Release|x64.ActiveCfg = Release|x64 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Release|x64.Build.0 = Release|x64 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Release|x86.ActiveCfg = Release|x86 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98}.Release|x86.Build.0 = Release|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Debug|Any CPU.ActiveCfg = Debug|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Debug|x64.ActiveCfg = Debug|x64 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Debug|x64.Build.0 = Debug|x64 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Debug|x86.ActiveCfg = Debug|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Debug|x86.Build.0 = Debug|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Release|Any CPU.ActiveCfg = Release|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Release|Mixed Platforms.Build.0 = Release|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Release|x64.ActiveCfg = Release|x64 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Release|x64.Build.0 = Release|x64 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Release|x86.ActiveCfg = Release|x86 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75}.Release|x86.Build.0 = Release|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Debug|Any CPU.ActiveCfg = Debug|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Debug|x64.ActiveCfg = Debug|x64 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Debug|x64.Build.0 = Debug|x64 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Debug|x86.ActiveCfg = Debug|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Debug|x86.Build.0 = Debug|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Release|Any CPU.ActiveCfg = Release|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Release|Mixed Platforms.Build.0 = Release|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Release|x64.ActiveCfg = Release|x64 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Release|x64.Build.0 = Release|x64 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Release|x86.ActiveCfg = Release|x86 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A}.Release|x86.Build.0 = Release|x86 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Debug|Any CPU.ActiveCfg = Debug|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Debug|Mixed Platforms.Build.0 = Debug|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Debug|x64.ActiveCfg = Debug|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Debug|x64.Build.0 = Debug|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Debug|x86.ActiveCfg = Debug|x86 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Debug|x86.Build.0 = Debug|x86 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Release|Any CPU.ActiveCfg = Release|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Release|Mixed Platforms.Build.0 = Release|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Release|x64.ActiveCfg = Release|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Release|x64.Build.0 = Release|x64 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Release|x86.ActiveCfg = Release|x86 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC}.Release|x86.Build.0 = Release|x86 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Debug|Any CPU.ActiveCfg = Debug|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Debug|Mixed Platforms.Build.0 = Debug|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Debug|x64.ActiveCfg = Debug|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Debug|x64.Build.0 = Debug|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Debug|x86.ActiveCfg = Debug|x86 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Debug|x86.Build.0 = Debug|x86 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Release|Any CPU.ActiveCfg = Release|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Release|Mixed Platforms.Build.0 = Release|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Release|x64.ActiveCfg = Release|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Release|x64.Build.0 = Release|x64 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Release|x86.ActiveCfg = Release|x86 + {36D05914-1A8A-484C-9FB7-8BE4582A665A}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/CSharpTestEcho-4C.suo b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/CSharpTestEcho-4C.suo new file mode 100644 index 000000000..f78087265 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/CSharpTestEcho-4C.suo differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/HPSocketCS.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/HPSocketCS.csproj new file mode 100644 index 000000000..79bdb00e8 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/HPSocketCS.csproj @@ -0,0 +1,95 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + Library + Properties + HPSocketCS + HPSocketCS + v4.0 + 512 + + + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\HPSocketCS.dll.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\HPSocketCS.dll.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..cee53805a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("HPSocketCS")] +[assembly: AssemblyDescription("HP-Socket for C#")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("JessMA Open Source")] +[assembly: AssemblyProduct("HPSocketCS")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("f54bd34d-cd0c-40dc-8c50-73c3ead0a894")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/Sdk.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/Sdk.cs new file mode 100644 index 000000000..ab56bef07 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/Sdk.cs @@ -0,0 +1,2280 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; +using HPSocketCS; + + +namespace HPSocketCS +{ + + /// + /// 通信组件服务状态,用程序可以通过通信组件的 GetState() 方法获取组件当前服务状态 + /// + public enum ServiceState + { + /// + /// 正在启动 + /// + Starting = 0, + /// + /// 已经启动 + /// + Started = 1, + /// + /// 正在停止 + /// + Stoping = 2, + /// + /// 已经启动 + /// + Stoped = 3, + } + + /// + /// Socket 操作类型,应用程序的 OnErrror() 事件中通过该参数标识是哪种操作导致的错误 + /// + public enum SocketOperation + { + Unknown = 0, // Unknown + Acccept = 1, // Acccept + Connnect = 2, // Connnect + Send = 3, // Send + Receive = 4, // Receive + Close = 5, // Receive + }; + + /// + /// 事件通知处理结果,事件通知的返回值,不同的返回值会影响通信组件的后续行为 + /// + public enum HandleResult + { + /// + /// 成功 + /// + Ok = 0, + /// + /// 忽略 + /// + Ignore = 1, + /// + /// 错误 + /// + Error = 2, + }; + + + /// + /// 名称:操作结果代码 + /// 描述:组件 Start() / Stop() 方法执行失败时,可通过 GetLastError() 获取错误代码 + /// + public enum SocketError + { + /// + /// 成功 + /// + Ok = 0, + /// + /// 当前状态不允许操作 + /// + IllegalState = 1, + /// + /// 非法参数 + /// + InvalidParam = 2, + /// + /// 创建 SOCKET 失败 + /// + SocketCreate = 3, + /// + /// 绑定 SOCKET 失败 + /// + SocketBind = 4, + /// + /// 设置 SOCKET 失败 + /// + SocketPrepare = 5, + /// + /// 监听 SOCKET 失败 + /// + SocketListen = 6, + /// + /// 创建完成端口失败 + /// + CPCreate = 7, + /// + /// 创建工作线程失败 + /// + WorkerThreadCreate = 8, + /// + /// 创建监测线程失败 + /// + DetectThreadCreate = 9, + /// + /// 绑定完成端口失败 + /// + SocketAttachToCP = 10, + /// + /// 连接服务器失败 + /// + ConnectServer = 11, + /// + /// 网络错误 + /// + Network = 12, + /// + /// 数据处理错误 + /// + DataProc = 13, + /// + /// 数据发送失败 + /// + DataSend = 14, + }; + + /// + /// 数据抓取结果,数据抓取操作的返回值 + /// + public enum FetchResult + { + /// + /// 成功 + /// + Ok = 0, + /// + /// 抓取长度过大 + /// + LengthTooLong = 1, + /// + /// 找不到 ConnID 对应的数据 + /// + DataNotFound = 2, + }; + + /// + /// 发送策略 + /// + public enum SendPolicy + { + /// + /// 打包模式(默认) + /// + Pack = 0, + /// + /// 安全模式 + /// + Safe = 1, + /// + /// 直接模式 + /// + Direct = 2, + }; + + /****************************************************/ + /************** sockaddr结构体,udp服务器时OnAccept最后个参数可转化 **************/ + [StructLayout(LayoutKind.Sequential)] + public struct in_addr + { + public ulong S_addr; + } + + //[StructLayout(LayoutKind.Sequential)] + //public struct in_addr + //{ + // public byte s_b1, s_b2, s_b3, s_b4; + //} + + [StructLayout(LayoutKind.Sequential)] + public struct sockaddr_in + { + public short sin_family; + public ushort sin_port; + public in_addr sin_addr; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] + public byte[] sLibNamesin_zero; + } + + /****************************************************/ + + [StructLayout(LayoutKind.Sequential)] + public struct WSABUF + { + public int Length; + public IntPtr Buffer; + } +} + + +namespace HPSocketCS.SDK +{ + /// + /// Unicode版本 + /// + public class HPSocketSdk + { + /// + /// HPSocket的文件路径 + /// +#if DEBUG + private const string SOCKET_DLL_PATH = "HPSocket4C_UD.dll"; +#else + private const string SOCKET_DLL_PATH = "HPSocket4C_U.dll"; +#endif + /*****************************************************************************************************/ + /******************************************** 公共类、接口 ********************************************/ + /*****************************************************************************************************/ + + + + /****************************************************/ + /************** HPSocket4C.dll 回调函数 **************/ + /* Agent & Server & Clent */ + public delegate HandleResult OnSend(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnReceive(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnPullReceive(IntPtr connId, int length); + public delegate HandleResult OnClose(IntPtr connId, SocketOperation enOperation, int errorCode); + + /* Agent & Server */ + public delegate HandleResult OnShutdown(); + + /* Agent & Client */ + public delegate HandleResult OnPrepareConnect(IntPtr connId /* IntPtr pClient */, uint socket); + public delegate HandleResult OnConnect(IntPtr connId /* IntPtr pClient */); + + /* Server */ + public delegate HandleResult OnPrepareListen(IntPtr soListen); + public delegate HandleResult OnAccept(IntPtr connId, IntPtr pClient); + + /****************************************************/ + /************** HPSocket4C.dll 导出函数 **************/ + + /// + /// 创建 TcpServer 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpServer(IntPtr pListener); + + /// + /// 创建 TcpClient 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpClient(IntPtr pListener); + + /// + /// 创建 TcpAgent 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpAgent(IntPtr pListener); + + /// + /// 创建 TcpPullServer 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPullServer(IntPtr pListener); + + /// + /// 创建 TcpPullClient 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPullClient(IntPtr pListener); + + /// + /// 创建 TcpPullAgent 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPullAgent(IntPtr pListener); + + /// + /// 创建 HP_TcpPackServer 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPackServer(IntPtr pListener); + + /// + /// 创建 HP_TcpPackAgent 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPackAgent(IntPtr pListener); + + /// + /// 创建 HP_TcpPackAgent 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPackClient(IntPtr pListener); + + /// + /// 创建 UdpServer 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_UdpServer(IntPtr pListener); + + /// + /// 创建 UdpAgent 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_UdpAgent(IntPtr pListener); + + /// + /// 创建 UdpClient 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_UdpClient(IntPtr pListener); + + + /// + /// 销毁 TcpServer 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpServer(IntPtr pServer); + + /// + /// 销毁 TcpClient 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpClient(IntPtr pClient); + + /// + /// 销毁 TcpAgent 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpAgent(IntPtr pAgent); + + /// + /// 销毁 TcpPullServer 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPullServer(IntPtr pServer); + + /// + /// 销毁 TcpPullClient 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPullClient(IntPtr pClient); + + /// + /// 销毁 TcpPullAgent 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPullAgent(IntPtr pAgent); + + /// + /// 销毁 HP_TcpPackServer 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPackServer(IntPtr pServer); + + /// + /// 销毁 HP_TcpPackAgent 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPackAgent(IntPtr pAgent); + + /// + /// 销毁 HP_TcpPackClient 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPackClient(IntPtr pClient); + + + /// + /// 销毁 UdpServer 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_UdpServer(IntPtr pServer); + + /// + /// 销毁 UdpAgent 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_UdpAgent(IntPtr pAgent); + + /// + /// 销毁 UdpClient 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_UdpClient(IntPtr pClient); + + + /// + /// 创建 TcpServerListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpServerListener(); + + /// + /// 创建 TcpClientListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpClientListener(); + + /// + /// 创建 TcpAgentListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpAgentListener(); + + /// + /// 创建 TcpPullServerListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPullServerListener(); + + /// + /// 创建 TcpPullClientListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPullClientListener(); + + /// + /// 创建 TcpPullAgentListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_TcpPullAgentListener(); + + /// + /// 创建 UdpServerListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_UdpServerListener(); + + /// + /// 创建 UdpAgentListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_UdpAgentListener(); + + /// + /// 创建 UdpClientListener 对象 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr Create_HP_UdpClientListener(); + + + /// + /// 销毁 TcpServerListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpServerListener(IntPtr pListener); + + /// + /// 销毁 TcpClientListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpClientListener(IntPtr pListener); + + /// + /// 销毁 TcpAgentListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpAgentListener(IntPtr pListener); + + + /// + /// 销毁 TcpPullServerListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPullServerListener(IntPtr pListener); + + /// + /// 销毁 TcpPullClientListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPullClientListener(IntPtr pListener); + + /// + /// 销毁 TcpPullAgentListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_TcpPullAgentListener(IntPtr pListener); + + /// + /// 销毁 UdpServerListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_UdpServerListener(IntPtr pListener); + + /// + /// 销毁 UdpAgentListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_UdpAgentListener(IntPtr pListener); + + /// + /// 销毁 UdpClientListener 对象 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void Destroy_HP_UdpClientListener(IntPtr pListener); + + + /**********************************************************************************/ + /***************************** Server 回调函数设置方法 *****************************/ + + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Server_OnPrepareListen(IntPtr pListener, OnPrepareListen fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Server_OnAccept(IntPtr pListener, OnAccept fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Server_OnSend(IntPtr pListener, OnSend fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Server_OnReceive(IntPtr pListener, OnReceive fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Server_OnPullReceive(IntPtr pListener, OnPullReceive fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Server_OnClose(IntPtr pListener, OnClose fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Server_OnShutdown(IntPtr pListener, OnShutdown fn); + + /**********************************************************************************/ + /***************************** Client 回调函数设置方法 *****************************/ + + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Client_OnPrepareConnect(IntPtr pListener, OnPrepareConnect fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Client_OnConnect(IntPtr pListener, OnConnect fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Client_OnSend(IntPtr pListener, OnSend fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Client_OnReceive(IntPtr pListener, OnReceive fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Client_OnPullReceive(IntPtr pListener, OnPullReceive fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Client_OnClose(IntPtr pListener, OnClose fn); + + /**********************************************************************************/ + /****************************** Agent 回调函数设置方法 *****************************/ + + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Agent_OnPrepareConnect(IntPtr pListener, OnPrepareConnect fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Agent_OnConnect(IntPtr pListener, OnConnect fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Agent_OnSend(IntPtr pListener, OnSend fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Agent_OnReceive(IntPtr pListener, OnReceive fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Agent_OnPullReceive(IntPtr pListener, OnPullReceive fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Agent_OnClose(IntPtr pListener, OnClose fn); + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Set_FN_Agent_OnShutdown(IntPtr pListener, OnShutdown fn); + + /**************************************************************************/ + /***************************** Server 操作方法 *****************************/ + + /// + /// 名称:启动通信组件 + /// 描述:启动服务端通信组件,启动完成后可开始接收客户端连接并收发数据 + /// + /// + /// 监听地址 + /// 监听端口 + /// 失败,可通过 GetLastError() 获取错误代码 + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Unicode)] + public static extern bool HP_Server_Start(IntPtr pServer, String pszBindAddress, ushort usPort); + + /// + /// 关闭服务端通信组件,关闭完成后断开所有客户端连接并释放所有资源 + /// + /// + /// 失败,可通过 GetLastError() 获取错误代码 + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_Stop(IntPtr pServer); + + /// + /// 用户通过该方法向指定客户端发送数据 + /// + /// + /// 连接 ID + /// 发送数据长度 + /// 发送数据长度 + /// + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)] + public static extern bool HP_Server_Send(IntPtr pServer, IntPtr connId, byte[] pBuffer, int length); + + /// + /// 用户通过该方法向指定客户端发送数据 + /// + /// + /// 连接 ID + /// 发送数据长度 + /// 发送数据长度 + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Server_Send(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length); + + /// + /// 用户通过该方法向指定客户端发送数据 + /// + /// + /// + /// + /// + /// 针对pBuffer的偏移 + /// + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)] + public static extern bool HP_Server_SendPart(IntPtr pServer, IntPtr connId, byte[] pBuffer, int length, int iOffset); + + /// + /// 用户通过该方法向指定客户端发送数据 + /// + /// + /// + /// + /// + /// 针对pBuffer的偏移 + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Server_SendPart(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length, int iOffset); + + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度) + /// + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码 + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Server_SendPackets(IntPtr pServer, IntPtr connId, WSABUF[] pBuffers, int iCount); + + + /// + /// 断开与某个客户端的连接 + /// + /// + /// 连接 ID + /// 是否强制断开连接 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_Disconnect(IntPtr pServer, IntPtr connId, bool bForce); + + /// + /// 断开超过指定时长的连接 + /// + /// + /// 时长(毫秒) + /// 是否强制断开连接 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_DisconnectLongConnections(IntPtr pServer, uint dwPeriod, bool bForce); + + /// + /// 断开超过指定时长的静默连接 + /// + /// + /// 时长(毫秒) + /// 是否强制断开连接 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_DisconnectSilenceConnections(IntPtr pServer, uint dwPeriod, bool bForce); + + /******************************************************************************/ + /***************************** Server 属性访问方法 *****************************/ + + /// + /// 设置数据发送策略 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Server_SetSendPolicy(IntPtr pServer, SendPolicy enSendPolicy); + + /// + /// 获取数据发送策略 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern SendPolicy HP_Server_GetSendPolicy(IntPtr pServer); + + /// + /// 设置连接的附加数据 + /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定 + /// + /// + /// 连接 ID + /// + /// 若返回 false 失败则为(无效的连接 ID) + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_SetConnectionExtra(IntPtr pServer, IntPtr connId, IntPtr pExtra); + + /// + /// 获取连接的附加数据 + /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定 + /// + /// + /// 连接 ID + /// 数据指针 + /// 若返回 false 失败则为(无效的连接 ID) + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_GetConnectionExtra(IntPtr pServer, IntPtr connId, ref IntPtr pExtra); + + /// + /// 检查通信组件是否已启动 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_HasStarted(IntPtr pServer); + + /// + /// 查看通信组件当前状态 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern ServiceState HP_Server_GetState(IntPtr pServer); + + /// + /// 获取最近一次失败操作的错误代码 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern SocketError HP_Server_GetLastError(IntPtr pServer); + + /// + /// 获取最近一次失败操作的错误描述 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr HP_Server_GetLastErrorDesc(IntPtr pServer); + + + /// + /// 获取连接中未发出数据的长度 + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_GetPendingDataLength(IntPtr pServer, IntPtr connId, ref int piPending); + + /// + /// 获取客户端连接数 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Server_GetConnectionCount(IntPtr pServer); + + /// + /// 获取所有连接的 CONNID + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_GetAllConnectionIDs(IntPtr pServer, IntPtr[] pIDs, ref uint pdwCount); + + /// + /// 获取某个客户端连接时长(毫秒) + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_GetConnectPeriod(IntPtr pServer, IntPtr connId, ref uint pdwPeriod); + + /// + /// 获取某个连接静默时间(毫秒) + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_GetSilencePeriod(IntPtr pServer, IntPtr connId, ref uint pdwPeriod); + + /// + /// 获取监听 Socket 的地址信息 + /// + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_GetListenAddress(IntPtr pServer, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort); + + /// + /// 获取某个客户端连接的地址信息 + /// + /// + /// + /// + /// 传入传出值,大小最好在222.222.222.222的长度以上 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_GetRemoteAddress(IntPtr pServer, IntPtr connId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort); + + + /// + /// 设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Server_SetFreeSocketObjLockTime(IntPtr pServer, uint dwFreeSocketObjLockTime); + + /// + /// 设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Server_SetFreeSocketObjPool(IntPtr pServer, uint dwFreeSocketObjPool); + + /// + /// 设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Server_SetFreeBufferObjPool(IntPtr pServer, uint dwFreeBufferObjPool); + + /// + /// 设置 Socket 缓存池回收阀值(通常设置为 Socket 缓存池大小的 3 倍) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Server_SetFreeSocketObjHold(IntPtr pServer, uint dwFreeSocketObjHold); + + /// + /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Server_SetFreeBufferObjHold(IntPtr pServer, uint dwFreeBufferObjHold); + + /// + /// 设置工作线程数量(通常设置为 2 * CPU + 2) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Server_SetWorkerThreadCount(IntPtr pServer, uint dwWorkerThreadCount); + + /// + /// 设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Server_SetMarkSilence(IntPtr pServer, bool bMarkSilence); + + /// + /// 获取 Socket 缓存对象锁定时间 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Server_GetFreeSocketObjLockTime(IntPtr pServer); + + /// + /// 获取 Socket 缓存池大小 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Server_GetFreeSocketObjPool(IntPtr pServer); + + /// + /// 获取内存块缓存池大小 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Server_GetFreeBufferObjPool(IntPtr pServer); + + /// + /// 获取 Socket 缓存池回收阀值 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Server_GetFreeSocketObjHold(IntPtr pServer); + + /// + /// 获取内存块缓存池回收阀值 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Server_GetFreeBufferObjHold(IntPtr pServer); + + /// + /// 获取工作线程数量 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Server_GetWorkerThreadCount(IntPtr pServer); + + /// + /// 检测是否标记静默时间 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Server_IsMarkSilence(IntPtr pServer); + + /**********************************************************************************/ + /***************************** TCP Server 操作方法 *****************************/ + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 连接 ID + /// 文件路径 + /// 头部附加数据 + /// 尾部附加数据 + /// TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码 + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Unicode, SetLastError = true)] + public static extern bool HP_TcpServer_SendSmallFile(IntPtr pServer, IntPtr connId, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail); + + /**********************************************************************************/ + /***************************** TCP Server 属性访问方法 *****************************/ + + /// + /// 设置 Accept 预投递数量(根据负载调整设置,Accept 预投递数量越大则支持的并发连接请求越多) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpServer_SetAcceptSocketCount(IntPtr pServer, uint dwAcceptSocketCount); + + /// + /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpServer_SetSocketBufferSize(IntPtr pServer, uint dwSocketBufferSize); + + /// + /// 设置监听 Socket 的等候队列大小(根据并发连接数量调整设置) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpServer_SetSocketListenQueue(IntPtr pServer, uint dwSocketListenQueue); + + /// + /// 设置心跳包间隔(毫秒,0 则不发送心跳包) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpServer_SetKeepAliveTime(IntPtr pServer, uint dwKeepAliveTime); + + /// + /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpServer_SetKeepAliveInterval(IntPtr pServer, uint dwKeepAliveInterval); + + + /// + /// 获取 Accept 预投递数量 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpServer_GetAcceptSocketCount(IntPtr pServer); + + /// + /// 获取通信数据缓冲区大小 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpServer_GetSocketBufferSize(IntPtr pServer); + + /// + /// 获取监听 Socket 的等候队列大小 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpServer_GetSocketListenQueue(IntPtr pServer); + + /// + /// 获取心跳检查次数 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpServer_GetKeepAliveTime(IntPtr pServer); + + /// + /// 获取心跳检查间隔 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpServer_GetKeepAliveInterval(IntPtr pServer); + + + /**********************************************************************************/ + /***************************** UDP Server 属性访问方法 *****************************/ + + /// + /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpServer_SetMaxDatagramSize(IntPtr pServer, uint dwMaxDatagramSize); + + /// + /// 获取数据报文最大长度 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpServer_GetMaxDatagramSize(IntPtr pServer); + + /// + /// 设置 Receive 预投递数量(根据负载调整设置,Receive 预投递数量越大则丢包概率越小) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpServer_SetPostReceiveCount(IntPtr pServer, uint dwPostReceiveCount); + + /// + /// 获取 Receive 预投递数量 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpServer_GetPostReceiveCount(IntPtr pServer); + + /// + /// 设置监测包尝试次数(0 则不发送监测跳包,如果超过最大尝试次数则认为已断线) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpServer_SetDetectAttempts(IntPtr pServer, uint dwMaxDatagramSize); + + /// + /// 设置监测包发送间隔(秒,0 不发送监测包) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpServer_SetDetectInterval(IntPtr pServer, uint dwMaxDatagramSize); + + /// + /// 获取心跳检查次数 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpServer_GetDetectAttempts(IntPtr pServer); + + /// + /// 获取心跳检查间隔 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpServer_GetDetectInterval(IntPtr pServer); + /******************************************************************************/ + /***************************** Client 组件操作方法 *****************************/ + + /// + /// 启动客户端通信组件并连接服务端,启动完成后可开始收发数据 + /// + /// + /// 服务端地址 + /// 服务端端口 + /// 是否采用异步 Connnect + /// 失败,可通过 GetLastError() 获取错误代码 + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Unicode)] + public static extern bool HP_Client_Start(IntPtr pClient, string pszRemoteAddress, ushort usPort, bool bAsyncConnect); + + /// + /// 关闭客户端通信组件,关闭完成后断开与服务端的连接并释放所有资源 + /// + /// + /// 失败,可通过 GetLastError() 获取错误代码 + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Client_Stop(IntPtr pClient); + + /// + /// 用户通过该方法向服务端发送数据 + /// + /// + /// 连接 ID(保留参数,目前该参数并未使用) + /// 发送数据缓冲区 + /// 发送数据长度 + /// 失败,可通过 GetLastError() 获取错误代码 + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)] + public static extern bool HP_Client_Send(IntPtr pClient, byte[] pBuffer, int length); + + /// + /// 用户通过该方法向服务端发送数据 + /// + /// + /// 连接 ID(保留参数,目前该参数并未使用) + /// 发送数据缓冲区 + /// 发送数据长度 + /// 失败,可通过 GetLastError() 获取错误代码 + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Client_Send(IntPtr pClient, IntPtr pBuffer, int length); + + /// + /// 用户通过该方法向服务端发送数据 + /// + /// + /// + /// + /// 针对pBuffer的偏移 + /// + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)] + public static extern bool HP_Client_SendPart(IntPtr pClient, byte[] pBuffer, int length, int iOffset); + + /// + /// 用户通过该方法向服务端发送数据 + /// + /// + /// + /// + /// 针对pBuffer的偏移 + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Client_SendPart(IntPtr pClient, IntPtr pBuffer, int length, int iOffset); + + + /// + /// 发送多组数据 + /// 向服务端发送多组数据 + /// TCP - 顺序发送所有数据包 + /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度) + /// + /// + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码 + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Client_SendPackets(IntPtr pClient, WSABUF[] pBuffers, int iCount); + + + /******************************************************************************/ + /***************************** Client 属性访问方法 *****************************/ + + /// + /// 设置连接的附加数据 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Client_SetExtra(IntPtr pClient, IntPtr pExtra); + + + /// + /// 获取连接的附加数据 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr HP_Client_GetExtra(IntPtr pClient); + + + /// + /// 检查通信组件是否已启动 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Client_HasStarted(IntPtr pClient); + + /// + /// 查看通信组件当前状态 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern ServiceState HP_Client_GetState(IntPtr pClient); + + /// + /// 获取最近一次失败操作的错误代码 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern SocketError HP_Client_GetLastError(IntPtr pClient); + + /// + /// 获取最近一次失败操作的错误描述 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr HP_Client_GetLastErrorDesc(IntPtr pClient); + + /// + /// 获取该组件对象的连接 ID + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr HP_Client_GetConnectionID(IntPtr pClient); + + /// + /// 获取 Client Socket 的地址信息 + /// + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Client_GetLocalAddress(IntPtr pClient, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort); + + /// + /// 获取连接中未发出数据的长度 + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Client_GetPendingDataLength(IntPtr pClient, ref int piPending); + + /// + /// 设置内存块缓存池大小(通常设置为 -> PUSH 模型:5 - 10;PULL 模型:10 - 20 ) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Client_SetFreeBufferPoolSize(IntPtr pClient, uint dwFreeBufferPoolSize); + + /// + /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Client_SetFreeBufferPoolHold(IntPtr pClient, uint dwFreeBufferPoolHold); + + /// + /// 获取内存块缓存池大小 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Client_GetFreeBufferPoolSize(IntPtr pClient); + + /// + /// 获取内存块缓存池回收阀值 + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Client_GetFreeBufferPoolHold(IntPtr pClient); + /**********************************************************************************/ + /***************************** TCP Client 操作方法 *****************************/ + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 文件路径 + /// 头部附加数据 + /// 尾部附加数据 + /// TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码 + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Unicode, SetLastError = true)] + public static extern bool HP_TcpClient_SendSmallFile(IntPtr pClient, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail); + + /**********************************************************************************/ + /***************************** TCP Client 属性访问方法 *****************************/ + + /// + /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为:(N * 1024) - sizeof(TBufferObj)) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpClient_SetSocketBufferSize(IntPtr pClient, uint dwSocketBufferSize); + + /// + /// 设置心跳包间隔(毫秒,0 则不发送心跳包) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpClient_SetKeepAliveTime(IntPtr pClient, uint dwKeepAliveTime); + + /// + /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpClient_SetKeepAliveInterval(IntPtr pClient, uint dwKeepAliveInterval); + + /// + /// 获取通信数据缓冲区大小 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpClient_GetSocketBufferSize(IntPtr pClient); + + /// + /// 获取心跳检查次数 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpClient_GetKeepAliveTime(IntPtr pClient); + + /// + /// 获取心跳检查间隔 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpClient_GetKeepAliveInterval(IntPtr pClient); + + /**********************************************************************************/ + /***************************** UDP Client 属性访问方法 *****************************/ + + /// + /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpClient_SetMaxDatagramSize(IntPtr pClient, uint dwMaxDatagramSize); + + /// + /// 获取数据报文最大长度 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpClient_GetMaxDatagramSize(IntPtr pClient); + + /// + /// 设置监测包尝试次数(0 则不发送监测跳包,如果超过最大尝试次数则认为已断线 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpClient_SetDetectAttempts(IntPtr pClient, uint dwDetectAttempts); + + /// + /// 设置监测包发送间隔(秒,0 不发送监测包) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpClient_SetDetectInterval(IntPtr pClient, uint dwDetectInterval); + + /// + /// 获取心跳检查次数 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpClient_GetDetectAttempts(IntPtr pClient); + + /// + /// 获取心跳检查间隔 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpClient_GetDetectInterval(IntPtr pClient); + + /**************************************************************************/ + /***************************** Agent 操作方法 *****************************/ + + /// + /// 启动通信组件 + /// 启动通信代理组件,启动完成后可开始连接远程服务器 + /// + /// + /// 监听地址 + /// 是否采用异步 Connect + /// 失败,可通过 GetLastError() 获取错误代码 + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Unicode)] + public static extern bool HP_Agent_Start(IntPtr pAgent, String pszBindAddress, bool bAsyncConnect); + + /// + /// 关闭通信组件 + /// 关闭通信组件,关闭完成后断开所有连接并释放所有资源 + /// + /// + /// -- 失败,可通过 GetLastError() 获取错误代码 + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_Stop(IntPtr pAgent); + + /// + /// 连接服务器 + /// 连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() 事件 + /// + /// + /// 服务端地址 + /// 服务端端口 + /// 传出连接 ID + /// 失败,可通过 SYS_GetLastError() 获取 Windows 错误代码 + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Unicode, SetLastError = true)] + public static extern bool HP_Agent_Connect(IntPtr pAgent, String pszBindAddress, ushort usPort, ref IntPtr pconnId); + + /// + /// 发送数据 + /// 用户通过该方法向指定连接发送数据 + /// + /// + /// 连接 ID + /// 发送数据缓冲区 + /// 发送数据长度 + /// + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)] + public static extern bool HP_Agent_Send(IntPtr pAgent, IntPtr connId, byte[] pBuffer, int length); + + /// + /// 发送数据 + /// 用户通过该方法向指定连接发送数据 + /// + /// + /// 连接 ID + /// 发送数据缓冲区 + /// 发送数据长度 + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Agent_Send(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length); + + /// + /// 发送数据 + /// 用户通过该方法向指定连接发送数据 + /// + /// + /// + /// + /// + /// 针对pBuffer的偏移 + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Agent_SendPart(IntPtr pAgent, IntPtr connId, byte[] pBuffer, int length, int iOffset); + + /// + /// 发送数据 + /// 用户通过该方法向指定连接发送数据 + /// + /// + /// + /// + /// + /// 针对pBuffer的偏移 + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Agent_SendPart(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length, int iOffset); + + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度) + /// + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE .失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码 + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern bool HP_Agent_SendPackets(IntPtr pAgent, IntPtr connId, WSABUF[] pBuffers, int iCount); + + /// + /// 断开某个连接 + /// + /// + /// 连接 ID + /// 是否强制断开连接 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_Disconnect(IntPtr pAgent, IntPtr connId, bool bForce); + + /// + /// 断开超过指定时长的连接 + /// + /// + /// 时长(毫秒) + /// 是否强制断开连接 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_DisconnectLongConnections(IntPtr pAgent, uint dwPeriod, bool bForce); + + /// + /// 断开超过指定时长的静默连接 + /// + /// + /// 时长(毫秒) + /// 是否强制断开连接 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_DisconnectSilenceConnections(IntPtr pAgent, uint dwPeriod, bool bForce); + + /******************************************************************************/ + /***************************** Agent 属性访问方法 *****************************/ + + /// + /// 设置数据发送策略 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Agent_SetSendPolicy(IntPtr pAgent, SendPolicy enSendPolicy); + + /// + /// 获取数据发送策略 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern SendPolicy HP_Agent_GetSendPolicy(IntPtr pAgent); + + /// + /// 设置连接的附加数据 + /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定 + /// + /// + /// 连接 ID + /// 数据 + /// FALSE -- 失败(无效的连接 ID) + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_SetConnectionExtra(IntPtr pAgent, IntPtr connId, IntPtr pExtra); + + /// + /// 获取连接的附加数据 + /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定 + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_GetConnectionExtra(IntPtr pAgent, IntPtr connId, ref IntPtr pExtra); + + /// + /// 检查通信组件是否已启动 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_HasStarted(IntPtr pAgent); + + /// + /// 查看通信组件当前状态 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern ServiceState HP_Agent_GetState(IntPtr pAgent); + + /// + /// 获取连接数 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Agent_GetConnectionCount(IntPtr pAgent); + + /// + /// 获取所有连接的 CONNID + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_GetAllConnectionIDs(IntPtr pAgent, IntPtr[] pIDs, ref uint pdwCount); + + /// + /// 获取某个连接时长(毫秒) + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_GetConnectPeriod(IntPtr pAgent, IntPtr connId, ref uint pdwPeriod); + + /// + /// 获取某个连接静默时间(毫秒) + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_GetSilencePeriod(IntPtr pAgent, IntPtr connId, ref uint pdwPeriod); + + /// + /// 获取监听 Socket 的地址信息 + /// + /// + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_GetLocalAddress(IntPtr pAgent, IntPtr connId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort); + + /// + /// 获取某个连接的地址信息 + /// + /// + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_GetRemoteAddress(IntPtr pAgent, IntPtr connId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort); + + /// + /// 获取最近一次失败操作的错误代码 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern SocketError HP_Agent_GetLastError(IntPtr pAgent); + + /// + /// 获取最近一次失败操作的错误描述 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr HP_Agent_GetLastErrorDesc(IntPtr pAgent); + + /// + /// 获取连接中未发出数据的长度 + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_GetPendingDataLength(IntPtr pAgent, IntPtr connId, ref int piPending); + + /// + /// 设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Agent_SetFreeSocketObjLockTime(IntPtr pAgent, uint dwFreeSocketObjLockTime); + + /// + /// 设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Agent_SetFreeSocketObjPool(IntPtr pAgent, uint dwFreeSocketObjPool); + + /// + /// 设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Agent_SetFreeBufferObjPool(IntPtr pAgent, uint dwFreeBufferObjPool); + + /// + /// 设置 Socket 缓存池回收阀值(通常设置为 Socket 缓存池大小的 3 倍) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Agent_SetFreeSocketObjHold(IntPtr pAgent, uint dwFreeSocketObjHold); + + /// + /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Agent_SetFreeBufferObjHold(IntPtr pAgent, uint dwFreeBufferObjHold); + + /// + /// 设置工作线程数量(通常设置为 2 * CPU + 2) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Agent_SetWorkerThreadCount(IntPtr pAgent, uint dwWorkerThreadCount); + + /// + /// 设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_Agent_SetMarkSilence(IntPtr pAgent, bool bMarkSilence); + + /// + /// 获取 Socket 缓存对象锁定时间 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Agent_GetFreeSocketObjLockTime(IntPtr pAgent); + + /// + /// 获取 Socket 缓存池大小 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Agent_GetFreeSocketObjPool(IntPtr pAgent); + + /// + /// 获取内存块缓存池大小 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Agent_GetFreeBufferObjPool(IntPtr pAgent); + + /// + /// 获取 Socket 缓存池回收阀值 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Agent_GetFreeSocketObjHold(IntPtr pAgent); + + /// + /// 获取内存块缓存池回收阀值 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Agent_GetFreeBufferObjHold(IntPtr pAgent); + + /// + /// 获取工作线程数量 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_Agent_GetWorkerThreadCount(IntPtr pAgent); + + /// + /// 检测是否标记静默时间 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_Agent_IsMarkSilence(IntPtr pAgent); + + /******************************************************************************/ + /***************************** TCP Agent 操作方法 *****************************/ + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 连接 ID + /// 文件路径 + /// 头部附加数据 + /// 尾部附加数据 + /// TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码 + [DllImport(SOCKET_DLL_PATH, CharSet = CharSet.Unicode, SetLastError = true)] + public static extern bool HP_TcpAgent_SendSmallFile(IntPtr pAgent, IntPtr connId, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail); + + /**********************************************************************************/ + /***************************** TCP Agent 属性访问方法 *****************************/ + + /// + /// 置是否启用地址重用机制(默认:不启用) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpAgent_SetReuseAddress(IntPtr pAgent, bool bReuseAddress); + + /// + /// 检测是否启用地址重用机制 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern bool HP_TcpAgent_IsReuseAddress(IntPtr pAgent); + + /// + /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpAgent_SetSocketBufferSize(IntPtr pAgent, uint dwSocketBufferSize); + + /// + /// 设置心跳包间隔(毫秒,0 则不发送心跳包) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpAgent_SetKeepAliveTime(IntPtr pAgent, uint dwKeepAliveTime); + + /// + /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpAgent_SetKeepAliveInterval(IntPtr pAgent, uint dwKeepAliveInterval); + + /// + /// 获取通信数据缓冲区大小 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpAgent_GetSocketBufferSize(IntPtr pAgent); + + /// + /// 获取心跳检查次数 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpAgent_GetKeepAliveTime(IntPtr pAgent); + + /// + /// 获取心跳检查间隔 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpAgent_GetKeepAliveInterval(IntPtr pAgent); + + /**********************************************************************************/ + /***************************** UDP Agent 属性访问方法 *****************************/ + + /// + /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpAgent_SetMaxDatagramSize(IntPtr pAgent, uint dwMaxDatagramSize); + + /// + /// 设置监测包尝试次数(0 则不发送监测跳包,如果超过最大尝试次数则认为已断线) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpAgent_SetDetectAttempts(IntPtr pAgent, uint dwDetectAttempts); + + /// + /// 设置监测包发送间隔(秒,0 不发送监测包) + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_UdpAgent_SetDetectInterval(IntPtr pAgent, uint dwDetectInterval); + + /// + /// 获取数据报文最大长度 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpAgent_GetMaxDatagramSize(IntPtr pAgent); + + /// + /// 获取心跳检查次数 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpAgent_GetDetectAttempts(IntPtr pAgent); + + /// + /// 获取心跳检查间隔 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_UdpAgent_GetDetectInterval(IntPtr pAgent); + + /***************************************************************************************/ + /***************************** TCP Pull Server 组件操作方法 *****************************/ + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// 连接 ID + /// 数据抓取缓冲区 + /// 抓取数据长度 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern FetchResult HP_TcpPullServer_Fetch(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length); + + /// + /// 窥探数据(不会移除缓冲区数据) + /// 描述:用户通过该方法从 Socket 组件中窥探数据 + /// + /// + /// 连接 ID + /// 窥探缓冲区 + /// 窥探数据长度 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern FetchResult HP_TcpPullServer_Peek(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length); + + /***************************************************************************************/ + /***************************** TCP Pull Server 属性访问方法 *****************************/ + + /***************************************************************************************/ + /***************************** TCP Pull Client 组件操作方法 *****************************/ + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// 连接 ID + /// 数据抓取缓冲区 + /// 抓取数据长度 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern FetchResult HP_TcpPullClient_Fetch(IntPtr pClient, IntPtr pBuffer, int length); + + /// + /// 名称:窥探数据(不会移除缓冲区数据) + /// 描述:用户通过该方法从 Socket 组件中窥探数据 + /// + /// + /// 连接 ID + /// 数据抓取缓冲区 + /// 抓取数据长度 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern FetchResult HP_TcpPullClient_Peek(IntPtr pClient, IntPtr pBuffer, int length); + + /***************************************************************************************/ + /***************************** TCP Pull Client 属性访问方法 *****************************/ + + /***************************************************************************************/ + /***************************** TCP Pull Agent 组件操作方法 *****************************/ + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// 连接 ID + /// 数据抓取缓冲区 + /// 抓取数据长度 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern FetchResult HP_TcpPullAgent_Fetch(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length); + + /// + /// 名称:窥探数据(不会移除缓冲区数据) + /// 描述:用户通过该方法从 Socket 组件中窥探数据 + /// + /// + /// 连接 ID + /// 数据抓取缓冲区 + /// 抓取数据长度 + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern FetchResult HP_TcpPullAgent_Peek(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length); + + /***************************************************************************************/ + /***************************** TCP Pull Agent 属性访问方法 *****************************/ + + /***************************************************************************************/ + + /***************************************************************************************/ + /***************************** TCP Pack Server 组件操作方法 *****************************/ + + /***************************************************************************************/ + /***************************** TCP Pack Server 属性访问方法 *****************************/ + + /// + /// 设置数据包最大长度(有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000) + /// + /// + /// 有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000 + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpPackServer_SetMaxPackSize(IntPtr pServer, uint dwMaxPackSize); + + /// + /// 设置包头标识(有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0) + /// + /// + /// 有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0 + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpPackServer_SetPackHeaderFlag(IntPtr pServer, ushort usPackHeaderFlag); + + /// + /// 获取数据包最大长度 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpPackServer_GetMaxPackSize(IntPtr pServer); + + /// + /// 获取包头标识 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern ushort HP_TcpPackServer_GetPackHeaderFlag(IntPtr pServer); + /***************************************************************************************/ + /***************************** TCP Pack Agent 组件操作方法 *****************************/ + + /***************************************************************************************/ + /***************************** TCP Pack Agent 属性访问方法 *****************************/ + + /// + /// 设置数据包最大长度(有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000) + /// + /// + /// 有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000 + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpPackAgent_SetMaxPackSize(IntPtr pAgent, uint dwMaxPackSize); + + /// + /// 设置包头标识(有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0) + /// + /// + /// 有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0 + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpPackAgent_SetPackHeaderFlag(IntPtr pAgent, ushort usPackHeaderFlag); + + /// + /// 获取数据包最大长度 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpPackAgent_GetMaxPackSize(IntPtr pAgent); + + /// + /// 获取包头标识 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern ushort HP_TcpPackAgent_GetPackHeaderFlag(IntPtr pAgent); + /***************************************************************************************/ + /***************************** TCP Pack Client 组件操作方法 *****************************/ + + /***************************************************************************************/ + /***************************** TCP Pack Client 属性访问方法 *****************************/ + /// + /// 设置数据包最大长度(有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000) + /// + /// + /// 有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000 + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpPackClient_SetMaxPackSize(IntPtr pClient, uint dwMaxPackSize); + + /// + /// 设置包头标识(有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0) + /// + /// + /// 有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0 + [DllImport(SOCKET_DLL_PATH)] + public static extern void HP_TcpPackClient_SetPackHeaderFlag(IntPtr pClient, ushort usPackHeaderFlag); + + /// + /// 获取数据包最大长度 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern uint HP_TcpPackClient_GetMaxPackSize(IntPtr pClient); + + /// + /// 获取包头标识 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern ushort HP_TcpPackClient_GetPackHeaderFlag(IntPtr pClient); + /***************************************************************************************/ + /*************************************** 其它方法 ***************************************/ + + /// + /// 获取错误描述文本 + /// + /// + /// + [DllImport(SOCKET_DLL_PATH)] + public static extern IntPtr HP_GetSocketErrorDesc(SocketError enCode); + + /// + /// 调用系统的 ::GetLastError() 方法获取系统错误代码 + /// + /// + public static int SYS_GetLastError() + { + return Marshal.GetLastWin32Error(); + } + + /// + /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码 + /// + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern int SYS_WSAGetLastError(); + + /// + /// 调用系统的 setsockopt() + /// + /// + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len); + + /// + /// 调用系统的 getsockopt() + /// + /// + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern int SYS_GetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len); + + /// + /// 调用系统的 ioctlsocket() + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern int SYS_IoctlSocket(IntPtr sock, long cmd, IntPtr arg); + + /// + /// 调用系统的 ::WSAIoctl() + /// + /// + /// + /// + /// + /// + /// + /// + /// + [DllImport(SOCKET_DLL_PATH, SetLastError = true)] + public static extern int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer, + IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned); + + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpAgent.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpAgent.cs new file mode 100644 index 000000000..f28c833d2 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpAgent.cs @@ -0,0 +1,1051 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using HPSocketCS.SDK; +using System.Runtime.InteropServices; +using System.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; + +namespace HPSocketCS +{ + public class TcpAgentEvent + { + public delegate HandleResult OnConnectEventHandler(IntPtr connId /* IntPtr pClient */); + public delegate HandleResult OnSendEventHandler(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnReceiveEventHandler(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnCloseEventHandler(IntPtr connId, SocketOperation enOperation, int errorCode); + public delegate HandleResult OnShutdownEventHandler(); + public delegate HandleResult OnPrepareConnectEventHandler(IntPtr connId /* IntPtr pClient */, uint socket); + } + public class TcpAgent + { + protected IntPtr _pAgent = IntPtr.Zero; + + protected IntPtr pAgent + { + get + { + //if (_pClient == IntPtr.Zero) + //{ + // throw new Exception("pClient == 0"); + //} + + return _pAgent; + } + + set + { + _pAgent = value; + } + } + + + protected IntPtr pListener = IntPtr.Zero; + + /// + /// 连接事件 + /// + public TcpAgentEvent.OnConnectEventHandler OnConnect; + /// + /// 数据发送事件 + /// + public TcpAgentEvent.OnSendEventHandler OnSend; + /// + /// 准备连接事件 + /// + public TcpAgentEvent.OnPrepareConnectEventHandler OnPrepareConnect; + /// + /// 数据到达事件 + /// + public TcpAgentEvent.OnReceiveEventHandler OnReceive; + /// + /// 连接关闭事件 + /// + public TcpAgentEvent.OnCloseEventHandler OnClose; + /// + /// 服务关闭事件 + /// + public TcpAgentEvent.OnShutdownEventHandler OnShutdown; + + + protected bool IsCreate = false; + + public TcpAgent() + { + CreateListener(); + } + + ~TcpAgent() + { + Destroy(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected virtual bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pAgent != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_TcpAgentListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pAgent = HPSocketSdk.Create_HP_TcpAgent(pListener); + if (pAgent == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 终止服务并释放资源 + /// + public virtual void Destroy() + { + Stop(); + + if (pAgent != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpAgent(pAgent); + pAgent = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpAgentListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + /// + /// 启动通讯组件 + /// 启动完成后可开始连接远程服务器 + /// + /// 绑定地址 + /// 是否异步 + /// + public bool Start(string address, bool async = false) + { + if (string.IsNullOrEmpty(address) == true) + { + throw new Exception("address is null"); + } + + if (IsStarted == true) + { + return false; + } + + SetCallback(); + + return HPSocketSdk.HP_Agent_Start(pAgent, address, async); + } + + /// + /// 停止通讯组件 + /// + /// + public bool Stop() + { + if (IsStarted == false) + { + return false; + } + return HPSocketSdk.HP_Agent_Stop(pAgent); + } + + + /// + /// 连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() 事件 + /// + /// + /// + /// + /// + public bool Connect(string address, ushort port, ref IntPtr connId) + { + return HPSocketSdk.HP_Agent_Connect(pAgent, address, port, ref connId); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, byte[] bytes, int size) + { + return HPSocketSdk.HP_Agent_Send(pAgent, connId, bytes, size); + } + + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, T obj) + { + byte[] buffer = StructureToByte(obj); + return Send(connId, buffer, buffer.Length); + } + + /// + /// 序列化对象后发送数据,序列化对象所属类必须标记[Serializable] + /// + /// + /// + /// + /// + public bool SendBySerializable(IntPtr connId, object obj) + { + byte[] buffer = ObjectToBytes(obj); + return Send(connId, buffer, buffer.Length); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, IntPtr bufferPtr, int size) + { + return HPSocketSdk.HP_Agent_Send(pAgent, connId, bufferPtr, size); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bytes的偏移 + /// 发多大 + /// + public bool Send(IntPtr connId, byte[] bytes, int offset, int size) + { + return HPSocketSdk.HP_Agent_SendPart(pAgent, connId, bytes, size, offset); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bufferPtr的偏移 + /// 发多大 + /// + public bool Send(IntPtr connId, IntPtr bufferPtr, int offset, int size) + { + return HPSocketSdk.HP_Agent_SendPart(pAgent, connId, bufferPtr, size, offset); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(IntPtr connId, WSABUF[] pBuffers, int count) + { + return HPSocketSdk.HP_Agent_SendPackets(pAgent, connId, pBuffers, count); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(IntPtr connId, T[] objects) + { + bool ret = false; + + WSABUF[] buffer = new WSABUF[objects.Length]; + IntPtr[] ptrs = new IntPtr[buffer.Length]; + try + { + + for (int i = 0; i < objects.Length; i++) + { + buffer[i].Length = Marshal.SizeOf(typeof(T)); + + ptrs[i] = Marshal.AllocHGlobal(buffer[i].Length); + Marshal.StructureToPtr(objects[i], ptrs[i], true); + + buffer[i].Buffer = ptrs[i]; + } + ret = SendPackets(connId, buffer, buffer.Length); + } + catch (Exception ex) + { + throw ex; + } + finally + { + for (int i = 0; i < ptrs.Length; i++) + { + if (ptrs[i] != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptrs[i]); + } + } + } + + return ret; + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 文件路径 + /// 头部附加数据 + /// 尾部附加数据 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(IntPtr connId, string filePath, ref WSABUF head, ref WSABUF tail) + { + return HPSocketSdk.HP_TcpAgent_SendSmallFile(pAgent, connId, filePath, ref head, ref tail); + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 文件路径 + /// 头部附加数据,可以为null + /// 尾部附加数据,可以为null + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(IntPtr connId, string filePath, byte[] head, byte[] tail) + { + IntPtr pHead = IntPtr.Zero; + IntPtr pTail = IntPtr.Zero; + WSABUF wsaHead = new WSABUF() { Length = 0, Buffer = pHead }; + WSABUF wsatail = new WSABUF() { Length = 0, Buffer = pTail }; + if (head != null) + { + wsaHead.Length = head.Length; + wsaHead.Buffer = Marshal.UnsafeAddrOfPinnedArrayElement(head, 0); + } + + if (tail != null) + { + wsaHead.Length = tail.Length; + wsaHead.Buffer = Marshal.UnsafeAddrOfPinnedArrayElement(tail, 0); + } + + return SendSmallFile(connId, filePath, ref wsaHead, ref wsatail); + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 文件路径 + /// 头部附加数据,可以为null + /// 尾部附加数据,可以为null + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(IntPtr connId, string filePath, T1 head, T2 tail) + { + + byte[] headBuffer = null; + if (head != null) + { + headBuffer = StructureToByte(head); + } + + byte[] tailBuffer = null; + if (tail != null) + { + StructureToByte(head); + } + return SendSmallFile(connId, filePath, headBuffer, tailBuffer); + } + + /// + /// 断开某个连接 + /// + /// + /// 强制 + /// + public bool Disconnect(IntPtr connId, bool force = true) + { + return HPSocketSdk.HP_Agent_Disconnect(pAgent, connId, force); + } + + /// + /// 断开超过指定时间的连接 + /// + /// 毫秒 + /// 强制 + /// + public bool DisconnectLongConnections(uint period, bool force = true) + { + return HPSocketSdk.HP_Agent_DisconnectLongConnections(pAgent, period, force); + } + + /// + /// 断开超过指定时长的静默连接 + /// + /// 毫秒 + /// 强制 + /// + public bool DisconnectSilenceConnections(uint period, bool force = true) + { + return HPSocketSdk.HP_Agent_DisconnectSilenceConnections(pAgent, period, force); + } + + /// + /// 设置连接的附加数据 + /// + /// + /// + /// + public bool SetConnectionExtra(IntPtr connId, object obj) + { + + IntPtr ptr = IntPtr.Zero; + // 释放附加数据 + if (HPSocketSdk.HP_Agent_GetConnectionExtra(pAgent, connId, ref ptr) && ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptr); + ptr = IntPtr.Zero; + } + + if (obj != null) + { + // 设置附加数据 + ptr = Marshal.AllocHGlobal(Marshal.SizeOf(obj)); + Marshal.StructureToPtr(obj, ptr, false); + } + return HPSocketSdk.HP_Agent_SetConnectionExtra(pAgent, connId, ptr); + } + + /// + /// 获取附加数据 + /// 如设置的是个结构体/类对象,可以用 Type objA = (Type)Marshal.PtrToStructure(ptr, typeof(Type)) 获取 + /// 其中Type是结构体/类名,ptr是该方法的传出值,在该方法返回为true的时候可用 + /// + /// + /// + /// + public bool GetConnectionExtra(IntPtr connId, ref IntPtr ptr) + { + return HPSocketSdk.HP_Agent_GetConnectionExtra(pAgent, connId, ref ptr) && ptr != IntPtr.Zero; + } + + /// + /// 获取错误码 + /// + public SocketError ErrorCode + { + get + { + return HPSocketSdk.HP_Agent_GetLastError(pAgent); + } + } + + /// + /// 获取错误信息 + /// + public string ErrorMessage + { + get + { + IntPtr ptr = HPSocketSdk.HP_Agent_GetLastErrorDesc(pAgent); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + } + + + /// + /// 获取连接中未发出数据的长度 + /// + /// + /// + /// + public bool GetPendingDataLength(IntPtr connId, ref int length) + { + return HPSocketSdk.HP_Agent_GetPendingDataLength(pAgent, connId, ref length); + } + + // 是否启动 + public bool IsStarted + { + get + { + if (pAgent == IntPtr.Zero) + { + return false; + } + return HPSocketSdk.HP_Agent_HasStarted(pAgent); + } + } + + /// + /// 状态 + /// + public ServiceState State + { + get + { + return HPSocketSdk.HP_Agent_GetState(pAgent); + } + } + + public uint ConnectionCount + { + get + { + return HPSocketSdk.HP_Agent_GetConnectionCount(pAgent); + } + } + + /// + /// 获取所有连接,未获取到连接返回null + /// + /// + public IntPtr[] GetAllConnectionIDs() + { + IntPtr[] arr = null; + do + { + uint count = ConnectionCount; + if (count == 0) + { + break; + } + arr = new IntPtr[count]; + if (HPSocketSdk.HP_Agent_GetAllConnectionIDs(pAgent, arr, ref count)) + { + if (arr.Length > count) + { + IntPtr[] newArr = new IntPtr[count]; + Array.Copy(arr, newArr, count); + arr = newArr; + } + break; + } + } while (true); + + return arr; + } + + /// + /// 获取监听socket的地址信息 + /// + /// + /// + /// + public bool GetLocalAddress(IntPtr connId, ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Agent_GetLocalAddress(pAgent, connId, sb, ref ipLength, ref port); + if (ret == true) + { + ip = sb.ToString(); + } + return ret; + } + + /// + /// 获取该组件对象的连接Id + /// + /// + public bool GetRemoteAddress(IntPtr connId, ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Agent_GetRemoteAddress(pAgent, connId, sb, ref ipLength, ref port); + if (ret == true) + { + ip = sb.ToString(); + } + return ret; + } + + /// + /// 获取指定连接的连接时长(毫秒) + /// + /// + /// + /// + public bool GetConnectPeriod(IntPtr connId, ref uint period) + { + return HPSocketSdk.HP_Agent_GetConnectPeriod(pAgent, connId, ref period); + } + + /// + /// 获取某个连接静默时间(毫秒) + /// + /// + /// + /// + public bool GetSilencePeriod(IntPtr connId, ref uint period) + { + return HPSocketSdk.HP_Agent_GetSilencePeriod(pAgent, connId, ref period); + } + + /////////////////////////////////////////////////////////////////////////////////////// + + /// + /// 获取或设置是否启用地址重用机制(默认:不启用) + /// + public bool IsReuseAddress + { + get + { + return HPSocketSdk.HP_TcpAgent_IsReuseAddress(pAgent); + } + set + { + HPSocketSdk.HP_TcpAgent_SetReuseAddress(pAgent, value); + } + } + + + /// + /// 读取或设置工作线程数量(通常设置为 2 * CPU + 2) + /// + public uint WorkerThreadCount + { + get + { + return HPSocketSdk.HP_Agent_GetWorkerThreadCount(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetWorkerThreadCount(pAgent, value); + } + } + + /// + /// 读取或设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数) + /// + public uint SocketBufferSize + { + get + { + return HPSocketSdk.HP_TcpAgent_GetSocketBufferSize(pAgent); + } + set + { + HPSocketSdk.HP_TcpAgent_SetSocketBufferSize(pAgent, value); + } + } + + /// + /// 读取或设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用) + /// + public uint FreeSocketObjLockTime + { + get + { + return HPSocketSdk.HP_Agent_GetFreeSocketObjLockTime(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeSocketObjLockTime(pAgent, value); + } + } + + /// + /// 读取或设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2) + /// + public uint FreeSocketObjPool + { + get + { + return HPSocketSdk.HP_Agent_GetFreeSocketObjPool(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeSocketObjPool(pAgent, value); + } + } + + /// + /// 读取或设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍) + /// + public uint FreeBufferObjPool + { + get + { + return HPSocketSdk.HP_Agent_GetFreeBufferObjPool(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeBufferObjPool(pAgent, value); + } + } + + /// + /// 读取或设置 Socket 缓存池回收阀值(通常设置为 Socket 缓存池大小的 3 倍) + /// + public uint FreeSocketObjHold + { + get + { + return HPSocketSdk.HP_Agent_GetFreeSocketObjHold(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeSocketObjHold(pAgent, value); + } + } + + /// + /// 读取或设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + public uint FreeBufferObjHold + { + get + { + return HPSocketSdk.HP_Agent_GetFreeBufferObjHold(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeBufferObjHold(pAgent, value); + } + } + + /// + /// 读取或设置心跳包间隔(毫秒,0 则不发送心跳包)) + /// + public uint KeepAliveTime + { + get + { + return HPSocketSdk.HP_TcpAgent_GetKeepAliveTime(pAgent); + } + set + { + HPSocketSdk.HP_TcpAgent_SetKeepAliveTime(pAgent, value); + } + } + + /// + /// 读取或设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线) + /// + public uint KeepAliveInterval + { + get + { + return HPSocketSdk.HP_TcpAgent_GetKeepAliveInterval(pAgent); + } + set + { + HPSocketSdk.HP_TcpAgent_SetKeepAliveInterval(pAgent, value); + } + } + + /// + /// 读取或设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE) + /// + public bool IsMarkSilence + { + get + { + return HPSocketSdk.HP_Agent_IsMarkSilence(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetMarkSilence(pAgent, value); + } + } + + /// + /// 读取或设置数据发送策略 + /// + public SendPolicy SendPolicy + { + get + { + return HPSocketSdk.HP_Agent_GetSendPolicy(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetSendPolicy(pAgent, value); + } + } + + /// + /// 根据错误码返回错误信息 + /// + /// + /// + public string GetSocketErrorDesc(SocketError code) + { + IntPtr ptr = HPSocketSdk.HP_GetSocketErrorDesc(code); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + + /////////////////////////////////////////////////////////////////////////////////////// + HPSocketCS.SDK.HPSocketSdk.OnPrepareConnect _OnPrepareConnect = null; + HPSocketCS.SDK.HPSocketSdk.OnConnect _OnConnect = null; + HPSocketCS.SDK.HPSocketSdk.OnReceive _OnReceive = null; + HPSocketCS.SDK.HPSocketSdk.OnSend _OnSend = null; + HPSocketCS.SDK.HPSocketSdk.OnClose _OnClose = null; + HPSocketCS.SDK.HPSocketSdk.OnShutdown _OnShutdown = null; + + /// + /// 设置回调函数 + /// + protected virtual void SetCallback() + { + _OnPrepareConnect = new HPSocketSdk.OnPrepareConnect(SDK_OnPrepareConnect); + _OnConnect = new HPSocketSdk.OnConnect(SDK_OnConnect); + _OnSend = new HPSocketSdk.OnSend(SDK_OnSend); + _OnReceive = new HPSocketSdk.OnReceive(SDK_OnReceive); + _OnClose = new HPSocketSdk.OnClose(SDK_OnClose); + _OnShutdown = new HPSocketSdk.OnShutdown(SDK_OnShutdown); + + // 设置 Socket 监听器回调函数 + HPSocketSdk.HP_Set_FN_Agent_OnPrepareConnect(pListener, _OnPrepareConnect); + HPSocketSdk.HP_Set_FN_Agent_OnConnect(pListener, _OnConnect); + HPSocketSdk.HP_Set_FN_Server_OnSend(pListener, _OnSend); + HPSocketSdk.HP_Set_FN_Server_OnReceive(pListener, _OnReceive); + HPSocketSdk.HP_Set_FN_Server_OnClose(pListener, _OnClose); + HPSocketSdk.HP_Set_FN_Agent_OnShutdown(pListener, _OnShutdown); + + } + + protected virtual HandleResult SDK_OnPrepareConnect(IntPtr connId, uint socket) + { + if (OnPrepareConnect != null) + { + return OnPrepareConnect(connId, socket); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnConnect(IntPtr connId) + { + if (OnConnect != null) + { + return OnConnect(connId); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnSend(IntPtr connId, IntPtr pData, int length) + { + if (OnSend != null) + { + return OnSend(connId, pData, length); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnReceive(IntPtr connId, IntPtr pData, int length) + { + if (OnReceive != null) + { + return OnReceive(connId, pData, length); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if (OnClose != null) + { + return OnClose(connId, enOperation, errorCode); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnShutdown() + { + if (OnShutdown != null) + { + return OnShutdown(); + } + return HandleResult.Ignore; + } + + + ///////////////////////////////////////////////////////////////////////// + + /// + /// 获取系统返回的错误码 + /// + /// + public int SYSGetLastError() + { + return HPSocketSdk.SYS_GetLastError(); + } + + /// + /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码 + /// + /// + public int SYSWSAGetLastError() + { + return HPSocketSdk.SYS_WSAGetLastError(); + } + + /// + /// 调用系统的 setsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len) + { + return HPSocketSdk.SYS_SetSocketOption(sock, level, name, val, len); + } + + /// + /// 调用系统的 getsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYSGetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len) + { + return HPSocketSdk.SYS_GetSocketOption(sock, level, name, val, ref len); + } + /// + /// 调用系统的 ioctlsocket() + /// + /// + /// + /// + /// + /// + public int SYSIoctlSocket(IntPtr sock, long cmd, IntPtr arg) + { + return HPSocketSdk.SYS_IoctlSocket(sock, cmd, arg); + } + + /// + /// 调用系统的 ::WSAIoctl() + /// + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer, + IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned) + { + return HPSocketSdk.SYS_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, + lpvOutBuffer, cbOutBuffer, lpcbBytesReturned); + } + + /// + /// 由结构体转换为byte数组 + /// + public byte[] StructureToByte(T structure) + { + int size = Marshal.SizeOf(typeof(T)); + byte[] buffer = new byte[size]; + IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(structure, bufferIntPtr, true); + Marshal.Copy(bufferIntPtr, buffer, 0, size); + } + finally + { + Marshal.FreeHGlobal(bufferIntPtr); + } + return buffer; + } + + /// + /// 由byte数组转换为结构体 + /// + public T ByteToStructure(byte[] dataBuffer) + { + object structure = null; + int size = Marshal.SizeOf(typeof(T)); + IntPtr allocIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.Copy(dataBuffer, 0, allocIntPtr, size); + structure = Marshal.PtrToStructure(allocIntPtr, typeof(T)); + } + finally + { + Marshal.FreeHGlobal(allocIntPtr); + } + return (T)structure; + } + + /// + /// 对象序列化成byte[] + /// + /// + /// + public byte[] ObjectToBytes(object obj) + { + using (MemoryStream ms = new MemoryStream()) + { + IFormatter formatter = new BinaryFormatter(); + formatter.Serialize(ms, obj); + return ms.GetBuffer(); + } + } + + /// + /// byte[]序列化成对象 + /// + /// + /// + public object BytesToObject(byte[] bytes) + { + using (MemoryStream ms = new MemoryStream(bytes)) + { + IFormatter formatter = new BinaryFormatter(); + return formatter.Deserialize(ms); + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpClient.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpClient.cs new file mode 100644 index 000000000..2842729e7 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpClient.cs @@ -0,0 +1,811 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; +using HPSocketCS.SDK; +using System.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; + +namespace HPSocketCS +{ + public class TcpClientEvent + { + public delegate HandleResult OnPrepareConnectEventHandler(TcpClient sender, uint socket); + public delegate HandleResult OnConnectEventHandler(TcpClient sender); + public delegate HandleResult OnSendEventHandler(TcpClient sender, IntPtr pData, int length); + public delegate HandleResult OnReceiveEventHandler(TcpClient sender, IntPtr pData, int length); + public delegate HandleResult OnCloseEventHandler(TcpClient sender, SocketOperation enOperation, int errorCode); + } + + public class TcpClient + { + protected IntPtr _pClient = IntPtr.Zero; + protected IntPtr pClient + { + get + { + return _pClient; + } + + set + { + _pClient = value; + } + } + + protected IntPtr pListener = IntPtr.Zero; + + protected bool IsCreate = false; + + /****************************************************/ + /// + /// 准备连接了事件 + /// + public event TcpClientEvent.OnPrepareConnectEventHandler OnPrepareConnect; + /// + /// 连接事件 + /// + public event TcpClientEvent.OnConnectEventHandler OnConnect; + /// + /// 数据发送事件 + /// + public event TcpClientEvent.OnSendEventHandler OnSend; + /// + /// 数据到达事件 + /// + public event TcpClientEvent.OnReceiveEventHandler OnReceive; + /// + /// 连接关闭事件 + /// + public event TcpClientEvent.OnCloseEventHandler OnClose; + + public TcpClient() + { + CreateListener(); + } + + ~TcpClient() + { + Destroy(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected virtual bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pClient != IntPtr.Zero) + { + return false; + } + + + pListener = HPSocketSdk.Create_HP_TcpClientListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pClient = HPSocketSdk.Create_HP_TcpClient(pListener); + if (pClient == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 终止服务并释放资源 + /// + public virtual void Destroy() + { + Stop(); + + if (pClient != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpClient(pClient); + pClient = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpClientListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + /// + /// 启动通讯组件并连接到服务器 + /// + /// + /// + /// 是否异步 + /// + public bool Connetion(string address, ushort port, bool async = false) + { + if (string.IsNullOrEmpty(address) == true) + { + throw new Exception("address is null"); + } + else if (port == 0) + { + throw new Exception("port is zero"); + } + + if (IsStarted == true) + { + return false; + } + + this.SetCallback(); + + return HPSocketSdk.HP_Client_Start(pClient, address, port, async); + } + + /// + /// 停止通讯组件 + /// + /// + public bool Stop() + { + if (IsStarted == false) + { + return false; + } + return HPSocketSdk.HP_Client_Stop(pClient); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(byte[] bytes, int size) + { + return HPSocketSdk.HP_Client_Send(pClient, bytes, size); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr bufferPtr, int size) + { + return HPSocketSdk.HP_Client_Send(pClient, bufferPtr, size); + } + + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(T obj) + { + byte[] buffer = StructureToByte(obj); + return Send(buffer, buffer.Length); + } + + /// + /// 序列化对象后发送数据,序列化对象所属类必须标记[Serializable] + /// + /// + /// + /// + /// + public bool SendBySerializable(object obj) + { + byte[] buffer = ObjectToBytes(obj); + return Send(buffer, buffer.Length); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bytes的偏移 + /// 发多大 + /// + public bool Send(byte[] bytes, int offset, int size) + { + return HPSocketSdk.HP_Client_SendPart(pClient, bytes, size, offset); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bufferPtr的偏移 + /// 发多大 + /// + public bool Send(IntPtr bufferPtr, int offset, int size) + { + return HPSocketSdk.HP_Client_SendPart(pClient, bufferPtr, size, offset); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(WSABUF[] buffers, int count) + { + return HPSocketSdk.HP_Client_SendPackets(pClient, buffers, count); + } + + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(T[] objects) + { + bool ret = false; + + WSABUF[] buffer = new WSABUF[objects.Length]; + IntPtr[] ptrs = new IntPtr[buffer.Length]; + try + { + + for (int i = 0; i < objects.Length; i++) + { + buffer[i].Length = Marshal.SizeOf(typeof(T)); + + ptrs[i] = Marshal.AllocHGlobal(buffer[i].Length); + Marshal.StructureToPtr(objects[i], ptrs[i], true); + + buffer[i].Buffer = ptrs[i]; + } + ret = SendPackets(buffer, buffer.Length); + } + catch (Exception ex) + { + throw ex; + } + finally + { + for (int i = 0; i < ptrs.Length; i++) + { + if (ptrs[i] != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptrs[i]); + } + } + } + + return ret; + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// 文件路径 + /// 头部附加数据 + /// 尾部附加数据 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(string filePath, ref WSABUF head, ref WSABUF tail) + { + return HPSocketSdk.HP_TcpClient_SendSmallFile(pClient, filePath, ref head, ref tail); + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// 文件路径 + /// 头部附加数据,可以为null + /// 尾部附加数据,可以为null + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(string filePath, byte[] head, byte[] tail) + { + IntPtr pHead = IntPtr.Zero; + IntPtr pTail = IntPtr.Zero; + WSABUF wsaHead = new WSABUF() { Length = 0, Buffer = pHead }; + WSABUF wsatail = new WSABUF() { Length = 0, Buffer = pTail }; + if (head != null) + { + wsaHead.Length = head.Length; + wsaHead.Buffer = Marshal.UnsafeAddrOfPinnedArrayElement(head, 0); + } + + if (tail != null) + { + wsaHead.Length = tail.Length; + wsaHead.Buffer = Marshal.UnsafeAddrOfPinnedArrayElement(tail, 0); + } + + return SendSmallFile(filePath, ref wsaHead, ref wsatail); + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// 文件路径 + /// 头部附加数据,可以为null + /// 尾部附加数据,可以为null + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(string filePath, T1 head, T2 tail) + { + + byte[] headBuffer = null; + if (head != null) + { + headBuffer = StructureToByte(head); + } + + byte[] tailBuffer = null; + if (tail != null) + { + StructureToByte(head); + } + return SendSmallFile(filePath, headBuffer, tailBuffer); + } + + /// + /// 获取错误码 + /// + public SocketError ErrorCode + { + get + { + return HPSocketSdk.HP_Client_GetLastError(pClient); + } + } + + /// + /// 获取错误信息 + /// + public string ErrorMessage + { + get + { + IntPtr ptr = HPSocketSdk.HP_Client_GetLastErrorDesc(pClient); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + } + + /// + /// + /// + /// + /// + public bool GetPendingDataLength(ref int length) + { + return HPSocketSdk.HP_Client_GetPendingDataLength(pClient, ref length); + } + + + /// + /// 设置连接的附加数据 + /// + /// + /// 如果为null,则为释放设置的数据 + /// + public void SetExtra(object obj) + { + // 释放附加数据 + IntPtr ptr = GetExtra(); + if (ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptr); + ptr = IntPtr.Zero; + } + + if (obj != null) + { + // 设置附加数据 + ptr = Marshal.AllocHGlobal(Marshal.SizeOf(obj)); + Marshal.StructureToPtr(obj, ptr, false); + } + HPSocketSdk.HP_Client_SetExtra(pClient, ptr); + } + + /// + /// 获取附加数据 + /// 如设置的是个结构体/类对象,可以用 Type objA = (Type)Marshal.PtrToStructure(ptr, typeof(Type)) 获取 + /// 其中Type是结构体/类名,ptr是该方法的传出值,在该方法返回为true的时候可用 + /// + /// + /// + /// + public IntPtr GetExtra() + { + return HPSocketSdk.HP_Client_GetExtra(pClient); + } + + /// + /// 获取监听socket的地址信息 + /// + /// + /// + /// + /// + public bool GetListenAddress(ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Client_GetLocalAddress(pClient, sb, ref ipLength, ref port); + if (ret == true) + { + ip = sb.ToString(); + } + return ret; + } + + /// + /// 是否启动 + /// + public bool IsStarted + { + get + { + if (pClient == IntPtr.Zero) + { + return false; + } + return HPSocketSdk.HP_Client_HasStarted(pClient); + } + } + + /// + /// 状态 + /// + public ServiceState State + { + get + { + return HPSocketSdk.HP_Client_GetState(pClient); + } + + } + + /// + /// 获取该组件对象的连接Id + /// + public IntPtr ConnectionId + { + get + { + return HPSocketSdk.HP_Client_GetConnectionID(pClient); + } + + } + /////////////////////////////////////////////////////////////////////////////////////// + + /// + /// 读取或设置内存块缓存池大小(通常设置为 -> PUSH 模型:5 - 10;PULL 模型:10 - 20 ) + /// + public uint FreeBufferPoolSize + { + get + { + return HPSocketSdk.HP_Client_GetFreeBufferPoolSize(pClient); + } + set + { + HPSocketSdk.HP_Client_SetFreeBufferPoolSize(pClient, value); + } + } + + /// + /// 读取或设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + public uint FreeBufferPoolHold + { + get + { + return HPSocketSdk.HP_Client_GetFreeBufferPoolHold(pClient); + } + set + { + HPSocketSdk.HP_Client_SetFreeBufferPoolHold(pClient, value); + } + } + + /////////////////////////////////////////////////////////////////////////////////////// + /// + /// 读取或设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为:(N * 1024) - sizeof(TBufferObj)) + /// + public uint SocketBufferSize + { + get + { + return HPSocketSdk.HP_TcpClient_GetSocketBufferSize(pClient); + } + set + { + HPSocketSdk.HP_TcpClient_SetSocketBufferSize(pClient, value); + } + } + + /// + /// 读取或设置心跳包间隔(毫秒,0 则不发送心跳包) + /// + public uint KeepAliveTime + { + get + { + return HPSocketSdk.HP_TcpClient_GetKeepAliveTime(pClient); + } + set + { + HPSocketSdk.HP_TcpClient_SetKeepAliveTime(pClient, value); + } + } + + /// + /// 读取或设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线) + /// + public uint KeepAliveInterval + { + get + { + return HPSocketSdk.HP_TcpClient_GetKeepAliveInterval(pClient); + } + set + { + HPSocketSdk.HP_TcpClient_SetKeepAliveInterval(pClient, value); + } + } + + + /// + /// 根据错误码返回错误信息 + /// + /// + /// + public string GetSocketErrorDesc(SocketError code) + { + IntPtr ptr = HPSocketSdk.HP_GetSocketErrorDesc(code); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + + /////////////////////////////////////////////////////////////////////////////////////// + HPSocketCS.SDK.HPSocketSdk.OnPrepareConnect _OnPrepareConnect = null; + HPSocketCS.SDK.HPSocketSdk.OnConnect _OnConnect = null; + HPSocketCS.SDK.HPSocketSdk.OnReceive _OnReceive = null; + HPSocketCS.SDK.HPSocketSdk.OnSend _OnSend = null; + HPSocketCS.SDK.HPSocketSdk.OnClose _OnClose = null; + /// + /// 设置回调函数 + /// + protected virtual void SetCallback() + { + // 设置 Socket 监听器回调函数 + _OnPrepareConnect = new HPSocketSdk.OnPrepareConnect(SDK_OnPrepareConnect); + _OnConnect = new HPSocketSdk.OnConnect(SDK_OnConnect); + _OnSend = new HPSocketSdk.OnSend(SDK_OnSend); + _OnReceive = new HPSocketSdk.OnReceive(SDK_OnReceive); + _OnClose = new HPSocketSdk.OnClose(SDK_OnClose); + + HPSocketSdk.HP_Set_FN_Client_OnPrepareConnect(pListener, _OnPrepareConnect); + HPSocketSdk.HP_Set_FN_Client_OnConnect(pListener, _OnConnect); + HPSocketSdk.HP_Set_FN_Client_OnSend(pListener, _OnSend); + HPSocketSdk.HP_Set_FN_Client_OnReceive(pListener, _OnReceive); + HPSocketSdk.HP_Set_FN_Client_OnClose(pListener, _OnClose); + } + + protected HandleResult SDK_OnPrepareConnect(IntPtr pClient, uint socket) + { + if (OnPrepareConnect != null) + { + return OnPrepareConnect(this, socket); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnConnect(IntPtr pClient) + { + if (OnConnect != null) + { + return OnConnect(this); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnSend(IntPtr pClient, IntPtr pData, int length) + { + if (OnSend != null) + { + return OnSend(this, pData, length); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnReceive(IntPtr pClient, IntPtr pData, int length) + { + if (OnReceive != null) + { + return OnReceive(this, pData, length); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnClose(IntPtr pClient, SocketOperation enOperation, int errorCode) + { + if (OnClose != null) + { + return OnClose(this, enOperation, errorCode); + } + return HandleResult.Ignore; + } + + /////////////////////////////////////////////////////////////////////////// + + /// + /// 获取系统返回的错误码 + /// + public int SYSGetLastError() + { + return HPSocketSdk.SYS_GetLastError(); + } + + /// + /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码 + /// + public int SYSWSAGetLastError() + { + return HPSocketSdk.SYS_WSAGetLastError(); + } + + /// + /// 调用系统的 setsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len) + { + return HPSocketSdk.SYS_SetSocketOption(sock, level, name, val, len); + } + + /// + /// 调用系统的 getsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYSGetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len) + { + return HPSocketSdk.SYS_GetSocketOption(sock, level, name, val, ref len); + } + /// + /// 调用系统的 ioctlsocket() + /// + /// + /// + /// + /// + /// + public int SYSIoctlSocket(IntPtr sock, long cmd, IntPtr arg) + { + return HPSocketSdk.SYS_IoctlSocket(sock, cmd, arg); + } + + /// + /// 调用系统的 ::WSAIoctl() + /// + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer, + IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned) + { + return HPSocketSdk.SYS_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, + lpvOutBuffer, cbOutBuffer, lpcbBytesReturned); + } + + /// + /// 由结构体转换为byte数组 + /// + public byte[] StructureToByte(T structure) + { + int size = Marshal.SizeOf(typeof(T)); + byte[] buffer = new byte[size]; + IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(structure, bufferIntPtr, true); + Marshal.Copy(bufferIntPtr, buffer, 0, size); + } + finally + { + Marshal.FreeHGlobal(bufferIntPtr); + } + return buffer; + } + + /// + /// 由byte数组转换为结构体 + /// + public T ByteToStructure(byte[] dataBuffer) + { + object structure = null; + int size = Marshal.SizeOf(typeof(T)); + IntPtr allocIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.Copy(dataBuffer, 0, allocIntPtr, size); + structure = Marshal.PtrToStructure(allocIntPtr, typeof(T)); + } + finally + { + Marshal.FreeHGlobal(allocIntPtr); + } + return (T)structure; + } + + /// + /// 对象序列化成byte[] + /// + /// + /// + public byte[] ObjectToBytes(object obj) + { + using (MemoryStream ms = new MemoryStream()) + { + IFormatter formatter = new BinaryFormatter(); + formatter.Serialize(ms, obj); + return ms.GetBuffer(); + } + } + + /// + /// byte[]序列化成对象 + /// + /// + /// + public object BytesToObject(byte[] bytes) + { + using (MemoryStream ms = new MemoryStream(bytes)) + { + IFormatter formatter = new BinaryFormatter(); + return formatter.Deserialize(ms); + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackAgent.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackAgent.cs new file mode 100644 index 000000000..878cc9cc6 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackAgent.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class TcpPackAgent : TcpAgent + { + public TcpPackAgent() + { + CreateListener(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected override bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pAgent != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_TcpAgentListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pAgent = HPSocketSdk.Create_HP_TcpPackAgent(pListener); + if (pAgent == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 终止服务并释放资源 + /// + public override void Destroy() + { + Stop(); + + if (pAgent != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPackAgent(pAgent); + pAgent = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpAgentListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + /// + /// 读取或设置数据包最大长度 + /// 有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000 + /// + public uint MaxPackSize + { + get + { + return HPSocketSdk.HP_TcpPackAgent_GetMaxPackSize(pAgent); + } + set + { + HPSocketSdk.HP_TcpPackAgent_SetMaxPackSize(pAgent, value); + } + } + + /// + /// 读取或设置包头标识 + /// 有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0 + /// + public ushort PackHeaderFlag + { + get + { + return HPSocketSdk.HP_TcpPackAgent_GetPackHeaderFlag(pAgent); + } + set + { + HPSocketSdk.HP_TcpPackAgent_SetPackHeaderFlag(pAgent, value); + } + } + + + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackClient.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackClient.cs new file mode 100644 index 000000000..8973fac0c --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackClient.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class TcpPackClient : TcpClient + { + public TcpPackClient() + { + CreateListener(); + } + + + /// + /// 创建socket监听&服务组件 + /// + /// + protected override bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pClient != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_TcpClientListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pClient = HPSocketSdk.Create_HP_TcpPackClient (pListener); + if (pClient == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 终止服务并释放资源 + /// + public override void Destroy() + { + Stop(); + + if (pClient != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPackClient(pClient); + pClient = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpClientListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + /// + /// 读取或设置数据包最大长度 + /// 有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000 + /// + public uint MaxPackSize + { + get + { + return HPSocketSdk.HP_TcpPackClient_GetMaxPackSize(pClient); + } + set + { + HPSocketSdk.HP_TcpPackClient_SetMaxPackSize(pClient, value); + } + } + + /// + /// 读取或设置包头标识 + /// 有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0 + /// + public ushort PackHeaderFlag + { + get + { + return HPSocketSdk.HP_TcpPackClient_GetPackHeaderFlag(pClient); + } + set + { + HPSocketSdk.HP_TcpPackClient_SetPackHeaderFlag(pClient, value); + } + } + + + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackServer.cs new file mode 100644 index 000000000..b2e515dc6 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPackServer.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class TcpPackServer : TcpServer + { + public TcpPackServer() + { + CreateListener(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected override bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pServer != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_TcpServerListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pServer = HPSocketSdk.Create_HP_TcpPackServer(pListener); + if (pServer == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 终止服务并释放资源 + /// + public override void Destroy() + { + Stop(); + + if (pServer != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPackServer(pServer); + pServer = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpServerListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + /// + /// 读取或设置数据包最大长度 + /// 有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000 + /// + public uint MaxPackSize + { + get + { + return HPSocketSdk.HP_TcpPackServer_GetMaxPackSize(pServer); + } + set + { + HPSocketSdk.HP_TcpPackServer_SetMaxPackSize(pServer, value ); + } + } + + /// + /// 读取或设置包头标识 + /// 有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0 + /// + public ushort PackHeaderFlag + { + get + { + return HPSocketSdk.HP_TcpPackServer_GetPackHeaderFlag(pServer); + } + set + { + HPSocketSdk.HP_TcpPackServer_SetPackHeaderFlag(pServer, value); + } + } + + + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullAgent.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullAgent.cs new file mode 100644 index 000000000..fd054d1cc --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullAgent.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class TcpPullAgentEvent + { + public delegate HandleResult OnReceiveEventHandler(IntPtr connId, int length); + } + public class TcpPullAgent : TcpAgent + { + protected new TcpPullAgentEvent.OnReceiveEventHandler OnReceive; + + public TcpPullAgent() + { + CreateListener(); + } + + ~TcpPullAgent() + { + Destroy(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected override bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pAgent != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_TcpPullAgentListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pAgent = HPSocketSdk.Create_HP_TcpPullAgent(pListener); + if (pAgent == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// + /// + /// + public FetchResult Fetch(IntPtr connId, IntPtr pBuffer, int size) + { + return HPSocketSdk.HP_TcpPullAgent_Fetch(pAgent, connId, pBuffer, size); + } + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// + /// + /// + public FetchResult Peek(IntPtr connId, IntPtr pBuffer, int size) + { + return HPSocketSdk.HP_TcpPullAgent_Peek(pAgent, connId, pBuffer, size); + } + + HPSocketCS.SDK.HPSocketSdk.OnPullReceive _OnReceive = null; + + /// + /// 设置回调函数 + /// + /// + /// + /// + /// + /// + /// + /// + protected override void SetCallback() + { + _OnReceive = new HPSocketSdk.OnPullReceive(SDK_OnReceive); + + // 设置 Socket 监听器回调函数 + HPSocketSdk.HP_Set_FN_Agent_OnPullReceive(pListener, _OnReceive); + base.SetCallback(); + } + + protected virtual HandleResult SDK_OnReceive(IntPtr connId, int length) + { + if (OnReceive != null) + { + return OnReceive(connId, length); + } + return HandleResult.Ignore; + } + + /// + /// 终止服务并释放资源 + /// + public override void Destroy() + { + Stop(); + + if (pAgent != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPullAgent(pAgent); + pAgent = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPullAgentListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullClient.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullClient.cs new file mode 100644 index 000000000..fc86b7f1c --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullClient.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class TcpPullClientEvent + { + + public delegate HandleResult OnReceiveEventHandler(TcpPullClient sender, int length); + } + + public class TcpPullClient : TcpClient + { + /// + /// 数据到达事件 + /// + public new event TcpPullClientEvent.OnReceiveEventHandler OnReceive; + + public TcpPullClient() + { + CreateListener(); + } + + ~TcpPullClient() + { + Destroy(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected override bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pClient != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_TcpPullClientListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pClient = HPSocketSdk.Create_HP_TcpPullClient(pListener); + if (pClient == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// + /// + /// + public FetchResult Fetch(IntPtr pBuffer, int size) + { + return HPSocketSdk.HP_TcpPullClient_Fetch(pClient, pBuffer, size); + } + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// + /// + /// + public FetchResult Peek(IntPtr pBuffer, int size) + { + return HPSocketSdk.HP_TcpPullClient_Peek(pClient, pBuffer, size); + } + + + HPSocketCS.SDK.HPSocketSdk.OnPullReceive _OnReceive = null; + + /// + /// 设置回调函数 + /// + protected override void SetCallback() + { + _OnReceive = new HPSocketSdk.OnPullReceive(SDK_OnReceive); + HPSocketSdk.HP_Set_FN_Client_OnPullReceive(pListener, _OnReceive); + base.SetCallback(); + } + + + protected HandleResult SDK_OnReceive(IntPtr pClient, int length) + { + if (OnReceive != null) + { + return OnReceive(this, length); + } + + return HandleResult.Ignore; + } + + /// + /// 终止服务并释放资源 + /// + public override void Destroy() + { + Stop(); + + if (pClient != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPullClient(pClient); + pClient = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPullClientListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullServer.cs new file mode 100644 index 000000000..a2aee1e27 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpPullServer.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class TcpPullServerEvent + { + public delegate HandleResult OnReceiveEventHandler(IntPtr connId, int length); + } + + public class TcpPullServer : TcpServer + { + + /// + /// 数据到达事件 + /// + public new event TcpPullServerEvent.OnReceiveEventHandler OnReceive; + + public TcpPullServer() + { + CreateListener(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected override bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pServer != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_TcpPullServerListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pServer = HPSocketSdk.Create_HP_TcpPullServer(pListener); + if (pServer == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + HPSocketCS.SDK.HPSocketSdk.OnPullReceive _OnReceive = null; + + protected override void SetCallback() + { + _OnReceive = new HPSocketSdk.OnPullReceive(SDK_OnReceive); + HPSocketSdk.HP_Set_FN_Server_OnPullReceive(pListener, _OnReceive); + base.SetCallback(); + } + + protected HandleResult SDK_OnReceive(IntPtr connId, int length) + { + if (OnReceive != null) + { + return OnReceive(connId, length); + } + return HandleResult.Ignore; + } + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// + /// + /// + public FetchResult Fetch(IntPtr connId, IntPtr pBuffer, int size) + { + return HPSocketSdk.HP_TcpPullServer_Fetch(pServer, connId, pBuffer, size); + } + + /// + /// 抓取数据 + /// 用户通过该方法从 Socket 组件中抓取数据 + /// + /// + /// + /// + /// + public FetchResult Peek(IntPtr connId, IntPtr pBuffer, int size) + { + return HPSocketSdk.HP_TcpPullServer_Peek(pServer, connId, pBuffer, size); + } + + + /// + /// 终止服务并释放资源 + /// + public override void Destroy() + { + Stop(); + + if (pServer != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPullServer(pServer); + pServer = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpPullServerListener(pListener); + pListener = IntPtr.Zero; + } + IsCreate = false; + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpServer.cs new file mode 100644 index 000000000..b5f96a5ae --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/TcpServer.cs @@ -0,0 +1,1066 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; +using HPSocketCS.SDK; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using System.Runtime.Serialization; + +namespace HPSocketCS +{ + public class TcpServerEvent + { + public delegate HandleResult OnSendEventHandler(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnReceiveEventHandler(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnCloseEventHandler(IntPtr connId, SocketOperation enOperation, int errorCode); + public delegate HandleResult OnShutdownEventHandler(); + public delegate HandleResult OnPrepareListenEventHandler(IntPtr soListen); + public delegate HandleResult OnAcceptEventHandler(IntPtr connId, IntPtr pClient); + } + + public class TcpServer + { + protected IntPtr _pServer = IntPtr.Zero; + protected IntPtr pServer + { + get + { + return _pServer; + } + + set + { + _pServer = value; + } + } + + protected IntPtr pListener = IntPtr.Zero; + + + /// + /// 服务器ip + /// + public string IpAddress { get; set; } + + /// + /// 服务器端口 + /// + public ushort Port { get; set; } + + /// + /// 连接到达事件 + /// + public event TcpServerEvent.OnAcceptEventHandler OnAccept; + /// + /// 数据包发送事件 + /// + public event TcpServerEvent.OnSendEventHandler OnSend; + /// + /// 准备监听了事件 + /// + public event TcpServerEvent.OnPrepareListenEventHandler OnPrepareListen; + /// + /// 数据到达事件 + /// + public event TcpServerEvent.OnReceiveEventHandler OnReceive; + /// + /// 连接关闭事件 + /// + public event TcpServerEvent.OnCloseEventHandler OnClose; + /// + /// 服务器关闭事件 + /// + public event TcpServerEvent.OnShutdownEventHandler OnShutdown; + + protected bool IsCreate = false; + + /// + /// tcpserver构造 + /// + public TcpServer() + { + CreateListener(); + } + + ~TcpServer() + { + Destroy(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// 是否使用tcpserver类默认回调函数 + /// + protected virtual bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pServer != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_TcpServerListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + pServer = HPSocketSdk.Create_HP_TcpServer(pListener); + if (pServer == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 终止服务并释放资源 + /// + public virtual void Destroy() + { + Stop(); + + if (pServer != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpServer(pServer); + pServer = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_TcpServerListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + + /// + /// 启动服务 + /// + /// + /// + /// + public bool Start() + { + if (IsStarted == true) + { + return false; + } + + SetCallback(); + + return HPSocketSdk.HP_Server_Start(pServer, IpAddress, Port); + } + + /// + /// 停止服务 + /// + /// + public bool Stop() + { + if (IsStarted == false) + { + return false; + } + + return HPSocketSdk.HP_Server_Stop(pServer); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, byte[] bytes, int size) + { + return HPSocketSdk.HP_Server_Send(pServer, connId, bytes, size); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, IntPtr bufferPtr, int size) + { + return HPSocketSdk.HP_Server_Send(pServer, connId, bufferPtr, size); + } + + + /// + /// 发送数据 + /// + /// + /// + /// 针对bytes的偏移 + /// 发多大 + /// + public bool Send(IntPtr connId, byte[] bytes, int offset, int size) + { + return HPSocketSdk.HP_Server_SendPart(pServer, connId, bytes, size, offset); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bufferPtr的偏移 + /// 发多大 + /// + public bool Send(IntPtr connId, IntPtr bufferPtr, int offset, int size) + { + return HPSocketSdk.HP_Server_SendPart(pServer, connId, bufferPtr, size, offset); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, T obj) + { + byte[] buffer = StructureToByte(obj); + return Send(connId, buffer, buffer.Length); + } + + /// + /// 序列化对象后发送数据,序列化对象所属类必须标记[Serializable] + /// + /// + /// + /// + /// + public bool SendBySerializable(IntPtr connId, object obj) + { + byte[] buffer = ObjectToBytes(obj); + return Send(connId, buffer, buffer.Length); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(IntPtr connId, WSABUF[] pBuffers, int count) + { + return HPSocketSdk.HP_Server_SendPackets(pServer, connId, pBuffers, count); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(IntPtr connId, T[] objects) + { + bool ret = false; + + WSABUF[] buffer = new WSABUF[objects.Length]; + IntPtr[] ptrs = new IntPtr[buffer.Length]; + try + { + + for (int i = 0; i < objects.Length; i++) + { + buffer[i].Length = Marshal.SizeOf(typeof(T)); + + ptrs[i] = Marshal.AllocHGlobal(buffer[i].Length); + Marshal.StructureToPtr(objects[i], ptrs[i], true); + + buffer[i].Buffer = ptrs[i]; + } + ret = SendPackets(connId, buffer, buffer.Length); + } + catch (Exception ex) + { + throw ex; + } + finally + { + for (int i = 0; i < ptrs.Length; i++) + { + if (ptrs[i] != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptrs[i]); + } + } + } + + return ret; + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 文件路径 + /// 头部附加数据 + /// 尾部附加数据 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(IntPtr connId, string filePath, ref WSABUF head, ref WSABUF tail) + { + return HPSocketSdk.HP_TcpServer_SendSmallFile(pServer, connId, filePath, ref head, ref tail); + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 文件路径 + /// 头部附加数据,可以为null + /// 尾部附加数据,可以为null + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(IntPtr connId, string filePath, byte[] head, byte[] tail) + { + IntPtr pHead = IntPtr.Zero; + IntPtr pTail = IntPtr.Zero; + WSABUF wsaHead = new WSABUF() { Length = 0, Buffer = pHead }; + WSABUF wsatail = new WSABUF() { Length = 0, Buffer = pTail }; + if (head != null) + { + wsaHead.Length = head.Length; + wsaHead.Buffer = Marshal.UnsafeAddrOfPinnedArrayElement(head, 0); + } + + if (tail != null) + { + wsaHead.Length = tail.Length; + wsaHead.Buffer = Marshal.UnsafeAddrOfPinnedArrayElement(tail, 0); + } + + return SendSmallFile(connId, filePath, ref wsaHead, ref wsatail); + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// + /// 文件路径 + /// 头部附加数据,可以为null + /// 尾部附加数据,可以为null + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(IntPtr connId, string filePath, T1 head, T2 tail) + { + + byte[] headBuffer = null; + if (head != null) + { + headBuffer = StructureToByte(head); + } + + byte[] tailBuffer = null; + if (tail != null) + { + StructureToByte(head); + } + return SendSmallFile(connId, filePath, headBuffer, tailBuffer); + } + + /// + /// 断开与某个客户的连接 + /// + /// + /// 是否强制断开 + /// + public bool Disconnect(IntPtr connId, bool force = true) + { + return HPSocketSdk.HP_Server_Disconnect(pServer, connId, force); + } + + /// + /// 断开超过指定时间的连接 + /// + /// 毫秒 + /// 强制 + /// + public bool DisconnectLongConnections(uint period, bool force = true) + { + return HPSocketSdk.HP_Server_DisconnectLongConnections(pServer, period, force); + } + + /// + /// 断开超过指定时长的静默连接 + /// + /// 毫秒 + /// 强制 + /// + public bool DisconnectSilenceConnections(uint period, bool force = true) + { + return HPSocketSdk.HP_Server_DisconnectSilenceConnections(pServer, period, force); + } + + /// + /// 获取某个连接的远程ip和端口 + /// + /// + /// + /// + /// + public bool GetRemoteAddress(IntPtr connId, ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Server_GetRemoteAddress(pServer, connId, sb, ref ipLength, ref port) && ipLength > 0; + if (ret == true) + { + ip = sb.ToString(); + } + + return ret; + } + + + /// + /// 获取连接中未发出数据的长度 + /// + /// + /// + /// + public bool GetPendingDataLength(IntPtr connId, ref int length) + { + return HPSocketSdk.HP_Server_GetPendingDataLength(pServer, connId, ref length); + } + + /// + /// 设置连接的附加数据 + /// + /// + /// 如果为null,则为释放设置的数据 + /// + public bool SetConnectionExtra(IntPtr connId, object obj) + { + + IntPtr ptr = IntPtr.Zero; + // 释放附加数据 + if (HPSocketSdk.HP_Server_GetConnectionExtra(pServer, connId, ref ptr) && ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptr); + ptr = IntPtr.Zero; + } + + if (obj != null) + { + // 设置附加数据 + ptr = Marshal.AllocHGlobal(Marshal.SizeOf(obj)); + Marshal.StructureToPtr(obj, ptr, false); + } + + return HPSocketSdk.HP_Server_SetConnectionExtra(pServer, connId, ptr); + } + + /// + /// 获取附加数据 + /// 如设置的是个结构体/类对象,可以用 Type objA = (Type)Marshal.PtrToStructure(ptr, typeof(Type)) 获取 + /// 其中Type是结构体/类名,ptr是该方法的传出值,在该方法返回为true的时候可用 + /// + /// + /// + /// + public bool GetConnectionExtra(IntPtr connId, ref IntPtr ptr) + { + return HPSocketSdk.HP_Server_GetConnectionExtra(pServer, connId, ref ptr) && ptr != IntPtr.Zero; + } + + // 是否启动 + public bool IsStarted + { + get + { + if (pServer == IntPtr.Zero) + { + return false; + } + return HPSocketSdk.HP_Server_HasStarted(pServer); + } + } + + /// + /// 状态 + /// + public ServiceState State + { + get + { + return HPSocketSdk.HP_Server_GetState(pServer); + } + + } + + /// + /// 连接数 + /// + public uint ConnectionCount + { + get + { + return HPSocketSdk.HP_Server_GetConnectionCount(pServer); + } + + } + + /// + /// 获取所有连接,未获取到连接返回null + /// + /// + public IntPtr[] GetAllConnectionIDs() + { + IntPtr[] arr = null; + do + { + uint count = ConnectionCount; + if (count == 0) + { + break; + } + arr = new IntPtr[count]; + if (HPSocketSdk.HP_Server_GetAllConnectionIDs(pServer, arr, ref count)) + { + if (arr.Length > count) + { + IntPtr[] newArr = new IntPtr[count]; + Array.Copy(arr, newArr, count); + arr = newArr; + } + break; + } + } while (true); + + return arr; + } + + /// + /// 获取监听socket的地址信息 + /// + /// + /// + /// + public bool GetListenAddress(ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Server_GetListenAddress(pServer, sb, ref ipLength, ref port); + if (ret == true) + { + ip = sb.ToString(); + } + return ret; + } + + + /// + /// 获取指定连接的连接时长(毫秒) + /// + /// + /// + /// + public bool GetConnectPeriod(IntPtr connId, ref uint period) + { + return HPSocketSdk.HP_Server_GetConnectPeriod(pServer, connId, ref period); + } + + /// + /// 获取某个连接静默时间(毫秒) + /// + /// + /// + /// + public bool GetSilencePeriod(IntPtr connId, ref uint period) + { + return HPSocketSdk.HP_Server_GetSilencePeriod(pServer, connId, ref period); + } + + /////////////////////////////////////////////////////////////////////////////////////// + + /// + /// 读取或设置工作线程数量(通常设置为 2 * CPU + 2) + /// + public uint WorkerThreadCount + { + get + { + return HPSocketSdk.HP_Server_GetWorkerThreadCount(pServer); + } + set + { + HPSocketSdk.HP_Server_SetWorkerThreadCount(pServer, value); + } + } + + /// + /// 读取或设置 Accept 预投递数量(根据负载调整设置,Accept 预投递数量越大则支持的并发连接请求越多) + /// + public uint AcceptSocketCount + { + get + { + return HPSocketSdk.HP_TcpServer_GetAcceptSocketCount(pServer); + } + set + { + HPSocketSdk.HP_TcpServer_SetAcceptSocketCount(pServer, value); + } + } + + /// + /// 读取或设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数) + /// + public uint SocketBufferSize + { + get + { + return HPSocketSdk.HP_TcpServer_GetSocketBufferSize(pServer); + } + set + { + HPSocketSdk.HP_TcpServer_SetSocketBufferSize(pServer, value); + } + } + + /// + /// 读取或设置监听 Socket 的等候队列大小(根据并发连接数量调整设置) + /// + public uint SocketListenQueue + { + get + { + return HPSocketSdk.HP_TcpServer_GetSocketListenQueue(pServer); + } + set + { + HPSocketSdk.HP_TcpServer_SetSocketListenQueue(pServer, value); + } + } + + /// + /// 读取或设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用) + /// + public uint FreeSocketObjLockTime + { + get + { + return HPSocketSdk.HP_Server_GetFreeSocketObjLockTime(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeSocketObjLockTime(pServer, value); + } + } + + /// + /// 读取或设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2) + /// + public uint FreeSocketObjPool + { + get + { + return HPSocketSdk.HP_Server_GetFreeSocketObjPool(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeSocketObjPool(pServer, value); + } + } + + /// + /// 读取或设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍) + /// + public uint FreeBufferObjPool + { + get + { + return HPSocketSdk.HP_Server_GetFreeBufferObjPool(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeBufferObjPool(pServer, value); + } + } + + /// + /// 读取或设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍) + /// + public uint FreeSocketObjHold + { + get + { + return HPSocketSdk.HP_Server_GetFreeSocketObjHold(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeSocketObjHold(pServer, value); + } + } + + /// + /// 读取或设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + public uint FreeBufferObjHold + { + get + { + return HPSocketSdk.HP_Server_GetFreeBufferObjHold(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeBufferObjHold(pServer, value); + } + } + + /// + /// 读取或设置心跳包间隔(毫秒,0 则不发送心跳包) + /// + public uint KeepAliveTime + { + get + { + return HPSocketSdk.HP_TcpServer_GetKeepAliveTime(pServer); + } + set + { + HPSocketSdk.HP_TcpServer_SetKeepAliveTime(pServer, value); + } + } + + /// + /// 读取或设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线) + /// + public uint KeepAliveInterval + { + get + { + return HPSocketSdk.HP_TcpServer_GetKeepAliveInterval(pServer); + } + set + { + HPSocketSdk.HP_TcpServer_SetKeepAliveInterval(pServer, value); + } + } + + /// + /// 读取或设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE) + /// + public bool MarkSilence + { + get + { + return HPSocketSdk.HP_Server_IsMarkSilence(pServer); + } + set + { + HPSocketSdk.HP_Server_SetMarkSilence(pServer, value); + } + } + + /// + /// 获取或设置数据发送策略 + /// + public SendPolicy SendPolicy + { + get + { + return HPSocketSdk.HP_Server_GetSendPolicy(pServer); + } + set + { + HPSocketSdk.HP_Server_SetSendPolicy(pServer, value); + } + } + + + /////////////////////////////////////////////////////////////////////////////////////// + + /// + /// 获取系统返回的错误码 + /// + public int SYSGetLastError() + { + return HPSocketSdk.SYS_GetLastError(); + } + + /// + /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码 + /// + public int SYSWSAGetLastError() + { + return HPSocketSdk.SYS_WSAGetLastError(); + } + + /// + /// 获取错误码 + /// + public SocketError ErrorCode + { + get + { + return HPSocketSdk.HP_Server_GetLastError(pServer); + } + } + + /// + /// 获取错误信息 + /// + public string ErrorMessage + { + get + { + IntPtr ptr = HPSocketSdk.HP_Server_GetLastErrorDesc(pServer); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + } + + + /////////////////////////////////////////////////////////////////////////////////////// + HPSocketCS.SDK.HPSocketSdk.OnPrepareListen _OnPrepareListen = null; + HPSocketCS.SDK.HPSocketSdk.OnAccept _OnAccept = null; + HPSocketCS.SDK.HPSocketSdk.OnReceive _OnReceive = null; + HPSocketCS.SDK.HPSocketSdk.OnSend _OnSend = null; + HPSocketCS.SDK.HPSocketSdk.OnClose _OnClose = null; + HPSocketCS.SDK.HPSocketSdk.OnShutdown _OnShutdown = null; + + protected virtual void SetCallback() + { + _OnPrepareListen = new HPSocketSdk.OnPrepareListen(SDK_OnPrepareListen); + _OnAccept = new HPSocketSdk.OnAccept(SDK_OnAccept); + _OnSend = new HPSocketSdk.OnSend(SDK_OnSend); + _OnReceive = new HPSocketSdk.OnReceive(SDK_OnReceive); + _OnClose = new HPSocketSdk.OnClose(SDK_OnClose); + _OnShutdown = new HPSocketSdk.OnShutdown(SDK_OnShutdown); + + HPSocketSdk.HP_Set_FN_Server_OnPrepareListen(pListener, _OnPrepareListen); + HPSocketSdk.HP_Set_FN_Server_OnAccept(pListener, _OnAccept); + HPSocketSdk.HP_Set_FN_Server_OnSend(pListener, _OnSend); + HPSocketSdk.HP_Set_FN_Server_OnReceive(pListener, _OnReceive); + HPSocketSdk.HP_Set_FN_Server_OnClose(pListener, _OnClose); + HPSocketSdk.HP_Set_FN_Server_OnShutdown(pListener, _OnShutdown); + } + + + protected HandleResult SDK_OnPrepareListen(IntPtr soListen) + { + if (OnPrepareListen != null) + { + return OnPrepareListen(soListen); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnAccept(IntPtr connId, IntPtr pClient) + { + if (OnAccept != null) + { + return OnAccept(connId, pClient); + } + + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnSend(IntPtr connId, IntPtr pData, int length) + { + if (OnSend != null) + { + return OnSend(connId, pData, length); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnReceive(IntPtr connId, IntPtr pData, int length) + { + if (OnReceive != null) + { + return OnReceive(connId, pData, length); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if (OnClose != null) + { + return OnClose(connId, enOperation, errorCode); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnShutdown() + { + if (OnShutdown != null) + { + return OnShutdown(); + } + return HandleResult.Ignore; + } + + + ///////////////////////////////////////////////////////////////////////// + + /// + /// 根据错误码返回错误信息 + /// + /// + /// + public string GetSocketErrorDesc(SocketError code) + { + IntPtr ptr = HPSocketSdk.HP_GetSocketErrorDesc(code); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + + + /// + /// 调用系统的 setsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len) + { + return HPSocketSdk.SYS_SetSocketOption(sock, level, name, val, len); + } + + /// + /// 调用系统的 getsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYSGetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len) + { + return HPSocketSdk.SYS_GetSocketOption(sock, level, name, val, ref len); + } + /// + /// 调用系统的 ioctlsocket() + /// + /// + /// + /// + /// + /// + public int SYSIoctlSocket(IntPtr sock, long cmd, IntPtr arg) + { + return HPSocketSdk.SYS_IoctlSocket(sock, cmd, arg); + } + + /// + /// 调用系统的 ::WSAIoctl() + /// + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer, + IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned) + { + return HPSocketSdk.SYS_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, + lpvOutBuffer, cbOutBuffer, lpcbBytesReturned); + } + + /// + /// 由结构体转换为byte数组 + /// + public byte[] StructureToByte(T structure) + { + int size = Marshal.SizeOf(typeof(T)); + byte[] buffer = new byte[size]; + IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(structure, bufferIntPtr, true); + Marshal.Copy(bufferIntPtr, buffer, 0, size); + } + finally + { + Marshal.FreeHGlobal(bufferIntPtr); + } + return buffer; + } + + /// + /// 由byte数组转换为结构体 + /// + public T ByteToStructure(byte[] dataBuffer) + { + object structure = null; + int size = Marshal.SizeOf(typeof(T)); + IntPtr allocIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.Copy(dataBuffer, 0, allocIntPtr, size); + structure = Marshal.PtrToStructure(allocIntPtr, typeof(T)); + } + finally + { + Marshal.FreeHGlobal(allocIntPtr); + } + return (T)structure; + } + + /// + /// 对象序列化成byte[] + /// + /// + /// + public byte[] ObjectToBytes(object obj) + { + using (MemoryStream ms = new MemoryStream()) + { + IFormatter formatter = new BinaryFormatter(); + formatter.Serialize(ms, obj); + return ms.GetBuffer(); + } + } + + /// + /// byte[]序列化成对象 + /// + /// + /// + public object BytesToObject(byte[] bytes) + { + using (MemoryStream ms = new MemoryStream(bytes)) + { + IFormatter formatter = new BinaryFormatter(); + return formatter.Deserialize(ms); + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpAgent.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpAgent.cs new file mode 100644 index 000000000..e583bfef7 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpAgent.cs @@ -0,0 +1,994 @@ +using System; +using System.Text; +using System.Runtime.InteropServices; +using System.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class UdpAgentEvent + { + public delegate HandleResult OnConnectEventHandler(IntPtr connId /* IntPtr pClient */); + public delegate HandleResult OnSendEventHandler(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnReceiveEventHandler(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnCloseEventHandler(IntPtr connId, SocketOperation enOperation, int errorCode); + public delegate HandleResult OnShutdownEventHandler(); + public delegate HandleResult OnPrepareConnectEventHandler(IntPtr connId /* IntPtr pClient */, uint socket); + } + public class UdpAgent + { + protected IntPtr _pAgent = IntPtr.Zero; + + protected IntPtr pAgent + { + get + { + //if (_pClient == IntPtr.Zero) + //{ + // throw new Exception("pClient == 0"); + //} + + return _pAgent; + } + + set + { + _pAgent = value; + } + } + + + protected IntPtr pListener = IntPtr.Zero; + + /// + /// 连接事件 + /// + public UdpAgentEvent.OnConnectEventHandler OnConnect; + /// + /// 数据发送事件 + /// + public UdpAgentEvent.OnSendEventHandler OnSend; + /// + /// 准备连接事件 + /// + public UdpAgentEvent.OnPrepareConnectEventHandler OnPrepareConnect; + /// + /// 数据到达事件 + /// + public UdpAgentEvent.OnReceiveEventHandler OnReceive; + /// + /// 连接关闭事件 + /// + public UdpAgentEvent.OnCloseEventHandler OnClose; + /// + /// 服务关闭事件 + /// + public UdpAgentEvent.OnShutdownEventHandler OnShutdown; + + + protected bool IsCreate = false; + + public UdpAgent() + { + CreateListener(); + } + + ~UdpAgent() + { + Destroy(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected virtual bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pAgent != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_UdpAgentListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pAgent = HPSocketSdk.Create_HP_UdpAgent(pListener); + if (pAgent == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 终止服务并释放资源 + /// + public virtual void Destroy() + { + Stop(); + + if (pAgent != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_UdpAgent(pAgent); + pAgent = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_UdpAgentListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + /// + /// 启动通讯组件 + /// 启动完成后可开始连接远程服务器 + /// + /// 绑定地址 + /// 是否异步 + /// + public bool Start(string address, bool async = false) + { + if (string.IsNullOrEmpty(address) == true) + { + throw new Exception("address is null"); + } + + if (IsStarted == true) + { + return false; + } + + SetCallback(); + + return HPSocketSdk.HP_Agent_Start(pAgent, address, async); + } + + /// + /// 停止通讯组件 + /// + /// + public bool Stop() + { + if (IsStarted == false) + { + return false; + } + return HPSocketSdk.HP_Agent_Stop(pAgent); + } + + + /// + /// 连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() 事件 + /// + /// + /// + /// + /// + public bool Connect(string address, ushort port, ref IntPtr connId) + { + return HPSocketSdk.HP_Agent_Connect(pAgent, address, port, ref connId); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, byte[] bytes, int size) + { + return HPSocketSdk.HP_Agent_Send(pAgent, connId, bytes, size); + } + + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, T obj) + { + byte[] buffer = StructureToByte(obj); + return Send(connId, buffer, buffer.Length); + } + + /// + /// 序列化对象后发送数据,序列化对象所属类必须标记[Serializable] + /// + /// + /// + /// + /// + public bool SendBySerializable(IntPtr connId, object obj) + { + byte[] buffer = ObjectToBytes(obj); + return Send(connId, buffer, buffer.Length); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, IntPtr bufferPtr, int size) + { + return HPSocketSdk.HP_Agent_Send(pAgent, connId, bufferPtr, size); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bytes的偏移 + /// 发多大 + /// + public bool Send(IntPtr connId, byte[] bytes, int offset, int size) + { + return HPSocketSdk.HP_Agent_SendPart(pAgent, connId, bytes, size, offset); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bufferPtr的偏移 + /// 发多大 + /// + public bool Send(IntPtr connId, IntPtr bufferPtr, int offset, int size) + { + return HPSocketSdk.HP_Agent_SendPart(pAgent, connId, bufferPtr, size, offset); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(IntPtr connId, WSABUF[] pBuffers, int count) + { + return HPSocketSdk.HP_Agent_SendPackets(pAgent, connId, pBuffers, count); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// TCP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(IntPtr connId, T[] objects) + { + bool ret = false; + + WSABUF[] buffer = new WSABUF[objects.Length]; + IntPtr[] ptrs = new IntPtr[buffer.Length]; + try + { + + for (int i = 0; i < objects.Length; i++) + { + buffer[i].Length = Marshal.SizeOf(typeof(T)); + + ptrs[i] = Marshal.AllocHGlobal(buffer[i].Length); + Marshal.StructureToPtr(objects[i], ptrs[i], true); + + buffer[i].Buffer = ptrs[i]; + } + ret = SendPackets(connId, buffer, buffer.Length); + } + catch (Exception ex) + { + throw ex; + } + finally + { + for (int i = 0; i < ptrs.Length; i++) + { + if (ptrs[i] != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptrs[i]); + } + } + } + + return ret; + } + + /// + /// 断开某个连接 + /// + /// + /// 强制 + /// + public bool Disconnect(IntPtr connId, bool force = true) + { + return HPSocketSdk.HP_Agent_Disconnect(pAgent, connId, force); + } + + /// + /// 断开超过指定时间的连接 + /// + /// 毫秒 + /// 强制 + /// + public bool DisconnectLongConnections(uint period, bool force = true) + { + return HPSocketSdk.HP_Agent_DisconnectLongConnections(pAgent, period, force); + } + + /// + /// 断开超过指定时长的静默连接 + /// + /// 毫秒 + /// 强制 + /// + public bool DisconnectSilenceConnections(uint period, bool force = true) + { + return HPSocketSdk.HP_Agent_DisconnectSilenceConnections(pAgent, period, force); + } + + /// + /// 设置连接的附加数据 + /// + /// + /// + /// + public bool SetConnectionExtra(IntPtr connId, object obj) + { + + IntPtr ptr = IntPtr.Zero; + // 释放附加数据 + if (HPSocketSdk.HP_Agent_GetConnectionExtra(pAgent, connId, ref ptr) && ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptr); + ptr = IntPtr.Zero; + } + + if (obj != null) + { + // 设置附加数据 + ptr = Marshal.AllocHGlobal(Marshal.SizeOf(obj)); + Marshal.StructureToPtr(obj, ptr, false); + } + return HPSocketSdk.HP_Agent_SetConnectionExtra(pAgent, connId, ptr); + } + + /// + /// 获取附加数据 + /// 如设置的是个结构体/类对象,可以用 Type objA = (Type)Marshal.PtrToStructure(ptr, typeof(Type)) 获取 + /// 其中Type是结构体/类名,ptr是该方法的传出值,在该方法返回为true的时候可用 + /// + /// + /// + /// + public bool GetConnectionExtra(IntPtr connId, ref IntPtr ptr) + { + return HPSocketSdk.HP_Agent_GetConnectionExtra(pAgent, connId, ref ptr) && ptr != IntPtr.Zero; + } + + /// + /// 获取错误码 + /// + public SocketError ErrorCode + { + get + { + return HPSocketSdk.HP_Agent_GetLastError(pAgent); + } + } + + /// + /// 获取错误信息 + /// + public string ErrorMessage + { + get + { + IntPtr ptr = HPSocketSdk.HP_Agent_GetLastErrorDesc(pAgent); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + } + + + /// + /// 获取连接中未发出数据的长度 + /// + /// + /// + /// + public bool GetPendingDataLength(IntPtr connId, ref int length) + { + return HPSocketSdk.HP_Agent_GetPendingDataLength(pAgent, connId, ref length); + } + + // 是否启动 + public bool IsStarted + { + get + { + if (pAgent == IntPtr.Zero) + { + return false; + } + return HPSocketSdk.HP_Agent_HasStarted(pAgent); + } + } + + /// + /// 状态 + /// + public ServiceState State + { + get + { + return HPSocketSdk.HP_Agent_GetState(pAgent); + } + } + + public uint ConnectionCount + { + get + { + return HPSocketSdk.HP_Agent_GetConnectionCount(pAgent); + } + } + + /// + /// 获取所有连接,未获取到连接返回null + /// + /// + public IntPtr[] GetAllConnectionIDs() + { + IntPtr[] arr = null; + do + { + uint count = ConnectionCount; + if (count == 0) + { + break; + } + arr = new IntPtr[count]; + if (HPSocketSdk.HP_Agent_GetAllConnectionIDs(pAgent, arr, ref count)) + { + if (arr.Length > count) + { + IntPtr[] newArr = new IntPtr[count]; + Array.Copy(arr, newArr, count); + arr = newArr; + } + break; + } + } while (true); + + return arr; + } + + /// + /// 获取监听socket的地址信息 + /// + /// + /// + /// + public bool GetLocalAddress(IntPtr connId, ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Agent_GetLocalAddress(pAgent, connId, sb, ref ipLength, ref port); + if (ret == true) + { + ip = sb.ToString(); + } + return ret; + } + + /// + /// 获取该组件对象的连接Id + /// + /// + public bool GetRemoteAddress(IntPtr connId, ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Agent_GetRemoteAddress(pAgent, connId, sb, ref ipLength, ref port); + if (ret == true) + { + ip = sb.ToString(); + } + return ret; + } + + /// + /// 获取指定连接的连接时长(毫秒) + /// + /// + /// + /// + public bool GetConnectPeriod(IntPtr connId, ref uint period) + { + return HPSocketSdk.HP_Agent_GetConnectPeriod(pAgent, connId, ref period); + } + + /// + /// 获取某个连接静默时间(毫秒) + /// + /// + /// + /// + public bool GetSilencePeriod(IntPtr connId, ref uint period) + { + return HPSocketSdk.HP_Agent_GetSilencePeriod(pAgent, connId, ref period); + } + + /////////////////////////////////////////////////////////////////////////////////////// + + /// + /// 获取或设置是否启用地址重用机制(默认:不启用) + /// +// public bool IsReuseAddress +// { +// get +// { +// return HPSocketSdk.HP_UdpAgent_IsReuseAddress(pAgent); +// } +// set +// { +// HPSocketSdk.HP_UdpAgent_SetReuseAddress(pAgent, value); +// } +// } + + + /// + /// 读取或设置工作线程数量(通常设置为 2 * CPU + 2) + /// + public uint WorkerThreadCount + { + get + { + return HPSocketSdk.HP_Agent_GetWorkerThreadCount(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetWorkerThreadCount(pAgent, value); + } + } + + /// + /// 读取或设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数) + /// + public uint SocketBufferSize + { + get + { + return HPSocketSdk.HP_TcpAgent_GetSocketBufferSize(pAgent); + } + set + { + HPSocketSdk.HP_TcpAgent_SetSocketBufferSize(pAgent, value); + } + } + + /// + /// 读取或设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用) + /// + public uint FreeSocketObjLockTime + { + get + { + return HPSocketSdk.HP_Agent_GetFreeSocketObjLockTime(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeSocketObjLockTime(pAgent, value); + } + } + + /// + /// 读取或设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2) + /// + public uint FreeSocketObjPool + { + get + { + return HPSocketSdk.HP_Agent_GetFreeSocketObjPool(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeSocketObjPool(pAgent, value); + } + } + + /// + /// 读取或设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍) + /// + public uint FreeBufferObjPool + { + get + { + return HPSocketSdk.HP_Agent_GetFreeBufferObjPool(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeBufferObjPool(pAgent, value); + } + } + + /// + /// 读取或设置 Socket 缓存池回收阀值(通常设置为 Socket 缓存池大小的 3 倍) + /// + public uint FreeSocketObjHold + { + get + { + return HPSocketSdk.HP_Agent_GetFreeSocketObjHold(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeSocketObjHold(pAgent, value); + } + } + + /// + /// 读取或设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + public uint FreeBufferObjHold + { + get + { + return HPSocketSdk.HP_Agent_GetFreeBufferObjHold(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetFreeBufferObjHold(pAgent, value); + } + } + + /// + /// 读取或设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE) + /// + public bool IsMarkSilence + { + get + { + return HPSocketSdk.HP_Agent_IsMarkSilence(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetMarkSilence(pAgent, value); + } + } + + /// + /// 读取或设置数据发送策略 + /// + public SendPolicy SendPolicy + { + get + { + return HPSocketSdk.HP_Agent_GetSendPolicy(pAgent); + } + set + { + HPSocketSdk.HP_Agent_SetSendPolicy(pAgent, value); + } + } + + /// + /// 读取或设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节) + /// + public uint MaxDatagramSize + { + get + { + return HPSocketSdk.HP_UdpAgent_GetMaxDatagramSize(pAgent); + } + set + { + HPSocketSdk.HP_UdpAgent_SetMaxDatagramSize(pAgent, value); + } + } + + /// + /// 读取或设置监测包尝试次数(0 则不发送监测跳包,如果超过最大尝试次数则认为已断线) + /// + public uint DetectAttempts + { + get + { + return HPSocketSdk.HP_UdpAgent_GetDetectAttempts(pAgent); + } + set + { + HPSocketSdk.HP_UdpAgent_SetDetectAttempts(pAgent, value); + } + } + + /// + /// 读取或设置设置监测包发送间隔(秒,0 不发送监测包) + /// + public uint DetectInterval + { + get + { + return HPSocketSdk.HP_UdpAgent_GetDetectInterval(pAgent); + } + set + { + HPSocketSdk.HP_UdpAgent_SetDetectInterval(pAgent, value); + } + } + + /// + /// 根据错误码返回错误信息 + /// + /// + /// + public string GetSocketErrorDesc(SocketError code) + { + IntPtr ptr = HPSocketSdk.HP_GetSocketErrorDesc(code); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + + /////////////////////////////////////////////////////////////////////////////////////// + HPSocketCS.SDK.HPSocketSdk.OnPrepareConnect _OnPrepareConnect = null; + HPSocketCS.SDK.HPSocketSdk.OnConnect _OnConnect = null; + HPSocketCS.SDK.HPSocketSdk.OnReceive _OnReceive = null; + HPSocketCS.SDK.HPSocketSdk.OnSend _OnSend = null; + HPSocketCS.SDK.HPSocketSdk.OnClose _OnClose = null; + HPSocketCS.SDK.HPSocketSdk.OnShutdown _OnShutdown = null; + + /// + /// 设置回调函数 + /// + protected virtual void SetCallback() + { + _OnPrepareConnect = new HPSocketSdk.OnPrepareConnect(SDK_OnPrepareConnect); + _OnConnect = new HPSocketSdk.OnConnect(SDK_OnConnect); + _OnSend = new HPSocketSdk.OnSend(SDK_OnSend); + _OnReceive = new HPSocketSdk.OnReceive(SDK_OnReceive); + _OnClose = new HPSocketSdk.OnClose(SDK_OnClose); + _OnShutdown = new HPSocketSdk.OnShutdown(SDK_OnShutdown); + + // 设置 Socket 监听器回调函数 + HPSocketSdk.HP_Set_FN_Agent_OnPrepareConnect(pListener, _OnPrepareConnect); + HPSocketSdk.HP_Set_FN_Agent_OnConnect(pListener, _OnConnect); + HPSocketSdk.HP_Set_FN_Server_OnSend(pListener, _OnSend); + HPSocketSdk.HP_Set_FN_Server_OnReceive(pListener, _OnReceive); + HPSocketSdk.HP_Set_FN_Server_OnClose(pListener, _OnClose); + HPSocketSdk.HP_Set_FN_Agent_OnShutdown(pListener, _OnShutdown); + + } + + protected virtual HandleResult SDK_OnPrepareConnect(IntPtr connId, uint socket) + { + if (OnPrepareConnect != null) + { + return OnPrepareConnect(connId, socket); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnConnect(IntPtr connId) + { + if (OnConnect != null) + { + return OnConnect(connId); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnSend(IntPtr connId, IntPtr pData, int length) + { + if (OnSend != null) + { + return OnSend(connId, pData, length); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnReceive(IntPtr connId, IntPtr pData, int length) + { + if (OnReceive != null) + { + return OnReceive(connId, pData, length); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if (OnClose != null) + { + return OnClose(connId, enOperation, errorCode); + } + return HandleResult.Ignore; + } + + protected virtual HandleResult SDK_OnShutdown() + { + if (OnShutdown != null) + { + return OnShutdown(); + } + return HandleResult.Ignore; + } + + + ///////////////////////////////////////////////////////////////////////// + + /// + /// 获取系统返回的错误码 + /// + /// + public int SYSGetLastError() + { + return HPSocketSdk.SYS_GetLastError(); + } + + /// + /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码 + /// + /// + public int SYSWSAGetLastError() + { + return HPSocketSdk.SYS_WSAGetLastError(); + } + + /// + /// 调用系统的 setsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len) + { + return HPSocketSdk.SYS_SetSocketOption(sock, level, name, val, len); + } + + /// + /// 调用系统的 getsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYSGetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len) + { + return HPSocketSdk.SYS_GetSocketOption(sock, level, name, val, ref len); + } + /// + /// 调用系统的 ioctlsocket() + /// + /// + /// + /// + /// + /// + public int SYSIoctlSocket(IntPtr sock, long cmd, IntPtr arg) + { + return HPSocketSdk.SYS_IoctlSocket(sock, cmd, arg); + } + + /// + /// 调用系统的 ::WSAIoctl() + /// + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer, + IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned) + { + return HPSocketSdk.SYS_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, + lpvOutBuffer, cbOutBuffer, lpcbBytesReturned); + } + + /// + /// 由结构体转换为byte数组 + /// + public byte[] StructureToByte(T structure) + { + int size = Marshal.SizeOf(typeof(T)); + byte[] buffer = new byte[size]; + IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(structure, bufferIntPtr, true); + Marshal.Copy(bufferIntPtr, buffer, 0, size); + } + finally + { + Marshal.FreeHGlobal(bufferIntPtr); + } + return buffer; + } + + /// + /// 由byte数组转换为结构体 + /// + public T ByteToStructure(byte[] dataBuffer) + { + object structure = null; + int size = Marshal.SizeOf(typeof(T)); + IntPtr allocIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.Copy(dataBuffer, 0, allocIntPtr, size); + structure = Marshal.PtrToStructure(allocIntPtr, typeof(T)); + } + finally + { + Marshal.FreeHGlobal(allocIntPtr); + } + return (T)structure; + } + + /// + /// 对象序列化成byte[] + /// + /// + /// + public byte[] ObjectToBytes(object obj) + { + using (MemoryStream ms = new MemoryStream()) + { + IFormatter formatter = new BinaryFormatter(); + formatter.Serialize(ms, obj); + return ms.GetBuffer(); + } + } + + /// + /// byte[]序列化成对象 + /// + /// + /// + public object BytesToObject(byte[] bytes) + { + using (MemoryStream ms = new MemoryStream(bytes)) + { + IFormatter formatter = new BinaryFormatter(); + return formatter.Deserialize(ms); + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpClient.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpClient.cs new file mode 100644 index 000000000..badce1e17 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpClient.cs @@ -0,0 +1,720 @@ +using System; +using System.Text; +using System.Runtime.InteropServices; +using System.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class UdpClientEvent + { + public delegate HandleResult OnPrepareConnectEventHandler(UdpClient sender, uint socket); + public delegate HandleResult OnConnectEventHandler(UdpClient sender); + public delegate HandleResult OnSendEventHandler(UdpClient sender, IntPtr pData, int length); + public delegate HandleResult OnReceiveEventHandler(UdpClient sender, IntPtr pData, int length); + public delegate HandleResult OnCloseEventHandler(UdpClient sender, SocketOperation enOperation, int errorCode); + } + + public class UdpClient + { + protected IntPtr _pClient = IntPtr.Zero; + protected IntPtr pClient + { + get + { + return _pClient; + } + + set + { + _pClient = value; + } + } + + protected IntPtr pListener = IntPtr.Zero; + + protected bool IsCreate = false; + + /****************************************************/ + /// + /// 准备连接了事件 + /// + public event UdpClientEvent.OnPrepareConnectEventHandler OnPrepareConnect; + /// + /// 连接事件 + /// + public event UdpClientEvent.OnConnectEventHandler OnConnect; + /// + /// 数据发送事件 + /// + public event UdpClientEvent.OnSendEventHandler OnSend; + /// + /// 数据到达事件 + /// + public event UdpClientEvent.OnReceiveEventHandler OnReceive; + /// + /// 连接关闭事件 + /// + public event UdpClientEvent.OnCloseEventHandler OnClose; + + public UdpClient() + { + CreateListener(); + } + + ~UdpClient() + { + Destroy(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// + protected virtual bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pClient != IntPtr.Zero) + { + return false; + } + + + pListener = HPSocketSdk.Create_HP_UdpClientListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + + pClient = HPSocketSdk.Create_HP_UdpClient(pListener); + if (pClient == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 终止服务并释放资源 + /// + public virtual void Destroy() + { + Stop(); + + if (pClient != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_UdpClient(pClient); + pClient = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_UdpClientListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + /// + /// 启动通讯组件并连接到服务器 + /// + /// + /// + /// 是否异步 + /// + public bool Connetion(string address, ushort port, bool async = false) + { + if (string.IsNullOrEmpty(address) == true) + { + throw new Exception("address is null"); + } + else if (port == 0) + { + throw new Exception("port is zero"); + } + + if (IsStarted == true) + { + return false; + } + + this.SetCallback(); + + return HPSocketSdk.HP_Client_Start(pClient, address, port, async); + } + + /// + /// 停止通讯组件 + /// + /// + public bool Stop() + { + if (IsStarted == false) + { + return false; + } + return HPSocketSdk.HP_Client_Stop(pClient); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(byte[] bytes, int size) + { + return HPSocketSdk.HP_Client_Send(pClient, bytes, size); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr bufferPtr, int size) + { + return HPSocketSdk.HP_Client_Send(pClient, bufferPtr, size); + } + + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(T obj) + { + byte[] buffer = StructureToByte(obj); + return Send(buffer, buffer.Length); + } + + /// + /// 序列化对象后发送数据,序列化对象所属类必须标记[Serializable] + /// + /// + /// + /// + /// + public bool SendBySerializable(object obj) + { + byte[] buffer = ObjectToBytes(obj); + return Send(buffer, buffer.Length); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bytes的偏移 + /// 发多大 + /// + public bool Send(byte[] bytes, int offset, int size) + { + return HPSocketSdk.HP_Client_SendPart(pClient, bytes, size, offset); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bufferPtr的偏移 + /// 发多大 + /// + public bool Send(IntPtr bufferPtr, int offset, int size) + { + return HPSocketSdk.HP_Client_SendPart(pClient, bufferPtr, size, offset); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// UDP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(WSABUF[] buffers, int count) + { + return HPSocketSdk.HP_Client_SendPackets(pClient, buffers, count); + } + + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// UDP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(T[] objects) + { + bool ret = false; + + WSABUF[] buffer = new WSABUF[objects.Length]; + IntPtr[] ptrs = new IntPtr[buffer.Length]; + try + { + + for (int i = 0; i < objects.Length; i++) + { + buffer[i].Length = Marshal.SizeOf(typeof(T)); + + ptrs[i] = Marshal.AllocHGlobal(buffer[i].Length); + Marshal.StructureToPtr(objects[i], ptrs[i], true); + + buffer[i].Buffer = ptrs[i]; + } + ret = SendPackets(buffer, buffer.Length); + } + catch (Exception ex) + { + throw ex; + } + finally + { + for (int i = 0; i < ptrs.Length; i++) + { + if (ptrs[i] != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptrs[i]); + } + } + } + + return ret; + } + + /// + /// 名称:发送小文件 + /// 描述:向指定连接发送 4096 KB 以下的小文件 + /// + /// 文件路径 + /// 头部附加数据,可以为null + /// 尾部附加数据,可以为null + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendSmallFile(string filePath, T1 head, T2 tail) + { + + byte[] headBuffer = null; + if (head != null) + { + headBuffer = StructureToByte(head); + } + + byte[] tailBuffer = null; + if (tail != null) + { + StructureToByte(head); + } + return SendSmallFile(filePath, headBuffer, tailBuffer); + } + + /// + /// 获取错误码 + /// + public SocketError ErrorCode + { + get + { + return HPSocketSdk.HP_Client_GetLastError(pClient); + } + } + + /// + /// 获取错误信息 + /// + public string ErrorMessage + { + get + { + IntPtr ptr = HPSocketSdk.HP_Client_GetLastErrorDesc(pClient); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + } + + /// + /// + /// + /// + /// + public bool GetPendingDataLength(ref int length) + { + return HPSocketSdk.HP_Client_GetPendingDataLength(pClient, ref length); + } + + + /// + /// 设置连接的附加数据 + /// + /// + /// 如果为null,则为释放设置的数据 + /// + public void SetExtra(object obj) + { + // 释放附加数据 + IntPtr ptr = GetExtra(); + if (ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptr); + ptr = IntPtr.Zero; + } + + if (obj != null) + { + // 设置附加数据 + ptr = Marshal.AllocHGlobal(Marshal.SizeOf(obj)); + Marshal.StructureToPtr(obj, ptr, false); + } + HPSocketSdk.HP_Client_SetExtra(pClient, ptr); + } + + /// + /// 获取附加数据 + /// 如设置的是个结构体/类对象,可以用 Type objA = (Type)Marshal.PtrToStructure(ptr, typeof(Type)) 获取 + /// 其中Type是结构体/类名,ptr是该方法的传出值,在该方法返回为true的时候可用 + /// + /// + /// + /// + public IntPtr GetExtra() + { + return HPSocketSdk.HP_Client_GetExtra(pClient); + } + + /// + /// 获取监听socket的地址信息 + /// + /// + /// + /// + /// + public bool GetListenAddress(ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Client_GetLocalAddress(pClient, sb, ref ipLength, ref port); + if (ret == true) + { + ip = sb.ToString(); + } + return ret; + } + + /// + /// 是否启动 + /// + public bool IsStarted + { + get + { + if (pClient == IntPtr.Zero) + { + return false; + } + return HPSocketSdk.HP_Client_HasStarted(pClient); + } + } + + /// + /// 状态 + /// + public ServiceState State + { + get + { + return HPSocketSdk.HP_Client_GetState(pClient); + } + + } + + /// + /// 获取该组件对象的连接Id + /// + public IntPtr ConnectionId + { + get + { + return HPSocketSdk.HP_Client_GetConnectionID(pClient); + } + + } + /////////////////////////////////////////////////////////////////////////////////////// + + /// + /// 读取或设置内存块缓存池大小(通常设置为 -> PUSH 模型:5 - 10;PULL 模型:10 - 20 ) + /// + public uint FreeBufferPoolSize + { + get + { + return HPSocketSdk.HP_Client_GetFreeBufferPoolSize(pClient); + } + set + { + HPSocketSdk.HP_Client_SetFreeBufferPoolSize(pClient, value); + } + } + + /// + /// 读取或设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + public uint FreeBufferPoolHold + { + get + { + return HPSocketSdk.HP_Client_GetFreeBufferPoolHold(pClient); + } + set + { + HPSocketSdk.HP_Client_SetFreeBufferPoolHold(pClient, value); + } + } + + /// + /// 根据错误码返回错误信息 + /// + /// + /// + public string GetSocketErrorDesc(SocketError code) + { + IntPtr ptr = HPSocketSdk.HP_GetSocketErrorDesc(code); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + + /////////////////////////////////////////////////////////////////////////////////////// + HPSocketCS.SDK.HPSocketSdk.OnPrepareConnect _OnPrepareConnect = null; + HPSocketCS.SDK.HPSocketSdk.OnConnect _OnConnect = null; + HPSocketCS.SDK.HPSocketSdk.OnReceive _OnReceive = null; + HPSocketCS.SDK.HPSocketSdk.OnSend _OnSend = null; + HPSocketCS.SDK.HPSocketSdk.OnClose _OnClose = null; + /// + /// 设置回调函数 + /// + protected virtual void SetCallback() + { + // 设置 Socket 监听器回调函数 + _OnPrepareConnect = new HPSocketSdk.OnPrepareConnect(SDK_OnPrepareConnect); + _OnConnect = new HPSocketSdk.OnConnect(SDK_OnConnect); + _OnSend = new HPSocketSdk.OnSend(SDK_OnSend); + _OnReceive = new HPSocketSdk.OnReceive(SDK_OnReceive); + _OnClose = new HPSocketSdk.OnClose(SDK_OnClose); + + HPSocketSdk.HP_Set_FN_Client_OnPrepareConnect(pListener, _OnPrepareConnect); + HPSocketSdk.HP_Set_FN_Client_OnConnect(pListener, _OnConnect); + HPSocketSdk.HP_Set_FN_Client_OnSend(pListener, _OnSend); + HPSocketSdk.HP_Set_FN_Client_OnReceive(pListener, _OnReceive); + HPSocketSdk.HP_Set_FN_Client_OnClose(pListener, _OnClose); + } + + protected HandleResult SDK_OnPrepareConnect(IntPtr pClient, uint socket) + { + if (OnPrepareConnect != null) + { + return OnPrepareConnect(this, socket); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnConnect(IntPtr pClient) + { + if (OnConnect != null) + { + return OnConnect(this); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnSend(IntPtr pClient, IntPtr pData, int length) + { + if (OnSend != null) + { + return OnSend(this, pData, length); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnReceive(IntPtr pClient, IntPtr pData, int length) + { + if (OnReceive != null) + { + return OnReceive(this, pData, length); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnClose(IntPtr pClient, SocketOperation enOperation, int errorCode) + { + if (OnClose != null) + { + return OnClose(this, enOperation, errorCode); + } + return HandleResult.Ignore; + } + + /////////////////////////////////////////////////////////////////////////// + + /// + /// 获取系统返回的错误码 + /// + public int SYSGetLastError() + { + return HPSocketSdk.SYS_GetLastError(); + } + + /// + /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码 + /// + public int SYSWSAGetLastError() + { + return HPSocketSdk.SYS_WSAGetLastError(); + } + + /// + /// 调用系统的 setsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len) + { + return HPSocketSdk.SYS_SetSocketOption(sock, level, name, val, len); + } + + /// + /// 调用系统的 getsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYSGetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len) + { + return HPSocketSdk.SYS_GetSocketOption(sock, level, name, val, ref len); + } + /// + /// 调用系统的 ioctlsocket() + /// + /// + /// + /// + /// + /// + public int SYSIoctlSocket(IntPtr sock, long cmd, IntPtr arg) + { + return HPSocketSdk.SYS_IoctlSocket(sock, cmd, arg); + } + + /// + /// 调用系统的 ::WSAIoctl() + /// + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer, + IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned) + { + return HPSocketSdk.SYS_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, + lpvOutBuffer, cbOutBuffer, lpcbBytesReturned); + } + + /// + /// 由结构体转换为byte数组 + /// + public byte[] StructureToByte(T structure) + { + int size = Marshal.SizeOf(typeof(T)); + byte[] buffer = new byte[size]; + IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(structure, bufferIntPtr, true); + Marshal.Copy(bufferIntPtr, buffer, 0, size); + } + finally + { + Marshal.FreeHGlobal(bufferIntPtr); + } + return buffer; + } + + /// + /// 由byte数组转换为结构体 + /// + public T ByteToStructure(byte[] dataBuffer) + { + object structure = null; + int size = Marshal.SizeOf(typeof(T)); + IntPtr allocIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.Copy(dataBuffer, 0, allocIntPtr, size); + structure = Marshal.PtrToStructure(allocIntPtr, typeof(T)); + } + finally + { + Marshal.FreeHGlobal(allocIntPtr); + } + return (T)structure; + } + + /// + /// 对象序列化成byte[] + /// + /// + /// + public byte[] ObjectToBytes(object obj) + { + using (MemoryStream ms = new MemoryStream()) + { + IFormatter formatter = new BinaryFormatter(); + formatter.Serialize(ms, obj); + return ms.GetBuffer(); + } + } + + /// + /// byte[]序列化成对象 + /// + /// + /// + public object BytesToObject(byte[] bytes) + { + using (MemoryStream ms = new MemoryStream(bytes)) + { + IFormatter formatter = new BinaryFormatter(); + return formatter.Deserialize(ms); + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpServer.cs new file mode 100644 index 000000000..baf02b98b --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/HPSocketCS/UdpServer.cs @@ -0,0 +1,919 @@ +using System; +using System.Text; +using System.Runtime.InteropServices; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using System.Runtime.Serialization; +using HPSocketCS.SDK; + +namespace HPSocketCS +{ + public class UdpServerEvent + { + public delegate HandleResult OnSendEventHandler(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnReceiveEventHandler(IntPtr connId, IntPtr pData, int length); + public delegate HandleResult OnCloseEventHandler(IntPtr connId, SocketOperation enOperation, int errorCode); + public delegate HandleResult OnShutdownEventHandler(); + public delegate HandleResult OnPrepareListenEventHandler(IntPtr soListen); + public delegate HandleResult OnAcceptEventHandler(IntPtr connId, IntPtr pClient); + } + + public class UdpServer + { + protected IntPtr _pServer = IntPtr.Zero; + protected IntPtr pServer + { + get + { + return _pServer; + } + + set + { + _pServer = value; + } + } + + protected IntPtr pListener = IntPtr.Zero; + + + /// + /// 服务器ip + /// + public string IpAddress { get; set; } + + /// + /// 服务器端口 + /// + public ushort Port { get; set; } + + /// + /// 连接到达事件 + /// + public event UdpServerEvent.OnAcceptEventHandler OnAccept; + /// + /// 数据包发送事件 + /// + public event UdpServerEvent.OnSendEventHandler OnSend; + /// + /// 准备监听了事件 + /// + public event UdpServerEvent.OnPrepareListenEventHandler OnPrepareListen; + /// + /// 数据到达事件 + /// + public event UdpServerEvent.OnReceiveEventHandler OnReceive; + /// + /// 连接关闭事件 + /// + public event UdpServerEvent.OnCloseEventHandler OnClose; + /// + /// 服务器关闭事件 + /// + public event UdpServerEvent.OnShutdownEventHandler OnShutdown; + + protected bool IsCreate = false; + + /// + /// udpserver构造 + /// + public UdpServer() + { + CreateListener(); + } + + ~UdpServer() + { + Destroy(); + } + + /// + /// 创建socket监听&服务组件 + /// + /// 是否使用udpserver类默认回调函数 + /// + protected virtual bool CreateListener() + { + if (IsCreate == true || pListener != IntPtr.Zero || pServer != IntPtr.Zero) + { + return false; + } + + pListener = HPSocketSdk.Create_HP_UdpServerListener(); + if (pListener == IntPtr.Zero) + { + return false; + } + pServer = HPSocketSdk.Create_HP_UdpServer(pListener); + if (pServer == IntPtr.Zero) + { + return false; + } + + IsCreate = true; + + return true; + } + + /// + /// 释放UdpServer和UdpServerListener + /// + public virtual void Destroy() + { + Stop(); + + if (pServer != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_UdpServer(pServer); + pServer = IntPtr.Zero; + } + if (pListener != IntPtr.Zero) + { + HPSocketSdk.Destroy_HP_UdpServerListener(pListener); + pListener = IntPtr.Zero; + } + + IsCreate = false; + } + + + /// + /// 启动服务 + /// + /// + /// + /// + public bool Start() + { + if (IsStarted == true) + { + return false; + } + + SetCallback(); + + return HPSocketSdk.HP_Server_Start(pServer, IpAddress, Port); + } + + /// + /// 停止服务 + /// + /// + public bool Stop() + { + if (IsStarted == false) + { + return false; + } + + return HPSocketSdk.HP_Server_Stop(pServer); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, byte[] bytes, int size) + { + return HPSocketSdk.HP_Server_Send(pServer, connId, bytes, size); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, IntPtr bufferPtr, int size) + { + return HPSocketSdk.HP_Server_Send(pServer, connId, bufferPtr, size); + } + + + /// + /// 发送数据 + /// + /// + /// + /// 针对bytes的偏移 + /// 发多大 + /// + public bool Send(IntPtr connId, byte[] bytes, int offset, int size) + { + return HPSocketSdk.HP_Server_SendPart(pServer, connId, bytes, size, offset); + } + + /// + /// 发送数据 + /// + /// + /// + /// 针对bufferPtr的偏移 + /// 发多大 + /// + public bool Send(IntPtr connId, IntPtr bufferPtr, int offset, int size) + { + return HPSocketSdk.HP_Server_SendPart(pServer, connId, bufferPtr, size, offset); + } + + /// + /// 发送数据 + /// + /// + /// + /// + /// + public bool Send(IntPtr connId, T obj) + { + byte[] buffer = StructureToByte(obj); + return Send(connId, buffer, buffer.Length); + } + + /// + /// 序列化对象后发送数据,序列化对象所属类必须标记[Serializable] + /// + /// + /// + /// + /// + public bool SendBySerializable(IntPtr connId, object obj) + { + byte[] buffer = ObjectToBytes(obj); + return Send(connId, buffer, buffer.Length); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// UDP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(IntPtr connId, WSABUF[] pBuffers, int count) + { + return HPSocketSdk.HP_Server_SendPackets(pServer, connId, pBuffers, count); + } + + /// + /// 发送多组数据 + /// 向指定连接发送多组数据 + /// UDP - 顺序发送所有数据包 + /// + /// 连接 ID + /// 发送缓冲区数组 + /// 发送缓冲区数目 + /// TRUE.成功,FALSE.失败,可通过 SYSGetLastError() 获取 Windows 错误代码 + public bool SendPackets(IntPtr connId, T[] objects) + { + bool ret = false; + + WSABUF[] buffer = new WSABUF[objects.Length]; + IntPtr[] ptrs = new IntPtr[buffer.Length]; + try + { + + for (int i = 0; i < objects.Length; i++) + { + buffer[i].Length = Marshal.SizeOf(typeof(T)); + + ptrs[i] = Marshal.AllocHGlobal(buffer[i].Length); + Marshal.StructureToPtr(objects[i], ptrs[i], true); + + buffer[i].Buffer = ptrs[i]; + } + ret = SendPackets(connId, buffer, buffer.Length); + } + catch (Exception ex) + { + throw ex; + } + finally + { + for (int i = 0; i < ptrs.Length; i++) + { + if (ptrs[i] != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptrs[i]); + } + } + } + + return ret; + } + + /// + /// 断开与某个客户的连接 + /// + /// + /// 是否强制断开 + /// + public bool Disconnect(IntPtr connId, bool force = true) + { + return HPSocketSdk.HP_Server_Disconnect(pServer, connId, force); + } + + /// + /// 断开超过指定时间的连接 + /// + /// 毫秒 + /// 强制 + /// + public bool DisconnectLongConnections(uint period, bool force = true) + { + return HPSocketSdk.HP_Server_DisconnectLongConnections(pServer, period, force); + } + + /// + /// 断开超过指定时长的静默连接 + /// + /// 毫秒 + /// 强制 + /// + public bool DisconnectSilenceConnections(uint period, bool force = true) + { + return HPSocketSdk.HP_Server_DisconnectSilenceConnections(pServer, period, force); + } + + /// + /// 获取某个连接的远程ip和端口 + /// + /// + /// + /// + /// + public bool GetRemoteAddress(IntPtr connId, ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Server_GetRemoteAddress(pServer, connId, sb, ref ipLength, ref port) && ipLength > 0; + if (ret == true) + { + ip = sb.ToString(); + } + + return ret; + } + + + /// + /// 获取连接中未发出数据的长度 + /// + /// + /// + /// + public bool GetPendingDataLength(IntPtr connId, ref int length) + { + return HPSocketSdk.HP_Server_GetPendingDataLength(pServer, connId, ref length); + } + + /// + /// 设置连接的附加数据 + /// + /// + /// 如果为null,则为释放设置的数据 + /// + public bool SetConnectionExtra(IntPtr connId, object obj) + { + + IntPtr ptr = IntPtr.Zero; + // 释放附加数据 + if (HPSocketSdk.HP_Server_GetConnectionExtra(pServer, connId, ref ptr) && ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptr); + ptr = IntPtr.Zero; + } + + if (obj != null) + { + // 设置附加数据 + ptr = Marshal.AllocHGlobal(Marshal.SizeOf(obj)); + Marshal.StructureToPtr(obj, ptr, false); + } + + return HPSocketSdk.HP_Server_SetConnectionExtra(pServer, connId, ptr); + } + + /// + /// 获取附加数据 + /// 如设置的是个结构体/类对象,可以用 Type objA = (Type)Marshal.PtrToStructure(ptr, typeof(Type)) 获取 + /// 其中Type是结构体/类名,ptr是该方法的传出值,在该方法返回为true的时候可用 + /// + /// + /// + /// + public bool GetConnectionExtra(IntPtr connId, ref IntPtr ptr) + { + return HPSocketSdk.HP_Server_GetConnectionExtra(pServer, connId, ref ptr) && ptr != IntPtr.Zero; + } + + // 是否启动 + public bool IsStarted + { + get + { + if (pServer == IntPtr.Zero) + { + return false; + } + return HPSocketSdk.HP_Server_HasStarted(pServer); + } + } + + /// + /// 状态 + /// + public ServiceState State + { + get + { + return HPSocketSdk.HP_Server_GetState(pServer); + } + + } + + /// + /// 连接数 + /// + public uint ConnectionCount + { + get + { + return HPSocketSdk.HP_Server_GetConnectionCount(pServer); + } + + } + + /// + /// 获取所有连接,未获取到连接返回null + /// + /// + public IntPtr[] GetAllConnectionIDs() + { + IntPtr[] arr = null; + do + { + uint count = ConnectionCount; + if (count == 0) + { + break; + } + arr = new IntPtr[count]; + if (HPSocketSdk.HP_Server_GetAllConnectionIDs(pServer, arr, ref count)) + { + if (arr.Length > count) + { + IntPtr[] newArr = new IntPtr[count]; + Array.Copy(arr, newArr, count); + arr = newArr; + } + break; + } + } while (true); + + return arr; + } + + /// + /// 获取监听socket的地址信息 + /// + /// + /// + /// + public bool GetListenAddress(ref string ip, ref ushort port) + { + int ipLength = 40; + + StringBuilder sb = new StringBuilder(ipLength); + + bool ret = HPSocketSdk.HP_Server_GetListenAddress(pServer, sb, ref ipLength, ref port); + if (ret == true) + { + ip = sb.ToString(); + } + return ret; + } + + /// + /// 获取指定连接的连接时长(毫秒) + /// + /// + /// + /// + public bool GetConnectPeriod(IntPtr connId, ref uint period) + { + return HPSocketSdk.HP_Server_GetConnectPeriod(pServer, connId, ref period); + } + + /// + /// 获取某个连接静默时间(毫秒) + /// + /// + /// + /// + public bool GetSilencePeriod(IntPtr connId, ref uint period) + { + return HPSocketSdk.HP_Server_GetSilencePeriod(pServer, connId, ref period); + } + + /////////////////////////////////////////////////////////////////////////////////////// + + /// + /// 读取或设置工作线程数量(通常设置为 2 * CPU + 2) + /// + public uint WorkerThreadCount + { + get + { + return HPSocketSdk.HP_Server_GetWorkerThreadCount(pServer); + } + set + { + HPSocketSdk.HP_Server_SetWorkerThreadCount(pServer, value); + } + } + + /// + /// 读取或设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用) + /// + public uint FreeSocketObjLockTime + { + get + { + return HPSocketSdk.HP_Server_GetFreeSocketObjLockTime(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeSocketObjLockTime(pServer, value); + } + } + + /// + /// 读取或设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2) + /// + public uint FreeSocketObjPool + { + get + { + return HPSocketSdk.HP_Server_GetFreeSocketObjPool(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeSocketObjPool(pServer, value); + } + } + + /// + /// 读取或设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍) + /// + public uint FreeBufferObjPool + { + get + { + return HPSocketSdk.HP_Server_GetFreeBufferObjPool(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeBufferObjPool(pServer, value); + } + } + + /// + /// 读取或设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍) + /// + public uint FreeSocketObjHold + { + get + { + return HPSocketSdk.HP_Server_GetFreeSocketObjHold(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeSocketObjHold(pServer, value); + } + } + + /// + /// 读取或设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍) + /// + public uint FreeBufferObjHold + { + get + { + return HPSocketSdk.HP_Server_GetFreeBufferObjHold(pServer); + } + set + { + HPSocketSdk.HP_Server_SetFreeBufferObjHold(pServer, value); + } + } + + /// + /// 读取或设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE) + /// + public bool MarkSilence + { + get + { + return HPSocketSdk.HP_Server_IsMarkSilence(pServer); + } + set + { + HPSocketSdk.HP_Server_SetMarkSilence(pServer, value); + } + } + + /// + /// 获取或设置数据发送策略 + /// + public SendPolicy SendPolicy + { + get + { + return HPSocketSdk.HP_Server_GetSendPolicy(pServer); + } + set + { + HPSocketSdk.HP_Server_SetSendPolicy(pServer, value); + } + } + + + + /////////////////////////////////////////////////////////////////////////////////////// + + /// + /// 获取系统返回的错误码 + /// + public int SYSGetLastError() + { + return HPSocketSdk.SYS_GetLastError(); + } + + /// + /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码 + /// + public int SYSWSAGetLastError() + { + return HPSocketSdk.SYS_WSAGetLastError(); + } + + /// + /// 获取错误码 + /// + public SocketError ErrorCode + { + get + { + return HPSocketSdk.HP_Server_GetLastError(pServer); + } + } + + /// + /// 获取错误信息 + /// + public string ErrorMessage + { + get + { + IntPtr ptr = HPSocketSdk.HP_Server_GetLastErrorDesc(pServer); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + } + + + /////////////////////////////////////////////////////////////////////////////////////// + HPSocketCS.SDK.HPSocketSdk.OnPrepareListen _OnPrepareListen = null; + HPSocketCS.SDK.HPSocketSdk.OnAccept _OnAccept = null; + HPSocketCS.SDK.HPSocketSdk.OnReceive _OnReceive = null; + HPSocketCS.SDK.HPSocketSdk.OnSend _OnSend = null; + HPSocketCS.SDK.HPSocketSdk.OnClose _OnClose = null; + HPSocketCS.SDK.HPSocketSdk.OnShutdown _OnShutdown = null; + + protected virtual void SetCallback() + { + _OnPrepareListen = new HPSocketSdk.OnPrepareListen(SDK_OnPrepareListen); + _OnAccept = new HPSocketSdk.OnAccept(SDK_OnAccept); + _OnSend = new HPSocketSdk.OnSend(SDK_OnSend); + _OnReceive = new HPSocketSdk.OnReceive(SDK_OnReceive); + _OnClose = new HPSocketSdk.OnClose(SDK_OnClose); + _OnShutdown = new HPSocketSdk.OnShutdown(SDK_OnShutdown); + + HPSocketSdk.HP_Set_FN_Server_OnPrepareListen(pListener, _OnPrepareListen); + HPSocketSdk.HP_Set_FN_Server_OnAccept(pListener, _OnAccept); + HPSocketSdk.HP_Set_FN_Server_OnSend(pListener, _OnSend); + HPSocketSdk.HP_Set_FN_Server_OnReceive(pListener, _OnReceive); + HPSocketSdk.HP_Set_FN_Server_OnClose(pListener, _OnClose); + HPSocketSdk.HP_Set_FN_Server_OnShutdown(pListener, _OnShutdown); + } + + + protected HandleResult SDK_OnPrepareListen(IntPtr soListen) + { + if (OnPrepareListen != null) + { + OnPrepareListen(soListen); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnAccept(IntPtr connId, IntPtr pClient) + { + if (OnAccept != null) + { + OnAccept(connId, pClient); + } + + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnSend(IntPtr connId, IntPtr pData, int length) + { + if (OnSend != null) + { + OnSend(connId, pData, length); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnReceive(IntPtr connId, IntPtr pData, int length) + { + if (OnReceive != null) + { + OnReceive(connId, pData, length); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if (OnClose != null) + { + OnClose(connId, enOperation, errorCode); + } + return HandleResult.Ignore; + } + + protected HandleResult SDK_OnShutdown() + { + if (OnShutdown != null) + { + OnShutdown(); + } + return HandleResult.Ignore; + } + + + ///////////////////////////////////////////////////////////////////////// + + /// + /// 根据错误码返回错误信息 + /// + /// + /// + public string GetSocketErrorDesc(SocketError code) + { + IntPtr ptr = HPSocketSdk.HP_GetSocketErrorDesc(code); + string desc = Marshal.PtrToStringUni(ptr); + return desc; + } + + + /// + /// 调用系统的 setsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len) + { + return HPSocketSdk.SYS_SetSocketOption(sock, level, name, val, len); + } + + /// + /// 调用系统的 getsockopt() + /// + /// + /// + /// + /// + /// + /// + /// + public int SYSGetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len) + { + return HPSocketSdk.SYS_GetSocketOption(sock, level, name, val, ref len); + } + /// + /// 调用系统的 ioctlsocket() + /// + /// + /// + /// + /// + /// + public int SYSIoctlSocket(IntPtr sock, long cmd, IntPtr arg) + { + return HPSocketSdk.SYS_IoctlSocket(sock, cmd, arg); + } + + /// + /// 调用系统的 ::WSAIoctl() + /// + /// + /// + /// + /// + /// + /// + /// + /// + public int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer, + IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned) + { + return HPSocketSdk.SYS_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, + lpvOutBuffer, cbOutBuffer, lpcbBytesReturned); + } + + /// + /// 由结构体转换为byte数组 + /// + public byte[] StructureToByte(T structure) + { + int size = Marshal.SizeOf(typeof(T)); + byte[] buffer = new byte[size]; + IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.StructureToPtr(structure, bufferIntPtr, true); + Marshal.Copy(bufferIntPtr, buffer, 0, size); + } + finally + { + Marshal.FreeHGlobal(bufferIntPtr); + } + return buffer; + } + + /// + /// 由byte数组转换为结构体 + /// + public T ByteToStructure(byte[] dataBuffer) + { + object structure = null; + int size = Marshal.SizeOf(typeof(T)); + IntPtr allocIntPtr = Marshal.AllocHGlobal(size); + try + { + Marshal.Copy(dataBuffer, 0, allocIntPtr, size); + structure = Marshal.PtrToStructure(allocIntPtr, typeof(T)); + } + finally + { + Marshal.FreeHGlobal(allocIntPtr); + } + return (T)structure; + } + + /// + /// 对象序列化成byte[] + /// + /// + /// + public byte[] ObjectToBytes(object obj) + { + using (MemoryStream ms = new MemoryStream()) + { + IFormatter formatter = new BinaryFormatter(); + formatter.Serialize(ms, obj); + return ms.GetBuffer(); + } + } + + /// + /// byte[]序列化成对象 + /// + /// + /// + public object BytesToObject(byte[] bytes) + { + using (MemoryStream ms = new MemoryStream(bytes)) + { + IFormatter formatter = new BinaryFormatter(); + return formatter.Deserialize(ms); + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Program.cs new file mode 100644 index 000000000..4fccde30d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpClient_PFM +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmClient()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..8b60a6022 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("TcpClient-PMF")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TcpClient-PMF")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("217b3b79-8789-49a0-b8bd-9e65a6ac63f3")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Resources.Designer.cs new file mode 100644 index 000000000..54c4a76e1 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.18444 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpClient_PFM.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpClient_PFM.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Settings.Designer.cs new file mode 100644 index 000000000..e32131dea --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.18444 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpClient_PFM.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/TcpClient-PFM.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/TcpClient-PFM.csproj new file mode 100644 index 000000000..f2ece938d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/TcpClient-PFM.csproj @@ -0,0 +1,122 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {9A2CEAF1-95CF-4E7D-91D5-42DB1F3FD29A} + WinExe + Properties + TcpClient_PFM + TcpClient-PFM + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpClient-PFM.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpClient-PFM.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + + + + + + + + + + + + + + Form + + + frmClient.cs + + + + + frmClient.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.Designer.cs new file mode 100644 index 000000000..5b06812ca --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.Designer.cs @@ -0,0 +1,291 @@ +namespace TcpClient_PFM +{ + partial class frmClient + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.cbxTestTime = new System.Windows.Forms.ComboBox(); + this.cbxTestInterv = new System.Windows.Forms.ComboBox(); + this.cbxThreadInterv = new System.Windows.Forms.ComboBox(); + this.cbxThreadCount = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.cbxDataLength = new System.Windows.Forms.ComboBox(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtIpAddress = new System.Windows.Forms.TextBox(); + this.btnStop = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(25, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(71, 12); + this.label1.TabIndex = 0; + this.label1.Text = "Test Times:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(19, 41); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(77, 12); + this.label2.TabIndex = 1; + this.label2.Text = "Test Interv:"; + // + // cbxTestTime + // + this.cbxTestTime.FormattingEnabled = true; + this.cbxTestTime.Items.AddRange(new object[] { + "1", + "5", + "10", + "30", + "50", + "100", + "300", + "500", + "1000"}); + this.cbxTestTime.Location = new System.Drawing.Point(101, 11); + this.cbxTestTime.Name = "cbxTestTime"; + this.cbxTestTime.Size = new System.Drawing.Size(82, 20); + this.cbxTestTime.TabIndex = 2; + // + // cbxTestInterv + // + this.cbxTestInterv.FormattingEnabled = true; + this.cbxTestInterv.Items.AddRange(new object[] { + "0", + "1", + "3", + "5", + "10", + "20", + "30", + "60", + "100"}); + this.cbxTestInterv.Location = new System.Drawing.Point(101, 38); + this.cbxTestInterv.Name = "cbxTestInterv"; + this.cbxTestInterv.Size = new System.Drawing.Size(82, 20); + this.cbxTestInterv.TabIndex = 3; + // + // cbxThreadInterv + // + this.cbxThreadInterv.FormattingEnabled = true; + this.cbxThreadInterv.Items.AddRange(new object[] { + "0", + "1", + "3", + "5", + "10", + "20", + "30", + "60", + "100"}); + this.cbxThreadInterv.Location = new System.Drawing.Point(303, 38); + this.cbxThreadInterv.Name = "cbxThreadInterv"; + this.cbxThreadInterv.Size = new System.Drawing.Size(82, 20); + this.cbxThreadInterv.TabIndex = 7; + // + // cbxThreadCount + // + this.cbxThreadCount.FormattingEnabled = true; + this.cbxThreadCount.Items.AddRange(new object[] { + "1", + "5", + "10", + "30", + "50", + "100", + "300", + "500", + "1000"}); + this.cbxThreadCount.Location = new System.Drawing.Point(303, 11); + this.cbxThreadCount.Name = "cbxThreadCount"; + this.cbxThreadCount.Size = new System.Drawing.Size(82, 20); + this.cbxThreadCount.TabIndex = 6; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(209, 41); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(89, 12); + this.label3.TabIndex = 5; + this.label3.Text = "Thread Interv:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(215, 15); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(83, 12); + this.label4.TabIndex = 4; + this.label4.Text = "Thread Count:"; + // + // cbxDataLength + // + this.cbxDataLength.FormattingEnabled = true; + this.cbxDataLength.Items.AddRange(new object[] { + "1", + "10", + "100", + "1000", + "3000", + "5000", + "10000"}); + this.cbxDataLength.Location = new System.Drawing.Point(500, 11); + this.cbxDataLength.Name = "cbxDataLength"; + this.cbxDataLength.Size = new System.Drawing.Size(82, 20); + this.cbxDataLength.TabIndex = 9; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(418, 15); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(77, 12); + this.label5.TabIndex = 8; + this.label5.Text = "Data Length:"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(399, 41); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(191, 12); + this.label6.TabIndex = 10; + this.label6.Text = "\'Interv\' is to slow down speed "; + // + // lbxMsg + // + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(21, 67); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(561, 352); + this.lbxMsg.TabIndex = 11; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(331, 430); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(40, 21); + this.txtPort.TabIndex = 16; + this.txtPort.Text = "5555"; + // + // txtIpAddress + // + this.txtIpAddress.Location = new System.Drawing.Point(227, 430); + this.txtIpAddress.Name = "txtIpAddress"; + this.txtIpAddress.Size = new System.Drawing.Size(98, 21); + this.txtIpAddress.TabIndex = 15; + this.txtIpAddress.Text = "127.0.0.1"; + // + // btnStop + // + this.btnStop.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.btnStop.Location = new System.Drawing.Point(476, 426); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(106, 26); + this.btnStop.TabIndex = 14; + this.btnStop.Text = "Stop && Check"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // btnStart + // + this.btnStart.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.btnStart.Location = new System.Drawing.Point(397, 426); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(73, 26); + this.btnStart.TabIndex = 13; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // frmClient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(600, 458); + this.Controls.Add(this.txtPort); + this.Controls.Add(this.txtIpAddress); + this.Controls.Add(this.btnStop); + this.Controls.Add(this.btnStart); + this.Controls.Add(this.lbxMsg); + this.Controls.Add(this.label6); + this.Controls.Add(this.cbxDataLength); + this.Controls.Add(this.label5); + this.Controls.Add(this.cbxThreadInterv); + this.Controls.Add(this.cbxThreadCount); + this.Controls.Add(this.label3); + this.Controls.Add(this.label4); + this.Controls.Add(this.cbxTestInterv); + this.Controls.Add(this.cbxTestTime); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Name = "frmClient"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Echo-PFM Client [ \'C\' - clear list box ]"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmClient_FormClosing); + this.Load += new System.EventHandler(this.frmClient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox cbxTestTime; + private System.Windows.Forms.ComboBox cbxTestInterv; + private System.Windows.Forms.ComboBox cbxThreadInterv; + private System.Windows.Forms.ComboBox cbxThreadCount; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.ComboBox cbxDataLength; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.TextBox txtPort; + private System.Windows.Forms.TextBox txtIpAddress; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Button btnStart; + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.cs new file mode 100644 index 000000000..e922f130a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.cs @@ -0,0 +1,392 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Threading; +using System.Diagnostics; +using HPSocketCS; + +namespace TcpClient_PFM +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public partial class frmClient : Form + { + private AppState appState = AppState.Stoped; + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + + Stopwatch StopWatch = new Stopwatch(); + + int TestTimes = 0; + int TestInterv = 0; + int ThreadCount = 0; + int ThreadInterv = 0; + int DataLength = 0; + + long Timeconsuming = 0; + Int64 TotalReceived = 0; + Int64 TotalSent = 0; + Int64 ExpectReceived = 0; + + Thread testThread = null; + + List clientList = new List(); + + public frmClient() + { + InitializeComponent(); + } + + private void frmClient_Load(object sender, EventArgs e) + { + + // 初始化测试值 + this.cbxTestTime.SelectedIndex = 5; + this.cbxTestInterv.SelectedIndex = 1; + this.cbxThreadInterv.SelectedIndex = 0; + this.cbxThreadCount.SelectedIndex = 5; + this.cbxDataLength.SelectedIndex = 5; + + try + { + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + SetAppState(AppState.Stoped); + + AddMsg("提示:32位系统和程序,调整参数时,组合包的【大小】不要超过系统支持的内存。"); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + private bool CheckParams() + { + bool ret = false; + if (TestTimes <= 0) + { + this.cbxTestTime.Focus(); + } + else if (TestInterv < 0) + { + this.cbxTestInterv.Focus(); + } + else if (ThreadCount <= 0) + { + this.cbxThreadCount.Focus(); + } + else if (ThreadInterv < 0) + { + this.cbxThreadInterv.Focus(); + } + else if (DataLength <= 0) + { + this.cbxDataLength.Focus(); + } + else + { + ret = true; + } + + return ret; + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + string address = this.txtIpAddress.Text.Trim(); + ushort port = ushort.Parse(this.txtPort.Text.Trim()); + TestTimes = int.Parse(this.cbxTestTime.Text.Trim()); + TestInterv = int.Parse(this.cbxTestInterv.Text.Trim()); + ThreadCount = int.Parse(this.cbxThreadCount.Text.Trim()); + ThreadInterv = int.Parse(this.cbxThreadInterv.Text.Trim()); + DataLength = int.Parse(this.cbxDataLength.Text.Trim()); + if (CheckParams() == false) + { + throw new Exception("params error!"); + } + + SetAppState(AppState.Starting); + + Timeconsuming = 0; + TotalReceived = 0; + TotalSent = 0; + ExpectReceived = (Int64)TestTimes * (Int64)ThreadCount * (Int64)DataLength; + + clientList.Clear(); + + // 创建指定线程个数的客户端 + for (int i = 0; i < ThreadCount; i++) + { + TcpClient client = new TcpClient(); + + // 设置client事件 + client.OnPrepareConnect += new TcpClientEvent.OnPrepareConnectEventHandler(OnPrepareConnect); + client.OnConnect += new TcpClientEvent.OnConnectEventHandler(OnConnect); + client.OnSend += new TcpClientEvent.OnSendEventHandler(OnSend); + client.OnReceive += new TcpClientEvent.OnReceiveEventHandler(OnReceive); + client.OnClose += new TcpClientEvent.OnCloseEventHandler(OnClose); + + if (client.Connetion(address, port) == true) + { + clientList.Add(client); + } + else + { + foreach (var c in clientList) + { + c.Stop(); + } + clientList.Clear(); + throw new Exception(string.Format(" > {2}, Connection to server fail ->({0},{1})", client.ErrorCode, client.ErrorMessage, i)); + } + } + + AddMsg(string.Format("$ Client start ok -> ({0}:{1})", address, port)); + + // 延迟3秒 + int sendDelay = 3; + AddMsg(string.Format(" *** willing to send data after {0} seconds ...", sendDelay)); + // Delay2(sendDelay * 1000); + + SetAppState(AppState.Started); + + testThread = new Thread(delegate() + { + Thread.Sleep(sendDelay * 1000); + AddMsg(string.Format(" *** begin... ***", sendDelay)); + // 发送的数据包 + byte[] sendBytes = new byte[DataLength]; + + + StopWatch.Restart(); + bool isTerminated = false; + for (int i = 0; i < TestTimes; i++) + { + for (int j = 0; j < ThreadCount; j++) + { + TcpClient client = clientList[j]; + if (client.Send(sendBytes, sendBytes.Length) == false) + { + AddMsg(string.Format("$ Client send fail [sock: {0}, seq: {1}] -> {3} ({2})", + i + 1, + j + 1, + client.SYSGetLastError(), + client.GetSocketErrorDesc(SocketError.DataSend))); + isTerminated = true; + break; + } + + if (ThreadInterv > 0 && j + 1 < ThreadCount) + { + Thread.Sleep(ThreadInterv); + //Delay2(ThreadInterv); + } + } + + if (isTerminated == true) + { + break; + } + + if (TestInterv > 0 && i + 1 < TestTimes) + { + Thread.Sleep(TestInterv); + //Delay2(TestInterv); + } + } + }); + testThread.Start(); + } + catch (Exception ex) + { + SetAppState(AppState.Stoped); + AddMsg(string.Format("$ Start fail msg:{0}", ex.Message)); + } + } + + private void btnStop_Click(object sender, EventArgs e) + { + SetAppState(AppState.Stoping); + + for (int i = 0; i < clientList.Count; i++) + { + if (clientList[i].Stop() == true) + { + AddMsg(string.Format("$ Client stopping ... --> ({0})", i + 1)); + } + } + + if (testThread.ThreadState == System.Threading.ThreadState.Running) + { + testThread.Abort(); + } + + Delay2(100); + + AddMsg(string.Format("*** Summary: expect - {0}, send - {1}, recv - {2}", + ExpectReceived, TotalSent, TotalReceived)); + + if (ExpectReceived == TotalSent && TotalSent == TotalReceived) + { + AddMsg(string.Format(" *** Success: time consuming - {0} millisecond !", Timeconsuming)); + } + else + { + AddMsg("*** Fail: manual terminated ? (or data lost)"); + } + + SetAppState(AppState.Stoped); + } + + HandleResult OnPrepareConnect(TcpClient sender, uint socket) + { + return HandleResult.Ok; + } + + HandleResult OnConnect(TcpClient sender) + { + // 已连接 到达一次 + AddMsg(string.Format(" > [{0}, OnConnect]", sender.ConnectionId)); + return HandleResult.Ok; + } + + HandleResult OnSend(TcpClient sender, IntPtr pData, int length) + { + // 客户端发数据了 + Interlocked.Add(ref TotalSent, length); + return HandleResult.Ok; + } + + HandleResult OnReceive(TcpClient sender, IntPtr pData, int length) + { + // 数据到达了 + + Interlocked.Add(ref TotalReceived, length); + if (TotalReceived == ExpectReceived) + { + StopWatch.Stop(); + Timeconsuming = StopWatch.ElapsedMilliseconds; + AddMsg(string.Format("Total time consuming: {0}", Timeconsuming)); + } + + return HandleResult.Ok; + } + + HandleResult OnClose(TcpClient sender, SocketOperation enOperation, int errorCode) + { + // 连接关闭了 + return HandleResult.Ok; + } + + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtIpAddress.Enabled = (appState == AppState.Stoped); + this.txtPort.Enabled = (appState == AppState.Stoped); + this.cbxTestTime.Enabled = (appState == AppState.Stoped); + this.cbxTestInterv.Enabled = (appState == AppState.Stoped); + this.cbxThreadInterv.Enabled = (appState == AppState.Stoped); + this.cbxThreadCount.Enabled = (appState == AppState.Stoped); + this.cbxDataLength.Enabled = (appState == AppState.Stoped); + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + public delegate void SleepDelegate(int num); + + /// + /// 精确延迟,摘自网络 + /// + /// + private void Delay1(long time) + { + long b = DateTime.Now.Ticks / 10000; + long e = 0; long c = 0; ; + do + { + e = DateTime.Now.Ticks / 10000; + c = e - b; + Application.DoEvents(); + } + while (c < time); + } + + private void AsyncDelay(int time) + { + Thread.Sleep(time); + } + + /// + /// 精确延迟,摘自网络 + /// + /// + private void Delay2(int time) + { + SleepDelegate delay = new SleepDelegate(AsyncDelay); + IAsyncResult ar = delay.BeginInvoke(time, null, null); + while (ar.IsCompleted == false) + { + Application.DoEvents(); + } + delay.EndInvoke(ar); + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + } + + private void frmClient_FormClosing(object sender, FormClosingEventArgs e) + { + if (appState == AppState.Started) + { + btnStop_Click(sender, e); + } + } + + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient-PFM/frmClient.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Program.cs new file mode 100644 index 000000000..23e05d625 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpClientNS +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmClient()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..6b85d6a51 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Client")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Client")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("0b4a498a-774e-4250-bf80-a05682b557fb")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Resources.Designer.cs new file mode 100644 index 000000000..200e7eec9 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpClientNS.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpClientNS.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Settings.Designer.cs new file mode 100644 index 000000000..df43ecd02 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpClientNS.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/TcpClient.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/TcpClient.csproj new file mode 100644 index 000000000..7c1051894 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/TcpClient.csproj @@ -0,0 +1,127 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {B6E43918-236A-4EA7-84C8-ED4A98049907} + WinExe + Properties + TcpClientNS + TcpClient + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + false + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpClient.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + true + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + true + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpClient.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + true + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + true + + + + + + + + + + + + + + + + Form + + + frmClient.cs + + + + + frmClient.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.Designer.cs new file mode 100644 index 000000000..baea9c6c4 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.Designer.cs @@ -0,0 +1,205 @@ +namespace TcpClientNS +{ + partial class frmClient + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.cbxAsyncConn = new System.Windows.Forms.CheckBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtIpAddress = new System.Windows.Forms.TextBox(); + this.btnStop = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.txtSend = new System.Windows.Forms.TextBox(); + this.btnSend = new System.Windows.Forms.Button(); + this.btnSendFile = new System.Windows.Forms.Button(); + this.btnSendSerializableObject = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.cbxAsyncConn); + this.groupBox1.Controls.Add(this.txtPort); + this.groupBox1.Controls.Add(this.txtIpAddress); + this.groupBox1.Controls.Add(this.btnStop); + this.groupBox1.Controls.Add(this.btnStart); + this.groupBox1.Location = new System.Drawing.Point(12, 2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(464, 47); + this.groupBox1.TabIndex = 11; + this.groupBox1.TabStop = false; + // + // cbxAsyncConn + // + this.cbxAsyncConn.AutoSize = true; + this.cbxAsyncConn.Checked = true; + this.cbxAsyncConn.CheckState = System.Windows.Forms.CheckState.Checked; + this.cbxAsyncConn.Location = new System.Drawing.Point(134, 20); + this.cbxAsyncConn.Name = "cbxAsyncConn"; + this.cbxAsyncConn.Size = new System.Drawing.Size(84, 16); + this.cbxAsyncConn.TabIndex = 13; + this.cbxAsyncConn.Text = "Async Conn"; + this.cbxAsyncConn.UseVisualStyleBackColor = true; + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(88, 18); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(40, 21); + this.txtPort.TabIndex = 12; + this.txtPort.Text = "5555"; + // + // txtIpAddress + // + this.txtIpAddress.Location = new System.Drawing.Point(11, 18); + this.txtIpAddress.Name = "txtIpAddress"; + this.txtIpAddress.Size = new System.Drawing.Size(71, 21); + this.txtIpAddress.TabIndex = 11; + this.txtIpAddress.Text = "127.0.0.1"; + // + // btnStop + // + this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStop.Location = new System.Drawing.Point(407, 15); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(47, 26); + this.btnStop.TabIndex = 10; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // btnStart + // + this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStart.Location = new System.Drawing.Point(354, 15); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(47, 26); + this.btnStart.TabIndex = 9; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // lbxMsg + // + this.lbxMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(12, 63); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(465, 244); + this.lbxMsg.TabIndex = 10; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // txtSend + // + this.txtSend.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtSend.Location = new System.Drawing.Point(11, 321); + this.txtSend.Name = "txtSend"; + this.txtSend.Size = new System.Drawing.Size(413, 21); + this.txtSend.TabIndex = 12; + this.txtSend.Text = "text to be sent"; + // + // btnSend + // + this.btnSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSend.Location = new System.Drawing.Point(430, 317); + this.btnSend.Name = "btnSend"; + this.btnSend.Size = new System.Drawing.Size(47, 26); + this.btnSend.TabIndex = 13; + this.btnSend.Text = "Send"; + this.btnSend.UseVisualStyleBackColor = true; + this.btnSend.Click += new System.EventHandler(this.btnSend_Click); + // + // btnSendFile + // + this.btnSendFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSendFile.Location = new System.Drawing.Point(206, 348); + this.btnSendFile.Name = "btnSendFile"; + this.btnSendFile.Size = new System.Drawing.Size(75, 26); + this.btnSendFile.TabIndex = 14; + this.btnSendFile.Text = "Send file"; + this.btnSendFile.UseVisualStyleBackColor = true; + this.btnSendFile.Click += new System.EventHandler(this.btnSendFile_Click); + // + // btnSendSerializableObject + // + this.btnSendSerializableObject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSendSerializableObject.Location = new System.Drawing.Point(313, 348); + this.btnSendSerializableObject.Name = "btnSendSerializableObject"; + this.btnSendSerializableObject.Size = new System.Drawing.Size(163, 26); + this.btnSendSerializableObject.TabIndex = 15; + this.btnSendSerializableObject.Text = "Send serializable object"; + this.btnSendSerializableObject.UseVisualStyleBackColor = true; + this.btnSendSerializableObject.Click += new System.EventHandler(this.btnSendSerializableObject_Click); + // + // frmClient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(485, 378); + this.Controls.Add(this.btnSendSerializableObject); + this.Controls.Add(this.btnSendFile); + this.Controls.Add(this.btnSend); + this.Controls.Add(this.txtSend); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.lbxMsg); + this.Name = "frmClient"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Echo-TcpClient [ \'C\' - clear list box ]"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmClient_FormClosed); + this.Load += new System.EventHandler(this.frmClient_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox txtPort; + private System.Windows.Forms.TextBox txtIpAddress; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.CheckBox cbxAsyncConn; + private System.Windows.Forms.TextBox txtSend; + private System.Windows.Forms.Button btnSend; + private System.Windows.Forms.Button btnSendFile; + private System.Windows.Forms.Button btnSendSerializableObject; + + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.cs new file mode 100644 index 000000000..800392bf2 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.cs @@ -0,0 +1,544 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using HPSocketCS; +using System.Runtime.InteropServices; +using System.IO; +using System.Threading; + +namespace TcpClientNS +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public enum StudentType + { + None, Array, List, Single, + } + + public partial class frmClient : Form + { + private AppState appState = AppState.Stoped; + + private delegate void ConnectUpdateUiDelegate(); + private delegate void SetAppStateDelegate(AppState state); + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + HPSocketCS.TcpClient client = new HPSocketCS.TcpClient(); + + bool isSendFile = false; + StudentType studentType = StudentType.None; + public frmClient() + { + InitializeComponent(); + } + + private void frmClient_Load(object sender, EventArgs e) + { + try + { + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + // 设置client事件 + client.OnPrepareConnect += new TcpClientEvent.OnPrepareConnectEventHandler(OnPrepareConnect); + client.OnConnect += new TcpClientEvent.OnConnectEventHandler(OnConnect); + client.OnSend += new TcpClientEvent.OnSendEventHandler(OnSend); + client.OnReceive += new TcpClientEvent.OnReceiveEventHandler(OnReceive); + client.OnClose += new TcpClientEvent.OnCloseEventHandler(OnClose); + + SetAppState(AppState.Stoped); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + String ip = this.txtIpAddress.Text.Trim(); + ushort port = ushort.Parse(this.txtPort.Text.Trim()); + + // 写在这个位置是上面可能会异常 + SetAppState(AppState.Starting); + + AddMsg(string.Format("$Client Starting ... -> ({0}:{1})", ip, port)); + + if (client.Connetion(ip, port, this.cbxAsyncConn.Checked)) + { + if (cbxAsyncConn.Checked == false) + { + SetAppState(AppState.Started); + } + + AddMsg(string.Format("$Client Start OK -> ({0}:{1})", ip, port)); + } + else + { + SetAppState(AppState.Stoped); + throw new Exception(string.Format("$Client Start Error -> {0}({1})", client.ErrorMessage, client.ErrorCode)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + private void btnStop_Click(object sender, EventArgs e) + { + + // 停止服务 + AddMsg("$Server Stop"); + if (client.Stop()) + { + SetAppState(AppState.Stoped); + } + else + { + AddMsg(string.Format("$Stop Error -> {0}({1})", client.ErrorMessage, client.ErrorCode)); + } + } + + private void btnSend_Click(object sender, EventArgs e) + { + try + { + string send = this.txtSend.Text; + if (send.Length == 0) + { + return; + } + + byte[] bytes = Encoding.Default.GetBytes(send); + IntPtr connId = client.ConnectionId; + + // 发送 + if (client.Send(bytes, bytes.Length)) + { + AddMsg(string.Format("$ ({0}) Send OK --> {1}", connId, send)); + } + else + { + AddMsg(string.Format("$ ({0}) Send Fail --> {1} ({2})", connId, send, bytes.Length)); + } + + } + catch (Exception ex) + { + AddMsg(string.Format("$ Send Fail --> msg ({0})", ex.Message)); + } + + } + + private void btnSendSerializableObject_Click(object sender, EventArgs e) + { + try + { + // 注: 对象序列化发送数据较大 + + if (studentType != StudentType.None) + { + // 正在执行 + throw new Exception("being implemented"); + } + + + + IntPtr connId = client.ConnectionId; + + Thread thread = new Thread(new ThreadStart(delegate() + { + Student[] students = new Student[2]; + students[0] = new Student(); + students[0].Id = 1; + students[0].Name = "张三"; + students[0].Sex = Sex.Female; + students[1] = new Student(); + students[1].Id = 2; + students[1].Name = "李四"; + students[1].Sex = Sex.Male; + + // 发送数组对象 + studentType = StudentType.Array; + if (client.SendBySerializable(students)) + { + AddMsg(string.Format("$ ({0}) Send OK --> {1}", connId, "Student[]")); + } + else + { + AddMsg(string.Format("$ ({0}) Send Fail --> {1}", connId, "Student[]")); + } + + //////////////////////////////////////////////////////////////////////////////// + + // 改变性别 + students[0].Sex = Sex.Transsexual; + + List stuList = new List(); + stuList.Add(students[0]); + stuList.Add(students[1]); + + // 防止粘包,延迟2秒发送下一组数据 + AddMsg(" *** 2 seconds after sending ..."); + Thread.Sleep(2000); + + // 发送list对象 + studentType = StudentType.List; + if (client.SendBySerializable(stuList)) + { + AddMsg(string.Format("$ ({0}) Send OK --> {1}", connId, "List")); + } + else + { + AddMsg(string.Format("$ ({0}) Send Fail --> {1}", connId, "List")); + } + + //////////////////////////////////////////////////////////////////////////////// + + // 防止粘包,延迟2秒发送下一组数据 + AddMsg(" *** 2 seconds after sending ..."); + Thread.Sleep(2000); + + // 改变性别 + students[0].Sex = Sex.Unknown; + + // 发送单个学员信息 + studentType = StudentType.Single; + if (client.SendBySerializable(students[0])) + { + AddMsg(string.Format("$ ({0}) Send OK --> {1}", connId, "Student")); + } + else + { + AddMsg(string.Format("$ ({0}) Send Fail --> {1}", connId, "Student")); + } + + })); + thread.Start(); + } + catch (Exception ex) + { + studentType = StudentType.None; + AddMsg(string.Format("$ Send Fail --> msg ({0})", ex.Message)); + } + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + } + + void ConnectUpdateUi() + { + if (this.cbxAsyncConn.Checked == true) + { + SetAppState(AppState.Started); + } + } + + + private bool SendFileToServer(string filePath) + { + FileInfo fi = new FileInfo(filePath); + if (fi.Length > 4096 * 1024) + { + throw new Exception("被发送文件大小不能超过4096KB。"); + } + else if (fi.Length == 0) + { + throw new Exception("文件大小不能为0。"); + } + + // 头附加数据 + MyFileInfo myFile = new MyFileInfo() + { + FilePath = filePath, + FileSize = fi.Length, + }; + + // 发送文件标记,用来在onrecv里判断是否文件回包 + isSendFile = true; + + // 不附加尾数据 + bool ret = client.SendSmallFile(filePath, myFile, null); + if (ret == false) + { + isSendFile = false; + int error = client.SYSGetLastError(); + AddMsg(string.Format(" > [SendSmallFile] errorCode:{0}", error)); + } + + return ret; + } + + HandleResult OnPrepareConnect(TcpClient sender, uint socket) + { + return HandleResult.Ok; + } + + HandleResult OnConnect(TcpClient sender) + { + // 已连接 到达一次 + + // 如果是异步联接,更新界面状态 + this.Invoke(new ConnectUpdateUiDelegate(ConnectUpdateUi)); + + AddMsg(string.Format(" > [{0},OnConnect]", sender.ConnectionId)); + + return HandleResult.Ok; + } + + HandleResult OnSend(TcpClient sender, IntPtr pData, int length) + { + // 客户端发数据了 + AddMsg(string.Format(" > [{0},OnSend] -> ({1} bytes)", sender.ConnectionId, length)); + + return HandleResult.Ok; + } + + HandleResult OnReceive(TcpClient sender, IntPtr pData, int length) + { + // 数据到达了 + if (isSendFile == true) + { + // 如果发送了文件,并接收到了返回数据 + isSendFile = false; + MyFileInfo myFile = (MyFileInfo)Marshal.PtrToStructure(pData, typeof(MyFileInfo)); + int objSize = Marshal.SizeOf(myFile); + // 因为没有附加尾数据,所以大小可以用length - objSize + byte[] bytes = new byte[length - objSize]; + Marshal.Copy(pData + objSize, bytes, 0, length - objSize); + + string txt = Encoding.Default.GetString(bytes); + string msg = string.Empty; + if (txt.Length > 100) + { + msg = txt.Substring(0, 100) + "......"; + } + else + { + msg = txt; + } + + AddMsg(string.Format(" > [{0},OnReceive] -> FileInfo(Path:\"{1}\",Size:{2})", sender.ConnectionId, myFile.FilePath, myFile.FileSize)); + AddMsg(string.Format(" > [{0},OnReceive] -> FileContent(\"{1}\")", sender.ConnectionId, msg)); + } + else if (studentType != StudentType.None) + { + byte[] bytes = new byte[length]; + Marshal.Copy(pData, bytes, 0, length); + + switch (studentType) + { + case StudentType.Array: + Student[] students = sender.BytesToObject(bytes) as Student[]; + foreach (var stu in students) + { + AddMsg(string.Format(" > [{0},OnReceive] -> Student({1},{2},{3})", sender.ConnectionId, stu.Id, stu.Name, stu.GetSexString())); + } + break; + case StudentType.List: + List stuList = sender.BytesToObject(bytes) as List; + foreach (var stu in stuList) + { + AddMsg(string.Format(" > [{0},OnReceive] -> Student({1},{2},{3})", sender.ConnectionId, stu.Id, stu.Name, stu.GetSexString())); + } + break; + case StudentType.Single: + Student student = sender.BytesToObject(bytes) as Student; + AddMsg(string.Format(" > [{0},OnReceive] -> Student({1},{2},{3})", sender.ConnectionId, student.Id, student.Name, student.GetSexString())); + studentType = StudentType.None; + break; + } + } + else + { + AddMsg(string.Format(" > [{0},OnReceive] -> ({1} bytes)", sender.ConnectionId, length)); + } + + return HandleResult.Ok; + } + + HandleResult OnClose(TcpClient sender, SocketOperation enOperation, int errorCode) + { + if(errorCode == 0) + // 连接关闭了 + AddMsg(string.Format(" > [{0},OnClose]", sender.ConnectionId)); + else + // 出错了 + AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", sender.ConnectionId, enOperation, errorCode)); + + // 通知界面,只处理了连接错误,也没进行是不是连接错误的判断,所以有错误就会设置界面 + // 生产环境请自己控制 + this.Invoke(new SetAppStateDelegate(SetAppState), AppState.Stoped); + + return HandleResult.Ok; + } + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtIpAddress.Enabled = (appState == AppState.Stoped); + this.txtPort.Enabled = (appState == AppState.Stoped); + this.cbxAsyncConn.Enabled = (appState == AppState.Stoped); + this.btnSend.Enabled = (appState == AppState.Started); + this.btnSendFile.Enabled = (appState == AppState.Started); + this.btnSendSerializableObject.Enabled = (appState == AppState.Started); + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + private void frmClient_FormClosed(object sender, FormClosedEventArgs e) + { + client.Destroy(); + } + + + + private void btnSendFile_Click(object sender, EventArgs e) + { + try + { + + OpenFileDialog ofd = new OpenFileDialog(); + // ofd.InitialDirectory = "c:\\" ; + //ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; + ofd.Filter = "txt files (*.txt)|*.txt"; + ofd.RestoreDirectory = true; + ofd.CheckFileExists = true; + ofd.CheckPathExists = true; + if (ofd.ShowDialog() == DialogResult.OK) + { + SendFileToServer(ofd.FileName); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + + } + } + + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct MyFileInfo + { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)] + public string FilePath; + public long FileSize; + } + + /// + /// 学员性别 + /// + public enum Sex + { + /// + /// 男 + /// + Male = 1, + + /// + /// 女 + /// + Female = 2, + + /// + /// 变性人 + /// + Transsexual = 3, + + /// + /// 未知 + /// + Unknown = 4, + + } + + /// + /// 学员类 + /// + [Serializable] + public class Student + { + /// + /// 编号 + /// + public int Id { get; set; } + + /// + /// 姓名 + /// + public string Name { get; set; } + + /// + /// 性别 + /// + public Sex Sex { get; set; } + + public string GetSexString() + { + string sex = string.Empty; + switch (Sex) + { + case Sex.Male: + sex = "男"; + break; + case Sex.Female: + sex = "女"; + break; + case Sex.Transsexual: + sex = "变性人"; + break; + default: + sex = "未知"; + break; + } + return sex; + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpClient/frmClient.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Program.cs new file mode 100644 index 000000000..23e05d625 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpClientNS +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmClient()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..6b85d6a51 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Client")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Client")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("0b4a498a-774e-4250-bf80-a05682b557fb")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Resources.Designer.cs new file mode 100644 index 000000000..5b73c5ee5 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpPackClient.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpPackClient.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Settings.Designer.cs new file mode 100644 index 000000000..e16e503b8 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpPackClient.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/TcpPackClient.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/TcpPackClient.csproj new file mode 100644 index 000000000..b8a16cb8a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/TcpPackClient.csproj @@ -0,0 +1,127 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {36D05914-1A8A-484C-9FB7-8BE4582A665A} + WinExe + Properties + TcpPackClient + TcpPackClient + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + false + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpClient.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + true + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + true + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpClient.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + true + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + true + + + + + + + + + + + + + + + + Form + + + frmClient.cs + + + + + frmClient.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.Designer.cs new file mode 100644 index 000000000..3930b6b9b --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.Designer.cs @@ -0,0 +1,177 @@ +namespace TcpClientNS +{ + partial class frmClient + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.cbxAsyncConn = new System.Windows.Forms.CheckBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtIpAddress = new System.Windows.Forms.TextBox(); + this.btnStop = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.txtSend = new System.Windows.Forms.TextBox(); + this.btnSend = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.cbxAsyncConn); + this.groupBox1.Controls.Add(this.txtPort); + this.groupBox1.Controls.Add(this.txtIpAddress); + this.groupBox1.Controls.Add(this.btnStop); + this.groupBox1.Controls.Add(this.btnStart); + this.groupBox1.Location = new System.Drawing.Point(12, 2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(464, 47); + this.groupBox1.TabIndex = 11; + this.groupBox1.TabStop = false; + // + // cbxAsyncConn + // + this.cbxAsyncConn.AutoSize = true; + this.cbxAsyncConn.Checked = true; + this.cbxAsyncConn.CheckState = System.Windows.Forms.CheckState.Checked; + this.cbxAsyncConn.Location = new System.Drawing.Point(134, 20); + this.cbxAsyncConn.Name = "cbxAsyncConn"; + this.cbxAsyncConn.Size = new System.Drawing.Size(84, 16); + this.cbxAsyncConn.TabIndex = 13; + this.cbxAsyncConn.Text = "Async Conn"; + this.cbxAsyncConn.UseVisualStyleBackColor = true; + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(88, 18); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(40, 21); + this.txtPort.TabIndex = 12; + this.txtPort.Text = "5555"; + // + // txtIpAddress + // + this.txtIpAddress.Location = new System.Drawing.Point(11, 18); + this.txtIpAddress.Name = "txtIpAddress"; + this.txtIpAddress.Size = new System.Drawing.Size(71, 21); + this.txtIpAddress.TabIndex = 11; + this.txtIpAddress.Text = "127.0.0.1"; + // + // btnStop + // + this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStop.Location = new System.Drawing.Point(407, 15); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(47, 26); + this.btnStop.TabIndex = 10; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // btnStart + // + this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStart.Location = new System.Drawing.Point(354, 15); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(47, 26); + this.btnStart.TabIndex = 9; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // lbxMsg + // + this.lbxMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(12, 59); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(465, 256); + this.lbxMsg.TabIndex = 10; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // txtSend + // + this.txtSend.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtSend.Location = new System.Drawing.Point(12, 327); + this.txtSend.Name = "txtSend"; + this.txtSend.Size = new System.Drawing.Size(413, 21); + this.txtSend.TabIndex = 12; + this.txtSend.Text = "text to be sent"; + // + // btnSend + // + this.btnSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSend.Location = new System.Drawing.Point(431, 323); + this.btnSend.Name = "btnSend"; + this.btnSend.Size = new System.Drawing.Size(47, 26); + this.btnSend.TabIndex = 13; + this.btnSend.Text = "Send"; + this.btnSend.UseVisualStyleBackColor = true; + this.btnSend.Click += new System.EventHandler(this.btnSend_Click); + // + // frmClient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(485, 355); + this.Controls.Add(this.btnSend); + this.Controls.Add(this.txtSend); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.lbxMsg); + this.Name = "frmClient"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Echo-TcpPackClient [ \'C\' - clear list box ]"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmClient_FormClosed); + this.Load += new System.EventHandler(this.frmClient_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox txtPort; + private System.Windows.Forms.TextBox txtIpAddress; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.CheckBox cbxAsyncConn; + private System.Windows.Forms.TextBox txtSend; + private System.Windows.Forms.Button btnSend; + + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.cs new file mode 100644 index 000000000..5aeb312c3 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.cs @@ -0,0 +1,259 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using HPSocketCS; +using System.Runtime.InteropServices; +using System.IO; +using System.Threading; + +namespace TcpClientNS +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public enum StudentType + { + None, Array, List, Single, + } + + public partial class frmClient : Form + { + private AppState appState = AppState.Stoped; + + private delegate void ConnectUpdateUiDelegate(); + private delegate void SetAppStateDelegate(AppState state); + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + HPSocketCS.TcpPackClient client = new HPSocketCS.TcpPackClient(); + + public frmClient() + { + InitializeComponent(); + } + + private void frmClient_Load(object sender, EventArgs e) + { + try + { + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + // 设置client事件 + client.OnPrepareConnect += new TcpClientEvent.OnPrepareConnectEventHandler(OnPrepareConnect); + client.OnConnect += new TcpClientEvent.OnConnectEventHandler(OnConnect); + client.OnSend += new TcpClientEvent.OnSendEventHandler(OnSend); + client.OnReceive += new TcpClientEvent.OnReceiveEventHandler(OnReceive); + client.OnClose += new TcpClientEvent.OnCloseEventHandler(OnClose); + + // 设置包头标识,与对端设置保证一致性 + client.PackHeaderFlag = 0xff; + // 设置最大封包大小 + client.MaxPackSize = 0x1000; + + SetAppState(AppState.Stoped); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + String ip = this.txtIpAddress.Text.Trim(); + ushort port = ushort.Parse(this.txtPort.Text.Trim()); + + // 写在这个位置是上面可能会异常 + SetAppState(AppState.Starting); + + AddMsg(string.Format("$Client Starting ... -> ({0}:{1})", ip, port)); + + if (client.Connetion(ip, port, this.cbxAsyncConn.Checked)) + { + if (cbxAsyncConn.Checked == false) + { + SetAppState(AppState.Started); + } + + AddMsg(string.Format("$Client Start OK -> ({0}:{1})", ip, port)); + } + else + { + SetAppState(AppState.Stoped); + throw new Exception(string.Format("$Client Start Error -> {0}({1})", client.ErrorMessage, client.ErrorCode)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + private void btnStop_Click(object sender, EventArgs e) + { + + // 停止服务 + AddMsg("$Server Stop"); + if (client.Stop()) + { + SetAppState(AppState.Stoped); + } + else + { + AddMsg(string.Format("$Stop Error -> {0}({1})", client.ErrorMessage, client.ErrorCode)); + } + } + + private void btnSend_Click(object sender, EventArgs e) + { + try + { + string send = this.txtSend.Text; + if (send.Length == 0) + { + return; + } + + byte[] bytes = Encoding.Default.GetBytes(send); + IntPtr connId = client.ConnectionId; + + // 发送 + if (client.Send(bytes, bytes.Length)) + { + AddMsg(string.Format("$ ({0}) Send OK --> {1}", connId, send)); + } + else + { + AddMsg(string.Format("$ ({0}) Send Fail --> {1} ({2})", connId, send, bytes.Length)); + } + + } + catch (Exception ex) + { + AddMsg(string.Format("$ Send Fail --> msg ({0})", ex.Message)); + } + + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + } + + void ConnectUpdateUi() + { + if (this.cbxAsyncConn.Checked == true) + { + SetAppState(AppState.Started); + } + } + + HandleResult OnPrepareConnect(TcpClient sender, uint socket) + { + return HandleResult.Ok; + } + + HandleResult OnConnect(TcpClient sender) + { + // 已连接 到达一次 + + // 如果是异步联接,更新界面状态 + this.Invoke(new ConnectUpdateUiDelegate(ConnectUpdateUi)); + + AddMsg(string.Format(" > [{0},OnConnect]", sender.ConnectionId)); + + return HandleResult.Ok; + } + + HandleResult OnSend(TcpClient sender, IntPtr pData, int length) + { + // 客户端发数据了 + AddMsg(string.Format(" > [{0},OnSend] -> ({1} bytes)", sender.ConnectionId, length)); + + return HandleResult.Ok; + } + + HandleResult OnReceive(TcpClient sender, IntPtr pData, int length) + { + // 数据到达了 + + AddMsg(string.Format(" > [{0},OnReceive] -> ({1} bytes)", sender.ConnectionId, length)); + + return HandleResult.Ok; + } + + HandleResult OnClose(TcpClient sender, SocketOperation enOperation, int errorCode) + { + if (errorCode == 0) + // 连接关闭了 + AddMsg(string.Format(" > [{0},OnClose]", sender.ConnectionId)); + else + // 出错了 + AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", sender.ConnectionId, enOperation, errorCode)); + + // 通知界面,只处理了连接错误,也没进行是不是连接错误的判断,所以有错误就会设置界面 + // 生产环境请自己控制 + this.Invoke(new SetAppStateDelegate(SetAppState), AppState.Stoped); + + return HandleResult.Ok; + } + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtIpAddress.Enabled = (appState == AppState.Stoped); + this.txtPort.Enabled = (appState == AppState.Stoped); + this.cbxAsyncConn.Enabled = (appState == AppState.Stoped); + this.btnSend.Enabled = (appState == AppState.Started); + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + private void frmClient_FormClosed(object sender, FormClosedEventArgs e) + { + client.Destroy(); + } + + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackClient/frmClient.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Program.cs new file mode 100644 index 000000000..4a3923e91 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpServer_PFM +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmServer()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f99c7b3bd --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Server")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("a8f79261-fd62-4f4b-aed5-01bf44660ad1")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Resources.Designer.cs new file mode 100644 index 000000000..adf89766a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpPackServer.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpPackServer.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Settings.Designer.cs new file mode 100644 index 000000000..e4d003d9d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpPackServer.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/TcpPackServer.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/TcpPackServer.csproj new file mode 100644 index 000000000..b4272e2d5 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/TcpPackServer.csproj @@ -0,0 +1,122 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {2C7A6E29-980B-4A4C-9645-E2CA26FCEAAC} + WinExe + Properties + TcpPackServer + TcpPackServer + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpServer.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpServer.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + + + + + + + + + + + + + + Form + + + frmServer.cs + + + + + frmServer.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.Designer.cs new file mode 100644 index 000000000..cfd0ca76d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.Designer.cs @@ -0,0 +1,169 @@ +namespace TcpServer_PFM +{ + partial class frmServer + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label1 = new System.Windows.Forms.Label(); + this.btnDisconn = new System.Windows.Forms.Button(); + this.txtDisConn = new System.Windows.Forms.TextBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtIpAddress = new System.Windows.Forms.TextBox(); + this.btnStop = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // lbxMsg + // + this.lbxMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(11, 62); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(465, 304); + this.lbxMsg.TabIndex = 4; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.btnDisconn); + this.groupBox1.Controls.Add(this.txtDisConn); + this.groupBox1.Controls.Add(this.txtPort); + this.groupBox1.Controls.Add(this.txtIpAddress); + this.groupBox1.Controls.Add(this.btnStop); + this.groupBox1.Controls.Add(this.btnStart); + this.groupBox1.Location = new System.Drawing.Point(12, 2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(462, 47); + this.groupBox1.TabIndex = 9; + this.groupBox1.TabStop = false; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(132, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 15; + this.label1.Text = "CONNID"; + // + // btnDisconn + // + this.btnDisconn.Location = new System.Drawing.Point(223, 15); + this.btnDisconn.Name = "btnDisconn"; + this.btnDisconn.Size = new System.Drawing.Size(33, 26); + this.btnDisconn.TabIndex = 14; + this.btnDisconn.Text = "Dis"; + this.btnDisconn.UseVisualStyleBackColor = true; + this.btnDisconn.Click += new System.EventHandler(this.btnDisconn_Click); + // + // txtDisConn + // + this.txtDisConn.Location = new System.Drawing.Point(178, 18); + this.txtDisConn.Name = "txtDisConn"; + this.txtDisConn.Size = new System.Drawing.Size(40, 21); + this.txtDisConn.TabIndex = 13; + this.txtDisConn.TextChanged += new System.EventHandler(this.txtDisConn_TextChanged); + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(88, 18); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(40, 21); + this.txtPort.TabIndex = 12; + this.txtPort.Text = "5555"; + // + // txtIpAddress + // + this.txtIpAddress.Location = new System.Drawing.Point(11, 18); + this.txtIpAddress.Name = "txtIpAddress"; + this.txtIpAddress.Size = new System.Drawing.Size(71, 21); + this.txtIpAddress.TabIndex = 11; + this.txtIpAddress.Text = "0.0.0.0"; + // + // btnStop + // + this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStop.Location = new System.Drawing.Point(403, 15); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(47, 26); + this.btnStop.TabIndex = 10; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // btnStart + // + this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStart.Location = new System.Drawing.Point(350, 15); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(47, 26); + this.btnStart.TabIndex = 9; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // frmServer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(486, 377); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.lbxMsg); + this.Name = "frmServer"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmServer_FormClosed); + this.Load += new System.EventHandler(this.Form1_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnDisconn; + private System.Windows.Forms.TextBox txtDisConn; + private System.Windows.Forms.TextBox txtPort; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.TextBox txtIpAddress; + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.cs new file mode 100644 index 000000000..e911adda2 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.cs @@ -0,0 +1,317 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Runtime.InteropServices; +using HPSocketCS; + +namespace TcpServer_PFM +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public partial class frmServer : Form + { + private AppState appState = AppState.Stoped; + + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + + HPSocketCS.TcpPackServer server = new HPSocketCS.TcpPackServer(); + + private string title = "Echo TcpPackServer [ 'C' - clear list box ]"; + public frmServer() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + try + { + + this.Text = title; + // 本机测试没必要改地址,有需求请注释或删除 + this.txtIpAddress.ReadOnly = true; + + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + // 设置服务器事件 + server.OnPrepareListen += new TcpServerEvent.OnPrepareListenEventHandler(OnPrepareListen); + server.OnAccept += new TcpServerEvent.OnAcceptEventHandler(OnAccept); + server.OnSend += new TcpServerEvent.OnSendEventHandler(OnSend); + server.OnReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive); + server.OnClose += new TcpServerEvent.OnCloseEventHandler(OnClose); + server.OnShutdown += new TcpServerEvent.OnShutdownEventHandler(OnShutdown); + + // 设置包头标识,与对端设置保证一致性 + server.PackHeaderFlag = 0xff; + // 设置最大封包大小 + server.MaxPackSize = 0x1000; + + SetAppState(AppState.Stoped); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + String ip = this.txtIpAddress.Text.Trim(); + ushort port = ushort.Parse(this.txtPort.Text.Trim()); + + // 写在这个位置是上面可能会异常 + SetAppState(AppState.Starting); + server.IpAddress = ip; + server.Port = port; + // 启动服务 + if (server.Start()) + { + this.Text = string.Format("{2} - ({0}:{1})", ip, port, title); + SetAppState(AppState.Started); + AddMsg(string.Format("$Server Start OK -> ({0}:{1})", ip, port)); + } + else + { + SetAppState(AppState.Stoped); + throw new Exception(string.Format("$Server Start Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + private void btnStop_Click(object sender, EventArgs e) + { + SetAppState(AppState.Stoping); + + // 停止服务 + AddMsg("$Server Stop"); + if (server.Stop()) + { + this.Text = title; + SetAppState(AppState.Stoped); + } + else + { + AddMsg(string.Format("$Stop Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + } + } + + private void btnDisconn_Click(object sender, EventArgs e) + { + try + { + IntPtr connId = (IntPtr)Convert.ToInt32(this.txtDisConn.Text.Trim()); + // 断开指定客户 + if (server.Disconnect(connId, true)) + { + AddMsg(string.Format("$({0}) Disconnect OK", connId)); + } + else + { + throw new Exception(string.Format("Disconnect({0}) Error", connId)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + + HandleResult OnPrepareListen(IntPtr soListen) + { + // 监听事件到达了,一般没什么用吧? + + return HandleResult.Ok; + } + + HandleResult OnAccept(IntPtr connId, IntPtr pClient) + { + // 客户进入了 + + + // 获取客户端ip和端口 + string ip = string.Empty; + ushort port = 0; + if (server.GetRemoteAddress(connId, ref ip, ref port)) + { + AddMsg(string.Format(" > [{0},OnAccept] -> PASS({1}:{2})", connId, ip.ToString(), port)); + } + else + { + AddMsg(string.Format(" > [{0},OnAccept] -> Server_GetClientAddress() Error", connId)); + } + + + // 设置附加数据 + ClientInfo ci = new ClientInfo(); + ci.ConnId = connId; + ci.IpAddress = ip; + ci.Port = port; + if (server.SetConnectionExtra(connId, ci) == false) + { + AddMsg(string.Format(" > [{0},OnAccept] -> SetConnectionExtra fail", connId)); + } + + return HandleResult.Ok; + } + + HandleResult OnSend(IntPtr connId, IntPtr pData, int length) + { + // 服务器发数据了 + + + AddMsg(string.Format(" > [{0},OnSend] -> ({1} bytes)", connId, length)); + + return HandleResult.Ok; + } + + HandleResult OnReceive(IntPtr connId, IntPtr pData, int length) + { + // 数据到达了 + try + { + // 从pData中获取字符串 + // string str = Marshal.PtrToStringAnsi(pData, length); + + // intptr转byte[] + // byte[] bytes = new byte[length]; + // Marshal.Copy(pData, bytes, 0, length); + + + // 获取附加数据 + IntPtr clientPtr = IntPtr.Zero; + if (server.GetConnectionExtra(connId, ref clientPtr)) + { + // ci 就是accept里传入的附加数据了 + ClientInfo ci = (ClientInfo)Marshal.PtrToStructure(clientPtr, typeof(ClientInfo)); + AddMsg(string.Format(" > [{0},OnReceive] -> {1}:{2} ({3} bytes)", ci.ConnId, ci.IpAddress, ci.Port, length)); + } + else + { + AddMsg(string.Format(" > [{0},OnReceive] -> ({1} bytes)", connId, length)); + } + + if (server.Send(connId, pData, length)) + { + return HandleResult.Ok; + } + + return HandleResult.Error; + } + catch (Exception) + { + + return HandleResult.Ignore; + } + } + + HandleResult OnClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if(errorCode == 0) + AddMsg(string.Format(" > [{0},OnClose]", connId)); + else + AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode)); + // return HPSocketSdk.HandleResult.Ok; + + if (server.SetConnectionExtra(connId, null) == false) + { + AddMsg(string.Format(" > [{0},OnClose] -> SetConnectionExtra({0}, null) fail", connId)); + } + + return HandleResult.Ok; + } + + HandleResult OnShutdown() + { + // 服务关闭了 + + + AddMsg(" > [OnShutdown]"); + return HandleResult.Ok; + } + + + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtIpAddress.Enabled = (appState == AppState.Stoped); + this.txtPort.Enabled = (appState == AppState.Stoped); + this.txtDisConn.Enabled = (appState == AppState.Started); + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + private void txtDisConn_TextChanged(object sender, EventArgs e) + { + // CONNID框被改变事件 + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + } + + private void frmServer_FormClosed(object sender, FormClosedEventArgs e) + { + server.Destroy(); + } + } + + [StructLayout(LayoutKind.Sequential)] + public class ClientInfo + { + public IntPtr ConnId { get; set; } + public string IpAddress { get; set; } + public ushort Port { get; set; } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPackServer/frmServer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Program.cs new file mode 100644 index 000000000..3f5e79fc1 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpProxyServer +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmProxyServer()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..0ccc166c3 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("TcpProxyServer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TcpProxyServer")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("83e0db2e-c90a-4cd6-871e-83181027b537")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Resources.Designer.cs new file mode 100644 index 000000000..9869c2499 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.18444 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpProxyServer.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpProxyServer.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Settings.Designer.cs new file mode 100644 index 000000000..e79e77e2d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18444 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TcpProxyServer.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/ProxyServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/ProxyServer.cs new file mode 100644 index 000000000..a8e7cf308 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/ProxyServer.cs @@ -0,0 +1,408 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using HPSocketCS; +using System.Runtime.InteropServices; + +namespace TcpProxyServer +{ + public class ProxyServer + { + /// + /// 绑定地址 + /// + public string BindAddr { get; set; } + + /// + /// 绑定端口 + /// + public ushort BindPort { get; set; } + + /// + /// 目标地址 + /// + public string TargetAddr { get; set; } + + /// + /// 目标端口 + /// + public ushort TargetPort { get; set; } + + // 为了简单直接定义了一个支持log输出的委托 + public delegate void ShowMsg(string msg); + /// + /// 日志输出 + /// + public ShowMsg AddMsgDelegate; + + protected TcpServer server = new TcpServer(); + protected TcpAgent agent = new TcpAgent(); + + + public ProxyServer() + { + // 设置服务器事件 + server.OnPrepareListen += new TcpServerEvent.OnPrepareListenEventHandler(OnServerPrepareListen); + server.OnAccept += new TcpServerEvent.OnAcceptEventHandler(OnServerAccept); + server.OnSend += new TcpServerEvent.OnSendEventHandler(OnServerSend); + server.OnReceive += new TcpServerEvent.OnReceiveEventHandler(OnServerReceive); + server.OnClose += new TcpServerEvent.OnCloseEventHandler(OnServerClose); + server.OnShutdown += new TcpServerEvent.OnShutdownEventHandler(OnServerShutdown); + + + // 设置代理事件 + agent.OnPrepareConnect += new TcpAgentEvent.OnPrepareConnectEventHandler(OnAgentPrepareConnect); + agent.OnConnect += new TcpAgentEvent.OnConnectEventHandler(OnAgentConnect); + agent.OnSend += new TcpAgentEvent.OnSendEventHandler(OnAgentSend); + agent.OnReceive += new TcpAgentEvent.OnReceiveEventHandler(OnAgentReceive); + agent.OnClose += new TcpAgentEvent.OnCloseEventHandler(OnAgentClose); + agent.OnShutdown += new TcpAgentEvent.OnShutdownEventHandler(OnAgentShutdown); + + } + + public bool Start() + { + if (string.IsNullOrEmpty(BindAddr) || string.IsNullOrEmpty(TargetAddr) || + BindPort == 0 || TargetPort == 0 || AddMsgDelegate == null) + { + throw new Exception("请先设置属性[BindAddr,TargetAddr,BindPort,TargetPort,AddMsgDelegate]"); + } + + server.IpAddress = BindAddr; + server.Port = BindPort; + bool isStart = server.Start(); + if (isStart == false) + { + AddMsg(string.Format(" > Server start fail -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + return isStart; + } + + isStart = agent.Start(BindAddr, false); + if (isStart == false) + { + AddMsg(string.Format(" > Server start fail -> {0}({1})", agent.ErrorMessage, agent.ErrorCode)); + return isStart; + } + + return isStart; + } + + public bool Stop() + { + return server.Stop() && agent.Stop(); + } + + private void AddMsg(string msg) + { + AddMsgDelegate(msg); + } + + + public bool Disconnect(IntPtr connId, bool force = true) + { + return server.Disconnect(connId, force); + } + + //////////////////////////////Agent////////////////////////////////////////////////// + + /// + /// 准备连接了 + /// + /// + /// + /// + protected virtual HandleResult OnAgentPrepareConnect(IntPtr connId, uint socket) + { + return HandleResult.Ok; + } + + /// + /// 已连接 + /// + /// + /// + protected virtual HandleResult OnAgentConnect(IntPtr connId) + { + AddMsg(string.Format(" > [{0},OnAgentConnect]", connId)); + return HandleResult.Ok; + } + + /// + /// 客户端发数据了 + /// + /// + /// + /// + /// + protected virtual HandleResult OnAgentSend(IntPtr connId, IntPtr pData, int length) + { + AddMsg(string.Format(" > [{0},OnAgentSend] -> ({1} bytes)", connId, length)); + return HandleResult.Ok; + } + + /// + /// 数据到达了 + /// + /// + /// + /// + /// + protected virtual HandleResult OnAgentReceive(IntPtr connId, IntPtr pData, int length) + { + // 获取附加数据 + IntPtr extraPtr = IntPtr.Zero; + if (agent.GetConnectionExtra(connId, ref extraPtr) == false) + { + return HandleResult.Error; + } + + ConnExtraData extra = (ConnExtraData)Marshal.PtrToStructure(extraPtr, typeof(ConnExtraData)); + AddMsg(string.Format(" > [{0},OnAgentReceive] -> ({1} bytes)", connId, length)); + if (extra.Server.Send(extra.ConnIdForServer, pData, length) == false) + { + return HandleResult.Error; + } + + return HandleResult.Ok; + } + + /// + /// 出错了 + /// + /// + /// + /// + /// + protected virtual HandleResult OnAgentClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if(errorCode == 0) + AddMsg(string.Format(" > [{0},OnAgentClose]", connId)); + else + AddMsg(string.Format(" > [{0},OnAgentError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode)); + // return HPSocketSdk.HandleResult.Ok; + + // 获取附加数据 + IntPtr extraPtr = IntPtr.Zero; + if (agent.GetConnectionExtra(connId, ref extraPtr) == false) + { + return HandleResult.Error; + } + + ConnExtraData extra = (ConnExtraData)Marshal.PtrToStructure(extraPtr, typeof(ConnExtraData)); + + agent.SetConnectionExtra(connId, null); + + if (extra.FreeType == 0) + { + + // 由Target断开连接,释放server连接 + extra.FreeType = 1; + server.SetConnectionExtra(extra.ConnIdForServer, extra); + extra.Server.Disconnect(extra.ConnIdForServer); + } + + return HandleResult.Ok; + } + + /// + /// Agent关闭了 + /// + /// + protected virtual HandleResult OnAgentShutdown() + { + AddMsg(" > [OnAgentShutdown]"); + return HandleResult.Ok; + } + + //////////////////////////////Server////////////////////////////////////////////////// + + /// + /// 监听事件 + /// + /// + /// + protected virtual HandleResult OnServerPrepareListen(IntPtr soListen) + { + return HandleResult.Ok; + } + + /// + /// 客户进入 + /// + /// + /// + /// + protected virtual HandleResult OnServerAccept(IntPtr connId, IntPtr pClient) + { + // 获取客户端ip和端口 + string ip = string.Empty; + ushort port = 0; + if (server.GetRemoteAddress(connId, ref ip, ref port)) + { + AddMsg(string.Format(" > [{0},OnServerAccept] -> PASS({1}:{2})", connId, ip.ToString(), port)); + } + else + { + AddMsg(string.Format(" > [{0},OnServerAccept] -> Server_GetClientAddress() Error", connId)); + return HandleResult.Error; + } + + IntPtr clientConnId = IntPtr.Zero; + + // 一次不成功的事偶尔可能发生,三次连接都不成功,那就真连不上了 + // 当server有连接进入,使用agent连接到目标服务器 + if (agent.Connect(TargetAddr, TargetPort, ref clientConnId) == false) + { + if (agent.Connect(TargetAddr, TargetPort, ref clientConnId) == false) + { + if (agent.Connect(TargetAddr, TargetPort, ref clientConnId) == false) + { + AddMsg(string.Format(" > [Client->Connect] fail -> ID:{0}", clientConnId)); + return HandleResult.Error; + } + } + } + + + // 设置附加数据 + ConnExtraData extra = new ConnExtraData(); + extra.ConnIdForServer = connId; + extra.ConnIdForClient = clientConnId; + extra.Server = server; + extra.FreeType = 0; + if (server.SetConnectionExtra(connId, extra) == false) + { + AddMsg(string.Format(" > [{0},OnServerAccept] -> server.SetConnectionExtra fail", connId)); + return HandleResult.Error; + } + + if (agent.SetConnectionExtra(clientConnId, extra) == false) + { + server.SetConnectionExtra(connId, null); + AddMsg(string.Format(" > [{0}-{1},OnServerAccept] -> agent.SetConnectionExtra fail", connId, clientConnId)); + return HandleResult.Error; + } + + return HandleResult.Ok; + } + + /// + /// 服务器发数据了 + /// + /// + /// + /// + /// + protected virtual HandleResult OnServerSend(IntPtr connId, IntPtr pData, int length) + { + AddMsg(string.Format(" > [Server->OnServerSend] -> ({0} bytes)", length)); + return HandleResult.Ok; + } + + /// + /// 数据到达了 + /// + /// + /// + /// + /// + protected virtual HandleResult OnServerReceive(IntPtr connId, IntPtr pData, int length) + { + try + { + // 获取附加数据 + IntPtr extraPtr = IntPtr.Zero; + + if (server.GetConnectionExtra(connId, ref extraPtr) == false) + { + return HandleResult.Error; + } + + // extra 就是accept里传入的附加数据了 + ConnExtraData extra = (ConnExtraData)Marshal.PtrToStructure(extraPtr, typeof(ConnExtraData)); + + AddMsg(string.Format(" > [Server->OnServerReceive] -> ({0} bytes)", length)); + + // 服务端收到数据了,应该调用agent发送到顶层服务器,实现 client(N)->server->targetServer 的中转 + if (agent.Send(extra.ConnIdForClient, pData, length) == false) + { + return HandleResult.Error; + } + + return HandleResult.Ok; + + } + catch (Exception) + { + return HandleResult.Error; + } + + } + + /// + /// 出错了 + /// + /// + /// + /// + /// + protected virtual HandleResult OnServerClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if (errorCode == 0) + AddMsg(string.Format(" > [{0},OnServerClose]", connId)); + else + AddMsg(string.Format(" > [{0},OnServerError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode)); + // return HPSocketSdk.HandleResult.Ok; + + // 获取附加数据 + IntPtr extraPtr = IntPtr.Zero; + if (server.GetConnectionExtra(connId, ref extraPtr) == false) + { + return HandleResult.Error; + } + + // extra 就是accept里传入的附加数据了 + ConnExtraData extra = (ConnExtraData)Marshal.PtrToStructure(extraPtr, typeof(ConnExtraData)); + if (extra.FreeType == 0) + { + // 由client(N)断开连接,释放agent数据 + agent.Disconnect(extra.ConnIdForClient); + agent.SetConnectionExtra(extra.ConnIdForClient, null); + } + + server.SetConnectionExtra(connId, null); + + return HandleResult.Ok; + } + + /// + /// 服务关闭了 + /// + /// + protected virtual HandleResult OnServerShutdown() + { + AddMsg(" > [OnServerShutdown]"); + return HandleResult.Ok; + } + + //////////////////////////////////////////////////////////////////////////////// + } + + + [StructLayout(LayoutKind.Sequential)] + public class ConnExtraData + { + // server的CONNID + public IntPtr ConnIdForServer; + + // client的CONNID + public IntPtr ConnIdForClient; + + // 保存server端指针,方便在cclient里调用 + public TcpServer Server; + + // 释放方式 + public uint FreeType; + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/TcpProxyServer.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/TcpProxyServer.csproj new file mode 100644 index 000000000..b38a14435 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/TcpProxyServer.csproj @@ -0,0 +1,122 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {5FEB9E6D-2526-4F4F-957C-093D7FFB9B98} + WinExe + Properties + TcpProxyServer + TcpProxyServer + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpProxyServer.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpProxyServer.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + + + + + + + + + + + + + + Form + + + frmProxyServer.cs + + + + + + frmProxyServer.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.Designer.cs new file mode 100644 index 000000000..c407ebf67 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.Designer.cs @@ -0,0 +1,198 @@ +namespace TcpProxyServer +{ + partial class frmProxyServer + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.txtBindAddr = new System.Windows.Forms.TextBox(); + this.txtTargetAddr = new System.Windows.Forms.TextBox(); + this.txtBindPort = new System.Windows.Forms.TextBox(); + this.txtTargetPort = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtDisConn = new System.Windows.Forms.TextBox(); + this.btnDisconn = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.btnStop = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // lbxMsg + // + this.lbxMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(1, 1); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(474, 304); + this.lbxMsg.TabIndex = 5; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 319); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 6; + this.label1.Text = "Local:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 341); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(47, 12); + this.label2.TabIndex = 7; + this.label2.Text = "Target:"; + // + // txtBindAddr + // + this.txtBindAddr.Location = new System.Drawing.Point(60, 316); + this.txtBindAddr.Name = "txtBindAddr"; + this.txtBindAddr.Size = new System.Drawing.Size(100, 21); + this.txtBindAddr.TabIndex = 8; + this.txtBindAddr.Text = "0.0.0.0"; + // + // txtTargetAddr + // + this.txtTargetAddr.Location = new System.Drawing.Point(60, 343); + this.txtTargetAddr.Name = "txtTargetAddr"; + this.txtTargetAddr.Size = new System.Drawing.Size(100, 21); + this.txtTargetAddr.TabIndex = 9; + this.txtTargetAddr.Text = "127.0.0.1"; + // + // txtBindPort + // + this.txtBindPort.Location = new System.Drawing.Point(166, 316); + this.txtBindPort.Name = "txtBindPort"; + this.txtBindPort.Size = new System.Drawing.Size(48, 21); + this.txtBindPort.TabIndex = 10; + this.txtBindPort.Text = "7000"; + // + // txtTargetPort + // + this.txtTargetPort.Location = new System.Drawing.Point(166, 343); + this.txtTargetPort.Name = "txtTargetPort"; + this.txtTargetPort.Size = new System.Drawing.Size(48, 21); + this.txtTargetPort.TabIndex = 11; + this.txtTargetPort.Text = "5555"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(221, 336); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(47, 12); + this.label3.TabIndex = 12; + this.label3.Text = "CONNID:"; + // + // txtDisConn + // + this.txtDisConn.Location = new System.Drawing.Point(274, 332); + this.txtDisConn.Name = "txtDisConn"; + this.txtDisConn.Size = new System.Drawing.Size(47, 21); + this.txtDisConn.TabIndex = 13; + this.txtDisConn.TextChanged += new System.EventHandler(this.txtDisConn_TextChanged); + // + // btnDisconn + // + this.btnDisconn.Location = new System.Drawing.Point(328, 331); + this.btnDisconn.Name = "btnDisconn"; + this.btnDisconn.Size = new System.Drawing.Size(61, 23); + this.btnDisconn.TabIndex = 14; + this.btnDisconn.Text = "Dis conn"; + this.btnDisconn.UseVisualStyleBackColor = true; + this.btnDisconn.Click += new System.EventHandler(this.btnDisconn_Click); + // + // btnStart + // + this.btnStart.Location = new System.Drawing.Point(412, 314); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(61, 23); + this.btnStart.TabIndex = 15; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // btnStop + // + this.btnStop.Location = new System.Drawing.Point(412, 343); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(61, 23); + this.btnStop.TabIndex = 16; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // frmProxyServer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(475, 370); + this.Controls.Add(this.btnStop); + this.Controls.Add(this.btnStart); + this.Controls.Add(this.btnDisconn); + this.Controls.Add(this.txtDisConn); + this.Controls.Add(this.label3); + this.Controls.Add(this.txtTargetPort); + this.Controls.Add(this.txtBindPort); + this.Controls.Add(this.txtTargetAddr); + this.Controls.Add(this.txtBindAddr); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.lbxMsg); + this.Name = "frmProxyServer"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "ProxyServer [ \'C\' - clear list box ]"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmProxyServer_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtBindAddr; + private System.Windows.Forms.TextBox txtTargetAddr; + private System.Windows.Forms.TextBox txtBindPort; + private System.Windows.Forms.TextBox txtTargetPort; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtDisConn; + private System.Windows.Forms.Button btnDisconn; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.Button btnStop; + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.cs new file mode 100644 index 000000000..ccef4d8e5 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.cs @@ -0,0 +1,182 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace TcpProxyServer +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public partial class frmProxyServer : Form + { + private AppState appState = AppState.Stoped; + + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + + private ProxyServer proxyServer = null; + + + public frmProxyServer() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + try + { + proxyServer = new ProxyServer(); + + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + proxyServer.AddMsgDelegate = new ProxyServer.ShowMsg(AddMsg); + + SetAppState(AppState.Stoped); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtBindAddr.Enabled = (appState == AppState.Stoped); + this.txtBindPort.Enabled = (appState == AppState.Stoped); + this.txtTargetAddr.Enabled = (appState == AppState.Stoped); + this.txtTargetPort.Enabled = (appState == AppState.Stoped); + this.txtDisConn.Enabled = (appState == AppState.Started); + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + private void txtDisConn_TextChanged(object sender, EventArgs e) + { + // CONNID框被改变事件 + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + proxyServer.BindAddr = this.txtBindAddr.Text.Trim(); + proxyServer.BindPort = ushort.Parse(this.txtBindPort.Text.Trim()); + proxyServer.TargetAddr = this.txtTargetAddr.Text.Trim(); + proxyServer.TargetPort = ushort.Parse(this.txtTargetPort.Text.Trim()); + + // 写在这个位置是上面可能会异常 + SetAppState(AppState.Starting); + + // 启动服务 + if (proxyServer.Start()) + { + SetAppState(AppState.Started); + AddMsg(string.Format("$Server Start OK -> ({0}:{1}->{2}:{3})", + proxyServer.BindAddr, proxyServer.BindPort, + proxyServer.TargetAddr, proxyServer.TargetPort)); + } + else + { + SetAppState(AppState.Stoped); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + private void btnDisconn_Click(object sender, EventArgs e) + { + try + { + IntPtr connId = (IntPtr)Convert.ToUInt32(this.txtDisConn.Text.Trim()); + + // 断开指定客户 + if (proxyServer.Disconnect(connId)) + { + AddMsg(string.Format("$({0}) Disconnect OK", connId)); + } + else + { + throw new Exception(string.Format("Disconnect({0}) Error", connId)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + private void btnStop_Click(object sender, EventArgs e) + { + SetAppState(AppState.Stoping); + + // 停止服务 + AddMsg("$Server Stop"); + if (proxyServer.Stop()) + { + SetAppState(AppState.Stoped); + } + else + { + AddMsg("$Stop Error"); + } + } + + private void frmProxyServer_FormClosing(object sender, FormClosingEventArgs e) + { + proxyServer.Stop(); + } + + } + +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpProxyServer/frmProxyServer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Program.cs new file mode 100644 index 000000000..69739075d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpPullClientNS +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmClient()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..6b85d6a51 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Client")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Client")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("0b4a498a-774e-4250-bf80-a05682b557fb")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Resources.Designer.cs new file mode 100644 index 000000000..a4504581c --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18444 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TcpPullClientNS.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpPullClientNS.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Settings.Designer.cs new file mode 100644 index 000000000..a28edfc05 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18444 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TcpPullClientNS.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/TcpPullClient.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/TcpPullClient.csproj new file mode 100644 index 000000000..88881005b --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/TcpPullClient.csproj @@ -0,0 +1,127 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {B9965E66-853A-47CC-B0C9-197B5A29ABFC} + WinExe + Properties + TcpPullClientNS + TcpPullClient + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + false + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpPullClient.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + true + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + true + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpPullClient.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + true + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + true + + + + + + + + + + + + + + + + Form + + + frmClient.cs + + + + + frmClient.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.Designer.cs new file mode 100644 index 000000000..21882ee1b --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.Designer.cs @@ -0,0 +1,177 @@ +namespace TcpPullClientNS +{ + partial class frmClient + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.cbxAsyncConn = new System.Windows.Forms.CheckBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtIpAddress = new System.Windows.Forms.TextBox(); + this.btnStop = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.txtSend = new System.Windows.Forms.TextBox(); + this.btnSend = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.cbxAsyncConn); + this.groupBox1.Controls.Add(this.txtPort); + this.groupBox1.Controls.Add(this.txtIpAddress); + this.groupBox1.Controls.Add(this.btnStop); + this.groupBox1.Controls.Add(this.btnStart); + this.groupBox1.Location = new System.Drawing.Point(12, 2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(464, 47); + this.groupBox1.TabIndex = 11; + this.groupBox1.TabStop = false; + // + // cbxAsyncConn + // + this.cbxAsyncConn.AutoSize = true; + this.cbxAsyncConn.Checked = true; + this.cbxAsyncConn.CheckState = System.Windows.Forms.CheckState.Checked; + this.cbxAsyncConn.Location = new System.Drawing.Point(134, 20); + this.cbxAsyncConn.Name = "cbxAsyncConn"; + this.cbxAsyncConn.Size = new System.Drawing.Size(84, 16); + this.cbxAsyncConn.TabIndex = 13; + this.cbxAsyncConn.Text = "Async Conn"; + this.cbxAsyncConn.UseVisualStyleBackColor = true; + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(88, 18); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(40, 21); + this.txtPort.TabIndex = 12; + this.txtPort.Text = "5555"; + // + // txtIpAddress + // + this.txtIpAddress.Location = new System.Drawing.Point(11, 18); + this.txtIpAddress.Name = "txtIpAddress"; + this.txtIpAddress.Size = new System.Drawing.Size(71, 21); + this.txtIpAddress.TabIndex = 11; + this.txtIpAddress.Text = "127.0.0.1"; + // + // btnStop + // + this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStop.Location = new System.Drawing.Point(407, 15); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(47, 26); + this.btnStop.TabIndex = 10; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // btnStart + // + this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStart.Location = new System.Drawing.Point(354, 15); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(47, 26); + this.btnStart.TabIndex = 9; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // lbxMsg + // + this.lbxMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(11, 62); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(465, 256); + this.lbxMsg.TabIndex = 10; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // txtSend + // + this.txtSend.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtSend.Location = new System.Drawing.Point(12, 324); + this.txtSend.Name = "txtSend"; + this.txtSend.Size = new System.Drawing.Size(411, 21); + this.txtSend.TabIndex = 12; + this.txtSend.Text = "text to be sent"; + // + // btnSend + // + this.btnSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSend.Location = new System.Drawing.Point(429, 321); + this.btnSend.Name = "btnSend"; + this.btnSend.Size = new System.Drawing.Size(47, 26); + this.btnSend.TabIndex = 13; + this.btnSend.Text = "Send"; + this.btnSend.UseVisualStyleBackColor = true; + this.btnSend.Click += new System.EventHandler(this.btnSend_Click); + // + // frmClient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(485, 350); + this.Controls.Add(this.btnSend); + this.Controls.Add(this.txtSend); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.lbxMsg); + this.Name = "frmClient"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Echo-TcpPullClient [ \'C\' - clear list box ]"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmClient_FormClosed); + this.Load += new System.EventHandler(this.frmClient_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox txtPort; + private System.Windows.Forms.TextBox txtIpAddress; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.CheckBox cbxAsyncConn; + private System.Windows.Forms.TextBox txtSend; + private System.Windows.Forms.Button btnSend; + + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.cs new file mode 100644 index 000000000..8002dd7e0 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.cs @@ -0,0 +1,369 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using HPSocketCS; +using System.Runtime.InteropServices; + +namespace TcpPullClientNS +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public partial class frmClient : Form + { + private AppState appState = AppState.Stoped; + + private delegate void ConnectUpdateUiDelegate(); + private delegate void SetAppStateDelegate(AppState state); + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + HPSocketCS.TcpPullClient client = new HPSocketCS.TcpPullClient(); + + int id = 0; + + // 包头大小 + int pkgHeaderSize = Marshal.SizeOf(new PkgHeader()); + PkgInfo pkgInfo = new PkgInfo(); + + public frmClient() + { + InitializeComponent(); + } + + private void frmClient_Load(object sender, EventArgs e) + { + try + { + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + pkgInfo.IsHeader = true; + pkgInfo.Length = pkgHeaderSize; + + // 设置client事件 + client.OnPrepareConnect += new TcpClientEvent.OnPrepareConnectEventHandler(OnPrepareConnect); + client.OnConnect += new TcpClientEvent.OnConnectEventHandler(OnConnect); + client.OnSend += new TcpClientEvent.OnSendEventHandler(OnSend); + client.OnReceive += new TcpPullClientEvent.OnReceiveEventHandler(OnReceive); + client.OnClose += new TcpClientEvent.OnCloseEventHandler(OnClose); + + SetAppState(AppState.Stoped); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + String ip = this.txtIpAddress.Text.Trim(); + ushort port = ushort.Parse(this.txtPort.Text.Trim()); + + // 写在这个位置是上面可能会异常 + SetAppState(AppState.Starting); + + AddMsg(string.Format("$Client Starting ... -> ({0}:{1})", ip, port)); + + if (client.Connetion(ip, port, this.cbxAsyncConn.Checked)) + { + if (cbxAsyncConn.Checked == false) + { + SetAppState(AppState.Started); + } + } + else + { + SetAppState(AppState.Stoped); + throw new Exception(string.Format("$Client Start Error -> {0}({1})", client.ErrorMessage, client.ErrorCode)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + private void btnStop_Click(object sender, EventArgs e) + { + + // 停止服务 + AddMsg("$Server Stop"); + if (client.Stop()) + { + SetAppState(AppState.Stoped); + } + else + { + AddMsg(string.Format("$Stop Error -> {0}({1})", client.ErrorMessage, client.ErrorCode)); + } + } + + private void btnSend_Click(object sender, EventArgs e) + { + IntPtr bufferPtr = IntPtr.Zero; + try + { + string send = this.txtSend.Text; + if (send.Length == 0) + { + return; + } + + // 封包体 + byte[] bodyBytes = Encoding.Default.GetBytes(send); + + // 封包头 + PkgHeader header = new PkgHeader(); + header.Id = ++id; + header.BodySize = bodyBytes.Length; + byte[] headerBytes = client.StructureToByte(header); + + + // 组合最终发送的封包 (封包头+封包体) + byte[] sendBytes = GetSendBuffer(headerBytes, bodyBytes); + + // 发送 + IntPtr connId = client.ConnectionId; + if (client.Send(sendBytes, sendBytes.Length)) + { + AddMsg(string.Format("$ ({0}) Send OK --> {1}", connId, send)); + } + else + { + AddMsg(string.Format("$ ({0}) Send Fail --> {1} ({2})", connId, send, sendBytes.Length)); + } + + } + catch (Exception) + { + + } + finally + { + if (bufferPtr != IntPtr.Zero) + { + Marshal.FreeHGlobal(bufferPtr); + } + } + + + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + } + + void ConnectUpdateUi() + { + if (this.cbxAsyncConn.Checked == true) + { + SetAppState(AppState.Started); + } + } + + HandleResult OnPrepareConnect(TcpClient sender, uint socket) + { + return HandleResult.Ok; + } + + HandleResult OnConnect(TcpClient sender) + { + // 已连接 到达一次 + // 如果是异步联接,更新界面状态 + + this.Invoke(new ConnectUpdateUiDelegate(ConnectUpdateUi)); + + AddMsg(string.Format(" > [{0},OnConnect]", sender.ConnectionId)); + + return HandleResult.Ok; + } + + HandleResult OnSend(TcpClient sender, IntPtr pData, int length) + { + // 客户端发数据了 + AddMsg(string.Format(" > [{0},OnSend] -> ({1} bytes)", sender.ConnectionId, length)); + + return HandleResult.Ok; + } + + HandleResult OnReceive(TcpPullClient sender, int length) + { + // 数据到达了 + + // 需要长度 + int required = pkgInfo.Length; + + // 剩余大小 + int remain = length; + + + while (remain >= required) + { + IntPtr bufferPtr = IntPtr.Zero; + try + { + remain -= required; + bufferPtr = Marshal.AllocHGlobal(required); + if (sender.Fetch(bufferPtr, required) == FetchResult.Ok) + { + if (pkgInfo.IsHeader == true) + { + PkgHeader header = (PkgHeader)Marshal.PtrToStructure(bufferPtr, typeof(PkgHeader)); + + // 调试信息 + Console.WriteLine("[Client] head -> Id: {0}, BodySize: {1}\r\n", header.Id, header.BodySize); + + required = header.BodySize; + } + else + { + // 调试信息 + string recvString = Marshal.PtrToStringAnsi(bufferPtr, required); + Console.WriteLine("[Client] body -> text: {0}\r\n", recvString); + + required = pkgHeaderSize; + } + + AddMsg(string.Format(" > [{0},OnReceive] -> ({1} bytes)", sender.ConnectionId, pkgInfo.Length)); + + pkgInfo.IsHeader = !pkgInfo.IsHeader; + pkgInfo.Length = required; + } + } + catch + { + return HandleResult.Error; + } + finally + { + if (bufferPtr != IntPtr.Zero) + { + Marshal.FreeHGlobal(bufferPtr); + bufferPtr = IntPtr.Zero; + } + } + } + + return HandleResult.Ok; + } + + HandleResult OnClose(TcpClient sender, SocketOperation enOperation, int errorCode) + { + if(errorCode == 0) + // 连接关闭了 + AddMsg(string.Format(" > [{0},OnClose]", sender.ConnectionId)); + else + // 出错了 + AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", sender.ConnectionId, enOperation, errorCode)); + + // 通知界面,只处理了连接错误,也没进行是不是连接错误的判断,所以有错误就会设置界面 + // 生产环境请自己控制 + this.Invoke(new SetAppStateDelegate(SetAppState), AppState.Stoped); + + return HandleResult.Ok; + } + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtIpAddress.Enabled = (appState == AppState.Stoped); + this.txtPort.Enabled = (appState == AppState.Stoped); + this.cbxAsyncConn.Enabled = (appState == AppState.Stoped); + this.btnSend.Enabled = (appState == AppState.Started); + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + private void frmClient_FormClosed(object sender, FormClosedEventArgs e) + { + client.Destroy(); + } + + private byte[] GetSendBuffer(byte[] headerBytes, byte[] bodyBytes) + { + IntPtr ptr = IntPtr.Zero; + try + { + int bufferSize = headerBytes.Length + bodyBytes.Length; + ptr = Marshal.AllocHGlobal(bufferSize); + + // 拷贝包头到缓冲区首部 + Marshal.Copy(headerBytes, 0, ptr, headerBytes.Length); + + // 拷贝包体到缓冲区剩余部分 + Marshal.Copy(bodyBytes, 0, ptr + headerBytes.Length, bodyBytes.Length); + + byte[] bytes = new byte[bufferSize]; + Marshal.Copy(ptr, bytes, 0, bufferSize); + + return bytes; + } + finally + { + if (ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(ptr); + } + } + + } + + } + + [StructLayout(LayoutKind.Sequential)] + public class PkgHeader + { + public int Id; + public int BodySize; + } + + [StructLayout(LayoutKind.Sequential)] + public class PkgInfo + { + public bool IsHeader; + public int Length; + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullClient/frmClient.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Program.cs new file mode 100644 index 000000000..181f94d05 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpPullServer +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmServer()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f99c7b3bd --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Server")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("a8f79261-fd62-4f4b-aed5-01bf44660ad1")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Resources.Designer.cs new file mode 100644 index 000000000..fa7465295 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.18444 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpPullServer.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpPullServer.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Settings.Designer.cs new file mode 100644 index 000000000..5b98cbb5f --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.18444 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpPullServer.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/TcpPullServer.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/TcpPullServer.csproj new file mode 100644 index 000000000..e4f9382b6 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/TcpPullServer.csproj @@ -0,0 +1,126 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {B6654857-4C82-4F92-AD7A-21FD3ED5BBFA} + WinExe + Properties + TcpPullServer + TcpPullServer + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpPullServer.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + true + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + true + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpPullServer.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + true + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + true + + + + + + + + + + + + + + + + Form + + + frmServer.cs + + + + + frmServer.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.Designer.cs new file mode 100644 index 000000000..c0c227869 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.Designer.cs @@ -0,0 +1,169 @@ +namespace TcpPullServer +{ + partial class frmServer + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label1 = new System.Windows.Forms.Label(); + this.btnDisconn = new System.Windows.Forms.Button(); + this.txtDisConn = new System.Windows.Forms.TextBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtIpAddress = new System.Windows.Forms.TextBox(); + this.btnStop = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // lbxMsg + // + this.lbxMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(11, 62); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(465, 304); + this.lbxMsg.TabIndex = 4; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.btnDisconn); + this.groupBox1.Controls.Add(this.txtDisConn); + this.groupBox1.Controls.Add(this.txtPort); + this.groupBox1.Controls.Add(this.txtIpAddress); + this.groupBox1.Controls.Add(this.btnStop); + this.groupBox1.Controls.Add(this.btnStart); + this.groupBox1.Location = new System.Drawing.Point(12, 2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(462, 47); + this.groupBox1.TabIndex = 9; + this.groupBox1.TabStop = false; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(132, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 15; + this.label1.Text = "CONNID"; + // + // btnDisconn + // + this.btnDisconn.Location = new System.Drawing.Point(223, 15); + this.btnDisconn.Name = "btnDisconn"; + this.btnDisconn.Size = new System.Drawing.Size(33, 26); + this.btnDisconn.TabIndex = 14; + this.btnDisconn.Text = "Dis"; + this.btnDisconn.UseVisualStyleBackColor = true; + this.btnDisconn.Click += new System.EventHandler(this.btnDisconn_Click); + // + // txtDisConn + // + this.txtDisConn.Location = new System.Drawing.Point(178, 18); + this.txtDisConn.Name = "txtDisConn"; + this.txtDisConn.Size = new System.Drawing.Size(40, 21); + this.txtDisConn.TabIndex = 13; + this.txtDisConn.TextChanged += new System.EventHandler(this.txtDisConn_TextChanged); + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(88, 18); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(40, 21); + this.txtPort.TabIndex = 12; + this.txtPort.Text = "5555"; + // + // txtIpAddress + // + this.txtIpAddress.Location = new System.Drawing.Point(11, 18); + this.txtIpAddress.Name = "txtIpAddress"; + this.txtIpAddress.Size = new System.Drawing.Size(71, 21); + this.txtIpAddress.TabIndex = 11; + this.txtIpAddress.Text = "0.0.0.0"; + // + // btnStop + // + this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStop.Location = new System.Drawing.Point(403, 15); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(47, 26); + this.btnStop.TabIndex = 10; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // btnStart + // + this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStart.Location = new System.Drawing.Point(350, 15); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(47, 26); + this.btnStart.TabIndex = 9; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // frmServer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(486, 377); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.lbxMsg); + this.Name = "frmServer"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmServer_FormClosed); + this.Load += new System.EventHandler(this.Form1_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnDisconn; + private System.Windows.Forms.TextBox txtDisConn; + private System.Windows.Forms.TextBox txtPort; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.TextBox txtIpAddress; + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.cs new file mode 100644 index 000000000..6fe751e2c --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.cs @@ -0,0 +1,390 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Runtime.InteropServices; +using HPSocketCS; + +namespace TcpPullServer +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public partial class frmServer : Form + { + private AppState appState = AppState.Stoped; + + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + + HPSocketCS.TcpPullServer server = new HPSocketCS.TcpPullServer(); + + + // 包头大小 + int pkgHeaderSize = Marshal.SizeOf(new PkgHeader()); + + private string title = "Echo TcpPullServer [ 'C' - clear list box ]"; + public frmServer() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + try + { + + this.Text = title; + // 本机测试没必要改地址,有需求请注释或删除 + this.txtIpAddress.ReadOnly = true; + + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + // 设置服务器事件 + server.OnPrepareListen += new TcpServerEvent.OnPrepareListenEventHandler(OnPrepareListen); + server.OnAccept += new TcpServerEvent.OnAcceptEventHandler(OnAccept); + server.OnSend += new TcpServerEvent.OnSendEventHandler(OnSend); + server.OnReceive += new TcpPullServerEvent.OnReceiveEventHandler(OnReceive); + server.OnClose += new TcpServerEvent.OnCloseEventHandler(OnClose); + server.OnShutdown += new TcpServerEvent.OnShutdownEventHandler(OnShutdown); + + SetAppState(AppState.Stoped); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + String ip = this.txtIpAddress.Text.Trim(); + ushort port = ushort.Parse(this.txtPort.Text.Trim()); + + // 写在这个位置是上面可能会异常 + SetAppState(AppState.Starting); + + server.IpAddress = ip; + server.Port = port; + // 启动服务 + if (server.Start()) + { + this.Text = string.Format("{2} - ({0}:{1})", ip, port, title); + SetAppState(AppState.Started); + AddMsg(string.Format("$Server Start OK -> ({0}:{1})", ip, port)); + } + else + { + SetAppState(AppState.Stoped); + throw new Exception(string.Format("$Server Start Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + private void btnStop_Click(object sender, EventArgs e) + { + SetAppState(AppState.Stoping); + + // 停止服务 + AddMsg("$Server Stop"); + if (server.Stop()) + { + this.Text = title; + SetAppState(AppState.Stoped); + } + else + { + AddMsg(string.Format("$Stop Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + } + } + + private void btnDisconn_Click(object sender, EventArgs e) + { + try + { + IntPtr connId = (IntPtr)Convert.ToUInt32(this.txtDisConn.Text.Trim()); + + // 断开指定客户 + if (server.Disconnect(connId, true)) + { + AddMsg(string.Format("$({0}) Disconnect OK", connId)); + } + else + { + throw new Exception(string.Format("Disconnect({0}) Error", connId)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + + HandleResult OnPrepareListen(IntPtr soListen) + { + // 监听事件到达了,一般没什么用吧? + + return HandleResult.Ok; + } + + HandleResult OnAccept(IntPtr connId, IntPtr pClient) + { + // 客户进入了 + + + // 获取客户端ip和端口 + string ip = string.Empty; + ushort port = 0; + if (server.GetRemoteAddress(connId, ref ip, ref port)) + { + AddMsg(string.Format(" > [{0},OnAccept] -> PASS({1}:{2})", connId, ip.ToString(), port)); + } + else + { + AddMsg(string.Format(" > [{0},OnAccept] -> Server_GetClientAddress() Error", connId)); + } + + + // 设置附加数据 + ClientInfo ci = new ClientInfo(); + ci.ConnId = connId; + ci.IpAddress = ip; + ci.Port = port; + ci.PkgInfo = new PkgInfo() + { + IsHeader = true, + Length = pkgHeaderSize, + }; + if (server.SetConnectionExtra(connId, ci) == false) + { + AddMsg(string.Format(" > [{0},OnAccept] -> SetConnectionExtra fail", connId)); + } + + return HandleResult.Ok; + } + + HandleResult OnSend(IntPtr connId, IntPtr pData, int length) + { + // 服务器发数据了 + + + AddMsg(string.Format(" > [{0},OnSend] -> ({1} bytes)", connId, length)); + + return HandleResult.Ok; + } + + HandleResult OnReceive(IntPtr connId, int length) + { + // 数据到达了 + IntPtr clientPtr = IntPtr.Zero; + if (server.GetConnectionExtra(connId, ref clientPtr) == false) + { + return HandleResult.Error; + } + ClientInfo ci = (ClientInfo)Marshal.PtrToStructure(clientPtr, typeof(ClientInfo)); + PkgInfo pkgInfo = ci.PkgInfo; + + + // 需要长度 + int required = pkgInfo.Length; + + // 剩余大小 + int remain = length; + + while (remain >= required) + { + IntPtr bufferPtr = IntPtr.Zero; + try + { + remain -= required; + bufferPtr = Marshal.AllocHGlobal(required); ; + if (server.Fetch(connId, bufferPtr, required) == FetchResult.Ok) + { + if (pkgInfo.IsHeader == true) + { + PkgHeader header = (PkgHeader)Marshal.PtrToStructure(bufferPtr, typeof(PkgHeader)); + + // 调试信息 + Console.WriteLine("[Server] head -> Id: {0}, BodySize: {1}\r\n", header.Id, header.BodySize); + + required = header.BodySize; + } + else + { + // 调试信息 + string recvString = Marshal.PtrToStringAnsi(bufferPtr, required); + Console.WriteLine("[Server] body -> text: {0}\r\n", recvString); + + // intptr转string + //Marshal.PtrToStringAnsi(bufferPtr, required); + + //intptr转byte[] + // byte[] bytes = new byte[required]; + // Marshal.Copy(bufferPtr, bytes, 0, required); + + required = pkgHeaderSize; + + } + + AddMsg(string.Format(" > [{0},OnReceive] -> ({1} bytes)", connId, pkgInfo.Length)); + + // 回发数据 + byte[] sendBytes = new byte[pkgInfo.Length]; + Marshal.Copy(bufferPtr, sendBytes, 0, sendBytes.Length); + if (server.Send(connId, sendBytes, sendBytes.Length) == false) + { + throw new Exception("server.Send() == false"); + } + + // 在后面赋值,因为前面需要用到pkgInfo.Length + pkgInfo.IsHeader = !pkgInfo.IsHeader; + pkgInfo.Length = required; + if (server.SetConnectionExtra(connId, ci) == false) + { + return HandleResult.Error; + } + } + + } + catch + { + return HandleResult.Error; + } + finally + { + if (bufferPtr != IntPtr.Zero) + { + Marshal.FreeHGlobal(bufferPtr); + bufferPtr = IntPtr.Zero; + } + } + } + + return HandleResult.Ok; + } + + HandleResult OnClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if(errorCode == 0) + // 客户离开了 + AddMsg(string.Format(" > [{0},OnClose]", connId)); + else + // 客户出错了 + AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode)); + // return HPSocketSdk.HandleResult.Ok; + + // 释放附加数据 + if (server.SetConnectionExtra(connId, null) == false) + { + AddMsg(string.Format(" > [{0},OnClose] -> SetConnectionExtra({0}, null) fail", connId)); + } + + return HandleResult.Ok; + } + + HandleResult OnShutdown() + { + // 服务关闭了 + + + AddMsg(" > [OnShutdown]"); + return HandleResult.Ok; + } + + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtIpAddress.Enabled = (appState == AppState.Stoped); + this.txtPort.Enabled = (appState == AppState.Stoped); + this.txtDisConn.Enabled = (appState == AppState.Started); + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + private void txtDisConn_TextChanged(object sender, EventArgs e) + { + // CONNID框被改变事件 + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + } + + private void frmServer_FormClosed(object sender, FormClosedEventArgs e) + { + server.Destroy(); + } + } + + [StructLayout(LayoutKind.Sequential)] + public class ClientInfo + { + public IntPtr ConnId { get; set; } + public string IpAddress { get; set; } + public ushort Port { get; set; } + public PkgInfo PkgInfo { get; set; } + } + + [StructLayout(LayoutKind.Sequential)] + public class PkgHeader + { + public int Id; + public int BodySize; + } + + [StructLayout(LayoutKind.Sequential)] + public class PkgInfo + { + public bool IsHeader; + public int Length; + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpPullServer/frmServer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Program.cs new file mode 100644 index 000000000..4a3923e91 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpServer_PFM +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmServer()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f99c7b3bd --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Server")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("a8f79261-fd62-4f4b-aed5-01bf44660ad1")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Resources.Designer.cs new file mode 100644 index 000000000..fe2b41333 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.18444 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpServer_PFM.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpServer_PFM.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Settings.Designer.cs new file mode 100644 index 000000000..20366263c --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.18444 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpServer_PFM.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/TcpServer-PFM.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/TcpServer-PFM.csproj new file mode 100644 index 000000000..b55bdcd4a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/TcpServer-PFM.csproj @@ -0,0 +1,122 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {10426A79-A3B3-4CD2-BD84-02AAEE27FB75} + WinExe + Properties + TcpServer_PFM + TcpServer-PFM + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpServer-PFM.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpServer-PFM.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + + + + + + + + + + + + + + Form + + + frmServer.cs + + + + + frmServer.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.Designer.cs new file mode 100644 index 000000000..cfd0ca76d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.Designer.cs @@ -0,0 +1,169 @@ +namespace TcpServer_PFM +{ + partial class frmServer + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label1 = new System.Windows.Forms.Label(); + this.btnDisconn = new System.Windows.Forms.Button(); + this.txtDisConn = new System.Windows.Forms.TextBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtIpAddress = new System.Windows.Forms.TextBox(); + this.btnStop = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // lbxMsg + // + this.lbxMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(11, 62); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(465, 304); + this.lbxMsg.TabIndex = 4; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.btnDisconn); + this.groupBox1.Controls.Add(this.txtDisConn); + this.groupBox1.Controls.Add(this.txtPort); + this.groupBox1.Controls.Add(this.txtIpAddress); + this.groupBox1.Controls.Add(this.btnStop); + this.groupBox1.Controls.Add(this.btnStart); + this.groupBox1.Location = new System.Drawing.Point(12, 2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(462, 47); + this.groupBox1.TabIndex = 9; + this.groupBox1.TabStop = false; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(132, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 15; + this.label1.Text = "CONNID"; + // + // btnDisconn + // + this.btnDisconn.Location = new System.Drawing.Point(223, 15); + this.btnDisconn.Name = "btnDisconn"; + this.btnDisconn.Size = new System.Drawing.Size(33, 26); + this.btnDisconn.TabIndex = 14; + this.btnDisconn.Text = "Dis"; + this.btnDisconn.UseVisualStyleBackColor = true; + this.btnDisconn.Click += new System.EventHandler(this.btnDisconn_Click); + // + // txtDisConn + // + this.txtDisConn.Location = new System.Drawing.Point(178, 18); + this.txtDisConn.Name = "txtDisConn"; + this.txtDisConn.Size = new System.Drawing.Size(40, 21); + this.txtDisConn.TabIndex = 13; + this.txtDisConn.TextChanged += new System.EventHandler(this.txtDisConn_TextChanged); + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(88, 18); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(40, 21); + this.txtPort.TabIndex = 12; + this.txtPort.Text = "5555"; + // + // txtIpAddress + // + this.txtIpAddress.Location = new System.Drawing.Point(11, 18); + this.txtIpAddress.Name = "txtIpAddress"; + this.txtIpAddress.Size = new System.Drawing.Size(71, 21); + this.txtIpAddress.TabIndex = 11; + this.txtIpAddress.Text = "0.0.0.0"; + // + // btnStop + // + this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStop.Location = new System.Drawing.Point(403, 15); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(47, 26); + this.btnStop.TabIndex = 10; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // btnStart + // + this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStart.Location = new System.Drawing.Point(350, 15); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(47, 26); + this.btnStart.TabIndex = 9; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // frmServer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(486, 377); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.lbxMsg); + this.Name = "frmServer"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmServer_FormClosed); + this.Load += new System.EventHandler(this.Form1_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnDisconn; + private System.Windows.Forms.TextBox txtDisConn; + private System.Windows.Forms.TextBox txtPort; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.TextBox txtIpAddress; + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.cs new file mode 100644 index 000000000..1c557e7fc --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.cs @@ -0,0 +1,375 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Runtime.InteropServices; +using HPSocketCS; +using System.Threading; + +namespace TcpServer_PFM +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public partial class frmServer : Form + { + private AppState appState = AppState.Stoped; + + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + + HPSocketCS.TcpServer server = new HPSocketCS.TcpServer(); + + private static string title = "Echo-PFM Server [ 'C' - clear list box, 'R' - reset statics data ]"; + + + private long totalReceived = 0; + private long totalSent = 0; + private long clientCount = 0; + + + + public frmServer() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + try + { + + this.Text = title; + // 本机测试没必要改地址,有需求请注释或删除 + this.txtIpAddress.ReadOnly = true; + + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + // 设置服务器事件 + server.OnPrepareListen += new TcpServerEvent.OnPrepareListenEventHandler(OnPrepareListen); + server.OnAccept += new TcpServerEvent.OnAcceptEventHandler(OnAccept); + server.OnSend += new TcpServerEvent.OnSendEventHandler(OnSend); + server.OnReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive); + server.OnClose += new TcpServerEvent.OnCloseEventHandler(OnClose); + server.OnShutdown += new TcpServerEvent.OnShutdownEventHandler(OnShutdown); + + SetAppState(AppState.Stoped); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + String ip = this.txtIpAddress.Text.Trim(); + ushort port = ushort.Parse(this.txtPort.Text.Trim()); + + // 写在这个位置是上面可能会异常 + SetAppState(AppState.Starting); + + Reset(); + + server.IpAddress = ip; + server.Port = port; + + // 启动服务 + if (server.Start()) + { + this.Text = string.Format("{2} - ({0}:{1})", ip, port, title); + SetAppState(AppState.Started); + AddMsg(string.Format("$Server Start OK -> ({0}:{1})", ip, port)); + } + else + { + SetAppState(AppState.Stoped); + throw new Exception(string.Format("$Server Start Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + private void btnStop_Click(object sender, EventArgs e) + { + SetAppState(AppState.Stoping); + + // 停止服务 + AddMsg("$Server Stop"); + if (server.Stop()) + { + this.Text = title; + SetAppState(AppState.Stoped); + } + else + { + AddMsg(string.Format("$Stop Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + } + } + + private void btnDisconn_Click(object sender, EventArgs e) + { + try + { + IntPtr connId = (IntPtr)Convert.ToUInt32(this.txtDisConn.Text.Trim()); + + // 断开指定客户 + if (server.Disconnect(connId, true)) + { + AddMsg(string.Format("$({0}) Disconnect OK", connId)); + } + else + { + throw new Exception(string.Format("Disconnect({0}) Error", connId)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + void Reset(bool isSetClientCount = true) + { + if (isSetClientCount) + { + clientCount = 0; + } + + totalReceived = 0; + totalSent = 0; + } + + HandleResult OnPrepareListen(IntPtr soListen) + { + // 监听事件到达了,一般没什么用吧? + + return HandleResult.Ok; + } + + HandleResult OnAccept(IntPtr connId, IntPtr pClient) + { + // 客户进入了 + if (clientCount == 0) + { + lock (title) + { + if (clientCount == 0) + { + Reset(false); + } + } + } + + Interlocked.Increment(ref clientCount); + + // 获取客户端ip和端口 + string ip = string.Empty; + ushort port = 0; + if (server.GetRemoteAddress(connId, ref ip, ref port)) + { + AddMsg(string.Format(" > [{0},OnAccept] -> PASS({1}:{2})", connId, ip.ToString(), port)); + } + else + { + AddMsg(string.Format(" > [{0},OnAccept] -> Server_GetClientAddress() Error", connId)); + } + + return HandleResult.Ok; + } + + HandleResult OnSend(IntPtr connId, IntPtr pData, int length) + { + // 服务器发数据了 + Interlocked.Add(ref totalSent, length); + + //AddMsg(string.Format(" > [{0},OnSend] -> ({1} bytes)", connId, length)); + + return HandleResult.Ok; + } + + HandleResult OnReceive(IntPtr connId, IntPtr pData, int length) + { + // 数据到达了 + + Interlocked.Add(ref totalReceived, length); + + if (server.Send(connId, pData, length)) + { + return HandleResult.Ok; + } + + return HandleResult.Error; + + /*try + {*/ + /* + // 从pData中获取字符串 + // string str = Marshal.PtrToStringAnsi(pData, length); + + // intptr转byte[] + // byte[] bytes = new byte[length]; + // Marshal.Copy(pData, bytes, 0, length); + + + // 获取附加数据 + IntPtr clientPtr = IntPtr.Zero; + if (server.GetConnectionExtra(connId, ref clientPtr)) + { + // ci 就是accept里传入的附加数据了 + ClientInfo ci = (ClientInfo)Marshal.PtrToStructure(clientPtr, typeof(ClientInfo)); + AddMsg(string.Format(" > [{0},OnReceive] -> {1}:{2} ({3} bytes)", ci.ConnId, ci.IpAddress, ci.Port, length)); + } + else + { + AddMsg(string.Format(" > [{0},OnReceive] -> ({1} bytes)", connId, length)); + } + + if (server.Send(connId, pData, length)) + { + return HandleResult.Ok; + } + + return HandleResult.Error;*/ + /*} + catch (Exception) + { + return HandleResult.IGNORE; + }*/ + + + } + + HandleResult OnClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if(errorCode == 0) + AddMsg(string.Format(" > [{0},OnClose]", connId)); + else + AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode)); + + Calculate(); + + return HandleResult.Ok; + } + + HandleResult OnShutdown() + { + // 服务关闭了 + + + AddMsg(" > [OnShutdown]"); + return HandleResult.Ok; + } + + void Calculate() + { + if(clientCount > 0) + { + lock(title) + { + + if(clientCount > 0) + { + Interlocked.Decrement(ref clientCount); + + if(clientCount == 0) + { + //::WaitWithMessageLoop(600L); + Thread tmpThread = new Thread(ShowTotalMsg); + tmpThread.Start(); + } + } + } + } + } + + void ShowTotalMsg() + { + Thread.Sleep(600); + AddMsg(string.Format(" *** Summary: send - {0}, recv - {1}", totalSent, totalReceived)); + } + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtIpAddress.Enabled = (appState == AppState.Stoped); + this.txtPort.Enabled = (appState == AppState.Stoped); + this.txtDisConn.Enabled = (appState == AppState.Started); + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + private void txtDisConn_TextChanged(object sender, EventArgs e) + { + // CONNID框被改变事件 + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + else if (e.KeyChar == 'r' || e.KeyChar == 'R') + { + Reset(); + AddMsg(string.Format(" *** Reset Statics: CC - {0}, TS - {1}, TR - {2}", clientCount, totalSent, totalReceived)); + } + } + + private void frmServer_FormClosed(object sender, FormClosedEventArgs e) + { + server.Destroy(); + } + } + + [StructLayout(LayoutKind.Sequential)] + public class ClientInfo + { + public uint ConnId { get; set; } + public string IpAddress { get; set; } + public ushort Port { get; set; } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer-PFM/frmServer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Program.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Program.cs new file mode 100644 index 000000000..4a3923e91 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TcpServer_PFM +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmServer()); + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/AssemblyInfo.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f99c7b3bd --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Server")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("a8f79261-fd62-4f4b-aed5-01bf44660ad1")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: + +[assembly: AssemblyVersion("3.4.3")] +[assembly: AssemblyFileVersion("3.4.3")] diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Resources.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Resources.Designer.cs new file mode 100644 index 000000000..f05ed944f --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpServer.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TcpServer.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Resources.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Settings.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Settings.Designer.cs new file mode 100644 index 000000000..9c3530897 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace TcpServer.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Settings.settings b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/TcpServer.csproj b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/TcpServer.csproj new file mode 100644 index 000000000..135e01d38 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/TcpServer.csproj @@ -0,0 +1,122 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {9A3339BC-37F0-4D03-9ACE-51CC4CF75277} + WinExe + Properties + TcpServer + TcpServer + v4.0 + Client + 512 + + + x86 + true + full + false + ..\bin\x86\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + ..\bin\x86\Release\ + TRACE + prompt + 4 + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + ..\bin\Debug\TcpServer.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + ..\bin\Release\TcpServer.exe.CodeAnalysisLog.xml + true + GlobalSuppressions.cs + prompt + MinimumRecommendedRules.ruleset + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets + ;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules + + + + + + + + + + + + + + + + Form + + + frmServer.cs + + + + + frmServer.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {DFA935E2-CF37-4E26-B697-D7F3DEE19DD8} + HPSocketCS + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.Designer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.Designer.cs new file mode 100644 index 000000000..cfd0ca76d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.Designer.cs @@ -0,0 +1,169 @@ +namespace TcpServer_PFM +{ + partial class frmServer + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.lbxMsg = new System.Windows.Forms.ListBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label1 = new System.Windows.Forms.Label(); + this.btnDisconn = new System.Windows.Forms.Button(); + this.txtDisConn = new System.Windows.Forms.TextBox(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.txtIpAddress = new System.Windows.Forms.TextBox(); + this.btnStop = new System.Windows.Forms.Button(); + this.btnStart = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // lbxMsg + // + this.lbxMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbxMsg.FormattingEnabled = true; + this.lbxMsg.ItemHeight = 12; + this.lbxMsg.Location = new System.Drawing.Point(11, 62); + this.lbxMsg.Name = "lbxMsg"; + this.lbxMsg.Size = new System.Drawing.Size(465, 304); + this.lbxMsg.TabIndex = 4; + this.lbxMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lbxMsg_KeyPress); + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.btnDisconn); + this.groupBox1.Controls.Add(this.txtDisConn); + this.groupBox1.Controls.Add(this.txtPort); + this.groupBox1.Controls.Add(this.txtIpAddress); + this.groupBox1.Controls.Add(this.btnStop); + this.groupBox1.Controls.Add(this.btnStart); + this.groupBox1.Location = new System.Drawing.Point(12, 2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(462, 47); + this.groupBox1.TabIndex = 9; + this.groupBox1.TabStop = false; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(132, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 15; + this.label1.Text = "CONNID"; + // + // btnDisconn + // + this.btnDisconn.Location = new System.Drawing.Point(223, 15); + this.btnDisconn.Name = "btnDisconn"; + this.btnDisconn.Size = new System.Drawing.Size(33, 26); + this.btnDisconn.TabIndex = 14; + this.btnDisconn.Text = "Dis"; + this.btnDisconn.UseVisualStyleBackColor = true; + this.btnDisconn.Click += new System.EventHandler(this.btnDisconn_Click); + // + // txtDisConn + // + this.txtDisConn.Location = new System.Drawing.Point(178, 18); + this.txtDisConn.Name = "txtDisConn"; + this.txtDisConn.Size = new System.Drawing.Size(40, 21); + this.txtDisConn.TabIndex = 13; + this.txtDisConn.TextChanged += new System.EventHandler(this.txtDisConn_TextChanged); + // + // txtPort + // + this.txtPort.Location = new System.Drawing.Point(88, 18); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(40, 21); + this.txtPort.TabIndex = 12; + this.txtPort.Text = "5555"; + // + // txtIpAddress + // + this.txtIpAddress.Location = new System.Drawing.Point(11, 18); + this.txtIpAddress.Name = "txtIpAddress"; + this.txtIpAddress.Size = new System.Drawing.Size(71, 21); + this.txtIpAddress.TabIndex = 11; + this.txtIpAddress.Text = "0.0.0.0"; + // + // btnStop + // + this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStop.Location = new System.Drawing.Point(403, 15); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(47, 26); + this.btnStop.TabIndex = 10; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.btnStop_Click); + // + // btnStart + // + this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStart.Location = new System.Drawing.Point(350, 15); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(47, 26); + this.btnStart.TabIndex = 9; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // frmServer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(486, 377); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.lbxMsg); + this.Name = "frmServer"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmServer_FormClosed); + this.Load += new System.EventHandler(this.Form1_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListBox lbxMsg; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnDisconn; + private System.Windows.Forms.TextBox txtDisConn; + private System.Windows.Forms.TextBox txtPort; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.TextBox txtIpAddress; + } +} + diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.cs b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.cs new file mode 100644 index 000000000..a3b60228b --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.cs @@ -0,0 +1,312 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Runtime.InteropServices; +using HPSocketCS; + +namespace TcpServer_PFM +{ + public enum AppState + { + Starting, Started, Stoping, Stoped, Error + } + + public partial class frmServer : Form + { + private AppState appState = AppState.Stoped; + + private delegate void ShowMsg(string msg); + private ShowMsg AddMsgDelegate; + + HPSocketCS.TcpServer server = new HPSocketCS.TcpServer(); + + private string title = "Echo TcpServer [ 'C' - clear list box ]"; + public frmServer() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + try + { + + this.Text = title; + // 本机测试没必要改地址,有需求请注释或删除 + this.txtIpAddress.ReadOnly = true; + + // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作 + AddMsgDelegate = new ShowMsg(AddMsg); + + + // 设置服务器事件 + server.OnPrepareListen += new TcpServerEvent.OnPrepareListenEventHandler(OnPrepareListen); + server.OnAccept += new TcpServerEvent.OnAcceptEventHandler(OnAccept); + server.OnSend += new TcpServerEvent.OnSendEventHandler(OnSend); + server.OnReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive); + server.OnClose += new TcpServerEvent.OnCloseEventHandler(OnClose); + server.OnShutdown += new TcpServerEvent.OnShutdownEventHandler(OnShutdown); + + SetAppState(AppState.Stoped); + } + catch (Exception ex) + { + SetAppState(AppState.Error); + AddMsg(ex.Message); + } + } + + private void btnStart_Click(object sender, EventArgs e) + { + try + { + String ip = this.txtIpAddress.Text.Trim(); + ushort port = ushort.Parse(this.txtPort.Text.Trim()); + + // 写在这个位置是上面可能会异常 + SetAppState(AppState.Starting); + server.IpAddress = ip; + server.Port = port; + // 启动服务 + if (server.Start()) + { + this.Text = string.Format("{2} - ({0}:{1})", ip, port, title); + SetAppState(AppState.Started); + AddMsg(string.Format("$Server Start OK -> ({0}:{1})", ip, port)); + } + else + { + SetAppState(AppState.Stoped); + throw new Exception(string.Format("$Server Start Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + private void btnStop_Click(object sender, EventArgs e) + { + SetAppState(AppState.Stoping); + + // 停止服务 + AddMsg("$Server Stop"); + if (server.Stop()) + { + this.Text = title; + SetAppState(AppState.Stoped); + } + else + { + AddMsg(string.Format("$Stop Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); + } + } + + private void btnDisconn_Click(object sender, EventArgs e) + { + try + { + IntPtr connId = (IntPtr)Convert.ToInt32(this.txtDisConn.Text.Trim()); + // 断开指定客户 + if (server.Disconnect(connId, true)) + { + AddMsg(string.Format("$({0}) Disconnect OK", connId)); + } + else + { + throw new Exception(string.Format("Disconnect({0}) Error", connId)); + } + } + catch (Exception ex) + { + AddMsg(ex.Message); + } + } + + + HandleResult OnPrepareListen(IntPtr soListen) + { + // 监听事件到达了,一般没什么用吧? + + return HandleResult.Ok; + } + + HandleResult OnAccept(IntPtr connId, IntPtr pClient) + { + // 客户进入了 + + + // 获取客户端ip和端口 + string ip = string.Empty; + ushort port = 0; + if (server.GetRemoteAddress(connId, ref ip, ref port)) + { + AddMsg(string.Format(" > [{0},OnAccept] -> PASS({1}:{2})", connId, ip.ToString(), port)); + } + else + { + AddMsg(string.Format(" > [{0},OnAccept] -> Server_GetClientAddress() Error", connId)); + } + + + // 设置附加数据 + ClientInfo ci = new ClientInfo(); + ci.ConnId = connId; + ci.IpAddress = ip; + ci.Port = port; + if (server.SetConnectionExtra(connId, ci) == false) + { + AddMsg(string.Format(" > [{0},OnAccept] -> SetConnectionExtra fail", connId)); + } + + return HandleResult.Ok; + } + + HandleResult OnSend(IntPtr connId, IntPtr pData, int length) + { + // 服务器发数据了 + + + AddMsg(string.Format(" > [{0},OnSend] -> ({1} bytes)", connId, length)); + + return HandleResult.Ok; + } + + HandleResult OnReceive(IntPtr connId, IntPtr pData, int length) + { + // 数据到达了 + try + { + // 从pData中获取字符串 + // string str = Marshal.PtrToStringAnsi(pData, length); + + // intptr转byte[] + // byte[] bytes = new byte[length]; + // Marshal.Copy(pData, bytes, 0, length); + + + // 获取附加数据 + IntPtr clientPtr = IntPtr.Zero; + if (server.GetConnectionExtra(connId, ref clientPtr)) + { + // ci 就是accept里传入的附加数据了 + ClientInfo ci = (ClientInfo)Marshal.PtrToStructure(clientPtr, typeof(ClientInfo)); + AddMsg(string.Format(" > [{0},OnReceive] -> {1}:{2} ({3} bytes)", ci.ConnId, ci.IpAddress, ci.Port, length)); + } + else + { + AddMsg(string.Format(" > [{0},OnReceive] -> ({1} bytes)", connId, length)); + } + + if (server.Send(connId, pData, length)) + { + return HandleResult.Ok; + } + + return HandleResult.Error; + } + catch (Exception) + { + + return HandleResult.Ignore; + } + } + + HandleResult OnClose(IntPtr connId, SocketOperation enOperation, int errorCode) + { + if(errorCode == 0) + AddMsg(string.Format(" > [{0},OnClose]", connId)); + else + AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode)); + + if (server.SetConnectionExtra(connId, null) == false) + { + AddMsg(string.Format(" > [{0},OnClose] -> SetConnectionExtra({0}, null) fail", connId)); + } + + return HandleResult.Ok; + } + + HandleResult OnShutdown() + { + // 服务关闭了 + + + AddMsg(" > [OnShutdown]"); + return HandleResult.Ok; + } + + + + /// + /// 设置程序状态 + /// + /// + void SetAppState(AppState state) + { + appState = state; + this.btnStart.Enabled = (appState == AppState.Stoped); + this.btnStop.Enabled = (appState == AppState.Started); + this.txtIpAddress.Enabled = (appState == AppState.Stoped); + this.txtPort.Enabled = (appState == AppState.Stoped); + this.txtDisConn.Enabled = (appState == AppState.Started); + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + /// + /// 往listbox加一条项目 + /// + /// + void AddMsg(string msg) + { + if (this.lbxMsg.InvokeRequired) + { + // 很帅的调自己 + this.lbxMsg.Invoke(AddMsgDelegate, msg); + } + else + { + if (this.lbxMsg.Items.Count > 100) + { + this.lbxMsg.Items.RemoveAt(0); + } + this.lbxMsg.Items.Add(msg); + this.lbxMsg.TopIndex = this.lbxMsg.Items.Count - (int)(this.lbxMsg.Height / this.lbxMsg.ItemHeight); + } + } + + private void txtDisConn_TextChanged(object sender, EventArgs e) + { + // CONNID框被改变事件 + this.btnDisconn.Enabled = (appState == AppState.Started && this.txtDisConn.Text.Length > 0); + } + + private void lbxMsg_KeyPress(object sender, KeyPressEventArgs e) + { + // 清理listbox + if (e.KeyChar == 'c' || e.KeyChar == 'C') + { + this.lbxMsg.Items.Clear(); + } + } + + private void frmServer_FormClosed(object sender, FormClosedEventArgs e) + { + server.Destroy(); + } + } + + [StructLayout(LayoutKind.Sequential)] + public class ClientInfo + { + public IntPtr ConnId { get; set; } + public string IpAddress { get; set; } + public ushort Port { get; set; } + } +} diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.resx b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/TcpServer/frmServer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Debug/HPSocket4C_UD.dll b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Debug/HPSocket4C_UD.dll new file mode 100644 index 000000000..5b55ca8f9 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Debug/HPSocket4C_UD.dll differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Debug/HPSocketCS.dll b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Debug/HPSocketCS.dll new file mode 100644 index 000000000..1986893d7 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Debug/HPSocketCS.dll differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/HPSocket4C_U.dll b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/HPSocket4C_U.dll new file mode 100644 index 000000000..e95307766 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/HPSocket4C_U.dll differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/HPSocketCS.dll b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/HPSocketCS.dll new file mode 100644 index 000000000..28f01c33b Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/HPSocketCS.dll differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpClient-PFM.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpClient-PFM.exe new file mode 100644 index 000000000..f8906f915 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpClient-PFM.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpClient.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpClient.exe new file mode 100644 index 000000000..efe485adc Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpClient.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPackClient.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPackClient.exe new file mode 100644 index 000000000..7f9af6363 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPackClient.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPackServer.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPackServer.exe new file mode 100644 index 000000000..aa808041f Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPackServer.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpProxyServer.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpProxyServer.exe new file mode 100644 index 000000000..4c582a5e0 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpProxyServer.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPullClient.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPullClient.exe new file mode 100644 index 000000000..683f36005 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPullClient.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPullServer.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPullServer.exe new file mode 100644 index 000000000..ddb179e2b Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpPullServer.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpServer-PFM.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpServer-PFM.exe new file mode 100644 index 000000000..7641b5d03 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpServer-PFM.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpServer.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpServer.exe new file mode 100644 index 000000000..f0240fb1c Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x64/Release/TcpServer.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Debug/HPSocket4C_UD.dll b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Debug/HPSocket4C_UD.dll new file mode 100644 index 000000000..a78dd6535 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Debug/HPSocket4C_UD.dll differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Debug/HPSocketCS.dll b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Debug/HPSocketCS.dll new file mode 100644 index 000000000..dcaa61dd1 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Debug/HPSocketCS.dll differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/HPSocket4C_U.dll b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/HPSocket4C_U.dll new file mode 100644 index 000000000..6e49dabbd Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/HPSocket4C_U.dll differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/HPSocketCS.dll b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/HPSocketCS.dll new file mode 100644 index 000000000..28f01c33b Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/HPSocketCS.dll differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpClient-PFM.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpClient-PFM.exe new file mode 100644 index 000000000..7cc749b8d Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpClient-PFM.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpClient.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpClient.exe new file mode 100644 index 000000000..aa9e335a8 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpClient.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPackClient.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPackClient.exe new file mode 100644 index 000000000..114ae2462 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPackClient.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPackServer.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPackServer.exe new file mode 100644 index 000000000..05e21524b Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPackServer.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpProxyServer.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpProxyServer.exe new file mode 100644 index 000000000..e7e3285b3 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpProxyServer.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPullClient.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPullClient.exe new file mode 100644 index 000000000..9b9a32ef3 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPullClient.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPullServer.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPullServer.exe new file mode 100644 index 000000000..ac948b3f3 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpPullServer.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpServer-PFM.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpServer-PFM.exe new file mode 100644 index 000000000..ef5eafb4c Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpServer-PFM.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpServer.exe b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpServer.exe new file mode 100644 index 000000000..2ba2e3aa6 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/C#/HPSocket4CS/bin/x86/Release/TcpServer.exe differ diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/HPSocketSDKUnit.pas b/HP-Socket/Demo/Other Languages Demos/Delphi/HPSocketSDKUnit.pas new file mode 100644 index 000000000..483b0e6b5 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/HPSocketSDKUnit.pas @@ -0,0 +1,1180 @@ +unit HPSocketSDKUnit; + +interface + +uses + Windows; + +const + HPSocketDLL = 'HPSocket4C_UD.dll'; + +type +{$Z4} + SOCKET = Pointer; + PVOID = Pointer; + + WSABUF = packed record + len: ULONG; { the length of the buffer } + buf: PChar; { the pointer to the buffer } + end { WSABUF }; + + PWSABUF = ^WSABUF; + LPWSABUF = PWSABUF; + + WSABUFArray = array of WSABUF; + + PInteger = ^Integer; + PUShort = ^USHORT; + { /************************************************************************ + ƣ ID + ID + ************************************************************************/ } + HP_CONNID = DWORD; + PHP_CONNID = ^HP_CONNID; + HP_CONNIDArray = array of HP_CONNID; + { /************************************************************************ + ƣ Socket ָͱ + Socket ָ붨Ϊֱ۵ı + ************************************************************************/ } + HP_Object = PVOID; + + HP_Server = HP_Object; + HP_Agent = HP_Object; + HP_Client = HP_Object; + HP_TcpServer = HP_Object; + HP_TcpAgent = HP_Object; + HP_TcpClient = HP_Object; + HP_PullSocket = HP_Object; + HP_PullClient = HP_Object; + HP_TcpPullServer = HP_Object; + HP_TcpPullClient = HP_Object; + HP_TcpPullAgent = HP_Object; + HP_UdpServer = HP_Object; + HP_UdpClient = HP_Object; + HP_UdpCast = HP_Object; + + HP_Listener = HP_Object; + HP_ServerListener = HP_Object; + HP_ClientListener = HP_Object; + HP_AgentListener = HP_Object; + HP_TcpServerListener = HP_Object; + HP_TcpClientListener = HP_Object; + HP_PullSocketListener = HP_Object; + HP_TcpAgentListener = HP_Object; + HP_TcpPullServerListener = HP_Object; + HP_TcpPullClientListener = HP_Object; + HP_TcpPullAgentListener = HP_Object; + HP_UdpServerListener = HP_Object; + HP_UdpClientListener = HP_Object; + HP_UdpCastListener = HP_Object; + + { /*****************************************************************************************************/ + /******************************************** ࡢӿ ********************************************/ + /*****************************************************************************************************/ } + + { /************************************************************************ + ƣͨ״̬ + Ӧóͨͨ GetState() ȡǰ״̬ + ************************************************************************/ } + EnAppState = (ST_STARTING, ST_STARTED, ST_STOPING, ST_STOPED); + + { /************************************************************************ + ƣͨ״̬ + Ӧóͨͨ GetState() ȡǰ״̬ + ************************************************************************ } + En_HP_ServiceState = (HP_SS_STARTING = 0, // + HP_SS_STARTED = 1, // Ѿ + HP_SS_STOPING = 2, // ֹͣ + HP_SS_STOPED = 3 // Ѿ + ); + + { ************************************************************************ + ƣSocket + Ӧó OnErrror() ¼ͨòʶֲµĴ + ************************************************************************ } + En_HP_SocketOperation = (HP_SO_UNKNOWN = 0, // Unknown + HP_SO_ACCEPT = 1, // Acccept + HP_SO_CONNECT = 2, // Connnect + HP_SO_SEND = 3, // Send + HP_SO_RECEIVE = 4 // Receive + ); + + { ************************************************************************ + ƣ¼֪ͨ + ¼֪ͨķֵͬķֵӰͨĺΪ + ************************************************************************ } + En_HP_HandleResult = (HP_HR_OK = 0, // ɹ + HP_HR_IGNORE = 1, // + HP_HR_ERROR = 2 // + ); + + { /************************************************************************ + ƣץȡ + ץȡķֵ + ************************************************************************/ } + En_HP_FetchResult = (HP_FR_OK = 0, // ɹ + HP_FR_LENGTH_TOO_LONG = 1, // ץȡȹ + HP_FR_DATA_NOT_FOUND = 2 // Ҳ ConnID Ӧ + ); + + { /************************************************************************ + ƣݷͲ + Server Agent ݷͲ + + * ģʽĬϣ ѶͲһͣӴЧ + * ȫģʽ ѶͲһͣƴٶȣ⻺ + * ֱģʽ ÿһͲֱͶݣڸزߵҪʵʱԽϸߵij + + ************************************************************************/ } + En_HP_SendPolicy = (HP_SP_PACK = 0, // ģʽĬϣ + HP_SP_SAFE = 1, // ȫģʽ + HP_SP_DIRECT = 2 // ֱģʽ + ); + + { /************************************************************************ + ƣݽղ + Server Agent ݽղ + + * ģʽĬϣ ڵӣ˳򴥷 OnReceive OnClose/OnError ¼ + ӦóĸӶȣǿȫԣͬʱʧһЩܡ + * ģʽ ڵӣͬʱյ OnReceive OnClose/OnError ¼ʱ + ڲͬ ͨ߳ͬʱЩ¼ʹܵõӦó + Ҫ OnReceive ¼УijЩܱ OnClose/OnError + ¼ĻͷŵΣ߼øӣʱȱ + + ************************************************************************/ } + En_HP_RecvPolicy = (HP_RP_SERIAL = 0, // ģʽĬϣ + HP_RP_PARALLEL = 1 // ģʽ + ); + + { ************************************************************************ + ƣ + Start() / Stop() ִʧʱͨ GetLastError() ȡ + ************************************************************************ } + En_HP_SocketError = (HP_SE_OK = 0, // ɹ + HP_SE_ILLEGAL_STATE = 1, // ǰ״̬ + HP_SE_INVALID_PARAM = 2, // Ƿ + HP_SE_SOCKET_CREATE = 3, // SOCKET ʧ + HP_SE_SOCKET_BIND = 4, // SOCKET ʧ + HP_SE_SOCKET_PREPARE = 5, // SOCKET ʧ + HP_SE_SOCKET_LISTEN = 6, // SOCKET ʧ + HP_SE_CP_CREATE = 7, // ɶ˿ʧ + HP_SE_WORKER_THREAD_CREATE = 8, // ߳ʧ + HP_SE_DETECT_THREAD_CREATE = 9, // ߳ʧ + HP_SE_SOCKE_ATTACH_TO_CP = 10, // ɶ˿ʧ + HP_SE_CONNECT_SERVER = 11, // ӷʧ + HP_SE_NETWORK = 12, // + HP_SE_DATA_PROC = 13, // ݴ + HP_SE_DATA_SEND = 14 // ݷʧ + ); + + { + /************************************************************************ + ƣģʽ + UDP IJģʽ鲥㲥 + ************************************************************************/ + } + En_HP_CastMode = ( + HP_CM_MULTICAST = 0, // 鲥 + HP_CM_BROADCAST = 1 // 㲥 + ); + + { /****************************************************/ + /************** HPSocket4C.dll ص **************/ } + + { **************************************************** } + + { /* ص */ } + HP_FN_OnSend = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnReceive = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_Client_OnReceive = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnPullReceive = function(dwConnID: HP_CONNID; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnClose = function(dwConnID: HP_CONNID): En_HP_HandleResult; stdcall; + HP_FN_OnError = function(dwConnID: HP_CONNID; enOperation: En_HP_SocketOperation; iErrorCode: Integer) : En_HP_HandleResult; stdcall; + + { /* ˻ص */ } + HP_FN_OnPrepareListen = function(soListen: Pointer): En_HP_HandleResult; stdcall; + // Ϊ TCP ӣpClientΪ SOCKET Ϊ UDP ӣpClientΪ SOCKADDR_IN ָ룻 + HP_FN_OnAccept = function(dwConnID: HP_CONNID; pClient: Pointer): En_HP_HandleResult; stdcall; + HP_FN_OnServerShutdown = function(): En_HP_HandleResult; stdcall; + + { /* ͻ˺ Agent ص */ } + HP_FN_OnPrepareConnect = function(dwConnID: HP_CONNID; SOCKET: Pointer): En_HP_HandleResult; stdcall; + HP_FN_OnConnect = function(dwConnID: HP_CONNID): En_HP_HandleResult; stdcall; + + { /* Agent ص */ } + HP_FN_OnAgentShutdown = function(): En_HP_HandleResult; stdcall; + + { /****************************************************/ + /************** HPSocket4C.dll **************/ } + + // HP_TcpServer +function Create_HP_TcpServer(pListener: HP_TcpServerListener): HP_TcpPullServer; + stdcall; external HPSocketDLL; +// HP_TcpClient +function Create_HP_TcpClient(pListener: HP_TcpClientListener): HP_TcpClient; + stdcall; external HPSocketDLL; +// HP_TcpAgent +function Create_HP_TcpAgent(pListener: HP_TcpAgentListener): HP_TcpAgent; + stdcall; external HPSocketDLL; +// HP_TcpPullServer +function Create_HP_TcpPullServer(pListener: HP_TcpPullServerListener) + : HP_TcpPullServer; stdcall; external HPSocketDLL; +// HP_TcpPullClient +function Create_HP_TcpPullClient(pListener: HP_TcpPullClientListener) + : HP_TcpPullClient; stdcall; external HPSocketDLL; +// HP_TcpPullAgent +function Create_HP_TcpPullAgent(pListener: HP_TcpPullAgentListener) + : HP_TcpPullAgent; stdcall; external HPSocketDLL; +// HP_UdpServer +function Create_HP_UdpServer(pListener: HP_UdpServerListener): HP_UdpServer; + stdcall; external HPSocketDLL; +// HP_UdpClient +function Create_HP_UdpClient(pListener: HP_UdpClientListener): HP_UdpClient; + stdcall; external HPSocketDLL; + +// HP_TcpServer +procedure Destroy_HP_TcpServer(pServer: HP_TcpServer); stdcall; + external HPSocketDLL; +// HP_TcpClient +procedure Destroy_HP_TcpClient(pClient: HP_TcpClient); stdcall; + external HPSocketDLL; +// HP_TcpAgent +procedure Destroy_HP_TcpAgent(pAgent: HP_TcpAgent); stdcall; + external HPSocketDLL; +// HP_TcpPullServer +procedure Destroy_HP_TcpPullServer(pServer: HP_TcpPullServer); stdcall; + external HPSocketDLL; +// HP_TcpPullClient +procedure Destroy_HP_TcpPullClient(pClient: HP_TcpPullClient); stdcall; + external HPSocketDLL; +// HP_TcpPullAgent +procedure Destroy_HP_TcpPullAgent(pAgent: HP_TcpPullAgent); stdcall; + external HPSocketDLL; +// HP_UdpServer +procedure Destroy_HP_UdpServer(pServer: HP_UdpServer); stdcall; + external HPSocketDLL; +// HP_UdpClient + +// HP_TcpServerListener +function Create_HP_TcpServerListener(): HP_TcpServerListener; stdcall; + external HPSocketDLL; +// HP_TcpClientListener +function Create_HP_TcpClientListener(): HP_TcpClientListener; stdcall; + external HPSocketDLL; +// HP_TcpAgentListener +function Create_HP_TcpAgentListener(): HP_TcpAgentListener; stdcall; + external HPSocketDLL; +// HP_TcpPullServerListener +function Create_HP_TcpPullServerListener(): HP_TcpPullServerListener; stdcall; + external HPSocketDLL; +// HP_TcpPullClientListener +function Create_HP_TcpPullClientListener(): HP_TcpPullClientListener; stdcall; + external HPSocketDLL; +// HP_TcpPullAgentListener +function Create_HP_TcpPullAgentListener(): HP_TcpPullAgentListener; stdcall; + external HPSocketDLL; +// HP_UdpServerListener +function Create_HP_UdpServerListener(): HP_UdpServerListener; stdcall; + external HPSocketDLL; +// HP_UdpClientListener +function Create_HP_UdpClientListener(): HP_UdpClientListener; stdcall; + external HPSocketDLL; + +// HP_TcpServerListener +procedure Destroy_HP_TcpServerListener(pListener: HP_TcpServerListener); + stdcall; external HPSocketDLL; +// HP_TcpClientListener +procedure Destroy_HP_TcpClientListener(pListener: HP_TcpClientListener); + stdcall; external HPSocketDLL; +// HP_TcpAgentListener +procedure Destroy_HP_TcpAgentListener(pListener: HP_TcpAgentListener); stdcall; + external HPSocketDLL; +// HP_TcpPullServerListener +procedure Destroy_HP_TcpPullServerListener(pListener: HP_TcpPullServerListener); + stdcall; external HPSocketDLL; +// HP_TcpPullClientListener +procedure Destroy_HP_TcpPullClientListener(pListener: HP_TcpPullClientListener); + stdcall; external HPSocketDLL; +// HP_TcpPullAgentListener +procedure Destroy_HP_TcpPullAgentListener(pListener: HP_TcpPullAgentListener); + stdcall; external HPSocketDLL; +// HP_UdpServerListener +procedure Destroy_HP_UdpServerListener(pListener: HP_UdpServerListener); + stdcall; external HPSocketDLL; +// HP_UdpClientListener +procedure Destroy_HP_UdpClientListener(pListener: HP_UdpClientListener); + stdcall; external HPSocketDLL; + +{ ***************************** Server ص÷ ***************************** } +procedure HP_Set_FN_Server_OnPrepareListen(pListener: HP_TcpServerListener; + fn: HP_FN_OnPrepareListen); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnAccept(pListener: HP_TcpServerListener; + fn: HP_FN_OnAccept); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnSend(pListener: HP_TcpServerListener; + fn: HP_FN_OnSend); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnReceive(pListener: HP_TcpServerListener; + fn: HP_FN_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnPullReceive(pListener: HP_TcpServerListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnClose(pListener: HP_TcpServerListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnError(pListener: HP_TcpServerListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnShutdown(pListener: HP_TcpServerListener; + fn: HP_FN_OnServerShutdown); stdcall; external HPSocketDLL; + +{ /***************************** Client ص÷ *****************************/ } +procedure HP_Set_FN_Client_OnPrepareConnect(pListener: HP_TcpClientListener; + fn: HP_FN_OnPrepareConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnConnect(pListener: HP_TcpClientListener; + fn: HP_FN_OnConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnSend(pListener: HP_TcpClientListener; + fn: HP_FN_OnSend); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnReceive(pListener: HP_TcpClientListener; + fn : HP_FN_Client_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnPullReceive(pListener: HP_TcpClientListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnClose(pListener: HP_TcpClientListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnError(pListener: HP_TcpClientListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; + +{ /****************************** Agent ص÷ *****************************/ } +procedure HP_Set_FN_Agent_OnPrepareConnect(pListener: HP_AgentListener; + fn: HP_FN_OnPrepareConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnConnect(pListener: HP_AgentListener; + fn: HP_FN_OnConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnSend(pListener: HP_AgentListener; fn: HP_FN_OnSend); + stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnReceive(pListener: HP_AgentListener; + fn: HP_FN_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnPullReceive(pListener: HP_AgentListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnClose(pListener: HP_AgentListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnError(pListener: HP_AgentListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnAgentShutdown(pListener: HP_AgentListener; + fn: HP_FN_OnAgentShutdown); stdcall; external HPSocketDLL; + +{ /**************************************************************************/ } + +{ /***************************** Server *****************************/ } + +{ /* + * ƣͨ + * ͨɺɿʼտͻӲշ + * + * pszBindAddress -- ַ + * usPort -- ˿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Server_Start(pServer: HP_Server; pszBindAddress: PWideChar; + usPort: USHORT): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رշͨرɺϿпͻӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Server_Stop(pServer: HP_Server): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ûͨ÷ָͻ˷ + * + * dwConnID -- ID + * pBuffer -- ݻ + * iLength -- ݳ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_Send(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Server_SendPart(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer; iOffset: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣͶ + * ָӷͶ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * dwConnID -- ID + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Server_SendPackets(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffers: WSABUFArray; iCount: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣϿ + * Ͽijͻ˵ + * + * dwConnID -- ID + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_Disconnect(pServer: HP_Server; dwConnID: HP_CONNID; + bForce: LongInt): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣϿʱ + * Ͽָʱ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_DisconnectLongConnections(pServer: HP_Server; + dwPeriod: LongInt; bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Server Էʷ *****************************/ } + +{ /* + * ƣӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * pv -- + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Server_SetConnectionExtra(pServer: HP_Server; dwConnID: HP_CONNID; + pExtra: PVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣȡӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * ppv -- ָ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Server_GetConnectionExtra(pServer: HP_Server; dwConnID: HP_CONNID; + ppExtra: PPVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* ͨǷ */ } +function HP_Server_HasStarted(pServer: HP_Server): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Server_GetState(pServer: HP_Server): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Server_GetLastError(pServer: HP_Object): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Server_GetLastErrorDesc(pServer: HP_Server): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Server_GetPendingDataLength(pServer: HP_Server; dwConnID: HP_CONNID; + piPending: PInteger): BOOL; stdcall; external HPSocketDLL; +{ /* ȡͻ */ } +function HP_Server_GetConnectionCount(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡӵ CONNID */ } +function HP_Server_GetAllConnectionIDs(pServer: HP_Server; pIDs: HP_CONNIDArray; + pdwCount: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijͻʱ룩 */ } +function HP_Server_GetConnectPeriod(pServer: HP_Server; dwConnID: HP_CONNID; + pdwPeriod: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡ Socket ĵַϢ */ } +function HP_Server_GetListenAddress(pServer: HP_Server; lpszAddress: PWideChar; + piAddressLen: PInteger; pusPort: PUShort): BOOL; stdcall; + external HPSocketDLL; +{ /* ȡijӵԶ̵ַϢ */ } +function HP_Server_GetRemoteAddress(pServer: HP_Server; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; + +{ /* ݷͲ */ } +procedure HP_Server_SetSendPolicy(pServer: HP_Server; + enSendPolicy: En_HP_SendPolicy); stdcall; external HPSocketDLL; +{ /* ݽղ */ } +procedure HP_Server_SetRecvPolicy(pServer: HP_Server; + enRecvPolicy: En_HP_RecvPolicy); stdcall; external HPSocketDLL; +{ /* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ } +procedure HP_Server_SetFreeSocketObjLockTime(pServer: HP_Server; + dwFreeSocketObjLockTime: LongInt); stdcall; external HPSocketDLL; +{ /* Socket شСͨΪƽ 1/3 - 1/2 */ } +procedure HP_Server_SetFreeSocketObjPool(pServer: HP_Server; + dwFreeSocketObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ Socket شС 2 - 3 */ } +procedure HP_Server_SetFreeBufferObjPool(pServer: HP_Server; + dwFreeBufferObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* Socket ػշֵͨΪ Socket شС 3 */ } +procedure HP_Server_SetFreeSocketObjHold(pServer: HP_Server; + dwFreeSocketObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Server_SetFreeBufferObjHold(pServer: HP_Server; + dwFreeBufferObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ù߳ͨΪ 2 * CPU + 2 */ } +procedure HP_Server_SetWorkerThreadCount(pServer: HP_Server; + dwWorkerThreadCount: LongInt); stdcall; external HPSocketDLL; +{ /* ùرշǰȴӹرյʱޣ룬0 򲻵ȴ */ } +procedure HP_Server_SetMaxShutdownWaitTime(pServer: HP_Server; + dwMaxShutdownWaitTime: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡݷͲ */ } +function HP_Server_GetSendPolicy(pServer: HP_Server): En_HP_SendPolicy; stdcall; + external HPSocketDLL; +{ /* ȡݽղ */ } +function HP_Server_GetRecvPolicy(pServer: HP_Server): En_HP_RecvPolicy; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ʱ */ } +function HP_Server_GetFreeSocketObjLockTime(pServer: HP_Server): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ Socket شС */ } +function HP_Server_GetFreeSocketObjPool(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Server_GetFreeBufferObjPool(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ػշֵ */ } +function HP_Server_GetFreeSocketObjHold(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Server_GetFreeBufferObjHold(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ߳ */ } +function HP_Server_GetWorkerThreadCount(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡرշǰȴӹرյʱ */ } +function HP_Server_GetMaxShutdownWaitTime(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /******************************* TCP Server *******************************/ } + +{ /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpServer_SendSmallFile(pServer: HP_Server; dwConnID: HP_CONNID; + lpszFileName: PWideChar; const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Server Էʷ *****************************/ } + +{ /* ü Socket ĵȺдСݲã */ } +procedure HP_TcpServer_SetSocketListenQueue(pServer: HP_TcpServer; + dwSocketListenQueue: LongInt); stdcall; external HPSocketDLL; +{ /* Accept ԤͶݸصãAccept ԤͶԽֵ֧IJԽࣩ */ } +procedure HP_TcpServer_SetAcceptSocketCount(pServer: HP_TcpServer; + dwAcceptSocketCount: LongInt); stdcall; external HPSocketDLL; +{ /* ͨݻСƽͨݰСãͨΪ 1024 ı */ } +procedure HP_TcpServer_SetSocketBufferSize(pServer: HP_TcpServer; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpServer_SetKeepAliveTime(pServer: HP_TcpServer; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpServer_SetKeepAliveInterval(pServer: HP_TcpServer; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡ Accept ԤͶ */ } +function HP_TcpServer_GetAcceptSocketCount(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡͨݻС */ } +function HP_TcpServer_GetSocketBufferSize(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ Socket ĵȺдС */ } +function HP_TcpServer_GetSocketListenQueue(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpServer_GetKeepAliveTime(pServer: HP_TcpServer): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpServer_GetKeepAliveInterval(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** UDP Server Էʷ *****************************/ } + +{ /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ } +procedure HP_UdpServer_SetMaxDatagramSize(pServer: HP_UdpServer; + dwMaxDatagramSize: LongInt); stdcall; external HPSocketDLL; +{ /* ȡݱ󳤶 */ } +function HP_UdpServer_GetMaxDatagramSize(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /* Receive ԤͶݸصãReceive ԤͶԽ򶪰ԽС */ } +procedure HP_UdpServer_SetPostReceiveCount(pServer: HP_UdpServer; + dwPostReceiveCount: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ Receive ԤͶ */ } +function HP_UdpServer_GetPostReceiveCount(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /* üԴ0 򲻷ͼԴΪѶߣ */ } +procedure HP_UdpServer_SetDetectAttempts(pServer: HP_UdpServer; + dwDetectAttempts: LongInt); stdcall; external HPSocketDLL; +{ /* üͼ룬0 ͼ */ } +procedure HP_UdpServer_SetDetectInterval(pServer: HP_UdpServer; + dwDetectInterval: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpServer_GetDetectAttempts(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpServer_GetDetectInterval(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Client *****************************/ } + +{ /* + * ƣͨ + * ͻͨӷˣɺɿʼշ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Client_Start(pClient: HP_Client; pszRemoteAddress: PWideChar; + usPort: USHORT; bAsyncConnect: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رտͻͨرɺϿ˵ӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Client_Stop(pClient: HP_Client): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ˷ + * + * pBuffer -- ͻ + * iLength -- ͻ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_Send(pClient: HP_Client; const pBuffer: Pointer; + iLength: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣ + * ˷ + * + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_SendPart(pClient: HP_Client; const pBuffer: Pointer; + iLength: Integer; iOffset: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣͶ + * ˷Ͷ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_SendPackets(pClient: HP_Client; const pBuffers: WSABUFArray; + iCount: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Client Էʷ *****************************/ } + +{ /* ͨǷ */ } +function HP_Client_HasStarted(pClient: HP_Client): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Client_GetState(pClient: HP_Client): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Client_GetLastError(pClient: HP_Client): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Client_GetLastErrorDesc(pClient: HP_Client): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡ ID */ } +function HP_Client_GetConnectionID(pClient: HP_Client): HP_CONNID; stdcall; + external HPSocketDLL; +{ /* ȡ Client Socket ĵַϢ */ } +function HP_Client_GetLocalAddress(pClient: HP_Client; lpszAddress: PWideChar; + piAddressLen: PInteger; pusPort: PUShort): BOOL; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Client_GetPendingDataLength(pClient: HP_Client; piPending: PInteger) + : BOOL; stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ -> PUSH ģͣ5 - 10PULL ģͣ10 - 20 */ } +procedure HP_Client_SetFreeBufferPoolSize(pClient: HP_Client; + dwFreeBufferPoolSize: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Client_SetFreeBufferPoolHold(pClient: HP_Client; + dwFreeBufferPoolHold: LongInt); stdcall; external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Client_GetFreeBufferPoolSize(pClient: HP_Client): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Client_GetFreeBufferPoolHold(pClient: HP_Client): LongInt; stdcall; + external HPSocketDLL; +{ // ȡһʧܲĴ } + +{ /**********************************************************************************/ + /******************************* TCP Client *******************************/ } + +{ /* + * ƣСļ + * ˷ 4096 KB µСļ + * + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpClient_SendSmallFile(pClient: HP_Client; lpszFileName: PWideChar; + const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Client Էʷ *****************************/ } + +{ /* ͨݻСƽͨݰСãͨΪ(N * 1024) - sizeof(TBufferObj) */ } +procedure HP_TcpClient_SetSocketBufferSize(pClient: HP_TcpClient; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpClient_SetKeepAliveTime(pClient: HP_TcpClient; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpClient_SetKeepAliveInterval(pClient: HP_TcpClient; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡͨݻС */ } +function HP_TcpClient_GetSocketBufferSize(pClient: HP_TcpClient): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpClient_GetKeepAliveTime(pClient: HP_TcpClient): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpClient_GetKeepAliveInterval(pClient: HP_TcpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** UDP Client Էʷ *****************************/ } + +{ /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ } +procedure HP_UdpClient_SetMaxDatagramSize(pClient: HP_UdpClient; + dwMaxDatagramSize: LongInt); stdcall; external HPSocketDLL; +{ /* ȡݱ󳤶 */ } +function HP_UdpClient_GetMaxDatagramSize(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /* üԴ0 򲻷ͼԴΪѶߣ */ } +procedure HP_UdpClient_SetDetectAttempts(pClient: HP_UdpClient; + dwDetectAttempts: LongInt); stdcall; external HPSocketDLL; +{ /* üͼ룬0 ͼ */ } +procedure HP_UdpClient_SetDetectInterval(pClient: HP_UdpClient; + dwDetectInterval: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpClient_GetDetectAttempts(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpClient_GetDetectInterval(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /**************************************************************************/ + /***************************** Agent *****************************/ } + +{ /* + * ƣͨ + * ͨŴɺɿʼԶ̷ + * + * pszBindAddress -- ַ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Agent_Start(pAgent: HP_Agent; pszBindAddress: PWideChar; + bAsyncConnect: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رͨرɺϿӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Agent_Stop(pAgent: HP_Agent): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣӷ + * ӷӳɹ IAgentListener յ OnConnect() ¼ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * pdwConnID -- IDĬϣnullptrȡ ID + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ SYS_GetLastError() ȡ Windows + */ } +function HP_Agent_Connect(pAgent: HP_Agent; pszRemoteAddress: PWideChar; + usPort: USHORT; pdwConnID: PHP_CONNID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_Send(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_SendPart(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer; iOffset: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣͶ + * ָӷͶ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * dwConnID -- ID + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_SendPackets(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffers: WSABUFArray; iCount: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣϿ + * Ͽij + * + * dwConnID -- ID + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Agent_Disconnect(pAgent: HP_Agent; dwConnID: HP_CONNID; + bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣϿʱ + * Ͽָʱ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Agent_DisconnectLongConnections(pAgent: HP_Agent; dwPeriod: LongInt; + bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Agent Էʷ *****************************/ } + +{ /* + * ƣӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * pv -- + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Agent_SetConnectionExtra(pAgent: HP_Agent; dwConnID: HP_CONNID; + pExtra: PVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣȡӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * ppv -- ָ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Agent_GetConnectionExtra(pAgent: HP_Agent; dwConnID: HP_CONNID; + ppExtra: PPVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* ͨǷ */ } +function HP_Agent_HasStarted(pAgent: HP_Agent): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Agent_GetState(pAgent: HP_Agent): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_Agent_GetConnectionCount(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡӵ CONNID */ } +function HP_Agent_GetAllConnectionIDs(pAgent: HP_Agent; pIDs: HP_CONNIDArray; + pdwCount: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijʱ룩 */ } +function HP_Agent_GetConnectPeriod(pAgent: HP_Agent; dwConnID: HP_CONNID; + pdwPeriod: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijӵıصַϢ */ } +function HP_Agent_GetLocalAddress(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; +{ /* ȡijӵԶ̵ַϢ */ } +function HP_Agent_GetRemoteAddress(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Agent_GetLastError(pAgent: HP_Agent): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Agent_GetLastErrorDesc(pAgent: HP_Agent): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Agent_GetPendingDataLength(pAgent: HP_Agent; dwConnID: HP_CONNID; + piPending: PInteger): BOOL; stdcall; external HPSocketDLL; + +{ /* ݷͲ */ } +procedure HP_Agent_SetSendPolicy(pAgent: HP_Agent; + enSendPolicy: En_HP_SendPolicy); stdcall; external HPSocketDLL; +{ /* ݽղ */ } +procedure HP_Agent_SetRecvPolicy(pAgent: HP_Agent; + enRecvPolicy: En_HP_RecvPolicy); stdcall; external HPSocketDLL; +{ /* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ } +procedure HP_Agent_SetFreeSocketObjLockTime(pAgent: HP_Agent; + dwFreeSocketObjLockTime: LongInt); stdcall; external HPSocketDLL; +{ /* Socket شСͨΪƽ 1/3 - 1/2 */ } +procedure HP_Agent_SetFreeSocketObjPool(pAgent: HP_Agent; + dwFreeSocketObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ Socket شС 2 - 3 */ } +procedure HP_Agent_SetFreeBufferObjPool(pAgent: HP_Agent; + dwFreeBufferObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* Socket ػշֵͨΪ Socket شС 3 */ } +procedure HP_Agent_SetFreeSocketObjHold(pAgent: HP_Agent; + dwFreeSocketObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Agent_SetFreeBufferObjHold(pAgent: HP_Agent; + dwFreeBufferObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ù߳ͨΪ 2 * CPU + 2 */ } +procedure HP_Agent_SetWorkerThreadCount(pAgent: HP_Agent; + dwWorkerThreadCount: LongInt); stdcall; external HPSocketDLL; +{ /* ùرǰȴӹرյʱޣ룬0 򲻵ȴ */ } +procedure HP_Agent_SetMaxShutdownWaitTime(pAgent: HP_Agent; + dwMaxShutdownWaitTime: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡݷͲ */ } +function HP_Agent_GetSendPolicy(pAgent: HP_Agent): En_HP_SendPolicy; stdcall; + external HPSocketDLL; +{ /* ȡݽղ */ } +function HP_Agent_GetRecvPolicy(pAgent: HP_Agent): En_HP_RecvPolicy; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ʱ */ } +function HP_Agent_GetFreeSocketObjLockTime(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket شС */ } +function HP_Agent_GetFreeSocketObjPool(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Agent_GetFreeBufferObjPool(HpAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ػշֵ */ } +function HP_Agent_GetFreeSocketObjHold(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Agent_GetFreeBufferObjHold(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ߳ */ } +function HP_Agent_GetWorkerThreadCount(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡرǰȴӹرյʱ */ } +function HP_Agent_GetMaxShutdownWaitTime(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /******************************* TCP Agent *******************************/ } + +{ /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpAgent_SendSmallFile(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszFileName: PWideChar; const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Agent Էʷ *****************************/ } + +{ /* ǷõַûƣĬϣã */ } +procedure HP_TcpAgent_SetReuseAddress(pAgent: HP_TcpAgent; bReuseAddress: BOOL); + stdcall; external HPSocketDLL; +{ /* Ƿõַû */ } +function HP_TcpAgent_IsReuseAddress(pAgent: HP_TcpAgent): BOOL; stdcall; + external HPSocketDLL; + +{ /* ͨݻСƽͨݰСãͨΪ 1024 ı */ } +procedure HP_TcpAgent_SetSocketBufferSize(pAgent: HP_TcpAgent; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpAgent_SetKeepAliveTime(pAgent: HP_TcpAgent; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpAgent_SetKeepAliveInterval(pAgent: HP_TcpAgent; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡͨݻС */ } +function HP_TcpAgent_GetSocketBufferSize(pAgent: HP_TcpAgent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpAgent_GetKeepAliveTime(pAgent: HP_TcpAgent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpAgent_GetKeepAliveInterval(pAgent: HP_TcpAgent): LongInt; + stdcall; external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Server *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullServer_Fetch(pServer: HP_TcpPullServer; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Server Էʷ *****************************/ } + +{ /***************************************************************************************/ + /***************************** TCP Pull Client *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullClient_Fetch(pClient: HP_TcpPullClient; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Client Էʷ *****************************/ } + +{ /***************************************************************************************/ + /***************************** TCP Pull Agent *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullAgent_Fetch(pAgent: HP_TcpPullAgent; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Agent Էʷ *****************************/ } + +{ /***************************************************************************************/ + /*************************************** ***************************************/ } + +{ /* ȡı */ } +function HP_GetSocketErrorDesc(enCode: En_HP_SocketError): PWideChar; stdcall; + external HPSocketDLL; +{ /* ϵͳ ::GetLastError() ȡϵͳ */ } +function SYS_GetLastError(): LongInt; stdcall; external HPSocketDLL; +// ϵͳ ::WSAGetLastError() ȡͨŴ +function SYS_WSAGetLastError(): Integer; stdcall; external HPSocketDLL; +// ϵͳ setsockopt() +function SYS_SetSocketOption(sock: SOCKET; level: Integer; name: Integer; + val: LPVOID; len: Integer): Integer; stdcall; external HPSocketDLL; +// ϵͳ getsockopt() +function SYS_GetSocketOption(sock: SOCKET; level: Integer; name: Integer; + val: LPVOID; len: PInteger): Integer; stdcall; external HPSocketDLL; +// ϵͳ ioctlsocket() +function SYS_IoctlSocket(sock: SOCKET; cmd: LongInt; arg: PULONG): Integer; + stdcall; external HPSocketDLL; +// ϵͳ ::WSAIoctl() +function SYS_WSAIoctl(sock: SOCKET; dwIoControlCode: LongInt; + lpvInBuffer: LPVOID; cbInBuffer: LongInt; lpvOutBuffer: LPVOID; + cbOutBuffer: LongInt; lpcbBytesReturned: LPDWORD): Integer; stdcall; + external HPSocketDLL; + +implementation + +end. + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/ClientUnit.dfm b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/ClientUnit.dfm new file mode 100644 index 000000000..5a4eb61e5 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/ClientUnit.dfm @@ -0,0 +1,91 @@ +object Form1: TForm1 + Left = 0 + Top = 0 + BorderIcons = [biSystemMenu, biMinimize] + BorderStyle = bsSingle + Caption = 'Echo-Client [ '#39'C'#39' - clear list box ]' + ClientHeight = 331 + ClientWidth = 458 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + Position = poScreenCenter + OnClose = FormClose + OnCreate = FormCreate + PixelsPerInch = 96 + TextHeight = 13 + object lstMsg: TListBox + Left = 1 + Top = 24 + Width = 457 + Height = 274 + ItemHeight = 13 + TabOrder = 0 + OnKeyPress = lstMsgKeyPress + end + object edtIpAddress: TEdit + Left = 1 + Top = 304 + Width = 121 + Height = 21 + TabOrder = 1 + Text = '127.0.0.1' + end + object edtPort: TEdit + Left = 128 + Top = 304 + Width = 48 + Height = 21 + TabOrder = 2 + Text = '5555' + end + object btnStart: TButton + Left = 335 + Top = 304 + Width = 57 + Height = 23 + Caption = 'Start' + TabOrder = 4 + OnClick = btnStartClick + end + object btnStop: TButton + Left = 398 + Top = 304 + Width = 57 + Height = 23 + Caption = 'Stop' + TabOrder = 5 + OnClick = btnStopClick + end + object chkAsyncConnect: TCheckBox + Left = 182 + Top = 306 + Width = 83 + Height = 17 + Caption = 'Async Conn' + Checked = True + State = cbChecked + TabOrder = 3 + end + object edtMsg: TEdit + Left = 1 + Top = 1 + Width = 395 + Height = 21 + TabOrder = 6 + Text = 'text to be sent' + end + object btnSend: TButton + Left = 399 + Top = 0 + Width = 57 + Height = 23 + Caption = 'Send' + TabOrder = 7 + OnClick = btnSendClick + end +end diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/ClientUnit.pas b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/ClientUnit.pas new file mode 100644 index 000000000..9e67722d8 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/ClientUnit.pas @@ -0,0 +1,293 @@ +unit ClientUnit; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, HPSocketSDKUnit, ExePublic; + +type + TForm1 = class(TForm) + lstMsg: TListBox; + edtIpAddress: TEdit; + edtPort: TEdit; + btnStart: TButton; + btnStop: TButton; + chkAsyncConnect: TCheckBox; + edtMsg: TEdit; + btnSend: TButton; + procedure btnStartClick(Sender: TObject); + procedure btnStopClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure btnSendClick(Sender: TObject); + procedure lstMsgKeyPress(Sender: TObject; var Key: Char); + procedure FormClose(Sender: TObject; var Action: TCloseAction); + private + { Private declarations } + procedure AddMsg(msg: string); + procedure SetAppState(state: EnAppState); + public + { Public declarations } + end; + + TDoClientRec = class(TThread) + Flen : Integer; + fData: Pointer; + RecMsg : PTMsg; + procedure showmsg; + protected + procedure Execute;override; + public + + constructor Create(len : Integer; pData: Pointer); + end; + +var + Form1: TForm1; + appState: EnAppState; + pClient: Pointer; + pListener: Pointer; + FConnId : DWORD; + +implementation + +{$R *.dfm} + +procedure TForm1.SetAppState(state: EnAppState); +begin + appState := state; + btnStart.Enabled := (appState = EnAppState.ST_STOPED); + btnStop.Enabled := (appState = EnAppState.ST_STARTED); + edtIpAddress.Enabled := (appState = EnAppState.ST_STOPED); + chkAsyncConnect.Enabled := (appState = EnAppState.ST_STOPED); + btnSend.Enabled := (appState = EnAppState.ST_STARTED); +end; + +procedure TForm1.AddMsg(msg: string); +begin + if lstMsg.Items.Count > 100 then + begin + lstMsg.Items.Clear; + end; + lstMsg.Items.Add(msg); +end; + +function OnConnect(dwConnID: DWORD): En_HP_HandleResult; stdcall; +begin + if Form1.chkAsyncConnect.Checked = True then + Form1.SetAppState(ST_STARTED); + Result := HP_HR_OK; +end; + +function HowManyChineseChar(Const s: String): Integer; +var + SW: WideString; + C: String; + i, WCount: Integer; +begin + SW := s; + WCount := 0; + For i := 1 to Length(SW) do + begin + C := SW[i]; + if Length(C) > $7F then + Inc(WCount) + + end; + Result := WCount; +end; + +function SendString(str: string): Boolean; +var + { + sendBuffer: array of byte; + sendStr: AnsiString; + sendLength: Integer; } + SendMsg : PTMsg; +begin + { + sendStr := AnsiString(str); + // ȡansiַij + sendLength := Length(sendStr); + // bufij + SetLength(sendBuffer, sendLength); + // ݵbuf + Move(sendStr[1], sendBuffer[0], sendLength); } + + + New(SendMsg); + SendMsg.nType := 1000; + SendMsg.nMsg := str; + + Result := HP_Client_Send(pClient, SendMsg, SizeOf(ttmsg)); +end; + +procedure TForm1.btnSendClick(Sender: TObject); +var + dwConnID: DWORD; +begin + dwConnID := HP_Client_GetConnectionID(pClient); + if SendString(edtMsg.Text) then + begin + FConnId := HP_Client_GetConnectionID(pClient); + AddMsg(Format('$ (%d) Send OK --> %s', [FConnId, edtMsg.Text])); + end + else + begin + AddMsg(Format('$ (%d) Send Fail --> %s', [FConnId, edtMsg.Text])); + end; +end; + +procedure TForm1.btnStartClick(Sender: TObject); +var + ip: PWideChar; + port: USHORT; +begin + // 쳣Լ + ip := PWideChar(edtIpAddress.Text); + port := USHORT(StrToInt(edtPort.Text)); + + // дλܻ쳣 + SetAppState(ST_STARTING); + + if (HP_Client_Start(pClient, ip, port, chkAsyncConnect.Checked)) then + begin + if chkAsyncConnect.Checked = False then + SetAppState(ST_STARTED); + AddMsg(Format('$Client Starting ... -> (%s:%d)', [ip, port])); + end + else + begin + SetAppState(ST_STOPED); + AddMsg(Format('$Client Start Error -> %s(%d)', [HP_Client_GetLastErrorDesc(pClient), + Integer( HP_Client_GetLastError(pClient))])); + end; + +end; + +function OnSend(dwConnID: DWORD; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; +begin + Form1.AddMsg(Format(' > [%d,OnSend] -> (%d bytes)', [FConnId, iLength])); + Result := HP_HR_OK; +end; + +function OnReceive(dwConnID: DWORD; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; +var + testString: AnsiString; + + doRec : TDoClientRec; +begin + Form1.AddMsg(Format(' > [%d,OnReceive] -> (%d bytes)', [FConnId, iLength])); + + {// һpDataתַʾ + SetLength(testString, iLength); + Move(pData^, testString[1], iLength); + Form1.AddMsg(Format(' > [%d,OnReceive] -> say:%s', [dwConnId, testString])); + } + + doRec := TDoClientRec.Create(iLength, pData); + doRec.Resume; + + Result := HP_HR_OK; +end; + +function OnCloseConn(dwConnID: DWORD): En_HP_HandleResult; stdcall; +begin + + Form1.AddMsg(Format(' > [%d,OnCloseConn]', [FConnId])); + + Form1.SetAppState(ST_STOPED); + Result := HP_HR_OK; +end; + +function OnError(dwConnID: DWORD; enOperation: En_HP_SocketOperation; iErrorCode: Integer): En_HP_HandleResult; stdcall; +begin + + Form1.AddMsg(Format('> [%d,OnError] -> OP:%d,CODE:%d', [FConnId, Integer(enOperation), iErrorCode])); + + Form1.SetAppState(ST_STOPED); + Result := HP_HR_OK; +end; + +procedure TForm1.btnStopClick(Sender: TObject); +begin + + SetAppState(ST_STOPING); + + // ֹͣ + AddMsg('$Server Stop'); + if (HP_Client_Stop(pClient)) then + SetAppState(ST_STOPED) + else + begin + AddMsg(Format('$Stop Error -> %s(%d)', [HP_Client_GetLastErrorDesc(pClient), + Integer(HP_Client_GetLastError(pClient))])); + end; +end; + +procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); +begin + // Socket + Destroy_HP_TcpClient(pClient); + + // ټ + Destroy_HP_TcpClientListener(pListener); +end; + +procedure TForm1.FormCreate(Sender: TObject); +begin + // + pListener := Create_HP_TcpClientListener(); + // Socket + pClient := Create_HP_TcpClient(pListener); + + // Socket ص + HP_Set_FN_Client_OnConnect(pListener, OnConnect); + HP_Set_FN_Client_OnSend(pListener, OnSend); + HP_Set_FN_Client_OnReceive(pListener, OnReceive); + HP_Set_FN_Client_OnClose(pListener, OnCloseConn); + HP_Set_FN_Client_OnError(pListener, OnError); + + SetAppState(ST_STOPED) +end; + +procedure TForm1.lstMsgKeyPress(Sender: TObject; var Key: Char); +begin + if (Key = 'c') or (Key = 'C') then + lstMsg.Items.Clear; +end; + +{ TDoClientRec } + +constructor TDoClientRec.Create(len: Integer; pData: Pointer); +begin + inherited Create(True); + Flen := len; + Move(pdata, fData, Flen); +end; + +procedure TDoClientRec.Execute; +begin + inherited; + try + Move(fdata, RecMsg, Flen); + try + case RecMsg.nType of + 1001 : begin + Synchronize(showmsg); + end; + end; + except + + end; + finally + + end; +end; + +procedure TDoClientRec.showmsg; +begin + Form1.AddMsg('Rec:' + RecMsg.nMsg); +end; + +end. diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/HPSocketSDKUnit.pas b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/HPSocketSDKUnit.pas new file mode 100644 index 000000000..483b0e6b5 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/HPSocketSDKUnit.pas @@ -0,0 +1,1180 @@ +unit HPSocketSDKUnit; + +interface + +uses + Windows; + +const + HPSocketDLL = 'HPSocket4C_UD.dll'; + +type +{$Z4} + SOCKET = Pointer; + PVOID = Pointer; + + WSABUF = packed record + len: ULONG; { the length of the buffer } + buf: PChar; { the pointer to the buffer } + end { WSABUF }; + + PWSABUF = ^WSABUF; + LPWSABUF = PWSABUF; + + WSABUFArray = array of WSABUF; + + PInteger = ^Integer; + PUShort = ^USHORT; + { /************************************************************************ + ƣ ID + ID + ************************************************************************/ } + HP_CONNID = DWORD; + PHP_CONNID = ^HP_CONNID; + HP_CONNIDArray = array of HP_CONNID; + { /************************************************************************ + ƣ Socket ָͱ + Socket ָ붨Ϊֱ۵ı + ************************************************************************/ } + HP_Object = PVOID; + + HP_Server = HP_Object; + HP_Agent = HP_Object; + HP_Client = HP_Object; + HP_TcpServer = HP_Object; + HP_TcpAgent = HP_Object; + HP_TcpClient = HP_Object; + HP_PullSocket = HP_Object; + HP_PullClient = HP_Object; + HP_TcpPullServer = HP_Object; + HP_TcpPullClient = HP_Object; + HP_TcpPullAgent = HP_Object; + HP_UdpServer = HP_Object; + HP_UdpClient = HP_Object; + HP_UdpCast = HP_Object; + + HP_Listener = HP_Object; + HP_ServerListener = HP_Object; + HP_ClientListener = HP_Object; + HP_AgentListener = HP_Object; + HP_TcpServerListener = HP_Object; + HP_TcpClientListener = HP_Object; + HP_PullSocketListener = HP_Object; + HP_TcpAgentListener = HP_Object; + HP_TcpPullServerListener = HP_Object; + HP_TcpPullClientListener = HP_Object; + HP_TcpPullAgentListener = HP_Object; + HP_UdpServerListener = HP_Object; + HP_UdpClientListener = HP_Object; + HP_UdpCastListener = HP_Object; + + { /*****************************************************************************************************/ + /******************************************** ࡢӿ ********************************************/ + /*****************************************************************************************************/ } + + { /************************************************************************ + ƣͨ״̬ + Ӧóͨͨ GetState() ȡǰ״̬ + ************************************************************************/ } + EnAppState = (ST_STARTING, ST_STARTED, ST_STOPING, ST_STOPED); + + { /************************************************************************ + ƣͨ״̬ + Ӧóͨͨ GetState() ȡǰ״̬ + ************************************************************************ } + En_HP_ServiceState = (HP_SS_STARTING = 0, // + HP_SS_STARTED = 1, // Ѿ + HP_SS_STOPING = 2, // ֹͣ + HP_SS_STOPED = 3 // Ѿ + ); + + { ************************************************************************ + ƣSocket + Ӧó OnErrror() ¼ͨòʶֲµĴ + ************************************************************************ } + En_HP_SocketOperation = (HP_SO_UNKNOWN = 0, // Unknown + HP_SO_ACCEPT = 1, // Acccept + HP_SO_CONNECT = 2, // Connnect + HP_SO_SEND = 3, // Send + HP_SO_RECEIVE = 4 // Receive + ); + + { ************************************************************************ + ƣ¼֪ͨ + ¼֪ͨķֵͬķֵӰͨĺΪ + ************************************************************************ } + En_HP_HandleResult = (HP_HR_OK = 0, // ɹ + HP_HR_IGNORE = 1, // + HP_HR_ERROR = 2 // + ); + + { /************************************************************************ + ƣץȡ + ץȡķֵ + ************************************************************************/ } + En_HP_FetchResult = (HP_FR_OK = 0, // ɹ + HP_FR_LENGTH_TOO_LONG = 1, // ץȡȹ + HP_FR_DATA_NOT_FOUND = 2 // Ҳ ConnID Ӧ + ); + + { /************************************************************************ + ƣݷͲ + Server Agent ݷͲ + + * ģʽĬϣ ѶͲһͣӴЧ + * ȫģʽ ѶͲһͣƴٶȣ⻺ + * ֱģʽ ÿһͲֱͶݣڸزߵҪʵʱԽϸߵij + + ************************************************************************/ } + En_HP_SendPolicy = (HP_SP_PACK = 0, // ģʽĬϣ + HP_SP_SAFE = 1, // ȫģʽ + HP_SP_DIRECT = 2 // ֱģʽ + ); + + { /************************************************************************ + ƣݽղ + Server Agent ݽղ + + * ģʽĬϣ ڵӣ˳򴥷 OnReceive OnClose/OnError ¼ + ӦóĸӶȣǿȫԣͬʱʧһЩܡ + * ģʽ ڵӣͬʱյ OnReceive OnClose/OnError ¼ʱ + ڲͬ ͨ߳ͬʱЩ¼ʹܵõӦó + Ҫ OnReceive ¼УijЩܱ OnClose/OnError + ¼ĻͷŵΣ߼øӣʱȱ + + ************************************************************************/ } + En_HP_RecvPolicy = (HP_RP_SERIAL = 0, // ģʽĬϣ + HP_RP_PARALLEL = 1 // ģʽ + ); + + { ************************************************************************ + ƣ + Start() / Stop() ִʧʱͨ GetLastError() ȡ + ************************************************************************ } + En_HP_SocketError = (HP_SE_OK = 0, // ɹ + HP_SE_ILLEGAL_STATE = 1, // ǰ״̬ + HP_SE_INVALID_PARAM = 2, // Ƿ + HP_SE_SOCKET_CREATE = 3, // SOCKET ʧ + HP_SE_SOCKET_BIND = 4, // SOCKET ʧ + HP_SE_SOCKET_PREPARE = 5, // SOCKET ʧ + HP_SE_SOCKET_LISTEN = 6, // SOCKET ʧ + HP_SE_CP_CREATE = 7, // ɶ˿ʧ + HP_SE_WORKER_THREAD_CREATE = 8, // ߳ʧ + HP_SE_DETECT_THREAD_CREATE = 9, // ߳ʧ + HP_SE_SOCKE_ATTACH_TO_CP = 10, // ɶ˿ʧ + HP_SE_CONNECT_SERVER = 11, // ӷʧ + HP_SE_NETWORK = 12, // + HP_SE_DATA_PROC = 13, // ݴ + HP_SE_DATA_SEND = 14 // ݷʧ + ); + + { + /************************************************************************ + ƣģʽ + UDP IJģʽ鲥㲥 + ************************************************************************/ + } + En_HP_CastMode = ( + HP_CM_MULTICAST = 0, // 鲥 + HP_CM_BROADCAST = 1 // 㲥 + ); + + { /****************************************************/ + /************** HPSocket4C.dll ص **************/ } + + { **************************************************** } + + { /* ص */ } + HP_FN_OnSend = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnReceive = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_Client_OnReceive = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnPullReceive = function(dwConnID: HP_CONNID; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnClose = function(dwConnID: HP_CONNID): En_HP_HandleResult; stdcall; + HP_FN_OnError = function(dwConnID: HP_CONNID; enOperation: En_HP_SocketOperation; iErrorCode: Integer) : En_HP_HandleResult; stdcall; + + { /* ˻ص */ } + HP_FN_OnPrepareListen = function(soListen: Pointer): En_HP_HandleResult; stdcall; + // Ϊ TCP ӣpClientΪ SOCKET Ϊ UDP ӣpClientΪ SOCKADDR_IN ָ룻 + HP_FN_OnAccept = function(dwConnID: HP_CONNID; pClient: Pointer): En_HP_HandleResult; stdcall; + HP_FN_OnServerShutdown = function(): En_HP_HandleResult; stdcall; + + { /* ͻ˺ Agent ص */ } + HP_FN_OnPrepareConnect = function(dwConnID: HP_CONNID; SOCKET: Pointer): En_HP_HandleResult; stdcall; + HP_FN_OnConnect = function(dwConnID: HP_CONNID): En_HP_HandleResult; stdcall; + + { /* Agent ص */ } + HP_FN_OnAgentShutdown = function(): En_HP_HandleResult; stdcall; + + { /****************************************************/ + /************** HPSocket4C.dll **************/ } + + // HP_TcpServer +function Create_HP_TcpServer(pListener: HP_TcpServerListener): HP_TcpPullServer; + stdcall; external HPSocketDLL; +// HP_TcpClient +function Create_HP_TcpClient(pListener: HP_TcpClientListener): HP_TcpClient; + stdcall; external HPSocketDLL; +// HP_TcpAgent +function Create_HP_TcpAgent(pListener: HP_TcpAgentListener): HP_TcpAgent; + stdcall; external HPSocketDLL; +// HP_TcpPullServer +function Create_HP_TcpPullServer(pListener: HP_TcpPullServerListener) + : HP_TcpPullServer; stdcall; external HPSocketDLL; +// HP_TcpPullClient +function Create_HP_TcpPullClient(pListener: HP_TcpPullClientListener) + : HP_TcpPullClient; stdcall; external HPSocketDLL; +// HP_TcpPullAgent +function Create_HP_TcpPullAgent(pListener: HP_TcpPullAgentListener) + : HP_TcpPullAgent; stdcall; external HPSocketDLL; +// HP_UdpServer +function Create_HP_UdpServer(pListener: HP_UdpServerListener): HP_UdpServer; + stdcall; external HPSocketDLL; +// HP_UdpClient +function Create_HP_UdpClient(pListener: HP_UdpClientListener): HP_UdpClient; + stdcall; external HPSocketDLL; + +// HP_TcpServer +procedure Destroy_HP_TcpServer(pServer: HP_TcpServer); stdcall; + external HPSocketDLL; +// HP_TcpClient +procedure Destroy_HP_TcpClient(pClient: HP_TcpClient); stdcall; + external HPSocketDLL; +// HP_TcpAgent +procedure Destroy_HP_TcpAgent(pAgent: HP_TcpAgent); stdcall; + external HPSocketDLL; +// HP_TcpPullServer +procedure Destroy_HP_TcpPullServer(pServer: HP_TcpPullServer); stdcall; + external HPSocketDLL; +// HP_TcpPullClient +procedure Destroy_HP_TcpPullClient(pClient: HP_TcpPullClient); stdcall; + external HPSocketDLL; +// HP_TcpPullAgent +procedure Destroy_HP_TcpPullAgent(pAgent: HP_TcpPullAgent); stdcall; + external HPSocketDLL; +// HP_UdpServer +procedure Destroy_HP_UdpServer(pServer: HP_UdpServer); stdcall; + external HPSocketDLL; +// HP_UdpClient + +// HP_TcpServerListener +function Create_HP_TcpServerListener(): HP_TcpServerListener; stdcall; + external HPSocketDLL; +// HP_TcpClientListener +function Create_HP_TcpClientListener(): HP_TcpClientListener; stdcall; + external HPSocketDLL; +// HP_TcpAgentListener +function Create_HP_TcpAgentListener(): HP_TcpAgentListener; stdcall; + external HPSocketDLL; +// HP_TcpPullServerListener +function Create_HP_TcpPullServerListener(): HP_TcpPullServerListener; stdcall; + external HPSocketDLL; +// HP_TcpPullClientListener +function Create_HP_TcpPullClientListener(): HP_TcpPullClientListener; stdcall; + external HPSocketDLL; +// HP_TcpPullAgentListener +function Create_HP_TcpPullAgentListener(): HP_TcpPullAgentListener; stdcall; + external HPSocketDLL; +// HP_UdpServerListener +function Create_HP_UdpServerListener(): HP_UdpServerListener; stdcall; + external HPSocketDLL; +// HP_UdpClientListener +function Create_HP_UdpClientListener(): HP_UdpClientListener; stdcall; + external HPSocketDLL; + +// HP_TcpServerListener +procedure Destroy_HP_TcpServerListener(pListener: HP_TcpServerListener); + stdcall; external HPSocketDLL; +// HP_TcpClientListener +procedure Destroy_HP_TcpClientListener(pListener: HP_TcpClientListener); + stdcall; external HPSocketDLL; +// HP_TcpAgentListener +procedure Destroy_HP_TcpAgentListener(pListener: HP_TcpAgentListener); stdcall; + external HPSocketDLL; +// HP_TcpPullServerListener +procedure Destroy_HP_TcpPullServerListener(pListener: HP_TcpPullServerListener); + stdcall; external HPSocketDLL; +// HP_TcpPullClientListener +procedure Destroy_HP_TcpPullClientListener(pListener: HP_TcpPullClientListener); + stdcall; external HPSocketDLL; +// HP_TcpPullAgentListener +procedure Destroy_HP_TcpPullAgentListener(pListener: HP_TcpPullAgentListener); + stdcall; external HPSocketDLL; +// HP_UdpServerListener +procedure Destroy_HP_UdpServerListener(pListener: HP_UdpServerListener); + stdcall; external HPSocketDLL; +// HP_UdpClientListener +procedure Destroy_HP_UdpClientListener(pListener: HP_UdpClientListener); + stdcall; external HPSocketDLL; + +{ ***************************** Server ص÷ ***************************** } +procedure HP_Set_FN_Server_OnPrepareListen(pListener: HP_TcpServerListener; + fn: HP_FN_OnPrepareListen); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnAccept(pListener: HP_TcpServerListener; + fn: HP_FN_OnAccept); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnSend(pListener: HP_TcpServerListener; + fn: HP_FN_OnSend); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnReceive(pListener: HP_TcpServerListener; + fn: HP_FN_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnPullReceive(pListener: HP_TcpServerListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnClose(pListener: HP_TcpServerListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnError(pListener: HP_TcpServerListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnShutdown(pListener: HP_TcpServerListener; + fn: HP_FN_OnServerShutdown); stdcall; external HPSocketDLL; + +{ /***************************** Client ص÷ *****************************/ } +procedure HP_Set_FN_Client_OnPrepareConnect(pListener: HP_TcpClientListener; + fn: HP_FN_OnPrepareConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnConnect(pListener: HP_TcpClientListener; + fn: HP_FN_OnConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnSend(pListener: HP_TcpClientListener; + fn: HP_FN_OnSend); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnReceive(pListener: HP_TcpClientListener; + fn : HP_FN_Client_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnPullReceive(pListener: HP_TcpClientListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnClose(pListener: HP_TcpClientListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnError(pListener: HP_TcpClientListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; + +{ /****************************** Agent ص÷ *****************************/ } +procedure HP_Set_FN_Agent_OnPrepareConnect(pListener: HP_AgentListener; + fn: HP_FN_OnPrepareConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnConnect(pListener: HP_AgentListener; + fn: HP_FN_OnConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnSend(pListener: HP_AgentListener; fn: HP_FN_OnSend); + stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnReceive(pListener: HP_AgentListener; + fn: HP_FN_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnPullReceive(pListener: HP_AgentListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnClose(pListener: HP_AgentListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnError(pListener: HP_AgentListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnAgentShutdown(pListener: HP_AgentListener; + fn: HP_FN_OnAgentShutdown); stdcall; external HPSocketDLL; + +{ /**************************************************************************/ } + +{ /***************************** Server *****************************/ } + +{ /* + * ƣͨ + * ͨɺɿʼտͻӲշ + * + * pszBindAddress -- ַ + * usPort -- ˿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Server_Start(pServer: HP_Server; pszBindAddress: PWideChar; + usPort: USHORT): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رշͨرɺϿпͻӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Server_Stop(pServer: HP_Server): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ûͨ÷ָͻ˷ + * + * dwConnID -- ID + * pBuffer -- ݻ + * iLength -- ݳ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_Send(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Server_SendPart(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer; iOffset: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣͶ + * ָӷͶ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * dwConnID -- ID + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Server_SendPackets(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffers: WSABUFArray; iCount: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣϿ + * Ͽijͻ˵ + * + * dwConnID -- ID + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_Disconnect(pServer: HP_Server; dwConnID: HP_CONNID; + bForce: LongInt): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣϿʱ + * Ͽָʱ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_DisconnectLongConnections(pServer: HP_Server; + dwPeriod: LongInt; bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Server Էʷ *****************************/ } + +{ /* + * ƣӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * pv -- + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Server_SetConnectionExtra(pServer: HP_Server; dwConnID: HP_CONNID; + pExtra: PVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣȡӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * ppv -- ָ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Server_GetConnectionExtra(pServer: HP_Server; dwConnID: HP_CONNID; + ppExtra: PPVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* ͨǷ */ } +function HP_Server_HasStarted(pServer: HP_Server): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Server_GetState(pServer: HP_Server): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Server_GetLastError(pServer: HP_Object): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Server_GetLastErrorDesc(pServer: HP_Server): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Server_GetPendingDataLength(pServer: HP_Server; dwConnID: HP_CONNID; + piPending: PInteger): BOOL; stdcall; external HPSocketDLL; +{ /* ȡͻ */ } +function HP_Server_GetConnectionCount(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡӵ CONNID */ } +function HP_Server_GetAllConnectionIDs(pServer: HP_Server; pIDs: HP_CONNIDArray; + pdwCount: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijͻʱ룩 */ } +function HP_Server_GetConnectPeriod(pServer: HP_Server; dwConnID: HP_CONNID; + pdwPeriod: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡ Socket ĵַϢ */ } +function HP_Server_GetListenAddress(pServer: HP_Server; lpszAddress: PWideChar; + piAddressLen: PInteger; pusPort: PUShort): BOOL; stdcall; + external HPSocketDLL; +{ /* ȡijӵԶ̵ַϢ */ } +function HP_Server_GetRemoteAddress(pServer: HP_Server; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; + +{ /* ݷͲ */ } +procedure HP_Server_SetSendPolicy(pServer: HP_Server; + enSendPolicy: En_HP_SendPolicy); stdcall; external HPSocketDLL; +{ /* ݽղ */ } +procedure HP_Server_SetRecvPolicy(pServer: HP_Server; + enRecvPolicy: En_HP_RecvPolicy); stdcall; external HPSocketDLL; +{ /* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ } +procedure HP_Server_SetFreeSocketObjLockTime(pServer: HP_Server; + dwFreeSocketObjLockTime: LongInt); stdcall; external HPSocketDLL; +{ /* Socket شСͨΪƽ 1/3 - 1/2 */ } +procedure HP_Server_SetFreeSocketObjPool(pServer: HP_Server; + dwFreeSocketObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ Socket شС 2 - 3 */ } +procedure HP_Server_SetFreeBufferObjPool(pServer: HP_Server; + dwFreeBufferObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* Socket ػշֵͨΪ Socket شС 3 */ } +procedure HP_Server_SetFreeSocketObjHold(pServer: HP_Server; + dwFreeSocketObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Server_SetFreeBufferObjHold(pServer: HP_Server; + dwFreeBufferObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ù߳ͨΪ 2 * CPU + 2 */ } +procedure HP_Server_SetWorkerThreadCount(pServer: HP_Server; + dwWorkerThreadCount: LongInt); stdcall; external HPSocketDLL; +{ /* ùرշǰȴӹرյʱޣ룬0 򲻵ȴ */ } +procedure HP_Server_SetMaxShutdownWaitTime(pServer: HP_Server; + dwMaxShutdownWaitTime: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡݷͲ */ } +function HP_Server_GetSendPolicy(pServer: HP_Server): En_HP_SendPolicy; stdcall; + external HPSocketDLL; +{ /* ȡݽղ */ } +function HP_Server_GetRecvPolicy(pServer: HP_Server): En_HP_RecvPolicy; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ʱ */ } +function HP_Server_GetFreeSocketObjLockTime(pServer: HP_Server): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ Socket شС */ } +function HP_Server_GetFreeSocketObjPool(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Server_GetFreeBufferObjPool(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ػշֵ */ } +function HP_Server_GetFreeSocketObjHold(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Server_GetFreeBufferObjHold(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ߳ */ } +function HP_Server_GetWorkerThreadCount(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡرշǰȴӹرյʱ */ } +function HP_Server_GetMaxShutdownWaitTime(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /******************************* TCP Server *******************************/ } + +{ /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpServer_SendSmallFile(pServer: HP_Server; dwConnID: HP_CONNID; + lpszFileName: PWideChar; const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Server Էʷ *****************************/ } + +{ /* ü Socket ĵȺдСݲã */ } +procedure HP_TcpServer_SetSocketListenQueue(pServer: HP_TcpServer; + dwSocketListenQueue: LongInt); stdcall; external HPSocketDLL; +{ /* Accept ԤͶݸصãAccept ԤͶԽֵ֧IJԽࣩ */ } +procedure HP_TcpServer_SetAcceptSocketCount(pServer: HP_TcpServer; + dwAcceptSocketCount: LongInt); stdcall; external HPSocketDLL; +{ /* ͨݻСƽͨݰСãͨΪ 1024 ı */ } +procedure HP_TcpServer_SetSocketBufferSize(pServer: HP_TcpServer; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpServer_SetKeepAliveTime(pServer: HP_TcpServer; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpServer_SetKeepAliveInterval(pServer: HP_TcpServer; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡ Accept ԤͶ */ } +function HP_TcpServer_GetAcceptSocketCount(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡͨݻС */ } +function HP_TcpServer_GetSocketBufferSize(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ Socket ĵȺдС */ } +function HP_TcpServer_GetSocketListenQueue(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpServer_GetKeepAliveTime(pServer: HP_TcpServer): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpServer_GetKeepAliveInterval(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** UDP Server Էʷ *****************************/ } + +{ /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ } +procedure HP_UdpServer_SetMaxDatagramSize(pServer: HP_UdpServer; + dwMaxDatagramSize: LongInt); stdcall; external HPSocketDLL; +{ /* ȡݱ󳤶 */ } +function HP_UdpServer_GetMaxDatagramSize(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /* Receive ԤͶݸصãReceive ԤͶԽ򶪰ԽС */ } +procedure HP_UdpServer_SetPostReceiveCount(pServer: HP_UdpServer; + dwPostReceiveCount: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ Receive ԤͶ */ } +function HP_UdpServer_GetPostReceiveCount(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /* üԴ0 򲻷ͼԴΪѶߣ */ } +procedure HP_UdpServer_SetDetectAttempts(pServer: HP_UdpServer; + dwDetectAttempts: LongInt); stdcall; external HPSocketDLL; +{ /* üͼ룬0 ͼ */ } +procedure HP_UdpServer_SetDetectInterval(pServer: HP_UdpServer; + dwDetectInterval: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpServer_GetDetectAttempts(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpServer_GetDetectInterval(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Client *****************************/ } + +{ /* + * ƣͨ + * ͻͨӷˣɺɿʼշ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Client_Start(pClient: HP_Client; pszRemoteAddress: PWideChar; + usPort: USHORT; bAsyncConnect: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رտͻͨرɺϿ˵ӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Client_Stop(pClient: HP_Client): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ˷ + * + * pBuffer -- ͻ + * iLength -- ͻ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_Send(pClient: HP_Client; const pBuffer: Pointer; + iLength: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣ + * ˷ + * + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_SendPart(pClient: HP_Client; const pBuffer: Pointer; + iLength: Integer; iOffset: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣͶ + * ˷Ͷ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_SendPackets(pClient: HP_Client; const pBuffers: WSABUFArray; + iCount: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Client Էʷ *****************************/ } + +{ /* ͨǷ */ } +function HP_Client_HasStarted(pClient: HP_Client): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Client_GetState(pClient: HP_Client): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Client_GetLastError(pClient: HP_Client): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Client_GetLastErrorDesc(pClient: HP_Client): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡ ID */ } +function HP_Client_GetConnectionID(pClient: HP_Client): HP_CONNID; stdcall; + external HPSocketDLL; +{ /* ȡ Client Socket ĵַϢ */ } +function HP_Client_GetLocalAddress(pClient: HP_Client; lpszAddress: PWideChar; + piAddressLen: PInteger; pusPort: PUShort): BOOL; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Client_GetPendingDataLength(pClient: HP_Client; piPending: PInteger) + : BOOL; stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ -> PUSH ģͣ5 - 10PULL ģͣ10 - 20 */ } +procedure HP_Client_SetFreeBufferPoolSize(pClient: HP_Client; + dwFreeBufferPoolSize: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Client_SetFreeBufferPoolHold(pClient: HP_Client; + dwFreeBufferPoolHold: LongInt); stdcall; external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Client_GetFreeBufferPoolSize(pClient: HP_Client): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Client_GetFreeBufferPoolHold(pClient: HP_Client): LongInt; stdcall; + external HPSocketDLL; +{ // ȡһʧܲĴ } + +{ /**********************************************************************************/ + /******************************* TCP Client *******************************/ } + +{ /* + * ƣСļ + * ˷ 4096 KB µСļ + * + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpClient_SendSmallFile(pClient: HP_Client; lpszFileName: PWideChar; + const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Client Էʷ *****************************/ } + +{ /* ͨݻСƽͨݰСãͨΪ(N * 1024) - sizeof(TBufferObj) */ } +procedure HP_TcpClient_SetSocketBufferSize(pClient: HP_TcpClient; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpClient_SetKeepAliveTime(pClient: HP_TcpClient; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpClient_SetKeepAliveInterval(pClient: HP_TcpClient; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡͨݻС */ } +function HP_TcpClient_GetSocketBufferSize(pClient: HP_TcpClient): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpClient_GetKeepAliveTime(pClient: HP_TcpClient): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpClient_GetKeepAliveInterval(pClient: HP_TcpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** UDP Client Էʷ *****************************/ } + +{ /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ } +procedure HP_UdpClient_SetMaxDatagramSize(pClient: HP_UdpClient; + dwMaxDatagramSize: LongInt); stdcall; external HPSocketDLL; +{ /* ȡݱ󳤶 */ } +function HP_UdpClient_GetMaxDatagramSize(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /* üԴ0 򲻷ͼԴΪѶߣ */ } +procedure HP_UdpClient_SetDetectAttempts(pClient: HP_UdpClient; + dwDetectAttempts: LongInt); stdcall; external HPSocketDLL; +{ /* üͼ룬0 ͼ */ } +procedure HP_UdpClient_SetDetectInterval(pClient: HP_UdpClient; + dwDetectInterval: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpClient_GetDetectAttempts(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpClient_GetDetectInterval(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /**************************************************************************/ + /***************************** Agent *****************************/ } + +{ /* + * ƣͨ + * ͨŴɺɿʼԶ̷ + * + * pszBindAddress -- ַ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Agent_Start(pAgent: HP_Agent; pszBindAddress: PWideChar; + bAsyncConnect: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رͨرɺϿӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Agent_Stop(pAgent: HP_Agent): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣӷ + * ӷӳɹ IAgentListener յ OnConnect() ¼ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * pdwConnID -- IDĬϣnullptrȡ ID + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ SYS_GetLastError() ȡ Windows + */ } +function HP_Agent_Connect(pAgent: HP_Agent; pszRemoteAddress: PWideChar; + usPort: USHORT; pdwConnID: PHP_CONNID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_Send(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_SendPart(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer; iOffset: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣͶ + * ָӷͶ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * dwConnID -- ID + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_SendPackets(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffers: WSABUFArray; iCount: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣϿ + * Ͽij + * + * dwConnID -- ID + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Agent_Disconnect(pAgent: HP_Agent; dwConnID: HP_CONNID; + bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣϿʱ + * Ͽָʱ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Agent_DisconnectLongConnections(pAgent: HP_Agent; dwPeriod: LongInt; + bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Agent Էʷ *****************************/ } + +{ /* + * ƣӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * pv -- + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Agent_SetConnectionExtra(pAgent: HP_Agent; dwConnID: HP_CONNID; + pExtra: PVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣȡӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * ppv -- ָ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Agent_GetConnectionExtra(pAgent: HP_Agent; dwConnID: HP_CONNID; + ppExtra: PPVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* ͨǷ */ } +function HP_Agent_HasStarted(pAgent: HP_Agent): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Agent_GetState(pAgent: HP_Agent): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_Agent_GetConnectionCount(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡӵ CONNID */ } +function HP_Agent_GetAllConnectionIDs(pAgent: HP_Agent; pIDs: HP_CONNIDArray; + pdwCount: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijʱ룩 */ } +function HP_Agent_GetConnectPeriod(pAgent: HP_Agent; dwConnID: HP_CONNID; + pdwPeriod: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijӵıصַϢ */ } +function HP_Agent_GetLocalAddress(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; +{ /* ȡijӵԶ̵ַϢ */ } +function HP_Agent_GetRemoteAddress(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Agent_GetLastError(pAgent: HP_Agent): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Agent_GetLastErrorDesc(pAgent: HP_Agent): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Agent_GetPendingDataLength(pAgent: HP_Agent; dwConnID: HP_CONNID; + piPending: PInteger): BOOL; stdcall; external HPSocketDLL; + +{ /* ݷͲ */ } +procedure HP_Agent_SetSendPolicy(pAgent: HP_Agent; + enSendPolicy: En_HP_SendPolicy); stdcall; external HPSocketDLL; +{ /* ݽղ */ } +procedure HP_Agent_SetRecvPolicy(pAgent: HP_Agent; + enRecvPolicy: En_HP_RecvPolicy); stdcall; external HPSocketDLL; +{ /* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ } +procedure HP_Agent_SetFreeSocketObjLockTime(pAgent: HP_Agent; + dwFreeSocketObjLockTime: LongInt); stdcall; external HPSocketDLL; +{ /* Socket شСͨΪƽ 1/3 - 1/2 */ } +procedure HP_Agent_SetFreeSocketObjPool(pAgent: HP_Agent; + dwFreeSocketObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ Socket شС 2 - 3 */ } +procedure HP_Agent_SetFreeBufferObjPool(pAgent: HP_Agent; + dwFreeBufferObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* Socket ػշֵͨΪ Socket شС 3 */ } +procedure HP_Agent_SetFreeSocketObjHold(pAgent: HP_Agent; + dwFreeSocketObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Agent_SetFreeBufferObjHold(pAgent: HP_Agent; + dwFreeBufferObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ù߳ͨΪ 2 * CPU + 2 */ } +procedure HP_Agent_SetWorkerThreadCount(pAgent: HP_Agent; + dwWorkerThreadCount: LongInt); stdcall; external HPSocketDLL; +{ /* ùرǰȴӹرյʱޣ룬0 򲻵ȴ */ } +procedure HP_Agent_SetMaxShutdownWaitTime(pAgent: HP_Agent; + dwMaxShutdownWaitTime: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡݷͲ */ } +function HP_Agent_GetSendPolicy(pAgent: HP_Agent): En_HP_SendPolicy; stdcall; + external HPSocketDLL; +{ /* ȡݽղ */ } +function HP_Agent_GetRecvPolicy(pAgent: HP_Agent): En_HP_RecvPolicy; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ʱ */ } +function HP_Agent_GetFreeSocketObjLockTime(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket شС */ } +function HP_Agent_GetFreeSocketObjPool(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Agent_GetFreeBufferObjPool(HpAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ػշֵ */ } +function HP_Agent_GetFreeSocketObjHold(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Agent_GetFreeBufferObjHold(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ߳ */ } +function HP_Agent_GetWorkerThreadCount(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡرǰȴӹرյʱ */ } +function HP_Agent_GetMaxShutdownWaitTime(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /******************************* TCP Agent *******************************/ } + +{ /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpAgent_SendSmallFile(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszFileName: PWideChar; const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Agent Էʷ *****************************/ } + +{ /* ǷõַûƣĬϣã */ } +procedure HP_TcpAgent_SetReuseAddress(pAgent: HP_TcpAgent; bReuseAddress: BOOL); + stdcall; external HPSocketDLL; +{ /* Ƿõַû */ } +function HP_TcpAgent_IsReuseAddress(pAgent: HP_TcpAgent): BOOL; stdcall; + external HPSocketDLL; + +{ /* ͨݻСƽͨݰСãͨΪ 1024 ı */ } +procedure HP_TcpAgent_SetSocketBufferSize(pAgent: HP_TcpAgent; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpAgent_SetKeepAliveTime(pAgent: HP_TcpAgent; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpAgent_SetKeepAliveInterval(pAgent: HP_TcpAgent; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡͨݻС */ } +function HP_TcpAgent_GetSocketBufferSize(pAgent: HP_TcpAgent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpAgent_GetKeepAliveTime(pAgent: HP_TcpAgent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpAgent_GetKeepAliveInterval(pAgent: HP_TcpAgent): LongInt; + stdcall; external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Server *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullServer_Fetch(pServer: HP_TcpPullServer; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Server Էʷ *****************************/ } + +{ /***************************************************************************************/ + /***************************** TCP Pull Client *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullClient_Fetch(pClient: HP_TcpPullClient; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Client Էʷ *****************************/ } + +{ /***************************************************************************************/ + /***************************** TCP Pull Agent *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullAgent_Fetch(pAgent: HP_TcpPullAgent; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Agent Էʷ *****************************/ } + +{ /***************************************************************************************/ + /*************************************** ***************************************/ } + +{ /* ȡı */ } +function HP_GetSocketErrorDesc(enCode: En_HP_SocketError): PWideChar; stdcall; + external HPSocketDLL; +{ /* ϵͳ ::GetLastError() ȡϵͳ */ } +function SYS_GetLastError(): LongInt; stdcall; external HPSocketDLL; +// ϵͳ ::WSAGetLastError() ȡͨŴ +function SYS_WSAGetLastError(): Integer; stdcall; external HPSocketDLL; +// ϵͳ setsockopt() +function SYS_SetSocketOption(sock: SOCKET; level: Integer; name: Integer; + val: LPVOID; len: Integer): Integer; stdcall; external HPSocketDLL; +// ϵͳ getsockopt() +function SYS_GetSocketOption(sock: SOCKET; level: Integer; name: Integer; + val: LPVOID; len: PInteger): Integer; stdcall; external HPSocketDLL; +// ϵͳ ioctlsocket() +function SYS_IoctlSocket(sock: SOCKET; cmd: LongInt; arg: PULONG): Integer; + stdcall; external HPSocketDLL; +// ϵͳ ::WSAIoctl() +function SYS_WSAIoctl(sock: SOCKET; dwIoControlCode: LongInt; + lpvInBuffer: LPVOID; cbInBuffer: LongInt; lpvOutBuffer: LPVOID; + cbOutBuffer: LongInt; lpcbBytesReturned: LPDWORD): Integer; stdcall; + external HPSocketDLL; + +implementation + +end. + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dpr b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dpr new file mode 100644 index 000000000..8b205eb95 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dpr @@ -0,0 +1,16 @@ +program TCPClientProject; + +uses + Vcl.Forms, + ClientUnit in 'ClientUnit.pas' {Form1}, + HPSocketSDKUnit in 'HPSocketSDKUnit.pas', + ExePublic in '..\ExePublic.pas'; + +{$R *.res} + +begin + Application.Initialize; + Application.MainFormOnTaskbar := True; + Application.CreateForm(TForm1, Form1); + application.Run; +end. diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dproj b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dproj new file mode 100644 index 000000000..015b1a038 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dproj @@ -0,0 +1,531 @@ + + + {E7200A69-C615-4C49-AC0D-8B0ADC813178} + 16.0 + VCL + TCPClientProject.dpr + True + Debug + Win32 + 1 + Application + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + TCPClientProject + $(BDS)\bin\delphi_PROJECTICON.ico + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + false + false + false + false + false + + + $(BDS)\bin\default_app.manifest + true + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + 1033 + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + dxSkinCaramelRS19;dxSkinOffice2007BlackRS19;dxSkinSharpPlusRS19;cxSchedulerTreeBrowserRS19;dxPScxSSLnkRS19;dxSkinLiquidSkyRS19;dxPScxPivotGridLnkRS19;cxBarEditItemRS19;DBXSqliteDriver;dxPSdxDBTVLnkRS19;dxSkinOffice2007BlueRS19;cxDataRS19;cxLibraryRS19;fmx;dxWizardControlRS19;IndySystem;dxPScxCommonRS19;TeeDB;dxThemeRS19;dxPsPrVwAdvRS19;dxSkinHighContrastRS19;cxGridRS19;inetdbbde;vclib;DBXInterBaseDriver;dxPScxExtCommonRS19;DataSnapCommon;cxSchedulerRS19;DBXSybaseASEDriver;dxmdsRS19;DbxCommonDriver;dxSkinsdxBarPainterRS19;vclimg;dxSkinOffice2010SilverRS19;dbxcds;dxFlowChartRS19;MetropolisUILiveTile;dxPSdxOCLnkRS19;dxSkinSpringTimeRS19;dxdbtrRS19;vcldb;vcldsnap;dxDockingRS19;dxSkinsdxDLPainterRS19;dxdborRS19;cxSpreadSheetRS19;dxtrmdRS19;DBXDb2Driver;dxSpellCheckerRS19;dxSkinDevExpressDarkStyleRS19;DBXOracleDriver;CustomIPTransport;dxBarDBNavRS19;vclribbon;dxTileControlRS19;dsnap;IndyIPServer;dxSkinFoggyRS19;dxSkinSilverRS19;IndyCore;vcl;cxSchedulerGridRS19;dxSkinVS2010RS19;dxSkinStardustRS19;IndyIPCommon;CloudService;DBXMSSQLDriver;FmxTeeUI;CodeSiteExpressPkg;dxBarRS19;cxTreeListdxBarPopupMenuRS19;dxSkinXmas2008BlueRS19;dxPSCoreRS19;dxPSdxDBOCLnkRS19;cxPivotGridOLAPRS19;inetdbxpress;dxSkinValentineRS19;cxEditorsRS19;dxSkinMcSkinRS19;dxSkinDarkSideRS19;dxSkinLondonLiquidSkyRS19;dxPScxSchedulerLnkRS19;dxBarExtDBItemsRS19;dxTabbedMDIRS19;adortl;dxSkinOffice2007SilverRS19;dxSkinOffice2013WhiteRS19;dxSkinSevenRS19;dxDBXServerModeRS19;dxSkinSharpRS19;dxLayoutControlRS19;bindcompfmx;dxSkinBlueprintRS19;dxSkinOffice2007PinkRS19;cxPageControlRS19;vcldbx;cxExportRS19;dxSkinWhiteprintRS19;dxPSTeeChartRS19;rtl;dbrtl;DbxClientDriver;dcldxSkinsCoreRS19;dxSkinCoffeeRS19;bindcomp;dxPScxGridLnkRS19;dxSkinBlueRS19;Tee;cxPageControldxBarPopupMenuRS19;dxServerModeRS19;DBXOdbcDriver;cxVerticalGridRS19;dxSkinMoneyTwinsRS19;cxPivotGridChartRS19;xmlrtl;svnui;ibxpress;dxSkinsdxRibbonPainterRS19;dxSkiniMaginaryRS19;dxSkinSummer2008RS19;dxComnRS19;IndyProtocols;DBXMySQLDriver;dxSkinOffice2007GreenRS19;dxSkinTheAsphaltWorldRS19;cxPivotGridRS19;dxPSLnksRS19;bindcompdbx;vclactnband;bindengine;soaprtl;FMXTee;TeeUI;bindcompvcl;dxADOServerModeRS19;dxRibbonRS19;dxSkinDarkRoomRS19;vclie;dxSkinPumpkinRS19;dxBarExtItemsRS19;dxPSdxLCLnkRS19;vcltouch;dxNavBarRS19;dxSkinBlackRS19;dxSkinOffice2010BlackRS19;VclSmp;VCLRESTComponents;DBXInformixDriver;dxGDIPlusRS19;Intraweb;dxSkinSevenClassicRS19;dxCoreRS19;dsnapcon;DBXFirebirdDriver;dxSkinscxSchedulerPainterRS19;inet;dxSkinsCoreRS19;dxSkinsdxNavBarPainterRS19;dxSkinGlassOceansRS19;dxPScxTLLnkRS19;dxPScxVGridLnkRS19;dxPSdxFCLnkRS19;vclx;dxPSPrVwRibbonRS19;dxPSDBTeeChartRS19;svn;DBXSybaseASADriver;dxSkinOffice2010BlueRS19;dxPScxPCProdRS19;RESTComponents;dxSkinLilianRS19;dxSkinscxPCPainterRS19;bdertl;dxorgcRS19;cxTreeListRS19;dbexpress;DataSnapIndy10ServerTransport;dxSkinDevExpressStyleRS19;IndyIPClient;$(DCC_UsePackage) + + + dxSkinCaramelRS19;dxSkinOffice2007BlackRS19;dxSkinSharpPlusRS19;cxSchedulerTreeBrowserRS19;dxPScxSSLnkRS19;dxSkinLiquidSkyRS19;dxPScxPivotGridLnkRS19;cxBarEditItemRS19;DBXSqliteDriver;dxPSdxDBTVLnkRS19;dxSkinOffice2007BlueRS19;cxDataRS19;cxLibraryRS19;fmx;dxWizardControlRS19;IndySystem;dxPScxCommonRS19;TeeDB;dxThemeRS19;dxPsPrVwAdvRS19;dxSkinHighContrastRS19;cxGridRS19;vclib;DBXInterBaseDriver;dxPScxExtCommonRS19;DataSnapCommon;cxSchedulerRS19;DBXSybaseASEDriver;dxmdsRS19;DbxCommonDriver;dxSkinsdxBarPainterRS19;vclimg;dxSkinOffice2010SilverRS19;dbxcds;dxFlowChartRS19;MetropolisUILiveTile;dxPSdxOCLnkRS19;dxSkinSpringTimeRS19;dxdbtrRS19;vcldb;vcldsnap;dxDockingRS19;dxSkinsdxDLPainterRS19;dxdborRS19;cxSpreadSheetRS19;dxtrmdRS19;DBXDb2Driver;dxSpellCheckerRS19;dxSkinDevExpressDarkStyleRS19;DBXOracleDriver;CustomIPTransport;dxBarDBNavRS19;vclribbon;dxTileControlRS19;dsnap;IndyIPServer;dxSkinFoggyRS19;dxSkinSilverRS19;IndyCore;vcl;cxSchedulerGridRS19;dxSkinVS2010RS19;dxSkinStardustRS19;IndyIPCommon;CloudService;DBXMSSQLDriver;FmxTeeUI;dxBarRS19;cxTreeListdxBarPopupMenuRS19;dxSkinXmas2008BlueRS19;dxPSCoreRS19;dxPSdxDBOCLnkRS19;cxPivotGridOLAPRS19;inetdbxpress;dxSkinValentineRS19;cxEditorsRS19;dxSkinMcSkinRS19;dxSkinDarkSideRS19;dxSkinLondonLiquidSkyRS19;dxPScxSchedulerLnkRS19;dxBarExtDBItemsRS19;dxTabbedMDIRS19;adortl;dxSkinOffice2007SilverRS19;dxSkinOffice2013WhiteRS19;dxSkinSevenRS19;dxDBXServerModeRS19;dxSkinSharpRS19;dxLayoutControlRS19;bindcompfmx;dxSkinBlueprintRS19;dxSkinOffice2007PinkRS19;cxPageControlRS19;cxExportRS19;dxSkinWhiteprintRS19;dxPSTeeChartRS19;rtl;dbrtl;DbxClientDriver;dcldxSkinsCoreRS19;dxSkinCoffeeRS19;bindcomp;dxPScxGridLnkRS19;dxSkinBlueRS19;Tee;cxPageControldxBarPopupMenuRS19;dxServerModeRS19;DBXOdbcDriver;cxVerticalGridRS19;dxSkinMoneyTwinsRS19;cxPivotGridChartRS19;xmlrtl;ibxpress;dxSkinsdxRibbonPainterRS19;dxSkiniMaginaryRS19;dxSkinSummer2008RS19;dxComnRS19;IndyProtocols;DBXMySQLDriver;dxSkinOffice2007GreenRS19;dxSkinTheAsphaltWorldRS19;cxPivotGridRS19;dxPSLnksRS19;bindcompdbx;vclactnband;bindengine;soaprtl;FMXTee;TeeUI;bindcompvcl;dxADOServerModeRS19;dxRibbonRS19;dxSkinDarkRoomRS19;vclie;dxSkinPumpkinRS19;dxBarExtItemsRS19;dxPSdxLCLnkRS19;vcltouch;dxNavBarRS19;dxSkinBlackRS19;dxSkinOffice2010BlackRS19;VclSmp;VCLRESTComponents;DBXInformixDriver;dxGDIPlusRS19;Intraweb;dxSkinSevenClassicRS19;dxCoreRS19;dsnapcon;DBXFirebirdDriver;dxSkinscxSchedulerPainterRS19;inet;dxSkinsCoreRS19;dxSkinsdxNavBarPainterRS19;dxSkinGlassOceansRS19;dxPScxTLLnkRS19;dxPScxVGridLnkRS19;dxPSdxFCLnkRS19;vclx;dxPSPrVwRibbonRS19;dxPSDBTeeChartRS19;DBXSybaseASADriver;dxSkinOffice2010BlueRS19;dxPScxPCProdRS19;RESTComponents;dxSkinLilianRS19;dxSkinscxPCPainterRS19;dxorgcRS19;cxTreeListRS19;dbexpress;DataSnapIndy10ServerTransport;dxSkinDevExpressStyleRS19;IndyIPClient;$(DCC_UsePackage) + + + DEBUG;$(DCC_Define) + true + false + true + true + true + + + E:\MyProject\Hp_Socket\Delphi\TestEcho\bin\Win32\Release + 1033 + true + false + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + E:\MyProject\Hp_Socket\Delphi\TestEcho\bin\Win32\Release + 1033 + true + + + + MainSource + + +
Form1
+ dfm +
+ + + + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + +
+ + Delphi.Personality.12 + + + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 2052 + 936 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + TCPClientProject.dpr + + + Embarcadero C++Builder Office 2000 Servers Package + Embarcadero C++Builder Office XP Servers Package + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + File d:\vcl\devexpress\devexpress\library\rs21\win32\bpl\dcldxpscxgridlnkrs21.bpl not found + + + + + + TCPClientProject.exe + true + + + + + 1 + .dylib + + + 0 + .bpl + + + Contents\MacOS + 1 + .dylib + + + 1 + .dylib + + + + + 1 + .dylib + + + 0 + .dll;.bpl + + + Contents\MacOS + 1 + .dylib + + + 1 + .dylib + + + + + 1 + + + 1 + + + + + Contents + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + res\drawable-normal + 1 + + + + + library\lib\x86 + 1 + + + + + 1 + + + 1 + + + + + Contents + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + 1 + + + 1 + + + + + res\drawable-xlarge + 1 + + + + + res\drawable-xhdpi + 1 + + + + + 1 + + + 1 + + + + + res\drawable-xxhdpi + 1 + + + + + library\lib\mips + 1 + + + + + res\drawable + 1 + + + + + Contents\MacOS + 1 + + + 1 + + + 0 + + + + + Contents\MacOS + 1 + .framework + + + 0 + + + + + res\drawable-small + 1 + + + + + 1 + + + + + Contents\MacOS + 1 + + + 1 + + + Contents\MacOS + 0 + + + + + classes + 1 + + + + + 1 + + + 1 + + + + + 1 + + + 1 + + + + + res\drawable + 1 + + + + + Contents\Resources + 1 + + + + + 1 + + + + + 1 + + + 1 + + + + + 1 + + + library\lib\armeabi-v7a + 1 + + + 0 + + + Contents\MacOS + 1 + + + 1 + + + + + library\lib\armeabi + 1 + + + + + res\drawable-large + 1 + + + + + 0 + + + 0 + + + 0 + + + Contents\MacOS + 0 + + + 0 + + + + + 1 + + + 1 + + + + + res\drawable-ldpi + 1 + + + + + res\values + 1 + + + + + 1 + + + 1 + + + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + + + 1 + + + + + + + + + + + True + False + + + 12 + + + + +
diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dproj.local b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dproj.local new file mode 100644 index 000000000..2b385535e --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.dproj.local @@ -0,0 +1,14 @@ + + + + 2013/09/26 12:41:30.000.878,=E:\Documents\RAD Studio\Projects\Unit1.pas + 2014/03/28 14:37:52.000.944,=F:\Documents\RAD Studio\Projects\Unit2.pas + 2014/03/28 14:40:16.000.880,=F:\Documents\RAD Studio\Projects\Unit2.pas + 2014/03/28 14:40:24.000.985,F:\Documents\RAD Studio\Projects\Unit2.pas=F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Client\ClientUnit.pas + 2014/03/28 14:40:24.000.985,F:\Documents\RAD Studio\Projects\Unit2.dfm=F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Client\ClientUnit.dfm + 2014/03/28 14:40:33.000.094,F:\Documents\RAD Studio\Projects\Project1.dproj=F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Client\TCPClientProject.dproj + 2014/03/28 17:39:27.000.287,=F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Client\Unit1.pas + 2014/03/28 17:39:44.000.403,F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Client\HPSocketSDKUnit.pas=F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Client\Unit1.pas + 2015/01/22 21:16:31.000.078,=E:\MyProject\Hp_Socket\Delphi\TestEcho\ExePublic.pas + + diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.identcache b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.identcache new file mode 100644 index 000000000..e7b2caf14 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.identcache differ diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.res b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.res new file mode 100644 index 000000000..d6cf6329c Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.res differ diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.skincfg b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.skincfg new file mode 100644 index 000000000..c80eb9d63 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Client/TCPClientProject.skincfg @@ -0,0 +1,50 @@ +[ExpressSkins] +Default=1 +ShowNotifications=1 +Enabled=1 +dxSkinBlack=1 +dxSkinBlue=1 +dxSkinBlueprint=1 +dxSkinCaramel=1 +dxSkinCoffee=1 +dxSkinDarkRoom=1 +dxSkinDarkSide=1 +dxSkinDevExpressDarkStyle=1 +dxSkinDevExpressStyle=1 +dxSkinFoggy=1 +dxSkinGlassOceans=1 +dxSkinHighContrast=1 +dxSkiniMaginary=1 +dxSkinLilian=1 +dxSkinLiquidSky=1 +dxSkinLondonLiquidSky=1 +dxSkinMcSkin=1 +dxSkinMoneyTwins=1 +dxSkinOffice2007Black=1 +dxSkinOffice2007Blue=1 +dxSkinOffice2007Green=1 +dxSkinOffice2007Pink=1 +dxSkinOffice2007Silver=1 +dxSkinOffice2010Black=1 +dxSkinOffice2010Blue=1 +dxSkinOffice2010Silver=1 +dxSkinOffice2013White=1 +dxSkinPumpkin=1 +dxSkinSeven=1 +dxSkinSevenClassic=1 +dxSkinSharp=1 +dxSkinSharpPlus=1 +dxSkinSilver=1 +dxSkinSpringTime=1 +dxSkinStardust=1 +dxSkinSummer2008=1 +dxSkinTheAsphaltWorld=1 +dxSkinsDefaultPainters=1 +dxSkinValentine=1 +dxSkinVS2010=1 +dxSkinWhiteprint=1 +dxSkinXmas2008Blue=1 +dxSkinMetropolis=1 +dxSkinMetropolisDark=1 +dxSkinOffice2013DarkGray=1 +dxSkinOffice2013LightGray=1 diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ExePublic.pas b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ExePublic.pas new file mode 100644 index 000000000..a042409a8 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ExePublic.pas @@ -0,0 +1,16 @@ +unit ExePublic; + +interface + +type + PTMsg = ^TTMsg; + TTMsg = record + nType : Integer; + //ѡarray of charΪָ + //ֵṩַģʽ + nMsg : string[128] + end; + +implementation + +end. diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup.groupproj b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup.groupproj new file mode 100644 index 000000000..105636370 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup.groupproj @@ -0,0 +1,48 @@ + + + {3A6E6A00-50B6-41E9-B2CD-1E8A9D7770C9} + + + + + + + + + + + Default.Personality.12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup.groupproj.local b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup.groupproj.local new file mode 100644 index 000000000..e0756786d --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup.groupproj.local @@ -0,0 +1,6 @@ + + + + + + diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup_prjgroup.tvsconfig b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup_prjgroup.tvsconfig new file mode 100644 index 000000000..d43078016 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/ProjectGroup_prjgroup.tvsconfig @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/HPSocketSDKUnit.pas b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/HPSocketSDKUnit.pas new file mode 100644 index 000000000..483b0e6b5 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/HPSocketSDKUnit.pas @@ -0,0 +1,1180 @@ +unit HPSocketSDKUnit; + +interface + +uses + Windows; + +const + HPSocketDLL = 'HPSocket4C_UD.dll'; + +type +{$Z4} + SOCKET = Pointer; + PVOID = Pointer; + + WSABUF = packed record + len: ULONG; { the length of the buffer } + buf: PChar; { the pointer to the buffer } + end { WSABUF }; + + PWSABUF = ^WSABUF; + LPWSABUF = PWSABUF; + + WSABUFArray = array of WSABUF; + + PInteger = ^Integer; + PUShort = ^USHORT; + { /************************************************************************ + ƣ ID + ID + ************************************************************************/ } + HP_CONNID = DWORD; + PHP_CONNID = ^HP_CONNID; + HP_CONNIDArray = array of HP_CONNID; + { /************************************************************************ + ƣ Socket ָͱ + Socket ָ붨Ϊֱ۵ı + ************************************************************************/ } + HP_Object = PVOID; + + HP_Server = HP_Object; + HP_Agent = HP_Object; + HP_Client = HP_Object; + HP_TcpServer = HP_Object; + HP_TcpAgent = HP_Object; + HP_TcpClient = HP_Object; + HP_PullSocket = HP_Object; + HP_PullClient = HP_Object; + HP_TcpPullServer = HP_Object; + HP_TcpPullClient = HP_Object; + HP_TcpPullAgent = HP_Object; + HP_UdpServer = HP_Object; + HP_UdpClient = HP_Object; + HP_UdpCast = HP_Object; + + HP_Listener = HP_Object; + HP_ServerListener = HP_Object; + HP_ClientListener = HP_Object; + HP_AgentListener = HP_Object; + HP_TcpServerListener = HP_Object; + HP_TcpClientListener = HP_Object; + HP_PullSocketListener = HP_Object; + HP_TcpAgentListener = HP_Object; + HP_TcpPullServerListener = HP_Object; + HP_TcpPullClientListener = HP_Object; + HP_TcpPullAgentListener = HP_Object; + HP_UdpServerListener = HP_Object; + HP_UdpClientListener = HP_Object; + HP_UdpCastListener = HP_Object; + + { /*****************************************************************************************************/ + /******************************************** ࡢӿ ********************************************/ + /*****************************************************************************************************/ } + + { /************************************************************************ + ƣͨ״̬ + Ӧóͨͨ GetState() ȡǰ״̬ + ************************************************************************/ } + EnAppState = (ST_STARTING, ST_STARTED, ST_STOPING, ST_STOPED); + + { /************************************************************************ + ƣͨ״̬ + Ӧóͨͨ GetState() ȡǰ״̬ + ************************************************************************ } + En_HP_ServiceState = (HP_SS_STARTING = 0, // + HP_SS_STARTED = 1, // Ѿ + HP_SS_STOPING = 2, // ֹͣ + HP_SS_STOPED = 3 // Ѿ + ); + + { ************************************************************************ + ƣSocket + Ӧó OnErrror() ¼ͨòʶֲµĴ + ************************************************************************ } + En_HP_SocketOperation = (HP_SO_UNKNOWN = 0, // Unknown + HP_SO_ACCEPT = 1, // Acccept + HP_SO_CONNECT = 2, // Connnect + HP_SO_SEND = 3, // Send + HP_SO_RECEIVE = 4 // Receive + ); + + { ************************************************************************ + ƣ¼֪ͨ + ¼֪ͨķֵͬķֵӰͨĺΪ + ************************************************************************ } + En_HP_HandleResult = (HP_HR_OK = 0, // ɹ + HP_HR_IGNORE = 1, // + HP_HR_ERROR = 2 // + ); + + { /************************************************************************ + ƣץȡ + ץȡķֵ + ************************************************************************/ } + En_HP_FetchResult = (HP_FR_OK = 0, // ɹ + HP_FR_LENGTH_TOO_LONG = 1, // ץȡȹ + HP_FR_DATA_NOT_FOUND = 2 // Ҳ ConnID Ӧ + ); + + { /************************************************************************ + ƣݷͲ + Server Agent ݷͲ + + * ģʽĬϣ ѶͲһͣӴЧ + * ȫģʽ ѶͲһͣƴٶȣ⻺ + * ֱģʽ ÿһͲֱͶݣڸزߵҪʵʱԽϸߵij + + ************************************************************************/ } + En_HP_SendPolicy = (HP_SP_PACK = 0, // ģʽĬϣ + HP_SP_SAFE = 1, // ȫģʽ + HP_SP_DIRECT = 2 // ֱģʽ + ); + + { /************************************************************************ + ƣݽղ + Server Agent ݽղ + + * ģʽĬϣ ڵӣ˳򴥷 OnReceive OnClose/OnError ¼ + ӦóĸӶȣǿȫԣͬʱʧһЩܡ + * ģʽ ڵӣͬʱյ OnReceive OnClose/OnError ¼ʱ + ڲͬ ͨ߳ͬʱЩ¼ʹܵõӦó + Ҫ OnReceive ¼УijЩܱ OnClose/OnError + ¼ĻͷŵΣ߼øӣʱȱ + + ************************************************************************/ } + En_HP_RecvPolicy = (HP_RP_SERIAL = 0, // ģʽĬϣ + HP_RP_PARALLEL = 1 // ģʽ + ); + + { ************************************************************************ + ƣ + Start() / Stop() ִʧʱͨ GetLastError() ȡ + ************************************************************************ } + En_HP_SocketError = (HP_SE_OK = 0, // ɹ + HP_SE_ILLEGAL_STATE = 1, // ǰ״̬ + HP_SE_INVALID_PARAM = 2, // Ƿ + HP_SE_SOCKET_CREATE = 3, // SOCKET ʧ + HP_SE_SOCKET_BIND = 4, // SOCKET ʧ + HP_SE_SOCKET_PREPARE = 5, // SOCKET ʧ + HP_SE_SOCKET_LISTEN = 6, // SOCKET ʧ + HP_SE_CP_CREATE = 7, // ɶ˿ʧ + HP_SE_WORKER_THREAD_CREATE = 8, // ߳ʧ + HP_SE_DETECT_THREAD_CREATE = 9, // ߳ʧ + HP_SE_SOCKE_ATTACH_TO_CP = 10, // ɶ˿ʧ + HP_SE_CONNECT_SERVER = 11, // ӷʧ + HP_SE_NETWORK = 12, // + HP_SE_DATA_PROC = 13, // ݴ + HP_SE_DATA_SEND = 14 // ݷʧ + ); + + { + /************************************************************************ + ƣģʽ + UDP IJģʽ鲥㲥 + ************************************************************************/ + } + En_HP_CastMode = ( + HP_CM_MULTICAST = 0, // 鲥 + HP_CM_BROADCAST = 1 // 㲥 + ); + + { /****************************************************/ + /************** HPSocket4C.dll ص **************/ } + + { **************************************************** } + + { /* ص */ } + HP_FN_OnSend = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnReceive = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_Client_OnReceive = function(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnPullReceive = function(dwConnID: HP_CONNID; iLength: Integer): En_HP_HandleResult; stdcall; + HP_FN_OnClose = function(dwConnID: HP_CONNID): En_HP_HandleResult; stdcall; + HP_FN_OnError = function(dwConnID: HP_CONNID; enOperation: En_HP_SocketOperation; iErrorCode: Integer) : En_HP_HandleResult; stdcall; + + { /* ˻ص */ } + HP_FN_OnPrepareListen = function(soListen: Pointer): En_HP_HandleResult; stdcall; + // Ϊ TCP ӣpClientΪ SOCKET Ϊ UDP ӣpClientΪ SOCKADDR_IN ָ룻 + HP_FN_OnAccept = function(dwConnID: HP_CONNID; pClient: Pointer): En_HP_HandleResult; stdcall; + HP_FN_OnServerShutdown = function(): En_HP_HandleResult; stdcall; + + { /* ͻ˺ Agent ص */ } + HP_FN_OnPrepareConnect = function(dwConnID: HP_CONNID; SOCKET: Pointer): En_HP_HandleResult; stdcall; + HP_FN_OnConnect = function(dwConnID: HP_CONNID): En_HP_HandleResult; stdcall; + + { /* Agent ص */ } + HP_FN_OnAgentShutdown = function(): En_HP_HandleResult; stdcall; + + { /****************************************************/ + /************** HPSocket4C.dll **************/ } + + // HP_TcpServer +function Create_HP_TcpServer(pListener: HP_TcpServerListener): HP_TcpPullServer; + stdcall; external HPSocketDLL; +// HP_TcpClient +function Create_HP_TcpClient(pListener: HP_TcpClientListener): HP_TcpClient; + stdcall; external HPSocketDLL; +// HP_TcpAgent +function Create_HP_TcpAgent(pListener: HP_TcpAgentListener): HP_TcpAgent; + stdcall; external HPSocketDLL; +// HP_TcpPullServer +function Create_HP_TcpPullServer(pListener: HP_TcpPullServerListener) + : HP_TcpPullServer; stdcall; external HPSocketDLL; +// HP_TcpPullClient +function Create_HP_TcpPullClient(pListener: HP_TcpPullClientListener) + : HP_TcpPullClient; stdcall; external HPSocketDLL; +// HP_TcpPullAgent +function Create_HP_TcpPullAgent(pListener: HP_TcpPullAgentListener) + : HP_TcpPullAgent; stdcall; external HPSocketDLL; +// HP_UdpServer +function Create_HP_UdpServer(pListener: HP_UdpServerListener): HP_UdpServer; + stdcall; external HPSocketDLL; +// HP_UdpClient +function Create_HP_UdpClient(pListener: HP_UdpClientListener): HP_UdpClient; + stdcall; external HPSocketDLL; + +// HP_TcpServer +procedure Destroy_HP_TcpServer(pServer: HP_TcpServer); stdcall; + external HPSocketDLL; +// HP_TcpClient +procedure Destroy_HP_TcpClient(pClient: HP_TcpClient); stdcall; + external HPSocketDLL; +// HP_TcpAgent +procedure Destroy_HP_TcpAgent(pAgent: HP_TcpAgent); stdcall; + external HPSocketDLL; +// HP_TcpPullServer +procedure Destroy_HP_TcpPullServer(pServer: HP_TcpPullServer); stdcall; + external HPSocketDLL; +// HP_TcpPullClient +procedure Destroy_HP_TcpPullClient(pClient: HP_TcpPullClient); stdcall; + external HPSocketDLL; +// HP_TcpPullAgent +procedure Destroy_HP_TcpPullAgent(pAgent: HP_TcpPullAgent); stdcall; + external HPSocketDLL; +// HP_UdpServer +procedure Destroy_HP_UdpServer(pServer: HP_UdpServer); stdcall; + external HPSocketDLL; +// HP_UdpClient + +// HP_TcpServerListener +function Create_HP_TcpServerListener(): HP_TcpServerListener; stdcall; + external HPSocketDLL; +// HP_TcpClientListener +function Create_HP_TcpClientListener(): HP_TcpClientListener; stdcall; + external HPSocketDLL; +// HP_TcpAgentListener +function Create_HP_TcpAgentListener(): HP_TcpAgentListener; stdcall; + external HPSocketDLL; +// HP_TcpPullServerListener +function Create_HP_TcpPullServerListener(): HP_TcpPullServerListener; stdcall; + external HPSocketDLL; +// HP_TcpPullClientListener +function Create_HP_TcpPullClientListener(): HP_TcpPullClientListener; stdcall; + external HPSocketDLL; +// HP_TcpPullAgentListener +function Create_HP_TcpPullAgentListener(): HP_TcpPullAgentListener; stdcall; + external HPSocketDLL; +// HP_UdpServerListener +function Create_HP_UdpServerListener(): HP_UdpServerListener; stdcall; + external HPSocketDLL; +// HP_UdpClientListener +function Create_HP_UdpClientListener(): HP_UdpClientListener; stdcall; + external HPSocketDLL; + +// HP_TcpServerListener +procedure Destroy_HP_TcpServerListener(pListener: HP_TcpServerListener); + stdcall; external HPSocketDLL; +// HP_TcpClientListener +procedure Destroy_HP_TcpClientListener(pListener: HP_TcpClientListener); + stdcall; external HPSocketDLL; +// HP_TcpAgentListener +procedure Destroy_HP_TcpAgentListener(pListener: HP_TcpAgentListener); stdcall; + external HPSocketDLL; +// HP_TcpPullServerListener +procedure Destroy_HP_TcpPullServerListener(pListener: HP_TcpPullServerListener); + stdcall; external HPSocketDLL; +// HP_TcpPullClientListener +procedure Destroy_HP_TcpPullClientListener(pListener: HP_TcpPullClientListener); + stdcall; external HPSocketDLL; +// HP_TcpPullAgentListener +procedure Destroy_HP_TcpPullAgentListener(pListener: HP_TcpPullAgentListener); + stdcall; external HPSocketDLL; +// HP_UdpServerListener +procedure Destroy_HP_UdpServerListener(pListener: HP_UdpServerListener); + stdcall; external HPSocketDLL; +// HP_UdpClientListener +procedure Destroy_HP_UdpClientListener(pListener: HP_UdpClientListener); + stdcall; external HPSocketDLL; + +{ ***************************** Server ص÷ ***************************** } +procedure HP_Set_FN_Server_OnPrepareListen(pListener: HP_TcpServerListener; + fn: HP_FN_OnPrepareListen); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnAccept(pListener: HP_TcpServerListener; + fn: HP_FN_OnAccept); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnSend(pListener: HP_TcpServerListener; + fn: HP_FN_OnSend); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnReceive(pListener: HP_TcpServerListener; + fn: HP_FN_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnPullReceive(pListener: HP_TcpServerListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnClose(pListener: HP_TcpServerListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnError(pListener: HP_TcpServerListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Server_OnShutdown(pListener: HP_TcpServerListener; + fn: HP_FN_OnServerShutdown); stdcall; external HPSocketDLL; + +{ /***************************** Client ص÷ *****************************/ } +procedure HP_Set_FN_Client_OnPrepareConnect(pListener: HP_TcpClientListener; + fn: HP_FN_OnPrepareConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnConnect(pListener: HP_TcpClientListener; + fn: HP_FN_OnConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnSend(pListener: HP_TcpClientListener; + fn: HP_FN_OnSend); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnReceive(pListener: HP_TcpClientListener; + fn : HP_FN_Client_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnPullReceive(pListener: HP_TcpClientListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnClose(pListener: HP_TcpClientListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Client_OnError(pListener: HP_TcpClientListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; + +{ /****************************** Agent ص÷ *****************************/ } +procedure HP_Set_FN_Agent_OnPrepareConnect(pListener: HP_AgentListener; + fn: HP_FN_OnPrepareConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnConnect(pListener: HP_AgentListener; + fn: HP_FN_OnConnect); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnSend(pListener: HP_AgentListener; fn: HP_FN_OnSend); + stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnReceive(pListener: HP_AgentListener; + fn: HP_FN_OnReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnPullReceive(pListener: HP_AgentListener; + fn: HP_FN_OnPullReceive); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnClose(pListener: HP_AgentListener; + fn: HP_FN_OnClose); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnError(pListener: HP_AgentListener; + fn: HP_FN_OnError); stdcall; external HPSocketDLL; +procedure HP_Set_FN_Agent_OnAgentShutdown(pListener: HP_AgentListener; + fn: HP_FN_OnAgentShutdown); stdcall; external HPSocketDLL; + +{ /**************************************************************************/ } + +{ /***************************** Server *****************************/ } + +{ /* + * ƣͨ + * ͨɺɿʼտͻӲշ + * + * pszBindAddress -- ַ + * usPort -- ˿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Server_Start(pServer: HP_Server; pszBindAddress: PWideChar; + usPort: USHORT): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رշͨرɺϿпͻӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Server_Stop(pServer: HP_Server): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ûͨ÷ָͻ˷ + * + * dwConnID -- ID + * pBuffer -- ݻ + * iLength -- ݳ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_Send(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Server_SendPart(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer; iOffset: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣͶ + * ָӷͶ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * dwConnID -- ID + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Server_SendPackets(pServer: HP_Server; dwConnID: HP_CONNID; + const pBuffers: WSABUFArray; iCount: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣϿ + * Ͽijͻ˵ + * + * dwConnID -- ID + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_Disconnect(pServer: HP_Server; dwConnID: HP_CONNID; + bForce: LongInt): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣϿʱ + * Ͽָʱ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Server_DisconnectLongConnections(pServer: HP_Server; + dwPeriod: LongInt; bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Server Էʷ *****************************/ } + +{ /* + * ƣӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * pv -- + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Server_SetConnectionExtra(pServer: HP_Server; dwConnID: HP_CONNID; + pExtra: PVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣȡӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * ppv -- ָ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Server_GetConnectionExtra(pServer: HP_Server; dwConnID: HP_CONNID; + ppExtra: PPVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* ͨǷ */ } +function HP_Server_HasStarted(pServer: HP_Server): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Server_GetState(pServer: HP_Server): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Server_GetLastError(pServer: HP_Object): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Server_GetLastErrorDesc(pServer: HP_Server): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Server_GetPendingDataLength(pServer: HP_Server; dwConnID: HP_CONNID; + piPending: PInteger): BOOL; stdcall; external HPSocketDLL; +{ /* ȡͻ */ } +function HP_Server_GetConnectionCount(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡӵ CONNID */ } +function HP_Server_GetAllConnectionIDs(pServer: HP_Server; pIDs: HP_CONNIDArray; + pdwCount: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijͻʱ룩 */ } +function HP_Server_GetConnectPeriod(pServer: HP_Server; dwConnID: HP_CONNID; + pdwPeriod: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡ Socket ĵַϢ */ } +function HP_Server_GetListenAddress(pServer: HP_Server; lpszAddress: PWideChar; + piAddressLen: PInteger; pusPort: PUShort): BOOL; stdcall; + external HPSocketDLL; +{ /* ȡijӵԶ̵ַϢ */ } +function HP_Server_GetRemoteAddress(pServer: HP_Server; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; + +{ /* ݷͲ */ } +procedure HP_Server_SetSendPolicy(pServer: HP_Server; + enSendPolicy: En_HP_SendPolicy); stdcall; external HPSocketDLL; +{ /* ݽղ */ } +procedure HP_Server_SetRecvPolicy(pServer: HP_Server; + enRecvPolicy: En_HP_RecvPolicy); stdcall; external HPSocketDLL; +{ /* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ } +procedure HP_Server_SetFreeSocketObjLockTime(pServer: HP_Server; + dwFreeSocketObjLockTime: LongInt); stdcall; external HPSocketDLL; +{ /* Socket شСͨΪƽ 1/3 - 1/2 */ } +procedure HP_Server_SetFreeSocketObjPool(pServer: HP_Server; + dwFreeSocketObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ Socket شС 2 - 3 */ } +procedure HP_Server_SetFreeBufferObjPool(pServer: HP_Server; + dwFreeBufferObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* Socket ػշֵͨΪ Socket شС 3 */ } +procedure HP_Server_SetFreeSocketObjHold(pServer: HP_Server; + dwFreeSocketObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Server_SetFreeBufferObjHold(pServer: HP_Server; + dwFreeBufferObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ù߳ͨΪ 2 * CPU + 2 */ } +procedure HP_Server_SetWorkerThreadCount(pServer: HP_Server; + dwWorkerThreadCount: LongInt); stdcall; external HPSocketDLL; +{ /* ùرշǰȴӹرյʱޣ룬0 򲻵ȴ */ } +procedure HP_Server_SetMaxShutdownWaitTime(pServer: HP_Server; + dwMaxShutdownWaitTime: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡݷͲ */ } +function HP_Server_GetSendPolicy(pServer: HP_Server): En_HP_SendPolicy; stdcall; + external HPSocketDLL; +{ /* ȡݽղ */ } +function HP_Server_GetRecvPolicy(pServer: HP_Server): En_HP_RecvPolicy; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ʱ */ } +function HP_Server_GetFreeSocketObjLockTime(pServer: HP_Server): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ Socket شС */ } +function HP_Server_GetFreeSocketObjPool(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Server_GetFreeBufferObjPool(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ػշֵ */ } +function HP_Server_GetFreeSocketObjHold(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Server_GetFreeBufferObjHold(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ߳ */ } +function HP_Server_GetWorkerThreadCount(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡرշǰȴӹرյʱ */ } +function HP_Server_GetMaxShutdownWaitTime(pServer: HP_Server): LongInt; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /******************************* TCP Server *******************************/ } + +{ /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpServer_SendSmallFile(pServer: HP_Server; dwConnID: HP_CONNID; + lpszFileName: PWideChar; const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Server Էʷ *****************************/ } + +{ /* ü Socket ĵȺдСݲã */ } +procedure HP_TcpServer_SetSocketListenQueue(pServer: HP_TcpServer; + dwSocketListenQueue: LongInt); stdcall; external HPSocketDLL; +{ /* Accept ԤͶݸصãAccept ԤͶԽֵ֧IJԽࣩ */ } +procedure HP_TcpServer_SetAcceptSocketCount(pServer: HP_TcpServer; + dwAcceptSocketCount: LongInt); stdcall; external HPSocketDLL; +{ /* ͨݻСƽͨݰСãͨΪ 1024 ı */ } +procedure HP_TcpServer_SetSocketBufferSize(pServer: HP_TcpServer; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpServer_SetKeepAliveTime(pServer: HP_TcpServer; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpServer_SetKeepAliveInterval(pServer: HP_TcpServer; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡ Accept ԤͶ */ } +function HP_TcpServer_GetAcceptSocketCount(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡͨݻС */ } +function HP_TcpServer_GetSocketBufferSize(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ Socket ĵȺдС */ } +function HP_TcpServer_GetSocketListenQueue(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpServer_GetKeepAliveTime(pServer: HP_TcpServer): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpServer_GetKeepAliveInterval(pServer: HP_TcpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** UDP Server Էʷ *****************************/ } + +{ /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ } +procedure HP_UdpServer_SetMaxDatagramSize(pServer: HP_UdpServer; + dwMaxDatagramSize: LongInt); stdcall; external HPSocketDLL; +{ /* ȡݱ󳤶 */ } +function HP_UdpServer_GetMaxDatagramSize(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /* Receive ԤͶݸصãReceive ԤͶԽ򶪰ԽС */ } +procedure HP_UdpServer_SetPostReceiveCount(pServer: HP_UdpServer; + dwPostReceiveCount: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ Receive ԤͶ */ } +function HP_UdpServer_GetPostReceiveCount(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /* üԴ0 򲻷ͼԴΪѶߣ */ } +procedure HP_UdpServer_SetDetectAttempts(pServer: HP_UdpServer; + dwDetectAttempts: LongInt); stdcall; external HPSocketDLL; +{ /* üͼ룬0 ͼ */ } +procedure HP_UdpServer_SetDetectInterval(pServer: HP_UdpServer; + dwDetectInterval: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpServer_GetDetectAttempts(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpServer_GetDetectInterval(pServer: HP_UdpServer): LongInt; + stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Client *****************************/ } + +{ /* + * ƣͨ + * ͻͨӷˣɺɿʼշ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Client_Start(pClient: HP_Client; pszRemoteAddress: PWideChar; + usPort: USHORT; bAsyncConnect: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رտͻͨرɺϿ˵ӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Client_Stop(pClient: HP_Client): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ˷ + * + * pBuffer -- ͻ + * iLength -- ͻ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_Send(pClient: HP_Client; const pBuffer: Pointer; + iLength: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣ + * ˷ + * + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_SendPart(pClient: HP_Client; const pBuffer: Pointer; + iLength: Integer; iOffset: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣͶ + * ˷Ͷ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Client_SendPackets(pClient: HP_Client; const pBuffers: WSABUFArray; + iCount: Integer): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Client Էʷ *****************************/ } + +{ /* ͨǷ */ } +function HP_Client_HasStarted(pClient: HP_Client): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Client_GetState(pClient: HP_Client): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Client_GetLastError(pClient: HP_Client): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Client_GetLastErrorDesc(pClient: HP_Client): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡ ID */ } +function HP_Client_GetConnectionID(pClient: HP_Client): HP_CONNID; stdcall; + external HPSocketDLL; +{ /* ȡ Client Socket ĵַϢ */ } +function HP_Client_GetLocalAddress(pClient: HP_Client; lpszAddress: PWideChar; + piAddressLen: PInteger; pusPort: PUShort): BOOL; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Client_GetPendingDataLength(pClient: HP_Client; piPending: PInteger) + : BOOL; stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ -> PUSH ģͣ5 - 10PULL ģͣ10 - 20 */ } +procedure HP_Client_SetFreeBufferPoolSize(pClient: HP_Client; + dwFreeBufferPoolSize: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Client_SetFreeBufferPoolHold(pClient: HP_Client; + dwFreeBufferPoolHold: LongInt); stdcall; external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Client_GetFreeBufferPoolSize(pClient: HP_Client): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Client_GetFreeBufferPoolHold(pClient: HP_Client): LongInt; stdcall; + external HPSocketDLL; +{ // ȡһʧܲĴ } + +{ /**********************************************************************************/ + /******************************* TCP Client *******************************/ } + +{ /* + * ƣСļ + * ˷ 4096 KB µСļ + * + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpClient_SendSmallFile(pClient: HP_Client; lpszFileName: PWideChar; + const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Client Էʷ *****************************/ } + +{ /* ͨݻСƽͨݰСãͨΪ(N * 1024) - sizeof(TBufferObj) */ } +procedure HP_TcpClient_SetSocketBufferSize(pClient: HP_TcpClient; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpClient_SetKeepAliveTime(pClient: HP_TcpClient; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpClient_SetKeepAliveInterval(pClient: HP_TcpClient; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡͨݻС */ } +function HP_TcpClient_GetSocketBufferSize(pClient: HP_TcpClient): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpClient_GetKeepAliveTime(pClient: HP_TcpClient): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpClient_GetKeepAliveInterval(pClient: HP_TcpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** UDP Client Էʷ *****************************/ } + +{ /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ } +procedure HP_UdpClient_SetMaxDatagramSize(pClient: HP_UdpClient; + dwMaxDatagramSize: LongInt); stdcall; external HPSocketDLL; +{ /* ȡݱ󳤶 */ } +function HP_UdpClient_GetMaxDatagramSize(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /* üԴ0 򲻷ͼԴΪѶߣ */ } +procedure HP_UdpClient_SetDetectAttempts(pClient: HP_UdpClient; + dwDetectAttempts: LongInt); stdcall; external HPSocketDLL; +{ /* üͼ룬0 ͼ */ } +procedure HP_UdpClient_SetDetectInterval(pClient: HP_UdpClient; + dwDetectInterval: LongInt); stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpClient_GetDetectAttempts(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; +{ /* ȡ */ } +function HP_UdpClient_GetDetectInterval(pClient: HP_UdpClient): LongInt; + stdcall; external HPSocketDLL; + +{ /**************************************************************************/ + /***************************** Agent *****************************/ } + +{ /* + * ƣͨ + * ͨŴɺɿʼԶ̷ + * + * pszBindAddress -- ַ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Agent_Start(pAgent: HP_Agent; pszBindAddress: PWideChar; + bAsyncConnect: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣرͨ + * رͨرɺϿӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ } +function HP_Agent_Stop(pAgent: HP_Agent): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣӷ + * ӷӳɹ IAgentListener յ OnConnect() ¼ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * pdwConnID -- IDĬϣnullptrȡ ID + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ SYS_GetLastError() ȡ Windows + */ } +function HP_Agent_Connect(pAgent: HP_Agent; pszRemoteAddress: PWideChar; + usPort: USHORT; pdwConnID: PHP_CONNID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_Send(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_SendPart(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffer: Pointer; iLength: Integer; iOffset: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣͶ + * ָӷͶ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * dwConnID -- ID + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_Agent_SendPackets(pAgent: HP_Agent; dwConnID: HP_CONNID; + const pBuffers: WSABUFArray; iCount: Integer): BOOL; stdcall; + external HPSocketDLL; + +{ /* + * ƣϿ + * Ͽij + * + * dwConnID -- ID + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Agent_Disconnect(pAgent: HP_Agent; dwConnID: HP_CONNID; + bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣϿʱ + * Ͽָʱ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ } +function HP_Agent_DisconnectLongConnections(pAgent: HP_Agent; dwPeriod: LongInt; + bForce: BOOL): BOOL; stdcall; external HPSocketDLL; + +{ /******************************************************************************/ + /***************************** Agent Էʷ *****************************/ } + +{ /* + * ƣӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * pv -- + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Agent_SetConnectionExtra(pAgent: HP_Agent; dwConnID: HP_CONNID; + pExtra: PVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* + * ƣȡӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ + * + * dwConnID -- ID + * ppv -- ָ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ } +function HP_Agent_GetConnectionExtra(pAgent: HP_Agent; dwConnID: HP_CONNID; + ppExtra: PPVOID): BOOL; stdcall; external HPSocketDLL; + +{ /* ͨǷ */ } +function HP_Agent_HasStarted(pAgent: HP_Agent): BOOL; stdcall; + external HPSocketDLL; +{ /* 鿴ͨǰ״̬ */ } +function HP_Agent_GetState(pAgent: HP_Agent): En_HP_ServiceState; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_Agent_GetConnectionCount(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡӵ CONNID */ } +function HP_Agent_GetAllConnectionIDs(pAgent: HP_Agent; pIDs: HP_CONNIDArray; + pdwCount: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijʱ룩 */ } +function HP_Agent_GetConnectPeriod(pAgent: HP_Agent; dwConnID: HP_CONNID; + pdwPeriod: PLongint): BOOL; stdcall; external HPSocketDLL; +{ /* ȡijӵıصַϢ */ } +function HP_Agent_GetLocalAddress(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; +{ /* ȡijӵԶ̵ַϢ */ } +function HP_Agent_GetRemoteAddress(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszAddress: PWideChar; piAddressLen: PInteger; pusPort: PUShort): BOOL; + stdcall; external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Agent_GetLastError(pAgent: HP_Agent): En_HP_SocketError; stdcall; + external HPSocketDLL; +{ /* ȡһʧܲĴ */ } +function HP_Agent_GetLastErrorDesc(pAgent: HP_Agent): PWideChar; stdcall; + external HPSocketDLL; +{ /* ȡδݵij */ } +function HP_Agent_GetPendingDataLength(pAgent: HP_Agent; dwConnID: HP_CONNID; + piPending: PInteger): BOOL; stdcall; external HPSocketDLL; + +{ /* ݷͲ */ } +procedure HP_Agent_SetSendPolicy(pAgent: HP_Agent; + enSendPolicy: En_HP_SendPolicy); stdcall; external HPSocketDLL; +{ /* ݽղ */ } +procedure HP_Agent_SetRecvPolicy(pAgent: HP_Agent; + enRecvPolicy: En_HP_RecvPolicy); stdcall; external HPSocketDLL; +{ /* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ } +procedure HP_Agent_SetFreeSocketObjLockTime(pAgent: HP_Agent; + dwFreeSocketObjLockTime: LongInt); stdcall; external HPSocketDLL; +{ /* Socket شСͨΪƽ 1/3 - 1/2 */ } +procedure HP_Agent_SetFreeSocketObjPool(pAgent: HP_Agent; + dwFreeSocketObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺شСͨΪ Socket شС 2 - 3 */ } +procedure HP_Agent_SetFreeBufferObjPool(pAgent: HP_Agent; + dwFreeBufferObjPool: LongInt); stdcall; external HPSocketDLL; +{ /* Socket ػշֵͨΪ Socket شС 3 */ } +procedure HP_Agent_SetFreeSocketObjHold(pAgent: HP_Agent; + dwFreeSocketObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ڴ黺ػշֵͨΪڴ黺شС 3 */ } +procedure HP_Agent_SetFreeBufferObjHold(pAgent: HP_Agent; + dwFreeBufferObjHold: LongInt); stdcall; external HPSocketDLL; +{ /* ù߳ͨΪ 2 * CPU + 2 */ } +procedure HP_Agent_SetWorkerThreadCount(pAgent: HP_Agent; + dwWorkerThreadCount: LongInt); stdcall; external HPSocketDLL; +{ /* ùرǰȴӹرյʱޣ룬0 򲻵ȴ */ } +procedure HP_Agent_SetMaxShutdownWaitTime(pAgent: HP_Agent; + dwMaxShutdownWaitTime: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡݷͲ */ } +function HP_Agent_GetSendPolicy(pAgent: HP_Agent): En_HP_SendPolicy; stdcall; + external HPSocketDLL; +{ /* ȡݽղ */ } +function HP_Agent_GetRecvPolicy(pAgent: HP_Agent): En_HP_RecvPolicy; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ʱ */ } +function HP_Agent_GetFreeSocketObjLockTime(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket شС */ } +function HP_Agent_GetFreeSocketObjPool(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺شС */ } +function HP_Agent_GetFreeBufferObjPool(HpAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ Socket ػշֵ */ } +function HP_Agent_GetFreeSocketObjHold(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡڴ黺ػշֵ */ } +function HP_Agent_GetFreeBufferObjHold(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ߳ */ } +function HP_Agent_GetWorkerThreadCount(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡرǰȴӹرյʱ */ } +function HP_Agent_GetMaxShutdownWaitTime(pAgent: HP_Agent): LongInt; stdcall; + external HPSocketDLL; + +{ /**********************************************************************************/ + /******************************* TCP Agent *******************************/ } + +{ /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ } +function HP_TcpAgent_SendSmallFile(pAgent: HP_Agent; dwConnID: HP_CONNID; + lpszFileName: PWideChar; const pHead: LPWSABUF; const pTail: LPWSABUF): BOOL; + stdcall; external HPSocketDLL; + +{ /**********************************************************************************/ + /***************************** TCP Agent Էʷ *****************************/ } + +{ /* ǷõַûƣĬϣã */ } +procedure HP_TcpAgent_SetReuseAddress(pAgent: HP_TcpAgent; bReuseAddress: BOOL); + stdcall; external HPSocketDLL; +{ /* Ƿõַû */ } +function HP_TcpAgent_IsReuseAddress(pAgent: HP_TcpAgent): BOOL; stdcall; + external HPSocketDLL; + +{ /* ͨݻСƽͨݰСãͨΪ 1024 ı */ } +procedure HP_TcpAgent_SetSocketBufferSize(pAgent: HP_TcpAgent; + dwSocketBufferSize: LongInt); stdcall; external HPSocketDLL; +{ /* 룬0 򲻷 */ } +procedure HP_TcpAgent_SetKeepAliveTime(pAgent: HP_TcpAgent; + dwKeepAliveTime: LongInt); stdcall; external HPSocketDLL; +{ /* ȷϰ룬0 ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ } +procedure HP_TcpAgent_SetKeepAliveInterval(pAgent: HP_TcpAgent; + dwKeepAliveInterval: LongInt); stdcall; external HPSocketDLL; + +{ /* ȡͨݻС */ } +function HP_TcpAgent_GetSocketBufferSize(pAgent: HP_TcpAgent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpAgent_GetKeepAliveTime(pAgent: HP_TcpAgent): LongInt; stdcall; + external HPSocketDLL; +{ /* ȡ */ } +function HP_TcpAgent_GetKeepAliveInterval(pAgent: HP_TcpAgent): LongInt; + stdcall; external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Server *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullServer_Fetch(pServer: HP_TcpPullServer; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Server Էʷ *****************************/ } + +{ /***************************************************************************************/ + /***************************** TCP Pull Client *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullClient_Fetch(pClient: HP_TcpPullClient; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Client Էʷ *****************************/ } + +{ /***************************************************************************************/ + /***************************** TCP Pull Agent *****************************/ } + +{ /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pBuffer -- ץȡ + * iLength -- ץȡݳ + * ֵ En_HP_FetchResult + */ } +function HP_TcpPullAgent_Fetch(pAgent: HP_TcpPullAgent; dwConnID: HP_CONNID; + pBuffer: Pointer; iLength: Integer): En_HP_FetchResult; stdcall; + external HPSocketDLL; + +{ /***************************************************************************************/ + /***************************** TCP Pull Agent Էʷ *****************************/ } + +{ /***************************************************************************************/ + /*************************************** ***************************************/ } + +{ /* ȡı */ } +function HP_GetSocketErrorDesc(enCode: En_HP_SocketError): PWideChar; stdcall; + external HPSocketDLL; +{ /* ϵͳ ::GetLastError() ȡϵͳ */ } +function SYS_GetLastError(): LongInt; stdcall; external HPSocketDLL; +// ϵͳ ::WSAGetLastError() ȡͨŴ +function SYS_WSAGetLastError(): Integer; stdcall; external HPSocketDLL; +// ϵͳ setsockopt() +function SYS_SetSocketOption(sock: SOCKET; level: Integer; name: Integer; + val: LPVOID; len: Integer): Integer; stdcall; external HPSocketDLL; +// ϵͳ getsockopt() +function SYS_GetSocketOption(sock: SOCKET; level: Integer; name: Integer; + val: LPVOID; len: PInteger): Integer; stdcall; external HPSocketDLL; +// ϵͳ ioctlsocket() +function SYS_IoctlSocket(sock: SOCKET; cmd: LongInt; arg: PULONG): Integer; + stdcall; external HPSocketDLL; +// ϵͳ ::WSAIoctl() +function SYS_WSAIoctl(sock: SOCKET; dwIoControlCode: LongInt; + lpvInBuffer: LPVOID; cbInBuffer: LongInt; lpvOutBuffer: LPVOID; + cbOutBuffer: LongInt; lpcbBytesReturned: LPDWORD): Integer; stdcall; + external HPSocketDLL; + +implementation + +end. + \ No newline at end of file diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.ddp b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.ddp new file mode 100644 index 000000000..4370276c1 Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.ddp differ diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.dfm b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.dfm new file mode 100644 index 000000000..cf3e2cfa2 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.dfm @@ -0,0 +1,80 @@ +object Form1: TForm1 + Left = 687 + Top = 272 + BorderIcons = [biSystemMenu, biMinimize] + BorderStyle = bsSingle + Caption = 'Echo Server [ '#39'C'#39' - clear list box ]' + ClientHeight = 329 + ClientWidth = 457 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + Position = poScreenCenter + OnClose = FormClose + OnCreate = FormCreate + PixelsPerInch = 96 + TextHeight = 13 + object lbl1: TLabel + Left = 130 + Top = 308 + Width = 40 + Height = 13 + Caption = 'CONNID' + end + object lstMsg: TListBox + Left = 1 + Top = 0 + Width = 457 + Height = 298 + ItemHeight = 13 + TabOrder = 0 + OnKeyPress = lstMsgKeyPress + end + object edtIpAddress: TEdit + Left = 1 + Top = 304 + Width = 121 + Height = 21 + TabOrder = 1 + Text = '0.0.0.0' + end + object edtConnId: TEdit + Left = 176 + Top = 304 + Width = 48 + Height = 21 + TabOrder = 2 + OnChange = edtConnIdChange + end + object btnDisConn: TButton + Left = 230 + Top = 303 + Width = 57 + Height = 23 + Caption = 'Dis Conn' + TabOrder = 3 + OnClick = btnDisConnClick + end + object btnStart: TButton + Left = 336 + Top = 304 + Width = 57 + Height = 23 + Caption = 'Start' + TabOrder = 4 + OnClick = btnStartClick + end + object btnStop: TButton + Left = 398 + Top = 304 + Width = 57 + Height = 23 + Caption = 'Stop' + TabOrder = 5 + OnClick = btnStopClick + end +end diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.pas b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.pas new file mode 100644 index 000000000..5eb0f7d87 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/ServerUnit.pas @@ -0,0 +1,331 @@ +unit ServerUnit; + +interface + +uses + Windows, Messages, SysUtils, Variants, Classes, Graphics, + Controls, Forms, Dialogs, StdCtrls, HPSocketSDKUnit, ExePublic; + +type + + TForm1 = class(TForm) + lstMsg: TListBox; + edtIpAddress: TEdit; + edtConnId: TEdit; + lbl1: TLabel; + btnDisConn: TButton; + btnStart: TButton; + btnStop: TButton; + procedure FormCreate(Sender: TObject); + procedure btnStartClick(Sender: TObject); + procedure btnStopClick(Sender: TObject); + procedure btnDisConnClick(Sender: TObject); + procedure edtConnIdChange(Sender: TObject); + procedure lstMsgKeyPress(Sender: TObject; var Key: Char); + procedure FormClose(Sender: TObject; var Action: TCloseAction); + private + { Private declarations } + procedure AddMsg(msg: string); + procedure SetAppState(state: EnAppState); + public + { Public declarations } + procedure OnRec(dwConnId: DWORD; const pData: Pointer; iLength: Integer); + end; + + //ܿͻ˽ṹ + TDoSerRec = class(TThread) + FId : DWORD; + RecMsg : PTMsg; + procedure showmsg; + protected + procedure Execute;override; + public + //شͻ + ilen : Integer; + pdata : Pointer; + + constructor Create(connid : DWORD); + end; + +var + Form1: TForm1; + appState: EnAppState; + pServer: Pointer; + pListener: Pointer; + +implementation + +{$R *.dfm} + +procedure TForm1.SetAppState(state: EnAppState); +begin + appState := state; + btnStart.Enabled := (appState = EnAppState.ST_STOPED); + btnStop.Enabled := (appState = EnAppState.ST_STARTED); + edtIpAddress.Enabled := (appState = EnAppState.ST_STOPED); + edtConnId.Enabled := (appState = EnAppState.ST_STARTED); + btnDisConn.Enabled := ((appState = EnAppState.ST_STARTED) and (Length(edtConnId.Text) > 0)); +end; + +procedure TForm1.AddMsg(msg: string); +begin + if lstMsg.Items.Count > 100 then + begin + lstMsg.Items.Clear; + end; + lstMsg.Items.Add(msg); +end; + +function SendString(dwConnId: DWORD; str: string): Boolean; +var + sendBuffer: array of byte; + sendStr: AnsiString; + sendLength: Integer; +begin + sendStr := AnsiString(str); + // ȡansiַij + sendLength := Length(sendStr); + // bufij + SetLength(sendBuffer, sendLength); + // ݵbuf + Move(sendStr[1], sendBuffer[1], sendLength); + + Result := HP_Server_Send(pServer, dwConnId, sendBuffer, sendLength); +end; + +function OnPrepareListen(soListen: Pointer): En_HP_HandleResult; stdcall; +begin + + Result := HP_HR_OK; +end; + +function OnAccept(dwConnId: DWORD; pClient: Pointer): En_HP_HandleResult; stdcall; +var + ip: array [0 .. 40] of WideChar; + ipLength: Integer; + port: USHORT; +begin + ipLength := 40; + if HP_Server_GetRemoteAddress(pServer, dwConnId, ip, @ipLength, @port) then + begin + Form1.AddMsg(Format(' > [%d,OnAccept] -> PASS(%s:%d)', [dwConnId, string(ip), port])); + end + else + begin + Form1.AddMsg(Format(' > [[%d,OnAccept] -> HP_Server_GetClientAddress() Error', [dwConnId])); + end; + + Result := HP_HR_OK; +end; + +function OnServerShutdown(): En_HP_HandleResult; stdcall; +begin + + Form1.AddMsg(' > [OnServerShutdown]'); + Result := HP_HR_OK; +end; + +function OnSend(dwConnId: DWORD; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; +begin + Form1.AddMsg(Format(' > [%d,OnSend] -> (%d bytes)', [dwConnId, iLength])); + Result := HP_HR_OK; +end; + +function OnReceive(dwConnId: DWORD; const pData: Pointer; iLength: Integer): En_HP_HandleResult; stdcall; +var + testString: AnsiString; + + doRec : TDoSerRec; +begin + Form1.AddMsg(Format(' > [%d,OnReceive] -> (%d bytes)', [dwConnId, iLength])); + + {// һpDataתַʾ + SetLength(testString, iLength); + Move(pData^, testString[1], iLength); + Form1.AddMsg(Format(' > [%d,OnReceive] -> say:%s', [dwConnId, testString])); + + + if HP_Server_Send(pServer, dwConnId, pData, iLength) then + begin + Result := HP_HR_OK; + end + else + begin + Result := HP_HR_ERROR; + end; + } + + Form1.OnRec(dwConnId, pData, iLength); + + Result := HP_HR_OK; +end; + +function OnCloseConn(dwConnId: DWORD): En_HP_HandleResult; stdcall; +begin + + Form1.AddMsg(Format(' > [%d,OnCloseConn]', [dwConnId])); + Result := HP_HR_OK; +end; + +function OnError(dwConnId: DWORD; enOperation: En_HP_SocketOperation; iErrorCode: Integer): En_HP_HandleResult; stdcall; +begin + + Form1.AddMsg(Format('> [%d,OnError] -> OP:%d,CODE:%d', [dwConnId, Integer(enOperation), iErrorCode])); + Result := HP_HR_OK; +end; + +procedure TForm1.btnDisConnClick(Sender: TObject); +var + dwConnId: DWORD; +begin + dwConnId := StrToInt(edtConnId.Text); + if HP_Server_Disconnect(pServer, dwConnId, 1) then + Form1.AddMsg(Format('$(%d) Disconnect OK', [dwConnId])) + else + Form1.AddMsg(Format('$(%d) Disconnect Error', [dwConnId])); + +end; + +procedure TForm1.btnStartClick(Sender: TObject); +var + ip: PWideChar; + port: USHORT; + errorId: En_HP_SocketError; + errorMsg: PWideChar; +begin + ip := PWideChar(edtIpAddress.Text); + port := 5555; + SetAppState(ST_STARTING); + if HP_Server_Start(pServer, ip, port) then + begin + AddMsg(Format('$Server Start OK -> (%s:%d)', [ip, port])); + SetAppState(ST_STARTED); + end + else + begin + errorId := HP_Server_GetLastError(pServer); + errorMsg := HP_Server_GetLastErrorDesc(pServer); + AddMsg(Format('$Server Start Error -> %s(%d)', [errorMsg, Integer(errorId)])); + SetAppState(ST_STOPED); + end; +end; + +procedure TForm1.btnStopClick(Sender: TObject); +var + errorId: En_HP_SocketError; + errorMsg: PWideChar; +begin + + SetAppState(ST_STOPING); + AddMsg('$Server Stop'); + if HP_Server_Stop(pServer) then + begin + SetAppState(ST_STOPED); + end + else + begin + errorId := HP_Server_GetLastError(pServer); + errorMsg := HP_Server_GetLastErrorDesc(pServer); + AddMsg(Format('$Stop Error -> %s(%d)', [errorMsg, Integer(errorId)])); + + end; +end; + +procedure TForm1.edtConnIdChange(Sender: TObject); +begin + btnDisConn.Enabled := ((appState = ST_STARTED) and (Length(edtConnId.Text) > 0)); +end; + +procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); +begin + // Socket + Destroy_HP_TcpServer(pServer); + // ټ + Destroy_HP_TcpServerListener(pListener); +end; + +procedure TForm1.FormCreate(Sender: TObject); +begin + // + pListener := Create_HP_TcpServerListener(); + + // Socket + pServer := Create_HP_TcpServer(pListener); + + // Socket ص + HP_Set_FN_Server_OnPrepareListen(pListener, OnPrepareListen); + HP_Set_FN_Server_OnAccept(pListener, OnAccept); + HP_Set_FN_Server_OnSend(pListener, OnSend); + HP_Set_FN_Server_OnReceive(pListener, OnReceive); + HP_Set_FN_Server_OnClose(pListener, OnCloseConn); + HP_Set_FN_Server_OnError(pListener, OnError); + HP_Set_FN_Server_OnShutdown(pListener, OnServerShutdown); + + SetAppState(ST_STOPED); +end; + +procedure TForm1.lstMsgKeyPress(Sender: TObject; var Key: Char); +begin + if (Key = 'c') or (Key = 'C') then + lstMsg.Items.Clear; + +end; + +procedure TForm1.OnRec(dwConnId: DWORD; const pData: Pointer; + iLength: Integer); +var + doRec : TDoSerRec; + + SendMsg, RecMsg : PTMsg; +begin + doRec := TDoSerRec.Create(dwConnId); + //ָ + Move(pdata, dorec.pdata, iLength); + doRec.ilen := iLength; + doRec.Resume; +end; + +{ TDoSerRec } + +constructor TDoSerRec.Create(connid: DWORD); +begin + inherited Create(True); + FId := connid; +end; + +procedure TDoSerRec.Execute; +var + SendMsg : PTMsg; +begin + inherited; + try + Move(pdata, RecMsg, ilen); + try + case RecMsg.nType of + 1000 : begin + //Ϣ + Synchronize(showmsg); + New(SendMsg); + try + SendMsg.nType := 1001; + SendMsg.nMsg := 'Do Rec; Ready do other thing?'; + HP_Server_Send(pServer, FId, SendMsg, SizeOf(ttmsg)); + finally + Dispose(SendMsg); + end; + end; + end; + except + + end; + finally + + end; +end; + +procedure TDoSerRec.showmsg; +begin + form1.AddMsg('Rec from client:' + RecMsg.nMsg); +end; + +end. diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.cfg b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.cfg new file mode 100644 index 000000000..e9c1cc14e --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.cfg @@ -0,0 +1,38 @@ +-$A8 +-$B- +-$C+ +-$D+ +-$E- +-$F- +-$G+ +-$H+ +-$I+ +-$J- +-$K- +-$L+ +-$M- +-$N+ +-$O+ +-$P+ +-$Q- +-$R- +-$S- +-$T- +-$U- +-$V+ +-$W- +-$X+ +-$YD +-$Z1 +-cg +-AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; +-H+ +-W+ +-M +-$M16384,1048576 +-K$00400000 +-LE"c:\program files (x86)\borland\delphi7\Projects\Bpl" +-LN"c:\program files (x86)\borland\delphi7\Projects\Bpl" +-w-UNSAFE_TYPE +-w-UNSAFE_CODE +-w-UNSAFE_CAST diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dof b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dof new file mode 100644 index 000000000..4dd22c1d5 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dof @@ -0,0 +1,136 @@ +[FileVersion] +Version=7.0 +[Compiler] +A=8 +B=0 +C=1 +D=1 +E=0 +F=0 +G=1 +H=1 +I=1 +J=0 +K=0 +L=1 +M=0 +N=1 +O=1 +P=1 +Q=0 +R=0 +S=0 +T=0 +U=0 +V=1 +W=0 +X=1 +Y=1 +Z=1 +ShowHints=1 +ShowWarnings=1 +UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; +NamespacePrefix= +SymbolDeprecated=1 +SymbolLibrary=1 +SymbolPlatform=1 +UnitLibrary=1 +UnitPlatform=1 +UnitDeprecated=1 +HResultCompat=1 +HidingMember=1 +HiddenVirtual=1 +Garbage=1 +BoundsError=1 +ZeroNilCompat=1 +StringConstTruncated=1 +ForLoopVarVarPar=1 +TypedConstVarPar=1 +AsgToTypedConst=1 +CaseLabelRange=1 +ForVariable=1 +ConstructingAbstract=1 +ComparisonFalse=1 +ComparisonTrue=1 +ComparingSignedUnsigned=1 +CombiningSignedUnsigned=1 +UnsupportedConstruct=1 +FileOpen=1 +FileOpenUnitSrc=1 +BadGlobalSymbol=1 +DuplicateConstructorDestructor=1 +InvalidDirective=1 +PackageNoLink=1 +PackageThreadVar=1 +ImplicitImport=1 +HPPEMITIgnored=1 +NoRetVal=1 +UseBeforeDef=1 +ForLoopVarUndef=1 +UnitNameMismatch=1 +NoCFGFileFound=1 +MessageDirective=1 +ImplicitVariants=1 +UnicodeToLocale=1 +LocaleToUnicode=1 +ImagebaseMultiple=1 +SuspiciousTypecast=1 +PrivatePropAccessor=1 +UnsafeType=0 +UnsafeCode=0 +UnsafeCast=0 +[Linker] +MapFile=0 +OutputObjs=0 +ConsoleApp=1 +DebugInfo=0 +RemoteSymbols=0 +MinStackSize=16384 +MaxStackSize=1048576 +ImageBase=4194304 +ExeDescription= +[Directories] +OutputDir= +UnitOutputDir= +PackageDLLOutputDir= +PackageDCPOutputDir= +SearchPath= +Packages= +Conditionals= +DebugSourceDirs= +UsePackages=0 +[Parameters] +RunParams= +HostApplication= +Launcher= +UseLauncher=0 +DebugCWD= +[Language] +ActiveLang= +ProjectLang= +RootDir= +[Version Info] +IncludeVerInfo=1 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=2052 +CodePage=936 +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dpr b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dpr new file mode 100644 index 000000000..041fde28c --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dpr @@ -0,0 +1,16 @@ +program TCPServerProject; + +uses + Forms, + ServerUnit in 'ServerUnit.pas' {Form1}, + HPSocketSDKUnit in 'HPSocketSDKUnit.pas', + ExePublic in '..\ExePublic.pas'; + +{$R *.res} + +begin + Application.Initialize; + Application.MainFormOnTaskbar := True; + Application.CreateForm(TForm1, Form1); + application.Run; +end. diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dproj b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dproj new file mode 100644 index 000000000..cef3fe793 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dproj @@ -0,0 +1,531 @@ + + + {DEF347AD-8F53-4E2D-B214-A10E69FDA5AC} + 16.0 + VCL + TCPServerProject.dpr + True + Debug + Win32 + 1 + Application + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + TCPServerProject + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + $(BDS)\bin\delphi_PROJECTICON.ico + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + false + false + false + false + false + + + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + dxSkinCaramelRS19;dxSkinOffice2007BlackRS19;dxSkinSharpPlusRS19;cxSchedulerTreeBrowserRS19;dxPScxSSLnkRS19;dxSkinLiquidSkyRS19;dxPScxPivotGridLnkRS19;cxBarEditItemRS19;DBXSqliteDriver;dxPSdxDBTVLnkRS19;dxSkinOffice2007BlueRS19;cxDataRS19;cxLibraryRS19;fmx;dxWizardControlRS19;IndySystem;dxPScxCommonRS19;TeeDB;dxThemeRS19;dxPsPrVwAdvRS19;dxSkinHighContrastRS19;cxGridRS19;inetdbbde;vclib;DBXInterBaseDriver;dxPScxExtCommonRS19;DataSnapCommon;cxSchedulerRS19;DBXSybaseASEDriver;dxmdsRS19;DbxCommonDriver;dxSkinsdxBarPainterRS19;vclimg;dxSkinOffice2010SilverRS19;dbxcds;dxFlowChartRS19;MetropolisUILiveTile;dxPSdxOCLnkRS19;dxSkinSpringTimeRS19;dxdbtrRS19;vcldb;vcldsnap;dxDockingRS19;dxSkinsdxDLPainterRS19;dxdborRS19;cxSpreadSheetRS19;dxtrmdRS19;DBXDb2Driver;dxSpellCheckerRS19;dxSkinDevExpressDarkStyleRS19;DBXOracleDriver;CustomIPTransport;dxBarDBNavRS19;vclribbon;dxTileControlRS19;dsnap;IndyIPServer;dxSkinFoggyRS19;dxSkinSilverRS19;IndyCore;vcl;cxSchedulerGridRS19;dxSkinVS2010RS19;dxSkinStardustRS19;IndyIPCommon;CloudService;DBXMSSQLDriver;FmxTeeUI;CodeSiteExpressPkg;dxBarRS19;cxTreeListdxBarPopupMenuRS19;dxSkinXmas2008BlueRS19;dxPSCoreRS19;dxPSdxDBOCLnkRS19;cxPivotGridOLAPRS19;inetdbxpress;dxSkinValentineRS19;cxEditorsRS19;dxSkinMcSkinRS19;dxSkinDarkSideRS19;dxSkinLondonLiquidSkyRS19;dxPScxSchedulerLnkRS19;dxBarExtDBItemsRS19;dxTabbedMDIRS19;adortl;dxSkinOffice2007SilverRS19;dxSkinOffice2013WhiteRS19;dxSkinSevenRS19;dxDBXServerModeRS19;dxSkinSharpRS19;dxLayoutControlRS19;bindcompfmx;dxSkinBlueprintRS19;dxSkinOffice2007PinkRS19;cxPageControlRS19;vcldbx;cxExportRS19;dxSkinWhiteprintRS19;dxPSTeeChartRS19;rtl;dbrtl;DbxClientDriver;dcldxSkinsCoreRS19;dxSkinCoffeeRS19;bindcomp;dxPScxGridLnkRS19;dxSkinBlueRS19;Tee;cxPageControldxBarPopupMenuRS19;dxServerModeRS19;DBXOdbcDriver;cxVerticalGridRS19;dxSkinMoneyTwinsRS19;cxPivotGridChartRS19;xmlrtl;svnui;ibxpress;dxSkinsdxRibbonPainterRS19;dxSkiniMaginaryRS19;dxSkinSummer2008RS19;dxComnRS19;IndyProtocols;DBXMySQLDriver;dxSkinOffice2007GreenRS19;dxSkinTheAsphaltWorldRS19;cxPivotGridRS19;dxPSLnksRS19;bindcompdbx;vclactnband;bindengine;soaprtl;FMXTee;TeeUI;bindcompvcl;dxADOServerModeRS19;dxRibbonRS19;dxSkinDarkRoomRS19;vclie;dxSkinPumpkinRS19;dxBarExtItemsRS19;dxPSdxLCLnkRS19;vcltouch;dxNavBarRS19;dxSkinBlackRS19;dxSkinOffice2010BlackRS19;VclSmp;VCLRESTComponents;DBXInformixDriver;dxGDIPlusRS19;Intraweb;dxSkinSevenClassicRS19;dxCoreRS19;dsnapcon;DBXFirebirdDriver;dxSkinscxSchedulerPainterRS19;inet;dxSkinsCoreRS19;dxSkinsdxNavBarPainterRS19;dxSkinGlassOceansRS19;dxPScxTLLnkRS19;dxPScxVGridLnkRS19;dxPSdxFCLnkRS19;vclx;dxPSPrVwRibbonRS19;dxPSDBTeeChartRS19;svn;DBXSybaseASADriver;dxSkinOffice2010BlueRS19;dxPScxPCProdRS19;RESTComponents;dxSkinLilianRS19;dxSkinscxPCPainterRS19;bdertl;dxorgcRS19;cxTreeListRS19;dbexpress;DataSnapIndy10ServerTransport;dxSkinDevExpressStyleRS19;IndyIPClient;$(DCC_UsePackage) + true + 1033 + $(BDS)\bin\default_app.manifest + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + + + dxSkinCaramelRS19;dxSkinOffice2007BlackRS19;dxSkinSharpPlusRS19;cxSchedulerTreeBrowserRS19;dxPScxSSLnkRS19;dxSkinLiquidSkyRS19;dxPScxPivotGridLnkRS19;cxBarEditItemRS19;DBXSqliteDriver;dxPSdxDBTVLnkRS19;dxSkinOffice2007BlueRS19;cxDataRS19;cxLibraryRS19;fmx;dxWizardControlRS19;IndySystem;dxPScxCommonRS19;TeeDB;dxThemeRS19;dxPsPrVwAdvRS19;dxSkinHighContrastRS19;cxGridRS19;vclib;DBXInterBaseDriver;dxPScxExtCommonRS19;DataSnapCommon;cxSchedulerRS19;DBXSybaseASEDriver;dxmdsRS19;DbxCommonDriver;dxSkinsdxBarPainterRS19;vclimg;dxSkinOffice2010SilverRS19;dbxcds;dxFlowChartRS19;MetropolisUILiveTile;dxPSdxOCLnkRS19;dxSkinSpringTimeRS19;dxdbtrRS19;vcldb;vcldsnap;dxDockingRS19;dxSkinsdxDLPainterRS19;dxdborRS19;cxSpreadSheetRS19;dxtrmdRS19;DBXDb2Driver;dxSpellCheckerRS19;dxSkinDevExpressDarkStyleRS19;DBXOracleDriver;CustomIPTransport;dxBarDBNavRS19;vclribbon;dxTileControlRS19;dsnap;IndyIPServer;dxSkinFoggyRS19;dxSkinSilverRS19;IndyCore;vcl;cxSchedulerGridRS19;dxSkinVS2010RS19;dxSkinStardustRS19;IndyIPCommon;CloudService;DBXMSSQLDriver;FmxTeeUI;dxBarRS19;cxTreeListdxBarPopupMenuRS19;dxSkinXmas2008BlueRS19;dxPSCoreRS19;dxPSdxDBOCLnkRS19;cxPivotGridOLAPRS19;inetdbxpress;dxSkinValentineRS19;cxEditorsRS19;dxSkinMcSkinRS19;dxSkinDarkSideRS19;dxSkinLondonLiquidSkyRS19;dxPScxSchedulerLnkRS19;dxBarExtDBItemsRS19;dxTabbedMDIRS19;adortl;dxSkinOffice2007SilverRS19;dxSkinOffice2013WhiteRS19;dxSkinSevenRS19;dxDBXServerModeRS19;dxSkinSharpRS19;dxLayoutControlRS19;bindcompfmx;dxSkinBlueprintRS19;dxSkinOffice2007PinkRS19;cxPageControlRS19;cxExportRS19;dxSkinWhiteprintRS19;dxPSTeeChartRS19;rtl;dbrtl;DbxClientDriver;dcldxSkinsCoreRS19;dxSkinCoffeeRS19;bindcomp;dxPScxGridLnkRS19;dxSkinBlueRS19;Tee;cxPageControldxBarPopupMenuRS19;dxServerModeRS19;DBXOdbcDriver;cxVerticalGridRS19;dxSkinMoneyTwinsRS19;cxPivotGridChartRS19;xmlrtl;ibxpress;dxSkinsdxRibbonPainterRS19;dxSkiniMaginaryRS19;dxSkinSummer2008RS19;dxComnRS19;IndyProtocols;DBXMySQLDriver;dxSkinOffice2007GreenRS19;dxSkinTheAsphaltWorldRS19;cxPivotGridRS19;dxPSLnksRS19;bindcompdbx;vclactnband;bindengine;soaprtl;FMXTee;TeeUI;bindcompvcl;dxADOServerModeRS19;dxRibbonRS19;dxSkinDarkRoomRS19;vclie;dxSkinPumpkinRS19;dxBarExtItemsRS19;dxPSdxLCLnkRS19;vcltouch;dxNavBarRS19;dxSkinBlackRS19;dxSkinOffice2010BlackRS19;VclSmp;VCLRESTComponents;DBXInformixDriver;dxGDIPlusRS19;Intraweb;dxSkinSevenClassicRS19;dxCoreRS19;dsnapcon;DBXFirebirdDriver;dxSkinscxSchedulerPainterRS19;inet;dxSkinsCoreRS19;dxSkinsdxNavBarPainterRS19;dxSkinGlassOceansRS19;dxPScxTLLnkRS19;dxPScxVGridLnkRS19;dxPSdxFCLnkRS19;vclx;dxPSPrVwRibbonRS19;dxPSDBTeeChartRS19;DBXSybaseASADriver;dxSkinOffice2010BlueRS19;dxPScxPCProdRS19;RESTComponents;dxSkinLilianRS19;dxSkinscxPCPainterRS19;dxorgcRS19;cxTreeListRS19;dbexpress;DataSnapIndy10ServerTransport;dxSkinDevExpressStyleRS19;IndyIPClient;$(DCC_UsePackage) + + + DEBUG;$(DCC_Define) + true + false + true + true + true + + + E:\MyProject\Hp_Socket\Delphi\TestEcho\bin\Win32\Release + 1033 + true + false + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + 1033 + E:\MyProject\Hp_Socket\Delphi\TestEcho\bin\Win32\Release + true + + + + MainSource + + +
Form1
+ dfm +
+ + + + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + +
+ + Delphi.Personality.12 + + + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 2052 + 936 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + TCPServerProject.dpr + + + Embarcadero C++Builder Office 2000 Servers Package + Embarcadero C++Builder Office XP Servers Package + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + File d:\vcl\devexpress\devexpress\library\rs21\win32\bpl\dcldxpscxgridlnkrs21.bpl not found + + + + + + TCPServerProject.exe + true + + + + + 1 + .dylib + + + 0 + .bpl + + + Contents\MacOS + 1 + .dylib + + + 1 + .dylib + + + + + 1 + .dylib + + + 0 + .dll;.bpl + + + Contents\MacOS + 1 + .dylib + + + 1 + .dylib + + + + + 1 + + + 1 + + + + + Contents + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + res\drawable-normal + 1 + + + + + library\lib\x86 + 1 + + + + + 1 + + + 1 + + + + + Contents + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + 1 + + + 1 + + + + + res\drawable-xlarge + 1 + + + + + res\drawable-xhdpi + 1 + + + + + 1 + + + 1 + + + + + res\drawable-xxhdpi + 1 + + + + + library\lib\mips + 1 + + + + + res\drawable + 1 + + + + + Contents\MacOS + 1 + + + 1 + + + 0 + + + + + Contents\MacOS + 1 + .framework + + + 0 + + + + + res\drawable-small + 1 + + + + + 1 + + + + + Contents\MacOS + 1 + + + 1 + + + Contents\MacOS + 0 + + + + + classes + 1 + + + + + 1 + + + 1 + + + + + 1 + + + 1 + + + + + res\drawable + 1 + + + + + Contents\Resources + 1 + + + + + 1 + + + + + 1 + + + 1 + + + + + 1 + + + library\lib\armeabi-v7a + 1 + + + 0 + + + Contents\MacOS + 1 + + + 1 + + + + + library\lib\armeabi + 1 + + + + + res\drawable-large + 1 + + + + + 0 + + + 0 + + + 0 + + + Contents\MacOS + 0 + + + 0 + + + + + 1 + + + 1 + + + + + res\drawable-ldpi + 1 + + + + + res\values + 1 + + + + + 1 + + + 1 + + + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + + + 1 + + + + + + + + + + + True + False + + + 12 + + + + +
diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dproj.local b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dproj.local new file mode 100644 index 000000000..50520bcdb --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.dproj.local @@ -0,0 +1,14 @@ + + + + 2013/09/26 12:41:30.000.878,=E:\Documents\RAD Studio\Projects\Unit1.pas + 2014/03/28 14:36:31.000.945,=F:\Documents\RAD Studio\Projects\Unit1.pas + 2014/03/28 14:37:25.000.032,F:\Documents\RAD Studio\Projects\Unit1.pas=F:\Documents\RAD Studio\Projects\HPSocketDemo-4C\ServerUnit.pas + 2014/03/28 14:37:25.000.032,F:\Documents\RAD Studio\Projects\Unit1.dfm=F:\Documents\RAD Studio\Projects\HPSocketDemo-4C\ServerUnit.dfm + 2014/03/28 14:37:37.000.878,F:\Documents\RAD Studio\Projects\Project1.dproj=F:\Documents\RAD Studio\Projects\HPSocketDemo-4C\TCPServerProject.dproj + 2014/03/28 14:59:55.000.233,=F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Server\Unit1.pas + 2014/03/28 15:00:15.000.092,F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Server\Unit1.pas=F:\Documents\RAD Studio\Projects\DelphiEcho-4C\Server\HPSocketSDKUnit.pas + 2015/01/22 21:15:59.000.553,=E:\MyProject\Hp_Socket\Delphi\TestEcho\Server\Unit1.pas + 2015/01/22 21:16:24.000.337,E:\MyProject\Hp_Socket\Delphi\TestEcho\Server\Unit1.pas=E:\MyProject\Hp_Socket\Delphi\TestEcho\ExePublic.pas + + diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.identcache b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.identcache new file mode 100644 index 000000000..28d210b6d Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.identcache differ diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.res b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.res new file mode 100644 index 000000000..d6cf6329c Binary files /dev/null and b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.res differ diff --git a/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.skincfg b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.skincfg new file mode 100644 index 000000000..c80eb9d63 --- /dev/null +++ b/HP-Socket/Demo/Other Languages Demos/Delphi/TestEcho/Server/TCPServerProject.skincfg @@ -0,0 +1,50 @@ +[ExpressSkins] +Default=1 +ShowNotifications=1 +Enabled=1 +dxSkinBlack=1 +dxSkinBlue=1 +dxSkinBlueprint=1 +dxSkinCaramel=1 +dxSkinCoffee=1 +dxSkinDarkRoom=1 +dxSkinDarkSide=1 +dxSkinDevExpressDarkStyle=1 +dxSkinDevExpressStyle=1 +dxSkinFoggy=1 +dxSkinGlassOceans=1 +dxSkinHighContrast=1 +dxSkiniMaginary=1 +dxSkinLilian=1 +dxSkinLiquidSky=1 +dxSkinLondonLiquidSky=1 +dxSkinMcSkin=1 +dxSkinMoneyTwins=1 +dxSkinOffice2007Black=1 +dxSkinOffice2007Blue=1 +dxSkinOffice2007Green=1 +dxSkinOffice2007Pink=1 +dxSkinOffice2007Silver=1 +dxSkinOffice2010Black=1 +dxSkinOffice2010Blue=1 +dxSkinOffice2010Silver=1 +dxSkinOffice2013White=1 +dxSkinPumpkin=1 +dxSkinSeven=1 +dxSkinSevenClassic=1 +dxSkinSharp=1 +dxSkinSharpPlus=1 +dxSkinSilver=1 +dxSkinSpringTime=1 +dxSkinStardust=1 +dxSkinSummer2008=1 +dxSkinTheAsphaltWorld=1 +dxSkinsDefaultPainters=1 +dxSkinValentine=1 +dxSkinVS2010=1 +dxSkinWhiteprint=1 +dxSkinXmas2008Blue=1 +dxSkinMetropolis=1 +dxSkinMetropolisDark=1 +dxSkinOffice2013DarkGray=1 +dxSkinOffice2013LightGray=1 diff --git "a/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/Bin/HPSocket4C.dll" "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/Bin/HPSocket4C.dll" new file mode 100644 index 000000000..3e83509a4 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/Bin/HPSocket4C.dll" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/HPSocket.ec" "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/HPSocket.ec" new file mode 100644 index 000000000..59fc90836 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/HPSocket.ec" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-Pull/TestEcho-PullClient.e" "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-Pull/TestEcho-PullClient.e" new file mode 100644 index 000000000..a0783c5cc Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-Pull/TestEcho-PullClient.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-Pull/TestEcho-PullServer.e" "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-Pull/TestEcho-PullServer.e" new file mode 100644 index 000000000..707150fa1 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-Pull/TestEcho-PullServer.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-UDP/TestEcho-UdpClient.e" "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-UDP/TestEcho-UdpClient.e" new file mode 100644 index 000000000..24c1483e6 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-UDP/TestEcho-UdpClient.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-UDP/TestEcho-UdpServer.e" "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-UDP/TestEcho-UdpServer.e" new file mode 100644 index 000000000..a2b6adcb0 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho-UDP/TestEcho-UdpServer.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho/TestEcho-Client.e" "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho/TestEcho-Client.e" new file mode 100644 index 000000000..da551b65e Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho/TestEcho-Client.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho/TestEcho-Server.e" "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho/TestEcho-Server.e" new file mode 100644 index 000000000..cdf1b50dd Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/dll\350\260\203\347\224\250/TestEcho/TestEcho-Server.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho-Pull/TestEcho-PullClient.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho-Pull/TestEcho-PullClient.e" new file mode 100644 index 000000000..7464721da Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho-Pull/TestEcho-PullClient.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho-Pull/TestEcho-PullServer.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho-Pull/TestEcho-PullServer.e" new file mode 100644 index 000000000..203a2ef52 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho-Pull/TestEcho-PullServer.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho/TestEcho-Client.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho/TestEcho-Client.e" new file mode 100644 index 000000000..84d8f48b6 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho/TestEcho-Client.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho/TestEcho-Server.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho/TestEcho-Server.e" new file mode 100644 index 000000000..b3b38d025 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/TestEcho/TestEcho-Server.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/\344\275\277\347\224\250\346\226\271\346\263\225.txt" "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/\344\275\277\347\224\250\346\226\271\346\263\225.txt" new file mode 100644 index 000000000..7e0d352ef --- /dev/null +++ "b/HP-Socket/Demo/Other Languages Demos/E/\346\224\257\346\214\201\345\272\223/\344\275\277\347\224\250\346\226\271\346\263\225.txt" @@ -0,0 +1,4 @@ +Hp_Socket.fne 放入易语言Lib目录 +Hp_Socket_static.lib、HPSocket_4C.lib 放入static_Lib目录 + +本支持库需要易语言vs2010链接器(链接: http://pan.baidu.com/s/1i3ydamT 密码: baka) \ No newline at end of file diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/HPSocket.ec" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/HPSocket.ec" new file mode 100644 index 000000000..5c6f5066f Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/HPSocket.ec" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/HPSocket4C.ec" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/HPSocket4C.ec" new file mode 100644 index 000000000..f2d99d836 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/HPSocket4C.ec" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackClient-4C.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackClient-4C.e" new file mode 100644 index 000000000..e0ff68a8b Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackClient-4C.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackClient.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackClient.e" new file mode 100644 index 000000000..bde6e7b6e Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackClient.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackServer-4C.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackServer-4C.e" new file mode 100644 index 000000000..575100d35 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackServer-4C.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackServer.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackServer.e" new file mode 100644 index 000000000..7e55f90b3 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/TestEcho-Pack/TestEcho-PackServer.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackClient-4C.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackClient-4C.e" new file mode 100644 index 000000000..4e6d11863 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackClient-4C.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackClient.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackClient.e" new file mode 100644 index 000000000..98c570138 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackClient.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackServer-4C.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackServer-4C.e" new file mode 100644 index 000000000..d0410f292 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackServer-4C.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackServer.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackServer.e" new file mode 100644 index 000000000..b4cd54763 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pack/FileTransfer-PackServer.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullClient-4C.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullClient-4C.e" new file mode 100644 index 000000000..18f9331b8 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullClient-4C.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullClient.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullClient.e" new file mode 100644 index 000000000..41b687ce4 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullClient.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullServer-4C.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullServer-4C.e" new file mode 100644 index 000000000..1606bae3c Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullServer-4C.e" differ diff --git "a/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullServer.e" "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullServer.e" new file mode 100644 index 000000000..3a7689a29 Binary files /dev/null and "b/HP-Socket/Demo/Other Languages Demos/E/\346\250\241\345\235\227/\346\226\207\344\273\266\344\274\240\350\276\223-Pull/FileTransfer-PullServer.e" differ diff --git a/HP-Socket/Demo/Release/x64/HPSocket4C_U.dll b/HP-Socket/Demo/Release/x64/HPSocket4C_U.dll new file mode 100644 index 000000000..e95307766 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/HPSocket4C_U.dll differ diff --git a/HP-Socket/Demo/Release/x64/HPSocket_U.dll b/HP-Socket/Demo/Release/x64/HPSocket_U.dll new file mode 100644 index 000000000..f04f0c4d4 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/HPSocket_U.dll differ diff --git a/HP-Socket/Demo/Release/x64/HttpProxy-Server.exe b/HP-Socket/Demo/Release/x64/HttpProxy-Server.exe new file mode 100644 index 000000000..b45a8f195 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/HttpProxy-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-4C-Client.exe b/HP-Socket/Demo/Release/x64/TestEcho-4C-Client.exe new file mode 100644 index 000000000..f39939e18 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-4C-Client.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-4C-Server.exe b/HP-Socket/Demo/Release/x64/TestEcho-4C-Server.exe new file mode 100644 index 000000000..dc2c4c7ea Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-4C-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Agent-4C.exe b/HP-Socket/Demo/Release/x64/TestEcho-Agent-4C.exe new file mode 100644 index 000000000..011d3b638 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Agent-4C.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Agent-PFM.exe b/HP-Socket/Demo/Release/x64/TestEcho-Agent-PFM.exe new file mode 100644 index 000000000..7e4d48521 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Agent-PFM.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Agent-Pull.exe b/HP-Socket/Demo/Release/x64/TestEcho-Agent-Pull.exe new file mode 100644 index 000000000..2704c2283 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Agent-Pull.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Agent-Server.exe b/HP-Socket/Demo/Release/x64/TestEcho-Agent-Server.exe new file mode 100644 index 000000000..b4dc7da55 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Agent-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Client.exe b/HP-Socket/Demo/Release/x64/TestEcho-Client.exe new file mode 100644 index 000000000..968a65cd6 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Client.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-PFM-Client.exe b/HP-Socket/Demo/Release/x64/TestEcho-PFM-Client.exe new file mode 100644 index 000000000..413dc8b01 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-PFM-Client.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-PFM-Server.exe b/HP-Socket/Demo/Release/x64/TestEcho-PFM-Server.exe new file mode 100644 index 000000000..bd278b532 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-PFM-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Pack-Client.exe b/HP-Socket/Demo/Release/x64/TestEcho-Pack-Client.exe new file mode 100644 index 000000000..44edb1c62 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Pack-Client.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Pack-Server.exe b/HP-Socket/Demo/Release/x64/TestEcho-Pack-Server.exe new file mode 100644 index 000000000..d46233931 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Pack-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Pull-Client.exe b/HP-Socket/Demo/Release/x64/TestEcho-Pull-Client.exe new file mode 100644 index 000000000..8d1f64227 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Pull-Client.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Pull-Server.exe b/HP-Socket/Demo/Release/x64/TestEcho-Pull-Server.exe new file mode 100644 index 000000000..8bc9913f4 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Pull-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-Server.exe b/HP-Socket/Demo/Release/x64/TestEcho-Server.exe new file mode 100644 index 000000000..28dc52d43 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-UDP-Client.exe b/HP-Socket/Demo/Release/x64/TestEcho-UDP-Client.exe new file mode 100644 index 000000000..5ec3abe68 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-UDP-Client.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-UDP-PFM-Client.exe b/HP-Socket/Demo/Release/x64/TestEcho-UDP-PFM-Client.exe new file mode 100644 index 000000000..1abf496b1 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-UDP-PFM-Client.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-UDP-PFM-Server.exe b/HP-Socket/Demo/Release/x64/TestEcho-UDP-PFM-Server.exe new file mode 100644 index 000000000..0970f540d Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-UDP-PFM-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestEcho-UDP-Server.exe b/HP-Socket/Demo/Release/x64/TestEcho-UDP-Server.exe new file mode 100644 index 000000000..c65b9a8eb Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestEcho-UDP-Server.exe differ diff --git a/HP-Socket/Demo/Release/x64/TestUDPCast-Member.exe b/HP-Socket/Demo/Release/x64/TestUDPCast-Member.exe new file mode 100644 index 000000000..5753e55c0 Binary files /dev/null and b/HP-Socket/Demo/Release/x64/TestUDPCast-Member.exe differ diff --git a/HP-Socket/Demo/Release/x86/HPSocket4C_U.dll b/HP-Socket/Demo/Release/x86/HPSocket4C_U.dll new file mode 100644 index 000000000..e88c968ee Binary files /dev/null and b/HP-Socket/Demo/Release/x86/HPSocket4C_U.dll differ diff --git a/HP-Socket/Demo/Release/x86/HPSocket_U.dll b/HP-Socket/Demo/Release/x86/HPSocket_U.dll new file mode 100644 index 000000000..7ee68eb59 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/HPSocket_U.dll differ diff --git a/HP-Socket/Demo/Release/x86/HttpProxy-Server.exe b/HP-Socket/Demo/Release/x86/HttpProxy-Server.exe new file mode 100644 index 000000000..44a8908f2 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/HttpProxy-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-4C-Client.exe b/HP-Socket/Demo/Release/x86/TestEcho-4C-Client.exe new file mode 100644 index 000000000..d2b64a31d Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-4C-Client.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-4C-Server.exe b/HP-Socket/Demo/Release/x86/TestEcho-4C-Server.exe new file mode 100644 index 000000000..e66832cb1 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-4C-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Agent-4C.exe b/HP-Socket/Demo/Release/x86/TestEcho-Agent-4C.exe new file mode 100644 index 000000000..887d34219 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Agent-4C.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Agent-PFM.exe b/HP-Socket/Demo/Release/x86/TestEcho-Agent-PFM.exe new file mode 100644 index 000000000..2116da783 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Agent-PFM.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Agent-Pull.exe b/HP-Socket/Demo/Release/x86/TestEcho-Agent-Pull.exe new file mode 100644 index 000000000..286112086 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Agent-Pull.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Agent-Server.exe b/HP-Socket/Demo/Release/x86/TestEcho-Agent-Server.exe new file mode 100644 index 000000000..4d4ca85ba Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Agent-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Client.exe b/HP-Socket/Demo/Release/x86/TestEcho-Client.exe new file mode 100644 index 000000000..f920b1318 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Client.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-PFM-Client.exe b/HP-Socket/Demo/Release/x86/TestEcho-PFM-Client.exe new file mode 100644 index 000000000..e8e46a82f Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-PFM-Client.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-PFM-Server.exe b/HP-Socket/Demo/Release/x86/TestEcho-PFM-Server.exe new file mode 100644 index 000000000..3f6508293 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-PFM-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Pack-Client.exe b/HP-Socket/Demo/Release/x86/TestEcho-Pack-Client.exe new file mode 100644 index 000000000..467accc02 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Pack-Client.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Pack-Server.exe b/HP-Socket/Demo/Release/x86/TestEcho-Pack-Server.exe new file mode 100644 index 000000000..276e7c9be Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Pack-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Pull-Client.exe b/HP-Socket/Demo/Release/x86/TestEcho-Pull-Client.exe new file mode 100644 index 000000000..366fe2376 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Pull-Client.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Pull-Server.exe b/HP-Socket/Demo/Release/x86/TestEcho-Pull-Server.exe new file mode 100644 index 000000000..10119654e Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Pull-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-Server.exe b/HP-Socket/Demo/Release/x86/TestEcho-Server.exe new file mode 100644 index 000000000..e4aa30a5f Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-UDP-Client.exe b/HP-Socket/Demo/Release/x86/TestEcho-UDP-Client.exe new file mode 100644 index 000000000..562b770a9 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-UDP-Client.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-UDP-PFM-Client.exe b/HP-Socket/Demo/Release/x86/TestEcho-UDP-PFM-Client.exe new file mode 100644 index 000000000..8aadc2d43 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-UDP-PFM-Client.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-UDP-PFM-Server.exe b/HP-Socket/Demo/Release/x86/TestEcho-UDP-PFM-Server.exe new file mode 100644 index 000000000..3aad76ea1 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-UDP-PFM-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestEcho-UDP-Server.exe b/HP-Socket/Demo/Release/x86/TestEcho-UDP-Server.exe new file mode 100644 index 000000000..96643fbeb Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestEcho-UDP-Server.exe differ diff --git a/HP-Socket/Demo/Release/x86/TestUDPCast-Member.exe b/HP-Socket/Demo/Release/x86/TestUDPCast-Member.exe new file mode 100644 index 000000000..951ac89d8 Binary files /dev/null and b/HP-Socket/Demo/Release/x86/TestUDPCast-Member.exe differ diff --git a/HP-Socket/Demo/TestEcho-4C/Client/Client.cpp b/HP-Socket/Demo/TestEcho-4C/Client/Client.cpp new file mode 100644 index 000000000..a67fe0573 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-4C/Client/Client.h b/HP-Socket/Demo/TestEcho-4C/Client/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-4C/Client/Client.rc b/HP-Socket/Demo/TestEcho-4C/Client/Client.rc new file mode 100644 index 000000000..ad9cd6502 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/Client/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj b/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj new file mode 100644 index 000000000..96178f841 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj @@ -0,0 +1,227 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87E9} + Client + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket4C\x86\HPSocket4C_UD.lib + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket4C\x64\HPSocket4C_UD.lib + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket4C\x86\HPSocket4C_U.lib + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket4C\x64\HPSocket4C_U.lib + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj.filters b/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj.filters new file mode 100644 index 000000000..5ae98226c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj.filters @@ -0,0 +1,77 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {4416963f-6bca-4f60-8e6f-30f8129ed29e} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket4C + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj.user b/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/Client.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-4C/Client/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-4C/Client/ClientDlg.cpp new file mode 100644 index 000000000..8b5ca1698 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/ClientDlg.cpp @@ -0,0 +1,298 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" + + +// CClientDlg dialog + +#define DEFAULT_CONTENT _T("text to be sent") +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") + +CClientDlg* CClientDlg::m_spThis = nullptr; + +CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CClientDlg::IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + + m_spThis = this; + + // + m_pListener = ::Create_HP_TcpPullClientListener(); + // Socket + m_pClient = ::Create_HP_TcpPullClient(m_pListener); + // Socket ص + ::HP_Set_FN_Client_OnConnect(m_pListener, OnConnect); + ::HP_Set_FN_Client_OnSend(m_pListener, OnSend); + ::HP_Set_FN_Client_OnPullReceive(m_pListener, OnReceive); + ::HP_Set_FN_Client_OnClose(m_pListener, OnClose); +} + +CClientDlg::~CClientDlg() +{ + // Socket + ::Destroy_HP_TcpPullClient(m_pClient); + // ټ + ::Destroy_HP_TcpPullClientListener(m_pListener); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_CONTENT, m_Content); + DDX_Control(pDX, IDC_SEND, m_Send); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_ASYNC, m_Async); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_SEND, &CClientDlg::OnBnClickedSend) + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_Content.SetWindowText(DEFAULT_CONTENT); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + m_Async.SetCheck(BST_CHECKED); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + m_bAsyncConn = FALSE; + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Async.EnableWindow(m_enState == ST_STOPPED); + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Send.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); +} + +void CClientDlg::OnBnClickedSend() +{ + USES_CONVERSION; + + static DWORD SEQ = 0; + + CString strContent; + m_Content.GetWindowText(strContent); + + smart_simple_ptr buffer = ::GeneratePkgBuffer(++SEQ, _T("С"), 23, strContent); + + if(::HP_Client_Send(m_pClient, buffer->Ptr(), (int)buffer->Size())) + ::LogSend(::HP_Client_GetConnectionID(m_pClient), strContent); + else + ::LogSendFail(::HP_Client_GetConnectionID(m_pClient), ::SYS_GetLastError(), ::HP_GetSocketErrorDesc(HP_SE_DATA_SEND)); +} + +void CClientDlg::OnBnClickedStart() +{ + SetAppState(ST_STARTING); + + CString strAddress; + CString strPort; + + m_Address.GetWindowText(strAddress); + m_Port.GetWindowText(strPort); + + USHORT usPort = (USHORT)_ttoi(strPort); + m_bAsyncConn = m_Async.GetCheck(); + + m_pkgInfo.Reset(); + + ::LogClientStarting(strAddress, usPort); + + if(::HP_Client_Start(m_pClient, strAddress, usPort, m_bAsyncConn)) + { + + } + else + { + ::LogClientStartFail(::HP_Client_GetLastError(m_pClient), HP_Client_GetLastErrorDesc(m_pClient)); + SetAppState(ST_STOPPED); + } +} + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(::HP_Client_Stop(m_pClient)) + ::LogClientStopping(::HP_Client_GetConnectionID(m_pClient)); + else + ASSERT(FALSE); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +En_HP_HandleResult CClientDlg::OnConnect(HP_Client pClient) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + ::HP_Client_GetLocalAddress(pClient, szAddress, &iAddressLen, &usPort); + + ::PostOnConnect(::HP_Client_GetConnectionID(pClient), szAddress, usPort); + m_spThis->SetAppState(ST_STARTED); + + return HP_HR_OK; +} + +En_HP_HandleResult CClientDlg::OnSend(HP_Client pClient, const BYTE* pData, int iLength) +{ + ::PostOnSend(::HP_Client_GetConnectionID(pClient), pData, iLength); + return HP_HR_OK; +} + +En_HP_HandleResult CClientDlg::OnReceive(HP_Client pClient, int iLength) +{ + int required = m_spThis->m_pkgInfo.length; + int remain = iLength; + + while(remain >= required) + { + remain -= required; + CBufferPtr buffer(required); + + En_HP_FetchResult result = ::HP_TcpPullClient_Fetch(pClient, buffer, (int)buffer.Size()); + if(result == HP_FR_OK) + { + if(m_spThis->m_pkgInfo.is_header) + { + TPkgHeader* pHeader = (TPkgHeader*)buffer.Ptr(); + TRACE("[Client] head -> seq: %d, body_len: %d\n", pHeader->seq, pHeader->body_len); + + required = pHeader->body_len; + } + else + { + TPkgBody* pBody = (TPkgBody*)buffer.Ptr(); + TRACE("[Client] body -> name: %s, age: %d, desc: %s\n", pBody->name, pBody->age, pBody->desc); + + required = sizeof(TPkgHeader); + } + + m_spThis->m_pkgInfo.is_header = !m_spThis->m_pkgInfo.is_header; + m_spThis->m_pkgInfo.length = required; + + ::PostOnReceive(::HP_Client_GetConnectionID(pClient), buffer, (int)buffer.Size()); + } + } + + return HP_HR_OK; +} + +En_HP_HandleResult CClientDlg::OnClose(HP_Client pClient, En_HP_SocketOperation enOperation, int iErrorCode) +{ + iErrorCode == HP_SE_OK ? ::PostOnClose(::HP_Client_GetConnectionID(pClient)): + ::PostOnError(::HP_Client_GetConnectionID(pClient), enOperation, iErrorCode); + + m_spThis->SetAppState(ST_STOPPED); + + return HP_HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-4C/Client/ClientDlg.h b/HP-Socket/Demo/TestEcho-4C/Client/ClientDlg.h new file mode 100644 index 000000000..160679fe8 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/ClientDlg.h @@ -0,0 +1,70 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/HPSocket4C.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx +{ +// Construction +public: + CClientDlg(CWnd* pParent = NULL); // standard constructor + ~CClientDlg(); // standard destructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedSend(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() + +public: + void SetAppState(EnAppState state); + +private: + static En_HP_HandleResult __stdcall OnConnect(HP_Client pClient); + static En_HP_HandleResult __stdcall OnSend(HP_Client pClient, const BYTE* pData, int iLength); + static En_HP_HandleResult __stdcall OnReceive(HP_Client pClient, int iLength); + static En_HP_HandleResult __stdcall OnClose(HP_Client pClient, En_HP_SocketOperation enOperation, int iErrorCode); + +private: + CEdit m_Content; + CButton m_Send; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Async; + CButton m_Start; + CButton m_Stop; + + EnAppState m_enState; + BOOL m_bAsyncConn; + + TPkgInfo m_pkgInfo; + +private: + static CClientDlg* m_spThis; + + HP_TcpPullClient m_pClient; + HP_TcpPullClientListener m_pListener; +}; diff --git a/HP-Socket/Demo/TestEcho-4C/Client/ReadMe.txt b/HP-Socket/Demo/TestEcho-4C/Client/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-4C/Client/res/Client.ico b/HP-Socket/Demo/TestEcho-4C/Client/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/Client/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-4C/Client/res/Client.rc2 b/HP-Socket/Demo/TestEcho-4C/Client/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/Client/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-4C/Client/resource.h b/HP-Socket/Demo/TestEcho-4C/Client/resource.h new file mode 100644 index 000000000..82642c470 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/Client/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-4C/Client/stdafx.cpp b/HP-Socket/Demo/TestEcho-4C/Client/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-4C/Client/stdafx.h b/HP-Socket/Demo/TestEcho-4C/Client/stdafx.h new file mode 100644 index 000000000..8d5070e57 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/stdafx.h @@ -0,0 +1,16 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _RIBBONS_SUPPORT +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-4C/Client/targetver.h b/HP-Socket/Demo/TestEcho-4C/Client/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Client/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-4C/Server/ReadMe.txt b/HP-Socket/Demo/TestEcho-4C/Server/ReadMe.txt new file mode 100644 index 000000000..d97be25bf --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Server Project Overview +=============================================================================== + +The application wizard has created this Server application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Server application. + +Server.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Server.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CServerApp application class. + +Server.cpp + This is the main application source file that contains the application + class CServerApp. + +Server.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Server.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Server.rc. + +res\Server.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ServerDlg.h, ServerDlg.cpp - the dialog + These files contain your CServerDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Server.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Server.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Server.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-4C/Server/Server.cpp b/HP-Socket/Demo/TestEcho-4C/Server/Server.cpp new file mode 100644 index 000000000..578f1d755 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/Server.cpp @@ -0,0 +1,87 @@ + +// Server.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" + + +// CServerApp + +BEGIN_MESSAGE_MAP(CServerApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CServerApp construction + +CServerApp::CServerApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CServerApp object + +CServerApp theApp; + + +// CServerApp initialization + +BOOL CServerApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CServerDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-4C/Server/Server.h b/HP-Socket/Demo/TestEcho-4C/Server/Server.h new file mode 100644 index 000000000..df6a5f075 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/Server.h @@ -0,0 +1,32 @@ + +// Server.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CServerApp: +// See Server.cpp for the implementation of this class +// + +class CServerApp : public CWinApp +{ +public: + CServerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CServerApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-4C/Server/Server.rc b/HP-Socket/Demo/TestEcho-4C/Server/Server.rc new file mode 100644 index 000000000..5a805b93d Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/Server/Server.rc differ diff --git a/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj b/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj new file mode 100644 index 000000000..607b0c7b8 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj @@ -0,0 +1,229 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5A2EE763-53B1-462E-AE9F-7CC58436C879} + Server + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket4C\x86\HPSocket4C_UD.lib + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket4C\x64\HPSocket4C_UD.lib + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket4C\x86\HPSocket4C_U.lib + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket4C\x64\HPSocket4C_U.lib + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + CppHeader + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj.filters b/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj.filters new file mode 100644 index 000000000..a4a937332 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj.filters @@ -0,0 +1,77 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {48c55559-451a-4f0d-9cb2-884503406307} + + + {f57bc1d3-66f4-49c0-b1c8-c7e5d163de15} + + + {421e5dde-2633-4094-a3d8-c99b836b54da} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket4C + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj.user b/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/Server.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-4C/Server/ServerDlg.cpp b/HP-Socket/Demo/TestEcho-4C/Server/ServerDlg.cpp new file mode 100644 index 000000000..122a9a282 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/ServerDlg.cpp @@ -0,0 +1,342 @@ + +// ServerDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" +#include "afxdialogex.h" + + +// CServerDlg dialog + +const LPCTSTR CServerDlg::ADDRESS = _T("0.0.0.0"); +const USHORT CServerDlg::PORT = 5555; +CServerDlg* CServerDlg::m_spThis = nullptr; + +CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CServerDlg::IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + + m_spThis = this; + + // + m_pListener = ::Create_HP_TcpPullServerListener(); + // Socket + m_pServer = ::Create_HP_TcpPullServer(m_pListener); + // Socket ص + ::HP_Set_FN_Server_OnPrepareListen(m_pListener, OnPrepareListen); + ::HP_Set_FN_Server_OnAccept(m_pListener, OnAccept); + ::HP_Set_FN_Server_OnSend(m_pListener, OnSend); + ::HP_Set_FN_Server_OnPullReceive(m_pListener, OnReceive); + ::HP_Set_FN_Server_OnClose(m_pListener, OnClose); + ::HP_Set_FN_Server_OnShutdown(m_pListener, OnShutdown); +} + +CServerDlg::~CServerDlg() +{ + // Socket + ::Destroy_HP_TcpPullServer(m_spThis->m_pServer); + // ټ + ::Destroy_HP_TcpPullServerListener(m_pListener); +} + +void CServerDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_CONN_ID, m_HP_CONNID); + DDX_Control(pDX, IDC_DISCONNECT, m_DisConn); +} + +BEGIN_MESSAGE_MAP(CServerDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CServerDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CServerDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_BN_CLICKED(IDC_DISCONNECT, &CServerDlg::OnBnClickedDisconnect) + ON_EN_CHANGE(IDC_CONN_ID, &CServerDlg::OnEnChangeHP_CONNID) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CServerDlg message handlers + +BOOL CServerDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + CString strTitle; + CString strOriginTitle; + GetWindowText(strOriginTitle); + strTitle.Format(_T("%s - (%s:%d)"), strOriginTitle, ADDRESS, PORT); + SetWindowText(strTitle); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CServerDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CServerDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CServerDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_HP_CONNID.GetWindowTextLength() > 0); +} + +void CServerDlg::OnBnClickedStart() +{ + m_Address.GetWindowText(m_strAddress); + m_strAddress.Trim(); + + SetAppState(ST_STARTING); + //m_Server->SetSocketBufferSize(64); + if(::HP_Server_Start(m_spThis->m_pServer, ADDRESS, PORT)) + { + ::LogServerStart(ADDRESS, PORT); + SetAppState(ST_STARTED); + } + else + { + ::LogServerStartFail(::HP_Server_GetLastError(m_spThis->m_pServer), ::HP_Server_GetLastErrorDesc(m_spThis->m_pServer)); + SetAppState(ST_STOPPED); + } +} + +void CServerDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(::HP_Server_Stop(m_spThis->m_pServer)) + { + ::LogServerStop(); + SetAppState(ST_STOPPED); + } + else + { + ASSERT(FALSE); + } +} + +void CServerDlg::OnBnClickedDisconnect() +{ + CString strHP_CONNID; + m_HP_CONNID.GetWindowText(strHP_CONNID); + HP_CONNID dwHP_CONNID = (HP_CONNID)_ttoi(strHP_CONNID); + + if(::HP_Server_Disconnect(m_spThis->m_pServer, dwHP_CONNID, TRUE)) + ::LogDisconnect(dwHP_CONNID); + else + ::LogDisconnectFail(dwHP_CONNID); +} + +void CServerDlg::OnEnChangeHP_CONNID() +{ + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_HP_CONNID.GetWindowTextLength() > 0); +} + +int CServerDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +En_HP_HandleResult CServerDlg::OnPrepareListen(SOCKET soListen) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + ::HP_Server_GetListenAddress(m_spThis->m_pServer, szAddress, &iAddressLen, &usPort); + ::PostOnPrepareListen(szAddress, usPort); + return HP_HR_OK; +} + +En_HP_HandleResult CServerDlg::OnAccept(HP_CONNID dwHP_CONNID, SOCKET soClient) +{ + BOOL bPass = TRUE; + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + ::HP_Server_GetRemoteAddress(m_spThis->m_pServer, dwHP_CONNID, szAddress, &iAddressLen, &usPort); + + if(!m_spThis->m_strAddress.IsEmpty()) + { + if(m_spThis->m_strAddress.CompareNoCase(szAddress) == 0) + bPass = FALSE; + } + + ::PostOnAccept(dwHP_CONNID, szAddress, usPort, bPass); + + if(bPass) ::HP_Server_SetConnectionExtra(m_spThis->m_pServer, dwHP_CONNID, new TPkgInfo(true, sizeof(TPkgHeader))); + + return bPass ? HP_HR_OK : HP_HR_ERROR; +} + +En_HP_HandleResult CServerDlg::OnSend(HP_CONNID dwHP_CONNID, const BYTE* pData, int iLength) +{ + ::PostOnSend(dwHP_CONNID, pData, iLength); + return HP_HR_OK; +} + +En_HP_HandleResult CServerDlg::OnReceive(HP_CONNID dwHP_CONNID, int iLength) +{ + TPkgInfo* pInfo = m_spThis->FindPkgInfo(dwHP_CONNID); + + if(pInfo != nullptr) + { + int required = pInfo->length; + int remain = iLength; + + while(remain >= required) + { + remain -= required; + CBufferPtr buffer(required); + + En_HP_FetchResult result = ::HP_TcpPullServer_Fetch(m_spThis->m_pServer, dwHP_CONNID, buffer, (int)buffer.Size()); + if(result == HP_FR_OK) + { + if(pInfo->is_header) + { + TPkgHeader* pHeader = (TPkgHeader*)buffer.Ptr(); + TRACE("[Server] head -> seq: %d, body_len: %d\n", pHeader->seq, pHeader->body_len); + + required = pHeader->body_len; + } + else + { + TPkgBody* pBody = (TPkgBody*)(BYTE*)buffer; + TRACE("[Server] body -> name: %s, age: %d, desc: %s\n", pBody->name, pBody->age, pBody->desc); + + required = sizeof(TPkgHeader); + } + + pInfo->is_header = !pInfo->is_header; + pInfo->length = required; + + ::PostOnReceive(dwHP_CONNID, buffer, (int)buffer.Size()); + + if(!::HP_Server_Send(m_spThis->m_pServer, dwHP_CONNID, buffer, (int)buffer.Size())) + return HP_HR_ERROR; + } + } + } + + return HP_HR_OK; +} + +En_HP_HandleResult CServerDlg::OnClose(HP_CONNID dwHP_CONNID, En_HP_SocketOperation enOperation, int iErrorCode) +{ + iErrorCode == HP_SE_OK ? ::PostOnClose(dwHP_CONNID): + ::PostOnError(dwHP_CONNID, enOperation, iErrorCode); + + m_spThis->RemovePkgInfo(dwHP_CONNID); + + return HP_HR_OK; +} + +En_HP_HandleResult CServerDlg::OnShutdown() +{ + ::PostOnShutdown(); + + return HP_HR_OK; +} + +TPkgInfo* CServerDlg::FindPkgInfo(HP_CONNID dwHP_CONNID) +{ + PVOID pInfo = nullptr; + ::HP_Server_GetConnectionExtra(m_spThis->m_pServer, dwHP_CONNID, &pInfo); + + return (TPkgInfo*)pInfo; +} + +void CServerDlg::RemovePkgInfo(HP_CONNID dwHP_CONNID) +{ + //CCriSecLock locallock(m_spThis->m_csPkgInfo); + + TPkgInfo* pInfo = FindPkgInfo(dwHP_CONNID); + ASSERT(pInfo != nullptr); + + delete pInfo; +} diff --git a/HP-Socket/Demo/TestEcho-4C/Server/ServerDlg.h b/HP-Socket/Demo/TestEcho-4C/Server/ServerDlg.h new file mode 100644 index 000000000..6f3ce0cff --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/ServerDlg.h @@ -0,0 +1,77 @@ + +// ServerDlg.h : header file +// + +#pragma once +#include "afxwin.h" + +#include "../../../Src/HPSocket4C.h" +#include "../../Global/helper.h" + +// CServerDlg dialog +class CServerDlg : public CDialogEx +{ +// Construction +public: + CServerDlg(CWnd* pParent = NULL); // standard constructor + ~CServerDlg(); // standard destructor + +// Dialog Data + enum { IDD = IDD_SERVER_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + afx_msg void OnBnClickedDisconnect(); + afx_msg void OnEnChangeHP_CONNID(); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + static En_HP_HandleResult __stdcall OnPrepareListen(SOCKET soListen); + static En_HP_HandleResult __stdcall OnAccept(HP_CONNID dwHP_CONNID, SOCKET soClient); + static En_HP_HandleResult __stdcall OnSend(HP_CONNID dwHP_CONNID, const BYTE* pData, int iLength); + static En_HP_HandleResult __stdcall OnReceive(HP_CONNID dwHP_CONNID, int iLength); + static En_HP_HandleResult __stdcall OnClose(HP_CONNID dwHP_CONNID, En_HP_SocketOperation enOperation, int iErrorCode); + static En_HP_HandleResult __stdcall OnShutdown(); + +private: + TPkgInfo* FindPkgInfo(HP_CONNID dwHP_CONNID); + void RemovePkgInfo(HP_CONNID dwHP_CONNID); + +private: + CListBox m_Info; + CButton m_Start; + CButton m_Stop; + CEdit m_Address; + CEdit m_HP_CONNID; + CButton m_DisConn; + +private: + EnAppState m_enState; + CString m_strAddress; + + //CCriSec m_csPkgInfo; + +private: + static const USHORT PORT; + static const LPCTSTR ADDRESS; + + static CServerDlg* m_spThis; + + HP_TcpPullServer m_pServer; + HP_TcpPullServerListener m_pListener; +}; diff --git a/HP-Socket/Demo/TestEcho-4C/Server/res/Server.ico b/HP-Socket/Demo/TestEcho-4C/Server/res/Server.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/Server/res/Server.ico differ diff --git a/HP-Socket/Demo/TestEcho-4C/Server/res/Server.rc2 b/HP-Socket/Demo/TestEcho-4C/Server/res/Server.rc2 new file mode 100644 index 000000000..b77c9d1c1 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/Server/res/Server.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-4C/Server/resource.h b/HP-Socket/Demo/TestEcho-4C/Server/resource.h new file mode 100644 index 000000000..9791a41d9 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/Server/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-4C/Server/stdafx.cpp b/HP-Socket/Demo/TestEcho-4C/Server/stdafx.cpp new file mode 100644 index 000000000..22d19927c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-4C/Server/stdafx.h b/HP-Socket/Demo/TestEcho-4C/Server/stdafx.h new file mode 100644 index 000000000..dc0a47732 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/stdafx.h @@ -0,0 +1,14 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" diff --git a/HP-Socket/Demo/TestEcho-4C/Server/targetver.h b/HP-Socket/Demo/TestEcho-4C/Server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-4C/TestEcho-4C.sln b/HP-Socket/Demo/TestEcho-4C/TestEcho-4C.sln new file mode 100644 index 000000000..010727a48 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-4C/TestEcho-4C.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C879}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87E9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|Win32.Build.0 = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|x64.Build.0 = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|Win32.Build.0 = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|x64.ActiveCfg = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|x64.Build.0 = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestEcho-4C/TestEcho-4C.suo b/HP-Socket/Demo/TestEcho-4C/TestEcho-4C.suo new file mode 100644 index 000000000..159d60032 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-4C/TestEcho-4C.suo differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj new file mode 100644 index 000000000..48ce4d2ad --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj @@ -0,0 +1,232 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87F9} + Client + MFCProj + 4C + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj.filters b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj.filters new file mode 100644 index 000000000..5ae98226c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj.filters @@ -0,0 +1,77 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {4416963f-6bca-4f60-8e6f-30f8129ed29e} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket4C + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj.user b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Agent-4C.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.cpp new file mode 100644 index 000000000..a67fe0573 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.h b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.rc b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.rc new file mode 100644 index 000000000..b9a8104ec Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ClientDlg.cpp new file mode 100644 index 000000000..ae68624a6 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ClientDlg.cpp @@ -0,0 +1,349 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" + + +// CClientDlg dialog + +#define DEFAULT_CONTENT _T("text to be sent") +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") +#define LOCAL_ADDRESS _T("0.0.0.0") + +// link: ..\..\Bin\HPSocket\x86\HPSocket_UD.lib + +#ifdef _WIN64 + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket4C/x64/HPSocket4C_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket4C/x64/HPSocket4C_U.lib") + #endif +#else + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket4C/x86/HPSocket4C_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket4C/x86/HPSocket4C_U.lib") + #endif +#endif + +CClientDlg* CClientDlg::m_spThis = nullptr; +HP_TcpPullAgent CClientDlg::m_spAgent = nullptr; +HP_TcpPullAgentListener CClientDlg::m_spListener = nullptr; + +CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CClientDlg::IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + + m_spThis = this; + // + m_spListener = ::Create_HP_TcpPullAgentListener(); + // Socket + m_spAgent = ::Create_HP_TcpPullAgent(m_spListener); + // Socket ص + ::HP_Set_FN_Agent_OnConnect(m_spListener, OnConnect); + ::HP_Set_FN_Agent_OnSend(m_spListener, OnSend); + ::HP_Set_FN_Agent_OnPullReceive(m_spListener, OnReceive); + ::HP_Set_FN_Agent_OnClose(m_spListener, OnClose); + ::HP_Set_FN_Agent_OnShutdown(m_spListener, OnShutdown); +} + +CClientDlg::~CClientDlg() +{ + // Socket + ::Destroy_HP_TcpPullAgent(m_spAgent); + // ټ + ::Destroy_HP_TcpPullAgentListener(m_spListener); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_CONTENT, m_Content); + DDX_Control(pDX, IDC_SEND, m_Send); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_CONNECT, m_Connect); + DDX_Control(pDX, IDC_STOP, m_Stop); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_SEND, &CClientDlg::OnBnClickedSend) + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_CONNECT, &CClientDlg::OnBnClickedConnect) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_Content.SetWindowText(DEFAULT_CONTENT); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Connect.SetWindowText(m_enState == ST_CONNECTED ? _T("Dis Connect") : _T("Connect")); + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Connect.EnableWindow(m_enState == ST_STARTED || m_enState == ST_CONNECTED); + m_Stop.EnableWindow(m_enState == ST_STARTED || m_enState == ST_CONNECTED); + m_Send.EnableWindow(m_enState == ST_CONNECTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); +} + +void CClientDlg::OnBnClickedSend() +{ + USES_CONVERSION; + + static DWORD SEQ = 0; + + CString strContent; + m_Content.GetWindowText(strContent); + + smart_simple_ptr buffer = ::GeneratePkgBuffer(++SEQ, _T("С"), 23, strContent); + + if(::HP_Agent_Send(m_spAgent, m_dwConnID, buffer->Ptr(), (int)buffer->Size())) + ::LogSend(m_dwConnID, strContent); + else + ::LogSendFail(m_dwConnID, HP_SE_DATA_SEND, ::HP_GetSocketErrorDesc(HP_SE_DATA_SEND)); +} + + +void CClientDlg::OnBnClickedStart() +{ + SetAppState(ST_STARTING); + + CString strPort; + + m_Address.GetWindowText(m_strAddress); + m_Port.GetWindowText(strPort); + + m_usPort = (USHORT)_ttoi(strPort); + m_dwConnID = 0; + + m_pkgInfo.Reset(); + + ::LogClientStarting(m_strAddress, m_usPort); + + ::HP_TcpAgent_SetReuseAddress(m_spAgent, TRUE); + + if(::HP_Agent_Start(m_spAgent, LOCAL_ADDRESS, FALSE)) + { + SetAppState(ST_STARTED); + } + else + { + ::LogClientStartFail(::SYS_GetLastError(), ::HP_GetSocketErrorDesc(HP_SE_DATA_SEND)); + SetAppState(ST_STOPPED); + } +} + +void CClientDlg::OnBnClickedConnect() +{ + EnAppState enState = m_enState; + + SetAppState(ST_CONNECTING); + + if(enState != ST_CONNECTED) + { + if(::HP_Agent_Connect(m_spAgent, m_strAddress, m_usPort, &m_dwConnID)) + { + } + else + { + ::LogClientStartFail(::SYS_GetLastError(), ::HP_GetSocketErrorDesc(HP_SE_CONNECT_SERVER)); + SetAppState(ST_STARTED); + } + } + else + { + ::HP_Agent_Disconnect(m_spAgent, m_dwConnID, FALSE); + } +} + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(!::HP_Agent_Stop(m_spAgent)) + ASSERT(FALSE); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +En_HP_HandleResult CClientDlg::OnConnect(HP_CONNID m_dwConnID) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + ::HP_Agent_GetLocalAddress(m_spAgent, m_dwConnID, szAddress, &iAddressLen, &usPort); + + ::PostOnConnect(m_dwConnID, szAddress, usPort); + m_spThis->SetAppState(ST_CONNECTED); + + return HP_HR_OK; +} + +En_HP_HandleResult CClientDlg::OnSend(HP_CONNID m_dwConnID, const BYTE* pData, int iLength) +{ + ::PostOnSend(m_dwConnID, pData, iLength); + return HP_HR_OK; +} + +En_HP_HandleResult CClientDlg::OnReceive(HP_CONNID m_dwConnID, int iLength) +{ + int required = m_spThis->m_pkgInfo.length; + int remain = iLength; + + while(remain >= required) + { + remain -= required; + CBufferPtr buffer(required); + + En_HP_FetchResult result = ::HP_TcpPullAgent_Fetch(m_spAgent, m_dwConnID, buffer, (int)buffer.Size()); + + if(result == HP_FR_OK) + { + if(m_spThis->m_pkgInfo.is_header) + { + TPkgHeader* pHeader = (TPkgHeader*)buffer.Ptr(); + TRACE("[Agent] head -> seq: %d, body_len: %d\n", pHeader->seq, pHeader->body_len); + + required = pHeader->body_len; + } + else + { + TPkgBody* pBody = (TPkgBody*)buffer.Ptr(); + TRACE("[Agent] body -> name: %s, age: %d, desc: %s\n", pBody->name, pBody->age, pBody->desc); + + required = sizeof(TPkgHeader); + } + + m_spThis->m_pkgInfo.is_header = !m_spThis->m_pkgInfo.is_header; + m_spThis->m_pkgInfo.length = required; + + ::PostOnReceive(m_dwConnID, buffer, (int)buffer.Size()); + } + } + + return HP_HR_OK; +} + +En_HP_HandleResult CClientDlg::OnClose(HP_CONNID m_dwConnID, En_HP_SocketOperation enOperation, int iErrorCode) +{ + iErrorCode == HP_SE_OK ? ::PostOnClose(m_dwConnID): + ::PostOnError(m_dwConnID, enOperation, iErrorCode); + + m_spThis->SetAppState(ST_STARTED); + + return HP_HR_OK; +} + +En_HP_HandleResult CClientDlg::OnShutdown() +{ + ::PostOnShutdown(); + m_spThis->SetAppState(ST_STOPPED); + + return HP_HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ClientDlg.h b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ClientDlg.h new file mode 100644 index 000000000..ee87d664e --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ClientDlg.h @@ -0,0 +1,70 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/HPSocket4C.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx +{ +// Construction +public: + CClientDlg(CWnd* pParent = NULL); // standard constructor + ~CClientDlg(); + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedSend(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedConnect(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + static En_HP_HandleResult __stdcall OnConnect(HP_CONNID dwConnID); + static En_HP_HandleResult __stdcall OnSend(HP_CONNID dwConnID, const BYTE* pData, int iLength); + static En_HP_HandleResult __stdcall OnReceive(HP_CONNID dwConnID, int iLength); + static En_HP_HandleResult __stdcall OnClose(HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode); + static En_HP_HandleResult __stdcall OnShutdown(); +private: + CEdit m_Content; + CButton m_Send; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Start; + CButton m_Connect; + CButton m_Stop; + + EnAppState m_enState; + CString m_strAddress; + USHORT m_usPort; + HP_CONNID m_dwConnID; + + TPkgInfo m_pkgInfo; + +private: + static CClientDlg* m_spThis; + static HP_TcpPullAgent m_spAgent; + static HP_TcpPullAgentListener m_spListener; +}; diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ReadMe.txt b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/res/Client.ico b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/res/Client.rc2 b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/resource.h b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/resource.h new file mode 100644 index 000000000..d0a8f6ed4 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/stdafx.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/stdafx.h b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-4C/targetver.h b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-4C/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj new file mode 100644 index 000000000..a35f77ccd --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj @@ -0,0 +1,245 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87F8} + Client + MFCProj + PFM + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj.filters b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj.filters new file mode 100644 index 000000000..630ae4b81 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj.filters @@ -0,0 +1,140 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {0587eafb-7792-4a6b-ae21-574498772e9f} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + Common + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj.user b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Agent-PFM.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.cpp new file mode 100644 index 000000000..caa99572d --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != nullptr) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.h b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.rc b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.rc new file mode 100644 index 000000000..321b18db7 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ClientDlg.cpp new file mode 100644 index 000000000..a0f32f30e --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ClientDlg.cpp @@ -0,0 +1,466 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" +#include "../../../../Common/Src/WaitFor.h" +#include "../../../../Common/Src/SysHelper.h" + +/* +#ifdef _WIN64 + #ifdef _DEBUG + #pragma comment(lib, "../../Bin/HPSocket/x64/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../Bin/HPSocket/x64/HPSocket_U.lib") + #endif +#else + #ifdef _DEBUG + #pragma comment(lib, "../../Bin/HPSocket/x86/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../Bin/HPSocket/x86/HPSocket_U.lib") + #endif +#endif +*/ + +// CClientDlg dialog + +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") +#define LOCAL_ADDRESS _T("0.0.0.0") + +CClientDlg::CClientDlg(CWnd* pParent /*=nullptr*/) + : CDialogEx(CClientDlg::IDD, pParent), m_Agent(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_TEST_TIMES, m_TestTimes); + DDX_Control(pDX, IDC_SOCK_COUNT, m_SocketCount); + DDX_Control(pDX, IDC_THREAD_COUNT, m_ThreadCount); + DDX_Control(pDX, IDC_DATA_LEN, m_DataLen); + DDX_Control(pDX, IDC_TEST_TIMES_INTERV, m_TestInterv); + DDX_Control(pDX, IDC_SEND_POLICY, m_SendPolicy); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() + ON_WM_CLOSE() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_TestTimes.SetCurSel(5); + m_TestInterv.SetCurSel(1); + m_SocketCount.SetCurSel(5); + m_ThreadCount.SetCurSel(0); + m_DataLen.SetCurSel(5); + m_SendPolicy.SetCurSel(0); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CClientDlg::OnClose() +{ + ::SetMainWnd(nullptr); + __super::OnClose(); +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + if(m_enState == state) + return; + + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); + m_TestTimes.EnableWindow(m_enState == ST_STOPPED); + m_TestInterv.EnableWindow(m_enState == ST_STOPPED); + m_SocketCount.EnableWindow(m_enState == ST_STOPPED); + m_ThreadCount.EnableWindow(m_enState == ST_STOPPED); + m_DataLen.EnableWindow(m_enState == ST_STOPPED); + m_SendPolicy.EnableWindow(m_enState == ST_STOPPED); +} + +BOOL CClientDlg::CheckParams() +{ + BOOL isOK = TRUE; + + if(m_strAddress.IsEmpty()) + { + m_Address.SetFocus(); + isOK = FALSE; + } + else if(m_usPort == 0) + { + m_Port.SetFocus(); + isOK = FALSE; + } + else if(m_iTestTimes <= 0) + { + m_TestTimes.SetFocus(); + isOK = FALSE; + } + else if(m_iTestInterv < 0) + { + m_TestInterv.SetFocus(); + isOK = FALSE; + } + else if(m_iSocketCount <= 0) + { + m_SocketCount.SetFocus(); + isOK = FALSE; + } + else if(m_iThreadCount < 0 || m_iThreadCount > 500) + { + m_ThreadCount.SetFocus(); + isOK = FALSE; + } + else if(m_iDataLen <= 0) + { + m_DataLen.SetFocus(); + isOK = FALSE; + } + + if(!isOK) + MessageBox(_T("One or more settings invalid, pls check!"), _T("Params Error"), MB_OK); + + return isOK; +} + +void CClientDlg::OnBnClickedStart() +{ + CString strAddress; + CString strPort; + CString strTestTimes; + CString strTestInterv; + CString strSocketCount; + CString strThreadCount; + CString strDataLen; + + m_Address.GetWindowText(strAddress); + m_Port.GetWindowText(strPort); + m_TestTimes.GetWindowText(strTestTimes); + m_TestInterv.GetWindowText(strTestInterv); + m_SocketCount.GetWindowText(strSocketCount); + m_ThreadCount.GetWindowText(strThreadCount); + m_DataLen.GetWindowText(strDataLen); + + m_strAddress = strAddress.Trim(); + m_usPort = (USHORT)_ttoi(strPort); + m_iTestTimes = _ttoi(strTestTimes); + m_iTestInterv = _ttoi(strTestInterv); + m_iSocketCount = _ttoi(strSocketCount); + m_iThreadCount = _ttoi(strThreadCount); + m_iDataLen = _ttoi(strDataLen); + + EnSendPolicy enSendPolicy = (EnSendPolicy)m_SendPolicy.GetCurSel(); + + if(!CheckParams()) + return; + + if(m_iThreadCount == 0) + m_iThreadCount = min((::SysGetNumberOfProcessors() * 2 + 2), 500); + + SetAppState(ST_STARTING); + + m_hasError = FALSE; + m_dwBeginTickCount = 0; + m_dwTimeconsuming = 0; + m_llTotalReceived = 0; + m_llTotalSent = 0; + m_llExpectReceived = (LONGLONG)m_iTestTimes * (LONGLONG)m_iSocketCount * (LONGLONG)m_iDataLen; + + BOOL isOK = FALSE; + + m_Agent.SetWorkerThreadCount(m_iThreadCount); + m_Agent.SetSendPolicy(enSendPolicy); + + if(m_Agent.Start(LOCAL_ADDRESS, FALSE)) + { + for(int i = 0; i < m_iSocketCount; i++) + { + if(m_Agent.Connect(m_strAddress, m_usPort)) + { + if(i == m_iSocketCount - 1) + isOK = TRUE; + } + else + { + ::LogClientStartFail(::GetLastError(), ::GetSocketErrorDesc(SE_CONNECT_SERVER)); + break; + } + } + } + else + ::LogClientStartFail(m_Agent.GetLastError(), m_Agent.GetLastErrorDesc()); + + if(!isOK) + { + m_Agent.Stop(); + SetAppState(ST_STOPPED); + return; + } + + ::LogClientStart(m_strAddress, m_usPort); + + DWORD dwSendDelay = 3; + CString strMsg; + + strMsg.Format(_T(" *** willing to send data after %d seconds ..."), dwSendDelay); + ::LogMsg(strMsg); + + ::WaitWithMessageLoop(dwSendDelay * 500); + + while((int)m_connIDs.size() < m_iSocketCount) + { + if(m_hasError) + { + m_Agent.Stop(); + SetAppState(ST_STOPPED); + return; + } + else + ::WaitWithMessageLoop(1); + } + + int iCount = m_Info.GetCount(); + if(iCount > 0) m_Info.SetCurSel(iCount - 1); + ::WaitWithMessageLoop(dwSendDelay * 500); + + m_sendBuffer.Malloc(m_iDataLen, true); + SetAppState(ST_STARTED); + + ::LogMsg(_T(" *** Go Now !")); + + m_dwBeginTickCount = ::TimeGetTime(); + + BOOL bTerminated = FALSE; + for(int i = 0; i < m_iTestTimes; i++) + { + for(int j = 0; j < m_iSocketCount; j++) + { + if(!m_Agent.Send(m_connIDs[j], m_sendBuffer, (int)m_sendBuffer.Size())) + { + ::LogClientSendFail(i + 1, j + 1, ::GetLastError(), ::GetSocketErrorDesc(SE_DATA_SEND)); + + bTerminated = TRUE; + break; + } + } + + if(bTerminated) + break; + + if(m_iTestInterv > 0 && i + 1 < m_iTestTimes) + ::WaitWithMessageLoop(m_iTestInterv); + } + + m_sendBuffer.Free(); +} + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + m_Agent.Stop(); + + ::WaitWithMessageLoop(100L); + + CString strMsg; + strMsg.Format( _T(" *** Summary: expect - %lld, send - %lld, recv - %lld"), + m_llExpectReceived, m_llTotalSent, m_llTotalReceived); + + ::LogMsg(strMsg); + + if(m_llExpectReceived == m_llTotalSent && m_llTotalSent == m_llTotalReceived) + strMsg.Format(_T(" *** Success: time consuming - %u millisecond !"), m_dwTimeconsuming); + else + strMsg.Format(_T(" *** Fail: manual terminated ? (or data lost)")); + + ::LogMsg(strMsg); + + SetAppState(ST_STOPPED); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnPrepareConnect(CONNID dwConnID, SOCKET socket) +{ + //VERIFY(::SSO_SendBuffSize(socket, 512 * 1024) == NO_ERROR); + //VERIFY(::SSO_RecvBuffSize(socket, 512 * 1024) == NO_ERROR); + + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG2 + ::PostOnSend(dwConnID, pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalSent, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalSent, iLength); +#endif + + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG2 + ::PostOnReceive(dwConnID, pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalReceived, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalReceived, iLength); +#endif + + if(m_llTotalReceived == m_llExpectReceived) + { + m_dwTimeconsuming = ::GetTimeGap32(m_dwBeginTickCount); + ::PostTimeConsuming(m_dwTimeconsuming); + } + + ASSERT(m_llTotalReceived <= m_llExpectReceived); + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + if(iErrorCode == SE_OK) + ::PostOnClose(dwConnID); + else + { + m_hasError = TRUE; + ::PostOnError(dwConnID, enOperation, iErrorCode); + } + + return HR_OK; +} + +EnHandleResult CClientDlg::OnConnect(CONNID dwConnID) +{ + { + CCriSecLock locallock(m_cs); + m_connIDs.push_back(dwConnID); + } + + ::LogOnConnect2(dwConnID); + return HR_OK; +} + +EnHandleResult CClientDlg::OnShutdown() +{ + m_connIDs.clear(); + + ::PostOnShutdown(); + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ClientDlg.h b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ClientDlg.h new file mode 100644 index 000000000..f3632df7c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ClientDlg.h @@ -0,0 +1,85 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/TcpAgent.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CTcpAgentListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = nullptr); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnClose(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnPrepareConnect(CONNID dwConnID, SOCKET socket); + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(CONNID dwConnID); + virtual EnHandleResult OnShutdown(); +private: + BOOL CheckParams(); +private: + CComboBox m_TestTimes; + CComboBox m_SocketCount; + CComboBox m_TestInterv; + CComboBox m_ThreadCount; + CComboBox m_DataLen; + CComboBox m_SendPolicy; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Start; + CButton m_Stop; + + CString m_strAddress; + USHORT m_usPort; + int m_iTestTimes; + int m_iTestInterv; + int m_iSocketCount; + int m_iThreadCount; + int m_iDataLen; + + volatile LONGLONG m_llTotalReceived; + volatile LONGLONG m_llTotalSent; + LONGLONG m_llExpectReceived; + DWORD m_dwBeginTickCount; + DWORD m_dwTimeconsuming; + + EnAppState m_enState; + CBufferPtr m_sendBuffer; + + volatile BOOL m_hasError; + CCriSec m_cs; + vector m_connIDs; + CTcpAgent m_Agent; +}; diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ReadMe.txt b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/res/Client.ico b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/res/Client.rc2 b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/resource.h b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/resource.h new file mode 100644 index 000000000..eb65c9201 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/stdafx.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/stdafx.h b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/targetver.h b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-PFM/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj new file mode 100644 index 000000000..b273c9b96 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj @@ -0,0 +1,233 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87E9} + Client + MFCProj + Pull + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj.filters b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj.filters new file mode 100644 index 000000000..bebe8c357 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj.filters @@ -0,0 +1,80 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {4416963f-6bca-4f60-8e6f-30f8129ed29e} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj.user b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Agent-Pull.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.cpp new file mode 100644 index 000000000..a67fe0573 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.h b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.rc b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.rc new file mode 100644 index 000000000..72a4dcb9b Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ClientDlg.cpp new file mode 100644 index 000000000..775ba1f12 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ClientDlg.cpp @@ -0,0 +1,322 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" + + +// CClientDlg dialog + +#define DEFAULT_CONTENT _T("text to be sent") +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") +#define LOCAL_ADDRESS _T("0.0.0.0") + +// link: ..\..\Bin\HPSocket\x86\HPSocket_UD.lib + +#ifdef _WIN64 + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_U.lib") + #endif +#else + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_U.lib") + #endif +#endif + +CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CClientDlg::IDD, pParent), m_Agent(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_CONTENT, m_Content); + DDX_Control(pDX, IDC_SEND, m_Send); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_CONNECT, m_Connect); + DDX_Control(pDX, IDC_STOP, m_Stop); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_SEND, &CClientDlg::OnBnClickedSend) + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_CONNECT, &CClientDlg::OnBnClickedConnect) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_Content.SetWindowText(DEFAULT_CONTENT); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Connect.SetWindowText(m_enState == ST_CONNECTED ? _T("Dis Connect") : _T("Connect")); + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Connect.EnableWindow(m_enState == ST_STARTED || m_enState == ST_CONNECTED); + m_Stop.EnableWindow(m_enState == ST_STARTED || m_enState == ST_CONNECTED); + m_Send.EnableWindow(m_enState == ST_CONNECTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); +} + +void CClientDlg::OnBnClickedSend() +{ + USES_CONVERSION; + + static DWORD SEQ = 0; + + CString strContent; + m_Content.GetWindowText(strContent); + + smart_simple_ptr buffer = ::GeneratePkgBuffer(++SEQ, _T("С"), 23, strContent); + + if(m_Agent->Send(m_dwConnID, buffer->Ptr(), (int)buffer->Size())) + ::LogSend(m_dwConnID, strContent); + else + ::LogSendFail(m_dwConnID, SE_DATA_SEND, ::HP_GetSocketErrorDesc(SE_DATA_SEND)); +} + + +void CClientDlg::OnBnClickedStart() +{ + SetAppState(ST_STARTING); + + CString strPort; + + m_Address.GetWindowText(m_strAddress); + m_Port.GetWindowText(strPort); + + m_usPort = (USHORT)_ttoi(strPort); + m_dwConnID = 0; + + m_pkgInfo.Reset(); + + ::LogClientStarting(m_strAddress, m_usPort); + + if(m_Agent->Start(LOCAL_ADDRESS, TRUE)) + { + SetAppState(ST_STARTED); + } + else + { + ::LogClientStartFail(m_Agent->GetLastError(), m_Agent->GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + +void CClientDlg::OnBnClickedConnect() +{ + EnAppState enState = m_enState; + + SetAppState(ST_CONNECTING); + + if(enState != ST_CONNECTED) + { + if(m_Agent->Connect(m_strAddress, m_usPort, &m_dwConnID)) + { + } + else + { + ::LogClientStartFail(::SYS_GetLastError(), ::HP_GetSocketErrorDesc(SE_CONNECT_SERVER)); + SetAppState(ST_STARTED); + } + } + else + { + m_Agent->Disconnect(m_dwConnID, TRUE); + } +} + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(!m_Agent->Stop()) + ASSERT(FALSE); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnConnect(CONNID dwConnID) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Agent->GetLocalAddress(dwConnID, szAddress, iAddressLen, usPort); + + ::PostOnConnect(dwConnID, szAddress, usPort); + SetAppState(ST_CONNECTED); + + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ + ::PostOnSend(dwConnID, pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(CONNID dwConnID, int iLength) +{ + int required = m_pkgInfo.length; + int remain = iLength; + + while(remain >= required) + { + remain -= required; + CBufferPtr buffer(required); + + EnFetchResult result = m_Agent->Fetch(dwConnID, buffer, (int)buffer.Size()); + if(result == FR_OK) + { + if(m_pkgInfo.is_header) + { + TPkgHeader* pHeader = (TPkgHeader*)buffer.Ptr(); + TRACE("[Agent] head -> seq: %d, body_len: %d\n", pHeader->seq, pHeader->body_len); + + required = pHeader->body_len; + } + else + { + TPkgBody* pBody = (TPkgBody*)buffer.Ptr(); + TRACE("[Agent] body -> name: %s, age: %d, desc: %s\n", pBody->name, pBody->age, pBody->desc); + + required = sizeof(TPkgHeader); + } + + m_pkgInfo.is_header = !m_pkgInfo.is_header; + m_pkgInfo.length = required; + + ::PostOnReceive(dwConnID, buffer, (int)buffer.Size()); + } + } + + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(dwConnID) : + ::PostOnError(dwConnID, enOperation, iErrorCode); + + SetAppState(ST_STARTED); + + return HR_OK; +} + +EnHandleResult CClientDlg::OnShutdown() +{ + ::PostOnShutdown(); + SetAppState(ST_STOPPED); + + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ClientDlg.h b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ClientDlg.h new file mode 100644 index 000000000..69e002408 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ClientDlg.h @@ -0,0 +1,65 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CTcpPullAgentListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedSend(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedConnect(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(CONNID dwConnID); + virtual EnHandleResult OnShutdown(); +private: + CEdit m_Content; + CButton m_Send; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Start; + CButton m_Connect; + CButton m_Stop; + + EnAppState m_enState; + CString m_strAddress; + USHORT m_usPort; + CONNID m_dwConnID; + + TPkgInfo m_pkgInfo; + CTcpPullAgentPtr m_Agent; +}; diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ReadMe.txt b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/res/Client.ico b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/res/Client.rc2 b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/resource.h b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/resource.h new file mode 100644 index 000000000..d0a8f6ed4 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/stdafx.cpp b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/stdafx.h b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/targetver.h b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/Agent-Pull/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-Agent/TestEcho-Agent.sln b/HP-Socket/Demo/TestEcho-Agent/TestEcho-Agent.sln new file mode 100644 index 000000000..8e630f3af --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Agent/TestEcho-Agent.sln @@ -0,0 +1,56 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PFM", "Agent-PFM\Agent-PFM.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87F8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Pull", "Agent-Pull\Agent-Pull.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87E9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "..\TestEcho-PFM\Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C878}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "4C", "Agent-4C\Agent-4C.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87F9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E3791685-9CC8-426B-811C-FEBA775F87F8}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87F8}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87F8}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87F8}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87F8}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87F8}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87F8}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87F8}.Release|x64.Build.0 = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|x64.Build.0 = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.Build.0 = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.Build.0 = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.Build.0 = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.ActiveCfg = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.Build.0 = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87F9}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87F9}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87F9}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87F9}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87F9}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87F9}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87F9}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87F9}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestEcho-Agent/TestEcho-Agent.suo b/HP-Socket/Demo/TestEcho-Agent/TestEcho-Agent.suo new file mode 100644 index 000000000..1eea947c6 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Agent/TestEcho-Agent.suo differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/Client.cpp b/HP-Socket/Demo/TestEcho-PFM/Client/Client.cpp new file mode 100644 index 000000000..caa99572d --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != nullptr) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/Client.h b/HP-Socket/Demo/TestEcho-PFM/Client/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/Client.rc b/HP-Socket/Demo/TestEcho-PFM/Client/Client.rc new file mode 100644 index 000000000..6bd8b0f4b Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/Client/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj b/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj new file mode 100644 index 000000000..7ed1e9cfa --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj @@ -0,0 +1,226 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87E8} + Client + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj.filters b/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj.filters new file mode 100644 index 000000000..1fd18c3e1 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj.filters @@ -0,0 +1,86 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {7c3c0129-66d7-44ad-b6f9-9f5cf6d0a288} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj.user b/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/Client.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-PFM/Client/ClientDlg.cpp new file mode 100644 index 000000000..45cbb109c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/ClientDlg.cpp @@ -0,0 +1,398 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" +#include "../../../../Common/Src/WaitFor.h" + +#ifdef _WIN64 + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_U.lib") + #endif +#else + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_U.lib") + #endif +#endif + +// CClientDlg dialog + +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") + +CClientDlg::CClientDlg(CWnd* pParent /*=nullptr*/) + : CDialogEx(CClientDlg::IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_TEST_TIMES, m_TestTimes); + DDX_Control(pDX, IDC_SOCKET_COUNT, m_SocketCount); + DDX_Control(pDX, IDC_DATA_LEN, m_DataLen); + DDX_Control(pDX, IDC_TEST_TIMES_INTERV, m_TestInterv); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() + ON_WM_CLOSE() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_TestTimes.SetCurSel(5); + m_TestInterv.SetCurSel(1); + m_SocketCount.SetCurSel(5); + m_DataLen.SetCurSel(5); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CClientDlg::OnClose() +{ + ::SetMainWnd(nullptr); + __super::OnClose(); +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + if(m_enState == state) + return; + + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); + m_TestTimes.EnableWindow(m_enState == ST_STOPPED); + m_TestInterv.EnableWindow(m_enState == ST_STOPPED); + m_SocketCount.EnableWindow(m_enState == ST_STOPPED); + m_DataLen.EnableWindow(m_enState == ST_STOPPED); +} + +BOOL CClientDlg::CheckParams() +{ + BOOL isOK = TRUE; + + if(m_strAddress.IsEmpty()) + { + m_Address.SetFocus(); + isOK = FALSE; + } + else if(m_usPort == 0) + { + m_Port.SetFocus(); + isOK = FALSE; + } + else if(m_iTestTimes <= 0) + { + m_TestTimes.SetFocus(); + isOK = FALSE; + } + else if(m_iTestInterv < 0) + { + m_TestInterv.SetFocus(); + isOK = FALSE; + } + else if(m_iSocketCount <= 0) + { + m_SocketCount.SetFocus(); + isOK = FALSE; + } + else if(m_iDataLen <= 0) + { + m_DataLen.SetFocus(); + isOK = FALSE; + } + + if(!isOK) + MessageBox(_T("One or more settings invalid, pls check!"), _T("Params Error"), MB_OK); + + return isOK; +} + +void CClientDlg::OnBnClickedStart() +{ + CString strAddress; + CString strPort; + CString strTestTimes; + CString strTestInterv; + CString strSocketCount; + CString strDataLen; + + m_Address.GetWindowText(strAddress); + m_Port.GetWindowText(strPort); + m_TestTimes.GetWindowText(strTestTimes); + m_TestInterv.GetWindowText(strTestInterv); + m_SocketCount.GetWindowText(strSocketCount); + m_DataLen.GetWindowText(strDataLen); + + m_strAddress = strAddress.Trim(); + m_usPort = (USHORT)_ttoi(strPort); + m_iTestTimes = _ttoi(strTestTimes); + m_iTestInterv = _ttoi(strTestInterv); + m_iSocketCount = _ttoi(strSocketCount); + m_iDataLen = _ttoi(strDataLen); + + if(!CheckParams()) + return; + + SetAppState(ST_STARTING); + + m_dwBeginTickCount = 0; + m_dwTimeconsuming = 0; + m_llTotalReceived = 0; + m_llTotalSent = 0; + m_llExpectReceived = (LONGLONG)m_iTestTimes * (LONGLONG)m_iSocketCount * (LONGLONG)m_iDataLen; + + m_vtClients.Clear(); + + for(int i = 0; i < m_iSocketCount; i++) + { + smart_simple_ptr pSocket = new CTcpClientPtr(this); + + if((*pSocket)->Start(m_strAddress, m_usPort)) + m_vtClients->push_back(pSocket.release()); + else + { + ::LogClientStartFail((*pSocket)->GetLastError(), (*pSocket)->GetLastErrorDesc()); + m_vtClients.Clear(); + SetAppState(ST_STOPPED); + return; + } + } + + ::LogClientStart(m_strAddress, m_usPort); + + DWORD dwSendDelay = 3; + CString strMsg; + + strMsg.Format(_T(" *** willing to send data after %d seconds ..."), dwSendDelay); + ::LogMsg(strMsg); + + ::WaitWithMessageLoop(dwSendDelay * 1000); + m_sendBuffer.Malloc(m_iDataLen, true); + SetAppState(ST_STARTED); + + ::LogMsg(_T(" *** Go Now !")); + + m_dwBeginTickCount = ::TimeGetTime(); + + BOOL bTerminated = FALSE; + for(int i = 0; i < m_iTestTimes; i++) + { + for(int j = 0; j < m_iSocketCount; j++) + { + CTcpClientPtr* pSocket = m_vtClients[j]; + if(!(*pSocket)->Send(m_sendBuffer, (int)m_sendBuffer.Size())) + { + ::LogClientSendFail(i + 1, j + 1, ::SYS_GetLastError(), ::HP_GetSocketErrorDesc(SE_DATA_SEND)); + bTerminated = TRUE; + break; + } + } + + if(bTerminated) + break; + + if(m_iTestInterv > 0 && i + 1 < m_iTestTimes) + ::WaitWithMessageLoop(m_iTestInterv); + } + + m_sendBuffer.Free(); +} + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + for(size_t i = 0; i < m_vtClients.Size(); i++) + { + CTcpClientPtr* pSocket = m_vtClients[i]; + + if((*pSocket)->Stop()) + ::LogClientStopping((DWORD)i + 1); + //else + // ASSERT(FALSE); + } + + ::WaitWithMessageLoop(100L); + + CString strMsg; + strMsg.Format( _T(" *** Summary: expect - %lld, send - %lld, recv - %lld"), + m_llExpectReceived, m_llTotalSent, m_llTotalReceived); + + ::LogMsg(strMsg); + + if(m_llExpectReceived == m_llTotalSent && m_llTotalSent == m_llTotalReceived) + strMsg.Format(_T(" *** Success: time consuming - %u millisecond !"), m_dwTimeconsuming); + else + strMsg.Format(_T(" *** Fail: manual terminated ? (or data lost)")); + + ::LogMsg(strMsg); + + SetAppState(ST_STOPPED); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnPrepareConnect(IClient* pClient, SOCKET socket) +{ + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(IClient* pClient, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG2 + ::PostOnSend(pClient->GetConnectionID(), pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalSent, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalSent, iLength); +#endif + + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(IClient* pClient, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG2 + ::PostOnReceive(pClient->GetConnectionID(), pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalReceived, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalReceived, iLength); +#endif + + if(m_llTotalReceived == m_llExpectReceived) + { + m_dwTimeconsuming = ::GetTimeGap32(m_dwBeginTickCount); + ::PostTimeConsuming(m_dwTimeconsuming); + } + + ASSERT(m_llTotalReceived <= m_llExpectReceived); + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(pClient->GetConnectionID()) : + ::PostOnError(pClient->GetConnectionID(), enOperation, iErrorCode) ; + + return HR_OK; +} + +EnHandleResult CClientDlg::OnConnect(IClient* pClient) +{ + ::LogOnConnect2(pClient->GetConnectionID()); + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/ClientDlg.h b/HP-Socket/Demo/TestEcho-PFM/Client/ClientDlg.h new file mode 100644 index 000000000..6ce03fcdd --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/ClientDlg.h @@ -0,0 +1,79 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CTcpClientListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = nullptr); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnClose(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket); + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(IClient* pClient); +private: + BOOL CheckParams(); +private: + CComboBox m_TestTimes; + CComboBox m_SocketCount; + CComboBox m_TestInterv; + CComboBox m_DataLen; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Start; + CButton m_Stop; + + CString m_strAddress; + USHORT m_usPort; + int m_iTestTimes; + int m_iTestInterv; + int m_iSocketCount; + int m_iDataLen; + + volatile LONGLONG m_llTotalReceived; + volatile LONGLONG m_llTotalSent; + LONGLONG m_llExpectReceived; + DWORD m_dwBeginTickCount; + DWORD m_dwTimeconsuming; + + EnAppState m_enState; + CBufferPtr m_sendBuffer; + + VectorWrapper, PtrSet_Cleaner>> m_vtClients; + +}; diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/ReadMe.txt b/HP-Socket/Demo/TestEcho-PFM/Client/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/res/Client.ico b/HP-Socket/Demo/TestEcho-PFM/Client/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/Client/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/res/Client.rc2 b/HP-Socket/Demo/TestEcho-PFM/Client/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/Client/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/resource.h b/HP-Socket/Demo/TestEcho-PFM/Client/resource.h new file mode 100644 index 000000000..2ce0f3925 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/Client/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/stdafx.cpp b/HP-Socket/Demo/TestEcho-PFM/Client/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/stdafx.h b/HP-Socket/Demo/TestEcho-PFM/Client/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-PFM/Client/targetver.h b/HP-Socket/Demo/TestEcho-PFM/Client/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Client/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/ReadMe.txt b/HP-Socket/Demo/TestEcho-PFM/Server/ReadMe.txt new file mode 100644 index 000000000..d97be25bf --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Server Project Overview +=============================================================================== + +The application wizard has created this Server application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Server application. + +Server.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Server.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CServerApp application class. + +Server.cpp + This is the main application source file that contains the application + class CServerApp. + +Server.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Server.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Server.rc. + +res\Server.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ServerDlg.h, ServerDlg.cpp - the dialog + These files contain your CServerDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Server.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Server.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Server.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/Server.cpp b/HP-Socket/Demo/TestEcho-PFM/Server/Server.cpp new file mode 100644 index 000000000..417b91c90 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/Server.cpp @@ -0,0 +1,87 @@ + +// Server.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" + + +// CServerApp + +BEGIN_MESSAGE_MAP(CServerApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CServerApp construction + +CServerApp::CServerApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CServerApp object + +CServerApp theApp; + + +// CServerApp initialization + +BOOL CServerApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CServerDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != nullptr) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/Server.h b/HP-Socket/Demo/TestEcho-PFM/Server/Server.h new file mode 100644 index 000000000..df6a5f075 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/Server.h @@ -0,0 +1,32 @@ + +// Server.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CServerApp: +// See Server.cpp for the implementation of this class +// + +class CServerApp : public CWinApp +{ +public: + CServerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CServerApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/Server.rc b/HP-Socket/Demo/TestEcho-PFM/Server/Server.rc new file mode 100644 index 000000000..edae39f0c Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/Server/Server.rc differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj b/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj new file mode 100644 index 000000000..3380941b7 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj @@ -0,0 +1,228 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5A2EE763-53B1-462E-AE9F-7CC58436C878} + Server + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj.filters b/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj.filters new file mode 100644 index 000000000..5278c1286 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj.filters @@ -0,0 +1,92 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {48c55559-451a-4f0d-9cb2-884503406307} + + + {f57bc1d3-66f4-49c0-b1c8-c7e5d163de15} + + + {849bedeb-2d4e-4965-8c3a-c8ace1a89f27} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + HPSocket + + + HPSocket + + + Common + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + Common + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj.user b/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/Server.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/ServerDlg.cpp b/HP-Socket/Demo/TestEcho-PFM/Server/ServerDlg.cpp new file mode 100644 index 000000000..2ae8556fd --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/ServerDlg.cpp @@ -0,0 +1,366 @@ + +// ServerDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" +#include "afxdialogex.h" +#include "../../../../Common/Src/WaitFor.h" +#include "../../../../Common/Src/SysHelper.h" + +#ifdef _WIN64 + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_U.lib") + #endif +#else + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_U.lib") + #endif +#endif + +// CServerDlg dialog + +#define DEFAULT_ADDRESS _T("0.0.0.0") +#define DEFAULT_PORT _T("5555") + +CServerDlg::CServerDlg(CWnd* pParent /*=nullptr*/) + : CDialogEx(CServerDlg::IDD, pParent), m_Server(this) + , m_lClientCount(0L) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CServerDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_SEND_POLICY, m_SendPolicy); + DDX_Control(pDX, IDC_THREAD_COUNT, m_ThreadCount); +} + +BEGIN_MESSAGE_MAP(CServerDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CServerDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CServerDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() + ON_WM_CLOSE() +END_MESSAGE_MAP() + + +// CServerDlg message handlers + +BOOL CServerDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + CString strTitle; + CString strOriginTitle; + m_SendPolicy.SetCurSel(0); + m_ThreadCount.SetCurSel(0); + m_Port.SetWindowText(DEFAULT_PORT); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CServerDlg::OnClose() +{ + /* + if(m_Server->GetState() != SS_STOPED) + { + this->MessageBox(_T("stop IOCP Server first, pls !"), _T("forbiddden")); + return; + } + */ + + ::SetMainWnd(nullptr); + __super::OnClose(); +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CServerDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CServerDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CServerDlg::SetAppState(EnAppState state) +{ + if(m_enState == state) + return; + + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Port.EnableWindow(m_enState == ST_STOPPED); + m_SendPolicy.EnableWindow(m_enState == ST_STOPPED); + m_ThreadCount.EnableWindow(m_enState == ST_STOPPED); +} + +void CServerDlg::OnBnClickedStart() +{ + CString strPort; + m_Port.GetWindowText(strPort); + USHORT usPort = (USHORT)_ttoi(strPort); + + if(usPort == 0) + { + MessageBox(_T("Listen Port invalid, pls check!"), _T("Params Error"), MB_OK); + m_Port.SetFocus(); + return; + } + + EnSendPolicy enSendPolicy = (EnSendPolicy)m_SendPolicy.GetCurSel(); + + CString strThreadCount; + m_ThreadCount.GetWindowText(strThreadCount); + int iThreadCount = _ttoi(strThreadCount); + + if(iThreadCount == 0) + iThreadCount = min((::SysGetNumberOfProcessors() * 2 + 2), 500); + else if(iThreadCount < 0 || iThreadCount > 500) + { + m_ThreadCount.SetFocus(); + return; + } + + SetAppState(ST_STARTING); + + Reset(); + + m_Server->SetSendPolicy(enSendPolicy); + m_Server->SetWorkerThreadCount(iThreadCount); + + //m_Server->SetFreeSocketObjPool(500); + //m_Server->SetFreeSocketObjHold(1500); + //m_Server->SetFreeBufferObjPool(2000); + //m_Server->SetFreeBufferObjHold(6000); + //m_Server->SetSocketListenQueue(2000); + //m_Server->SetAcceptSocketCount(2000); + + + if(m_Server->Start(DEFAULT_ADDRESS, usPort)) + { + ::LogServerStart(DEFAULT_ADDRESS, usPort); + SetAppState(ST_STARTED); + } + else + { + ::LogServerStartFail(m_Server->GetLastError(), m_Server->GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + +void CServerDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Server->Stop()) + { + ::LogServerStop(); + SetAppState(ST_STOPPED); + } + else + { + ASSERT(FALSE); + } +} + +int CServerDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + else if(nKey == 'R') + { + Reset(); + + CString strMsg; + strMsg.Format( _T(" *** Reset Statics: CC - %u, TS - %lld, TR - %lld"), + m_lClientCount, m_llTotalSent, m_llTotalReceived); + + ::LogMsg(strMsg); + } + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CServerDlg::OnPrepareListen(SOCKET soListen) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Server->GetListenAddress(szAddress, iAddressLen, usPort); + ::PostOnPrepareListen(szAddress, usPort); + return HR_OK; +} + +EnHandleResult CServerDlg::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG2 + ::PostOnSend(dwConnID, pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalSent, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalSent, iLength); +#endif + + return HR_OK; +} + +EnHandleResult CServerDlg::OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG2 + ::PostOnReceive(dwConnID, pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalReceived, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalReceived, iLength); +#endif + + if(m_Server->Send(dwConnID, pData, iLength)) + return HR_OK; + else + return HR_ERROR; +} + +EnHandleResult CServerDlg::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(dwConnID) : + ::PostOnError(dwConnID, enOperation, iErrorCode); + + Statistics(); + + return HR_OK; +} + +EnHandleResult CServerDlg::OnAccept(CONNID dwConnID, SOCKET soClient) +{ + if(m_lClientCount == 0) + { + CCriSecLock lock(m_cs); + + if(m_lClientCount == 0) + { + Reset(FALSE); + } + } + + ::InterlockedIncrement(&m_lClientCount); + ::PostOnAccept2(dwConnID); + + return HR_OK; +} + +EnHandleResult CServerDlg::OnShutdown() +{ + ::PostOnShutdown(); + return HR_OK; +} + +void CServerDlg::Statistics() +{ + if(m_lClientCount > 0) + { + CCriSecLock lock(m_cs); + + if(m_lClientCount > 0) + { + ::InterlockedDecrement(&m_lClientCount); + + if(m_lClientCount == 0) + { + ::WaitWithMessageLoop(600L); + ::PostServerStatics((LONGLONG)m_llTotalSent, (LONGLONG)m_llTotalReceived); + } + } + } +} + +void CServerDlg::Reset(BOOL bResetClientCount) +{ + if(bResetClientCount) + m_lClientCount = 0L; + + m_llTotalSent = 0L; + m_llTotalReceived = 0L; +} diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/ServerDlg.h b/HP-Socket/Demo/TestEcho-PFM/Server/ServerDlg.h new file mode 100644 index 000000000..118ede710 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/ServerDlg.h @@ -0,0 +1,67 @@ + +// ServerDlg.h : header file +// + +#pragma once +#include "afxwin.h" + +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + +// CServerDlg dialog +class CServerDlg : public CDialogEx, public CTcpServerListener +{ +// Construction +public: + CServerDlg(CWnd* pParent = nullptr); // standard constructor + +// Dialog Data + enum { IDD = IDD_SERVER_DIALOG }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + afx_msg void OnClose(); + + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); + void Statistics(); + void Reset(BOOL bResetClientCount = TRUE); +private: + virtual EnHandleResult OnPrepareListen(SOCKET soListen); + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient); + virtual EnHandleResult OnShutdown(); + +private: + CListBox m_Info; + CEdit m_Port; + CComboBox m_SendPolicy; + CComboBox m_ThreadCount; + CButton m_Start; + CButton m_Stop; + EnAppState m_enState; + + volatile LONGLONG m_llTotalReceived; + volatile LONGLONG m_llTotalSent; + volatile LONG m_lClientCount; + + CCriSec m_cs; + CTcpServerPtr m_Server; +}; diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/res/Server.ico b/HP-Socket/Demo/TestEcho-PFM/Server/res/Server.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/Server/res/Server.ico differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/res/Server.rc2 b/HP-Socket/Demo/TestEcho-PFM/Server/res/Server.rc2 new file mode 100644 index 000000000..b77c9d1c1 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/Server/res/Server.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/resource.h b/HP-Socket/Demo/TestEcho-PFM/Server/resource.h new file mode 100644 index 000000000..100e83ec5 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/Server/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/stdafx.cpp b/HP-Socket/Demo/TestEcho-PFM/Server/stdafx.cpp new file mode 100644 index 000000000..22d19927c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/stdafx.h b/HP-Socket/Demo/TestEcho-PFM/Server/stdafx.h new file mode 100644 index 000000000..dc0a47732 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/stdafx.h @@ -0,0 +1,14 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" diff --git a/HP-Socket/Demo/TestEcho-PFM/Server/targetver.h b/HP-Socket/Demo/TestEcho-PFM/Server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-PFM/TestEcho-PFM.sln b/HP-Socket/Demo/TestEcho-PFM/TestEcho-PFM.sln new file mode 100644 index 000000000..755ee99c6 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-PFM/TestEcho-PFM.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C878}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87E8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.Build.0 = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.Build.0 = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.Build.0 = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.ActiveCfg = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.Build.0 = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestEcho-PFM/TestEcho-PFM.suo b/HP-Socket/Demo/TestEcho-PFM/TestEcho-PFM.suo new file mode 100644 index 000000000..e29d5c3bf Binary files /dev/null and b/HP-Socket/Demo/TestEcho-PFM/TestEcho-PFM.suo differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/Client.cpp b/HP-Socket/Demo/TestEcho-Pack/Client/Client.cpp new file mode 100644 index 000000000..a67fe0573 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/Client.h b/HP-Socket/Demo/TestEcho-Pack/Client/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/Client.rc b/HP-Socket/Demo/TestEcho-Pack/Client/Client.rc new file mode 100644 index 000000000..5f11f60ef Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/Client/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj b/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj new file mode 100644 index 000000000..45af8a7b6 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj @@ -0,0 +1,228 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87E7} + Client + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket\x86\HPSocket_UD.lib + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket\x64\HPSocket_UD.lib + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket\x86\HPSocket_U.lib + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket\x64\HPSocket_U.lib + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj.filters b/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj.filters new file mode 100644 index 000000000..bebe8c357 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj.filters @@ -0,0 +1,80 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {4416963f-6bca-4f60-8e6f-30f8129ed29e} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj.user b/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/Client.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-Pack/Client/ClientDlg.cpp new file mode 100644 index 000000000..7cd3789c1 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/ClientDlg.cpp @@ -0,0 +1,258 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" + + +// CClientDlg dialog + +#define DEFAULT_CONTENT _T("text to be sent") +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") + + +CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CClientDlg::IDD, pParent), m_Client(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_CONTENT, m_Content); + DDX_Control(pDX, IDC_SEND, m_Send); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_ASYNC, m_Async); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_SEND, &CClientDlg::OnBnClickedSend) + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_Content.SetWindowText(DEFAULT_CONTENT); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + m_Async.SetCheck(BST_CHECKED); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + m_bAsyncConn = FALSE; + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Async.EnableWindow(m_enState == ST_STOPPED); + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Send.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); +} + +void CClientDlg::OnBnClickedSend() +{ + static DWORD SEQ = 0; + + USES_CONVERSION; + + CString strContent; + m_Content.GetWindowText(strContent); + + LPCSTR name = "С"; + LPCSTR desc = T2A((LPCTSTR)strContent); + int desc_len = (int)strlen(desc) + 1; + int body_len = offsetof(TPkgBody, desc) + desc_len; + + TPkgBody* pBody = (TPkgBody*)_alloca(body_len); + memset(pBody, 0, body_len); + + pBody->age = 23; + strcpy(pBody->name, name); + strcpy(pBody->desc, desc); + + if(m_Client->Send((BYTE*)pBody, body_len)) + ::LogSend(m_Client->GetConnectionID(), strContent); + else + ::LogSendFail(m_Client->GetConnectionID(), ::SYS_GetLastError(), ::HP_GetSocketErrorDesc(SE_DATA_SEND)); +} + + +void CClientDlg::OnBnClickedStart() +{ + SetAppState(ST_STARTING); + + CString strAddress; + CString strPort; + + m_Address.GetWindowText(strAddress); + m_Port.GetWindowText(strPort); + + USHORT usPort = (USHORT)_ttoi(strPort); + m_bAsyncConn = m_Async.GetCheck(); + + ::LogClientStarting(strAddress, usPort); + + m_Client->SetMaxPackSize(0x01FFF); + m_Client->SetPackHeaderFlag(0x16C9); + + if(m_Client->Start(strAddress, usPort, m_bAsyncConn)) + { + + } + else + { + ::LogClientStartFail(m_Client->GetLastError(), m_Client->GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Client->Stop()) + ::LogClientStopping(m_Client->GetConnectionID()); + else + ASSERT(FALSE); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnConnect(IClient* pClient) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + pClient->GetLocalAddress(szAddress, iAddressLen, usPort); + + ::PostOnConnect(pClient->GetConnectionID(), szAddress, usPort); + SetAppState(ST_STARTED); + + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(IClient* pClient, const BYTE* pData, int iLength) +{ + ::PostOnSend(pClient->GetConnectionID(), pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(IClient* pClient, const BYTE* pData, int iLength) +{ + ::PostOnReceive(pClient->GetConnectionID(), pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(pClient->GetConnectionID()) : + ::PostOnError(pClient->GetConnectionID(), enOperation, iErrorCode) ; + + SetAppState(ST_STOPPED); + + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/ClientDlg.h b/HP-Socket/Demo/TestEcho-Pack/Client/ClientDlg.h new file mode 100644 index 000000000..a13a8acf8 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/ClientDlg.h @@ -0,0 +1,60 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CTcpClientListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedSend(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(IClient* pClient); +private: + CEdit m_Content; + CButton m_Send; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Async; + CButton m_Start; + CButton m_Stop; + + EnAppState m_enState; + BOOL m_bAsyncConn; + + CTcpPackClientPtr m_Client; +}; diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/ReadMe.txt b/HP-Socket/Demo/TestEcho-Pack/Client/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/res/Client.ico b/HP-Socket/Demo/TestEcho-Pack/Client/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/Client/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/res/Client.rc2 b/HP-Socket/Demo/TestEcho-Pack/Client/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/Client/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/resource.h b/HP-Socket/Demo/TestEcho-Pack/Client/resource.h new file mode 100644 index 000000000..82642c470 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/Client/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/stdafx.cpp b/HP-Socket/Demo/TestEcho-Pack/Client/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/stdafx.h b/HP-Socket/Demo/TestEcho-Pack/Client/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-Pack/Client/targetver.h b/HP-Socket/Demo/TestEcho-Pack/Client/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Client/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/ReadMe.txt b/HP-Socket/Demo/TestEcho-Pack/Server/ReadMe.txt new file mode 100644 index 000000000..d97be25bf --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Server Project Overview +=============================================================================== + +The application wizard has created this Server application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Server application. + +Server.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Server.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CServerApp application class. + +Server.cpp + This is the main application source file that contains the application + class CServerApp. + +Server.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Server.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Server.rc. + +res\Server.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ServerDlg.h, ServerDlg.cpp - the dialog + These files contain your CServerDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Server.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Server.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Server.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/Server.cpp b/HP-Socket/Demo/TestEcho-Pack/Server/Server.cpp new file mode 100644 index 000000000..578f1d755 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/Server.cpp @@ -0,0 +1,87 @@ + +// Server.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" + + +// CServerApp + +BEGIN_MESSAGE_MAP(CServerApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CServerApp construction + +CServerApp::CServerApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CServerApp object + +CServerApp theApp; + + +// CServerApp initialization + +BOOL CServerApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CServerDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/Server.h b/HP-Socket/Demo/TestEcho-Pack/Server/Server.h new file mode 100644 index 000000000..df6a5f075 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/Server.h @@ -0,0 +1,32 @@ + +// Server.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CServerApp: +// See Server.cpp for the implementation of this class +// + +class CServerApp : public CWinApp +{ +public: + CServerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CServerApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/Server.rc b/HP-Socket/Demo/TestEcho-Pack/Server/Server.rc new file mode 100644 index 000000000..402d3d82e Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/Server/Server.rc differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj b/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj new file mode 100644 index 000000000..a2d31850b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj @@ -0,0 +1,227 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5A2EE763-53B1-462E-AE9F-7CC58436C877} + Server + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket4C\x86\HPSocket4C_UD.lib + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket4C\x64\HPSocket4C_UD.lib + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket4C\x86\HPSocket4C_U.lib + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket4C\x64\HPSocket4C_U.lib + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj.filters b/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj.filters new file mode 100644 index 000000000..1b7ec883e --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj.filters @@ -0,0 +1,77 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {48c55559-451a-4f0d-9cb2-884503406307} + + + {f57bc1d3-66f4-49c0-b1c8-c7e5d163de15} + + + {421e5dde-2633-4094-a3d8-c99b836b54da} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj.user b/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/Server.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/ServerDlg.cpp b/HP-Socket/Demo/TestEcho-Pack/Server/ServerDlg.cpp new file mode 100644 index 000000000..d934f79dc --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/ServerDlg.cpp @@ -0,0 +1,287 @@ + +// ServerDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" +#include "afxdialogex.h" + + +// CServerDlg dialog + +const LPCTSTR CServerDlg::ADDRESS = _T("0.0.0.0"); +const USHORT CServerDlg::PORT = 5555; +CServerDlg* CServerDlg::m_spThis = nullptr; + +CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CServerDlg::IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + + m_spThis = this; + + // + m_pListener = ::Create_HP_TcpServerListener(); + // Socket + m_pServer = ::Create_HP_TcpPackServer(m_pListener); + // Socket ص + ::HP_Set_FN_Server_OnPrepareListen(m_pListener, OnPrepareListen); + ::HP_Set_FN_Server_OnAccept(m_pListener, OnAccept); + ::HP_Set_FN_Server_OnSend(m_pListener, OnSend); + ::HP_Set_FN_Server_OnReceive(m_pListener, OnReceive); + ::HP_Set_FN_Server_OnClose(m_pListener, OnClose); + ::HP_Set_FN_Server_OnShutdown(m_pListener, OnShutdown); +} + +CServerDlg::~CServerDlg() +{ + // Socket + ::Destroy_HP_TcpPackServer(m_spThis->m_pServer); + // ټ + ::Destroy_HP_TcpServerListener(m_pListener); +} + +void CServerDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_CONN_ID, m_ConnID); + DDX_Control(pDX, IDC_DISCONNECT, m_DisConn); +} + +BEGIN_MESSAGE_MAP(CServerDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CServerDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CServerDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_BN_CLICKED(IDC_DISCONNECT, &CServerDlg::OnBnClickedDisconnect) + ON_EN_CHANGE(IDC_CONN_ID, &CServerDlg::OnEnChangeConnId) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CServerDlg message handlers + +BOOL CServerDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + CString strTitle; + CString strOriginTitle; + GetWindowText(strOriginTitle); + strTitle.Format(_T("%s - (%s:%d)"), strOriginTitle, ADDRESS, PORT); + SetWindowText(strTitle); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CServerDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CServerDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CServerDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_ConnID.GetWindowTextLength() > 0); +} + +void CServerDlg::OnBnClickedStart() +{ + m_Address.GetWindowText(m_strAddress); + m_strAddress.Trim(); + + SetAppState(ST_STARTING); + + ::HP_TcpPackServer_SetMaxPackSize(m_spThis->m_pServer, 0xFFF); + ::HP_TcpPackServer_SetPackHeaderFlag(m_spThis->m_pServer, 0x16C9); + + if(::HP_Server_Start(m_spThis->m_pServer, ADDRESS, PORT)) + { + ::LogServerStart(ADDRESS, PORT); + SetAppState(ST_STARTED); + } + else + { + ::LogServerStartFail(::HP_Server_GetLastError(m_spThis->m_pServer), ::HP_Server_GetLastErrorDesc(m_spThis->m_pServer)); + SetAppState(ST_STOPPED); + } +} + +void CServerDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(::HP_Server_Stop(m_spThis->m_pServer)) + { + ::LogServerStop(); + SetAppState(ST_STOPPED); + } + else + { + ASSERT(FALSE); + } +} + +void CServerDlg::OnBnClickedDisconnect() +{ + CString strConnID; + m_ConnID.GetWindowText(strConnID); + HP_CONNID dwConnID = (HP_CONNID)_ttoi(strConnID); + + if(::HP_Server_Disconnect(m_spThis->m_pServer, dwConnID, TRUE)) + ::LogDisconnect(dwConnID); + else + ::LogDisconnectFail(dwConnID); +} + +void CServerDlg::OnEnChangeConnId() +{ + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_ConnID.GetWindowTextLength() > 0); +} + +int CServerDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +En_HP_HandleResult CServerDlg::OnPrepareListen(SOCKET soListen) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + ::HP_Server_GetListenAddress(m_spThis->m_pServer, szAddress, &iAddressLen, &usPort); + ::PostOnPrepareListen(szAddress, usPort); + return HP_HR_OK; +} + +En_HP_HandleResult CServerDlg::OnAccept(HP_CONNID dwConnID, SOCKET soClient) +{ + BOOL bPass = TRUE; + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + ::HP_Server_GetRemoteAddress(m_spThis->m_pServer, dwConnID, szAddress, &iAddressLen, &usPort); + + if(!m_spThis->m_strAddress.IsEmpty()) + { + if(m_spThis->m_strAddress.CompareNoCase(szAddress) == 0) + bPass = FALSE; + } + + ::PostOnAccept(dwConnID, szAddress, usPort, bPass); + + return bPass ? HP_HR_OK : HP_HR_ERROR; +} + +En_HP_HandleResult CServerDlg::OnSend(HP_CONNID dwConnID, const BYTE* pData, int iLength) +{ + ::PostOnSend(dwConnID, pData, iLength); + return HP_HR_OK; +} + +En_HP_HandleResult CServerDlg::OnReceive(HP_CONNID dwConnID, const BYTE* pData, int iLength) +{ + ::PostOnReceive(dwConnID, pData, iLength); + + if(!::HP_Server_Send(m_spThis->m_pServer, dwConnID, pData, iLength)) + return HP_HR_ERROR; + + return HP_HR_OK; +} + +En_HP_HandleResult CServerDlg::OnClose(HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode) +{ + iErrorCode == HP_SE_OK ? ::PostOnClose(dwConnID): + ::PostOnError(dwConnID, enOperation, iErrorCode); + + return HP_HR_OK; +} + +En_HP_HandleResult CServerDlg::OnShutdown() +{ + ::PostOnShutdown(); + + return HP_HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/ServerDlg.h b/HP-Socket/Demo/TestEcho-Pack/Server/ServerDlg.h new file mode 100644 index 000000000..c0bd3b433 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/ServerDlg.h @@ -0,0 +1,74 @@ + +// ServerDlg.h : header file +// + +#pragma once +#include "afxwin.h" + +#include "../../../Src/HPSocket4C.h" +#include "../../Global/helper.h" + +// CServerDlg dialog +class CServerDlg : public CDialogEx +{ +// Construction +public: + CServerDlg(CWnd* pParent = NULL); // standard constructor + ~CServerDlg(); // standard destructor +// Dialog Data + enum { IDD = IDD_SERVER_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + afx_msg void OnBnClickedDisconnect(); + afx_msg void OnEnChangeConnId(); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + static En_HP_HandleResult __stdcall OnPrepareListen(SOCKET soListen); + static En_HP_HandleResult __stdcall OnAccept(HP_CONNID dwConnID, SOCKET soClient); + static En_HP_HandleResult __stdcall OnSend(HP_CONNID dwConnID, const BYTE* pData, int iLength); + static En_HP_HandleResult __stdcall OnReceive(HP_CONNID dwConnID, const BYTE* pData, int iLength); + static En_HP_HandleResult __stdcall OnClose(HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode); + static En_HP_HandleResult __stdcall OnShutdown(); + +private: + TPkgInfo* FindPkgInfo(HP_CONNID dwConnID); + void RemovePkgInfo(HP_CONNID dwConnID); + +private: + CListBox m_Info; + CButton m_Start; + CButton m_Stop; + CEdit m_Address; + CEdit m_ConnID; + CButton m_DisConn; + +private: + static const USHORT PORT; + static const LPCTSTR ADDRESS; + + + EnAppState m_enState; + CString m_strAddress; + + static CServerDlg* m_spThis; + + HP_TcpPackServer m_pServer; + HP_TcpServerListener m_pListener; +}; diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/res/Server.ico b/HP-Socket/Demo/TestEcho-Pack/Server/res/Server.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/Server/res/Server.ico differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/res/Server.rc2 b/HP-Socket/Demo/TestEcho-Pack/Server/res/Server.rc2 new file mode 100644 index 000000000..b77c9d1c1 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/Server/res/Server.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/resource.h b/HP-Socket/Demo/TestEcho-Pack/Server/resource.h new file mode 100644 index 000000000..9791a41d9 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/Server/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/stdafx.cpp b/HP-Socket/Demo/TestEcho-Pack/Server/stdafx.cpp new file mode 100644 index 000000000..22d19927c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/stdafx.h b/HP-Socket/Demo/TestEcho-Pack/Server/stdafx.h new file mode 100644 index 000000000..dc0a47732 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/stdafx.h @@ -0,0 +1,14 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" diff --git a/HP-Socket/Demo/TestEcho-Pack/Server/targetver.h b/HP-Socket/Demo/TestEcho-Pack/Server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-Pack/TestEcho-Pack.sln b/HP-Socket/Demo/TestEcho-Pack/TestEcho-Pack.sln new file mode 100644 index 000000000..5792d7099 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pack/TestEcho-Pack.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C877}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87E7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A2EE763-53B1-462E-AE9F-7CC58436C877}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C877}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C877}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C877}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E7}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E7}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E7}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E7}.Release|x64.ActiveCfg = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestEcho-Pack/TestEcho-Pack.suo b/HP-Socket/Demo/TestEcho-Pack/TestEcho-Pack.suo new file mode 100644 index 000000000..1b2a1bc9b Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pack/TestEcho-Pack.suo differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/Client.cpp b/HP-Socket/Demo/TestEcho-Pull/Client/Client.cpp new file mode 100644 index 000000000..a67fe0573 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/Client.h b/HP-Socket/Demo/TestEcho-Pull/Client/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/Client.rc b/HP-Socket/Demo/TestEcho-Pull/Client/Client.rc new file mode 100644 index 000000000..d4855558c Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/Client/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj b/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj new file mode 100644 index 000000000..bd23d1ae9 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj @@ -0,0 +1,228 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87E9} + Client + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket\x86\HPSocket_UD.lib + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket\x64\HPSocket_UD.lib + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket\x86\HPSocket_U.lib + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket\x64\HPSocket_U.lib + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj.filters b/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj.filters new file mode 100644 index 000000000..bebe8c357 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj.filters @@ -0,0 +1,80 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {4416963f-6bca-4f60-8e6f-30f8129ed29e} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj.user b/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/Client.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-Pull/Client/ClientDlg.cpp new file mode 100644 index 000000000..a525d2ab3 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/ClientDlg.cpp @@ -0,0 +1,299 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" + + +// CClientDlg dialog + +#define DEFAULT_CONTENT _T("text to be sent") +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") + + +CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CClientDlg::IDD, pParent), m_Client(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_CONTENT, m_Content); + DDX_Control(pDX, IDC_SEND, m_Send); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_ASYNC, m_Async); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_SEND, &CClientDlg::OnBnClickedSend) + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_Content.SetWindowText(DEFAULT_CONTENT); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + m_Async.SetCheck(BST_CHECKED); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + m_bAsyncConn = FALSE; + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Async.EnableWindow(m_enState == ST_STOPPED); + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Send.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); +} + +void CClientDlg::OnBnClickedSend() +{ + static DWORD SEQ = 0; + + USES_CONVERSION; + + CString strContent; + m_Content.GetWindowText(strContent); + + LPCSTR name = "С"; + LPCSTR desc = T2A((LPCTSTR)strContent); + int desc_len = (int)strlen(desc) + 1; + int body_len = offsetof(TPkgBody, desc) + desc_len; + + TPkgBody* pBody = (TPkgBody*)_alloca(body_len); + memset(pBody, 0, body_len); + + pBody->age = 23; + strcpy(pBody->name, name); + strcpy(pBody->desc, desc); + + TPkgHeader header; + header.seq = ++SEQ; + header.body_len = body_len; + + WSABUF bufs[2]; + bufs[0].len = sizeof(TPkgHeader); + bufs[0].buf = (char*)&header; + bufs[1].len = body_len; + bufs[1].buf = (char*)pBody; + + if(m_Client->SendPackets(bufs, 2)) + ::LogSend(m_Client->GetConnectionID(), strContent); + else + ::LogSendFail(m_Client->GetConnectionID(), ::SYS_GetLastError(), ::HP_GetSocketErrorDesc(SE_DATA_SEND)); +} + + +void CClientDlg::OnBnClickedStart() +{ + SetAppState(ST_STARTING); + + CString strAddress; + CString strPort; + + m_Address.GetWindowText(strAddress); + m_Port.GetWindowText(strPort); + + USHORT usPort = (USHORT)_ttoi(strPort); + m_bAsyncConn = m_Async.GetCheck(); + + m_pkgInfo.Reset(); + + ::LogClientStarting(strAddress, usPort); + //m_Client->SetSocketBufferSize(5); + if(m_Client->Start(strAddress, usPort, m_bAsyncConn)) + { + + } + else + { + ::LogClientStartFail(m_Client->GetLastError(), m_Client->GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Client->Stop()) + ::LogClientStopping(m_Client->GetConnectionID()); + else + ASSERT(FALSE); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnConnect(IClient* pClient) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + pClient->GetLocalAddress(szAddress, iAddressLen, usPort); + + ::PostOnConnect(pClient->GetConnectionID(), szAddress, usPort); + SetAppState(ST_STARTED); + + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(IClient* pClient, const BYTE* pData, int iLength) +{ + ::PostOnSend(pClient->GetConnectionID(), pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(IClient* pClient, int iLength) +{ + int required = m_pkgInfo.length; + int remain = iLength; + + while(remain >= required) + { + remain -= required; + CBufferPtr buffer(required); + + EnFetchResult result = ITcpPullClient::ToPull(pClient)->Fetch(buffer, (int)buffer.Size()); + if(result == FR_OK) + { + if(m_pkgInfo.is_header) + { + TPkgHeader* pHeader = (TPkgHeader*)buffer.Ptr(); + TRACE("[Client] head -> seq: %d, body_len: %d\n", pHeader->seq, pHeader->body_len); + + required = pHeader->body_len; + } + else + { + TPkgBody* pBody = (TPkgBody*)buffer.Ptr(); + TRACE("[Client] body -> name: %s, age: %d, desc: %s\n", pBody->name, pBody->age, pBody->desc); + + required = sizeof(TPkgHeader); + } + + m_pkgInfo.is_header = !m_pkgInfo.is_header; + m_pkgInfo.length = required; + + ::PostOnReceive(pClient->GetConnectionID(), buffer, (int)buffer.Size()); + } + } + + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(pClient->GetConnectionID()) : + ::PostOnError(pClient->GetConnectionID(), enOperation, iErrorCode) ; + + SetAppState(ST_STOPPED); + + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/ClientDlg.h b/HP-Socket/Demo/TestEcho-Pull/Client/ClientDlg.h new file mode 100644 index 000000000..ade9ca748 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/ClientDlg.h @@ -0,0 +1,62 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CTcpPullClientListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedSend(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(IClient* pClient, int iLength); + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(IClient* pClient); +private: + CEdit m_Content; + CButton m_Send; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Async; + CButton m_Start; + CButton m_Stop; + + EnAppState m_enState; + BOOL m_bAsyncConn; + + TPkgInfo m_pkgInfo; + + CTcpPullClientPtr m_Client; +}; diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/ReadMe.txt b/HP-Socket/Demo/TestEcho-Pull/Client/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/res/Client.ico b/HP-Socket/Demo/TestEcho-Pull/Client/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/Client/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/res/Client.rc2 b/HP-Socket/Demo/TestEcho-Pull/Client/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/Client/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/resource.h b/HP-Socket/Demo/TestEcho-Pull/Client/resource.h new file mode 100644 index 000000000..82642c470 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/Client/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/stdafx.cpp b/HP-Socket/Demo/TestEcho-Pull/Client/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/stdafx.h b/HP-Socket/Demo/TestEcho-Pull/Client/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-Pull/Client/targetver.h b/HP-Socket/Demo/TestEcho-Pull/Client/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Client/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/ReadMe.txt b/HP-Socket/Demo/TestEcho-Pull/Server/ReadMe.txt new file mode 100644 index 000000000..d97be25bf --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Server Project Overview +=============================================================================== + +The application wizard has created this Server application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Server application. + +Server.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Server.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CServerApp application class. + +Server.cpp + This is the main application source file that contains the application + class CServerApp. + +Server.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Server.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Server.rc. + +res\Server.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ServerDlg.h, ServerDlg.cpp - the dialog + These files contain your CServerDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Server.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Server.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Server.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/Server.cpp b/HP-Socket/Demo/TestEcho-Pull/Server/Server.cpp new file mode 100644 index 000000000..578f1d755 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/Server.cpp @@ -0,0 +1,87 @@ + +// Server.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" + + +// CServerApp + +BEGIN_MESSAGE_MAP(CServerApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CServerApp construction + +CServerApp::CServerApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CServerApp object + +CServerApp theApp; + + +// CServerApp initialization + +BOOL CServerApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CServerDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/Server.h b/HP-Socket/Demo/TestEcho-Pull/Server/Server.h new file mode 100644 index 000000000..df6a5f075 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/Server.h @@ -0,0 +1,32 @@ + +// Server.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CServerApp: +// See Server.cpp for the implementation of this class +// + +class CServerApp : public CWinApp +{ +public: + CServerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CServerApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/Server.rc b/HP-Socket/Demo/TestEcho-Pull/Server/Server.rc new file mode 100644 index 000000000..808371646 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/Server/Server.rc differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj b/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj new file mode 100644 index 000000000..f6d937d1d --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj @@ -0,0 +1,228 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5A2EE763-53B1-462E-AE9F-7CC58436C879} + Server + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket\x86\HPSocket_UD.lib + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + ..\..\..\Bin\HPSocket\x64\HPSocket_UD.lib + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket\x86\HPSocket_U.lib + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + ..\..\..\Bin\HPSocket\x64\HPSocket_U.lib + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj.filters b/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj.filters new file mode 100644 index 000000000..9eb2a4d91 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj.filters @@ -0,0 +1,80 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {48c55559-451a-4f0d-9cb2-884503406307} + + + {f57bc1d3-66f4-49c0-b1c8-c7e5d163de15} + + + {421e5dde-2633-4094-a3d8-c99b836b54da} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj.user b/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/Server.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/ServerDlg.cpp b/HP-Socket/Demo/TestEcho-Pull/Server/ServerDlg.cpp new file mode 100644 index 000000000..4253506b9 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/ServerDlg.cpp @@ -0,0 +1,323 @@ + +// ServerDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" +#include "afxdialogex.h" + + +// CServerDlg dialog + +const LPCTSTR CServerDlg::ADDRESS = _T("0.0.0.0"); +const USHORT CServerDlg::PORT = 5555; + +CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CServerDlg::IDD, pParent), m_Server(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CServerDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_CONN_ID, m_ConnID); + DDX_Control(pDX, IDC_DISCONNECT, m_DisConn); +} + +BEGIN_MESSAGE_MAP(CServerDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CServerDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CServerDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_BN_CLICKED(IDC_DISCONNECT, &CServerDlg::OnBnClickedDisconnect) + ON_EN_CHANGE(IDC_CONN_ID, &CServerDlg::OnEnChangeConnId) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CServerDlg message handlers + +BOOL CServerDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + CString strTitle; + CString strOriginTitle; + GetWindowText(strOriginTitle); + strTitle.Format(_T("%s - (%s:%d)"), strOriginTitle, ADDRESS, PORT); + SetWindowText(strTitle); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CServerDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CServerDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CServerDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_ConnID.GetWindowTextLength() > 0); +} + +void CServerDlg::OnBnClickedStart() +{ + m_Address.GetWindowText(m_strAddress); + m_strAddress.Trim(); + + SetAppState(ST_STARTING); + //m_Server->SetSocketBufferSize(64); + if(m_Server->Start(ADDRESS, PORT)) + { + ::LogServerStart(ADDRESS, PORT); + SetAppState(ST_STARTED); + } + else + { + ::LogServerStartFail(m_Server->GetLastError(), m_Server->GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + +void CServerDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Server->Stop()) + { + ::LogServerStop(); + SetAppState(ST_STOPPED); + } + else + { + ASSERT(FALSE); + } +} + +void CServerDlg::OnBnClickedDisconnect() +{ + CString strConnID; + m_ConnID.GetWindowText(strConnID); + CONNID dwConnID = (CONNID)_ttoi(strConnID); + + if(m_Server->Disconnect(dwConnID)) + ::LogDisconnect(dwConnID); + else + ::LogDisconnectFail(dwConnID); +} + +void CServerDlg::OnEnChangeConnId() +{ + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_ConnID.GetWindowTextLength() > 0); +} + +int CServerDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CServerDlg::OnPrepareListen(SOCKET soListen) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Server->GetListenAddress(szAddress, iAddressLen, usPort); + ::PostOnPrepareListen(szAddress, usPort); + return HR_OK; +} + +EnHandleResult CServerDlg::OnAccept(CONNID dwConnID, SOCKET soClient) +{ + BOOL bPass = TRUE; + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Server->GetRemoteAddress(dwConnID, szAddress, iAddressLen, usPort); + + if(!m_strAddress.IsEmpty()) + { + if(m_strAddress.CompareNoCase(szAddress) == 0) + bPass = FALSE; + } + + ::PostOnAccept(dwConnID, szAddress, usPort, bPass); + + if(bPass) m_Server->SetConnectionExtra(dwConnID, new TPkgInfo(true, sizeof(TPkgHeader))); + + return bPass ? HR_OK : HR_ERROR; +} + +EnHandleResult CServerDlg::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ + //static int t = 0; + //if(++t % 3 == 0) return HR_ERROR; + + ::PostOnSend(dwConnID, pData, iLength); + return HR_OK; +} + +EnHandleResult CServerDlg::OnReceive(CONNID dwConnID, int iLength) +{ + TPkgInfo* pInfo = FindPkgInfo(dwConnID); + + if(pInfo != nullptr) + { + int required = pInfo->length; + int remain = iLength; + + while(remain >= required) + { + remain -= required; + CBufferPtr buffer(required); + + EnFetchResult result = m_Server->Fetch(dwConnID, buffer, (int)buffer.Size()); + if(result == FR_OK) + { + if(pInfo->is_header) + { + TPkgHeader* pHeader = (TPkgHeader*)buffer.Ptr(); + TRACE("[Server] head -> seq: %d, body_len: %d\n", pHeader->seq, pHeader->body_len); + + required = pHeader->body_len; + } + else + { + TPkgBody* pBody = (TPkgBody*)(BYTE*)buffer; + TRACE("[Server] body -> name: %s, age: %d, desc: %s\n", pBody->name, pBody->age, pBody->desc); + + required = sizeof(TPkgHeader); + } + + pInfo->is_header = !pInfo->is_header; + pInfo->length = required; + + ::PostOnReceive(dwConnID, buffer, (int)buffer.Size()); + + if(!m_Server->Send(dwConnID, buffer, (int)buffer.Size())) + return HR_ERROR; + } + } + } + + return HR_OK; +} + +EnHandleResult CServerDlg::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(dwConnID) : + ::PostOnError(dwConnID, enOperation, iErrorCode); + + RemovePkgInfo(dwConnID); + + return HR_OK; +} + +EnHandleResult CServerDlg::OnShutdown() +{ + ::PostOnShutdown(); + + return HR_OK; +} + +TPkgInfo* CServerDlg::FindPkgInfo(CONNID dwConnID) +{ + PVOID pInfo = nullptr; + + m_Server->GetConnectionExtra(dwConnID, &pInfo); + + return (TPkgInfo*)pInfo; +} + +void CServerDlg::RemovePkgInfo(CONNID dwConnID) +{ + //CCriSecLock locallock(m_csPkgInfo); + + TPkgInfo* pInfo = FindPkgInfo(dwConnID); + ASSERT(pInfo != nullptr); + + delete pInfo; +} diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/ServerDlg.h b/HP-Socket/Demo/TestEcho-Pull/Server/ServerDlg.h new file mode 100644 index 000000000..1a18dab80 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/ServerDlg.h @@ -0,0 +1,73 @@ + +// ServerDlg.h : header file +// + +#pragma once +#include "afxwin.h" + +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + +// CServerDlg dialog +class CServerDlg : public CDialogEx, public CTcpPullServerListener +{ +// Construction +public: + CServerDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_SERVER_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + afx_msg void OnBnClickedDisconnect(); + afx_msg void OnEnChangeConnId(); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnPrepareListen(SOCKET soListen); + virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient); + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnShutdown(); + +private: + TPkgInfo* FindPkgInfo(CONNID dwConnID); + void RemovePkgInfo(CONNID dwConnID); + +private: + CListBox m_Info; + CButton m_Start; + CButton m_Stop; + CEdit m_Address; + CEdit m_ConnID; + CButton m_DisConn; + +private: + static const USHORT PORT; + static const LPCTSTR ADDRESS; + + + EnAppState m_enState; + CString m_strAddress; + + //CCriSec m_csPkgInfo; + + CTcpPullServerPtr m_Server; +}; diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/res/Server.ico b/HP-Socket/Demo/TestEcho-Pull/Server/res/Server.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/Server/res/Server.ico differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/res/Server.rc2 b/HP-Socket/Demo/TestEcho-Pull/Server/res/Server.rc2 new file mode 100644 index 000000000..b77c9d1c1 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/Server/res/Server.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/resource.h b/HP-Socket/Demo/TestEcho-Pull/Server/resource.h new file mode 100644 index 000000000..9791a41d9 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/Server/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/stdafx.cpp b/HP-Socket/Demo/TestEcho-Pull/Server/stdafx.cpp new file mode 100644 index 000000000..22d19927c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/stdafx.h b/HP-Socket/Demo/TestEcho-Pull/Server/stdafx.h new file mode 100644 index 000000000..dc0a47732 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/stdafx.h @@ -0,0 +1,14 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" diff --git a/HP-Socket/Demo/TestEcho-Pull/Server/targetver.h b/HP-Socket/Demo/TestEcho-Pull/Server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-Pull/TestEcho-Pull.sln b/HP-Socket/Demo/TestEcho-Pull/TestEcho-Pull.sln new file mode 100644 index 000000000..010727a48 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-Pull/TestEcho-Pull.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C879}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87E9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|Win32.Build.0 = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|x64.Build.0 = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|Win32.Build.0 = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|x64.ActiveCfg = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|x64.Build.0 = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestEcho-Pull/TestEcho-Pull.suo b/HP-Socket/Demo/TestEcho-Pull/TestEcho-Pull.suo new file mode 100644 index 000000000..2f7512d8b Binary files /dev/null and b/HP-Socket/Demo/TestEcho-Pull/TestEcho-Pull.suo differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.cpp b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.cpp new file mode 100644 index 000000000..caa99572d --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != nullptr) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.rc b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.rc new file mode 100644 index 000000000..65ffb88b9 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj new file mode 100644 index 000000000..53199b975 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj @@ -0,0 +1,226 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87E8} + Client + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj.filters b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj.filters new file mode 100644 index 000000000..fe4c51619 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj.filters @@ -0,0 +1,86 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {7c3c0129-66d7-44ad-b6f9-9f5cf6d0a288} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj.user b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/Client.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ClientDlg.cpp new file mode 100644 index 000000000..4995f34a1 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ClientDlg.cpp @@ -0,0 +1,399 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" +#include "../../../../Common/Src/WaitFor.h" + +#ifdef _WIN64 + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_U.lib") + #endif +#else + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_U.lib") + #endif +#endif + +// CClientDlg dialog + +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") + +CClientDlg::CClientDlg(CWnd* pParent /*=nullptr*/) + : CDialogEx(CClientDlg::IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_TEST_TIMES, m_TestTimes); + DDX_Control(pDX, IDC_SOCKET_COUNT, m_SocketCount); + DDX_Control(pDX, IDC_DATA_LEN, m_DataLen); + DDX_Control(pDX, IDC_TEST_TIMES_INTERV, m_TestInterv); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() + ON_WM_CLOSE() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_TestTimes.SetCurSel(5); + m_TestInterv.SetCurSel(1); + m_SocketCount.SetCurSel(5); + m_DataLen.SetCurSel(5); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CClientDlg::OnClose() +{ + ::SetMainWnd(nullptr); + __super::OnClose(); +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + if(m_enState == state) + return; + + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); + m_TestTimes.EnableWindow(m_enState == ST_STOPPED); + m_TestInterv.EnableWindow(m_enState == ST_STOPPED); + m_SocketCount.EnableWindow(m_enState == ST_STOPPED); + m_DataLen.EnableWindow(m_enState == ST_STOPPED); +} + +BOOL CClientDlg::CheckParams() +{ + BOOL isOK = TRUE; + + if(m_strAddress.IsEmpty()) + { + m_Address.SetFocus(); + isOK = FALSE; + } + else if(m_usPort == 0) + { + m_Port.SetFocus(); + isOK = FALSE; + } + else if(m_iTestTimes <= 0) + { + m_TestTimes.SetFocus(); + isOK = FALSE; + } + else if(m_iTestInterv < 0) + { + m_TestInterv.SetFocus(); + isOK = FALSE; + } + else if(m_iSocketCount <= 0) + { + m_SocketCount.SetFocus(); + isOK = FALSE; + } + else if(m_iDataLen <= 0) + { + m_DataLen.SetFocus(); + isOK = FALSE; + } + + if(!isOK) + MessageBox(_T("One or more settings invalid, pls check!"), _T("Params Error"), MB_OK); + + return isOK; +} + +void CClientDlg::OnBnClickedStart() +{ + CString strAddress; + CString strPort; + CString strTestTimes; + CString strTestInterv; + CString strSocketCount; + CString strDataLen; + + m_Address.GetWindowText(strAddress); + m_Port.GetWindowText(strPort); + m_TestTimes.GetWindowText(strTestTimes); + m_TestInterv.GetWindowText(strTestInterv); + m_SocketCount.GetWindowText(strSocketCount); + m_DataLen.GetWindowText(strDataLen); + + m_strAddress = strAddress.Trim(); + m_usPort = (USHORT)_ttoi(strPort); + m_iTestTimes = _ttoi(strTestTimes); + m_iTestInterv = _ttoi(strTestInterv); + m_iSocketCount = _ttoi(strSocketCount); + m_iDataLen = _ttoi(strDataLen); + + if(!CheckParams()) + return; + + SetAppState(ST_STARTING); + + m_dwBeginTickCount = 0; + m_dwTimeconsuming = 0; + m_llTotalReceived = 0; + m_llTotalSent = 0; + m_llExpectReceived = (LONGLONG)m_iTestTimes * (LONGLONG)m_iSocketCount * (LONGLONG)m_iDataLen; + + m_vtClients.Clear(); + + for(int i = 0; i < m_iSocketCount; i++) + { + smart_simple_ptr pSocket = new CUdpClientPtr(this); + //(*pSocket)->SetDetectAttempts(0); + + if((*pSocket)->Start(m_strAddress, m_usPort)) + m_vtClients->push_back(pSocket.release()); + else + { + ::LogClientStartFail((*pSocket)->GetLastError(), (*pSocket)->GetLastErrorDesc()); + m_vtClients.Clear(); + SetAppState(ST_STOPPED); + return; + } + } + + ::LogClientStart(m_strAddress, m_usPort); + + DWORD dwSendDelay = 3; + CString strMsg; + + strMsg.Format(_T(" *** willing to send data after %d seconds ..."), dwSendDelay); + ::LogMsg(strMsg); + + ::WaitWithMessageLoop(dwSendDelay * 1000); + m_sendBuffer.Malloc(m_iDataLen, true); + SetAppState(ST_STARTED); + + ::LogMsg(_T(" *** Go Now !")); + + m_dwBeginTickCount = ::TimeGetTime(); + + BOOL bTerminated = FALSE; + for(int i = 0; i < m_iTestTimes; i++) + { + for(int j = 0; j < m_iSocketCount; j++) + { + CUdpClientPtr* pSocket = m_vtClients[j]; + if(!(*pSocket)->Send(m_sendBuffer, (int)m_sendBuffer.Size())) + { + ::LogClientSendFail(i + 1, j + 1, ::SYS_GetLastError(), ::HP_GetSocketErrorDesc(SE_DATA_SEND)); + bTerminated = TRUE; + break; + } + } + + if(bTerminated) + break; + + if(m_iTestInterv > 0 && i + 1 < m_iTestTimes) + ::WaitWithMessageLoop(m_iTestInterv); + } + + m_sendBuffer.Free(); +} + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + for(size_t i = 0; i < m_vtClients.Size(); i++) + { + CUdpClientPtr* pSocket = m_vtClients[i]; + + if((*pSocket)->Stop()) + ::LogClientStopping((DWORD)i + 1); + //else + // ASSERT(FALSE); + } + + ::WaitWithMessageLoop(100L); + + CString strMsg; + strMsg.Format( _T(" *** Summary: expect - %lld, send - %lld, recv - %lld"), + m_llExpectReceived, m_llTotalSent, m_llTotalReceived); + + ::LogMsg(strMsg); + + if(m_llExpectReceived == m_llTotalSent && m_llTotalSent == m_llTotalReceived) + strMsg.Format(_T(" *** Success: time consuming - %u millisecond !"), m_dwTimeconsuming); + else + strMsg.Format(_T(" *** Fail: manual terminated ? (or data lost)")); + + ::LogMsg(strMsg); + + SetAppState(ST_STOPPED); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnPrepareConnect(IClient* pClient, SOCKET socket) +{ + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(IClient* pClient, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG + ::PostOnSend(pClient->GetConnectionID(), pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalSent, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalSent, iLength); +#endif + + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(IClient* pClient, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG + ::PostOnReceive(pClient->GetConnectionID(), pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalReceived, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalReceived, iLength); +#endif + + if(m_llTotalReceived == m_llExpectReceived) + { + m_dwTimeconsuming = ::GetTimeGap32(m_dwBeginTickCount); + ::PostTimeConsuming(m_dwTimeconsuming); + } + + ASSERT(m_llTotalReceived <= m_llExpectReceived); + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(pClient->GetConnectionID()) : + ::PostOnError(pClient->GetConnectionID(), enOperation, iErrorCode) ; + + return HR_OK; +} + +EnHandleResult CClientDlg::OnConnect(IClient* pClient) +{ + ::LogOnConnect2(pClient->GetConnectionID()); + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ClientDlg.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ClientDlg.h new file mode 100644 index 000000000..3738475a1 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ClientDlg.h @@ -0,0 +1,79 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CUdpClientListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = nullptr); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnClose(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket); + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(IClient* pClient); +private: + BOOL CheckParams(); +private: + CComboBox m_TestTimes; + CComboBox m_SocketCount; + CComboBox m_TestInterv; + CComboBox m_DataLen; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Start; + CButton m_Stop; + + CString m_strAddress; + USHORT m_usPort; + int m_iTestTimes; + int m_iTestInterv; + int m_iSocketCount; + int m_iDataLen; + + volatile LONGLONG m_llTotalReceived; + volatile LONGLONG m_llTotalSent; + LONGLONG m_llExpectReceived; + DWORD m_dwBeginTickCount; + DWORD m_dwTimeconsuming; + + EnAppState m_enState; + CBufferPtr m_sendBuffer; + + VectorWrapper, PtrSet_Cleaner>> m_vtClients; + +}; diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ReadMe.txt b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/res/Client.ico b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/res/Client.rc2 b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/resource.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/resource.h new file mode 100644 index 000000000..2ce0f3925 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/stdafx.cpp b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/stdafx.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Client/targetver.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Client/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ReadMe.txt b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ReadMe.txt new file mode 100644 index 000000000..d97be25bf --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Server Project Overview +=============================================================================== + +The application wizard has created this Server application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Server application. + +Server.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Server.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CServerApp application class. + +Server.cpp + This is the main application source file that contains the application + class CServerApp. + +Server.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Server.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Server.rc. + +res\Server.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ServerDlg.h, ServerDlg.cpp - the dialog + These files contain your CServerDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Server.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Server.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Server.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.cpp b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.cpp new file mode 100644 index 000000000..417b91c90 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.cpp @@ -0,0 +1,87 @@ + +// Server.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" + + +// CServerApp + +BEGIN_MESSAGE_MAP(CServerApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CServerApp construction + +CServerApp::CServerApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CServerApp object + +CServerApp theApp; + + +// CServerApp initialization + +BOOL CServerApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CServerDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != nullptr) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.h new file mode 100644 index 000000000..df6a5f075 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.h @@ -0,0 +1,32 @@ + +// Server.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CServerApp: +// See Server.cpp for the implementation of this class +// + +class CServerApp : public CWinApp +{ +public: + CServerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CServerApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.rc b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.rc new file mode 100644 index 000000000..8bb92f261 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.rc differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj new file mode 100644 index 000000000..d2889d092 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj @@ -0,0 +1,226 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5A2EE763-53B1-462E-AE9F-7CC58436C878} + Server + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj.filters b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj.filters new file mode 100644 index 000000000..dd0168ca7 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj.filters @@ -0,0 +1,86 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {48c55559-451a-4f0d-9cb2-884503406307} + + + {f57bc1d3-66f4-49c0-b1c8-c7e5d163de15} + + + {849bedeb-2d4e-4965-8c3a-c8ace1a89f27} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj.user b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/Server.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ServerDlg.cpp b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ServerDlg.cpp new file mode 100644 index 000000000..a9c3a9bd4 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ServerDlg.cpp @@ -0,0 +1,370 @@ + +// ServerDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" +#include "afxdialogex.h" +#include "../../../../Common/Src/WaitFor.h" + +#ifdef _WIN64 + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x64/HPSocket_U.lib") + #endif +#else + #ifdef _DEBUG + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_UD.lib") + #else + #pragma comment(lib, "../../../Bin/HPSocket/x86/HPSocket_U.lib") + #endif +#endif + +// CServerDlg dialog + +#define DEFAULT_ADDRESS _T("0.0.0.0") +#define DEFAULT_PORT _T("5555") + +CServerDlg::CServerDlg(CWnd* pParent /*=nullptr*/) + : CDialogEx(CServerDlg::IDD, pParent), m_Server(this) + , m_lClientCount(0L) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CServerDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_STATISTICS, m_Statistics); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_SEND_POLICY, m_SendPolicy); + DDX_Control(pDX, IDC_RECV_COUNT, m_RecvCount); +} + +BEGIN_MESSAGE_MAP(CServerDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CServerDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CServerDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() + ON_WM_CLOSE() + ON_BN_CLICKED(IDC_STATISTICS, &CServerDlg::OnBnClickedStatistics) +END_MESSAGE_MAP() + + +// CServerDlg message handlers + +BOOL CServerDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_SendPolicy.SetCurSel(0); + m_RecvCount.SetCurSel(4); + m_Port.SetWindowText(DEFAULT_PORT); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CServerDlg::OnClose() +{ + /* + if(m_Server->GetState() != SS_STOPED) + { + this->MessageBox(_T("stop IOCP Server first, pls !"), _T("forbiddden")); + return; + } + */ + + ::SetMainWnd(nullptr); + __super::OnClose(); +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CServerDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CServerDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CServerDlg::SetAppState(EnAppState state) +{ + if(m_enState == state) + return; + + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Statistics.EnableWindow(m_enState == ST_STARTED); + m_Port.EnableWindow(m_enState == ST_STOPPED); + m_SendPolicy.EnableWindow(m_enState == ST_STOPPED); + m_RecvCount.EnableWindow(m_enState == ST_STOPPED); +} + +void CServerDlg::OnBnClickedStart() +{ + CString strPort; + m_Port.GetWindowText(strPort); + USHORT usPort = (USHORT)_ttoi(strPort); + + if(usPort == 0) + { + MessageBox(_T("Listen Port invalid, pls check!"), _T("Params Error"), MB_OK); + m_Port.SetFocus(); + return; + } + + CString strRecvCount; + m_RecvCount.GetWindowText(strRecvCount); + DWORD dwRecvCount = (DWORD)_ttoi(strRecvCount); + + if(dwRecvCount == 0 || dwRecvCount > MAXLONG) + { + MessageBox(_T("Recv Count invalid, pls check!"), _T("Params Error"), MB_OK); + m_RecvCount.SetFocus(); + return; + } + + EnSendPolicy enSendPolicy = (EnSendPolicy)m_SendPolicy.GetCurSel(); + + SetAppState(ST_STARTING); + + Reset(); + + //m_Server->SetFreeSocketObjPool(500); + //m_Server->SetFreeSocketObjHold(1500); + //m_Server->SetFreeBufferObjPool(2000); + //m_Server->SetFreeBufferObjHold(6000); + //m_Server->SetWorkerThreadCount(10); + //m_Server->SetDetectAttempts(0); + + m_Server->SetSendPolicy(enSendPolicy); + m_Server->SetPostReceiveCount(dwRecvCount); + + if(m_Server->Start(DEFAULT_ADDRESS, usPort)) + { + ::LogServerStart(DEFAULT_ADDRESS, usPort); + SetAppState(ST_STARTED); + } + else + { + ::LogServerStartFail(m_Server->GetLastError(), m_Server->GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + +void CServerDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Server->Stop()) + { + ::LogServerStop(); + SetAppState(ST_STOPPED); + } + else + { + ASSERT(FALSE); + } +} + + +void CServerDlg::OnBnClickedStatistics() +{ + m_Server->DisconnectLongConnections(0); +} + +int CServerDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + else if(nKey == 'R') + { + Reset(); + + CString strMsg; + strMsg.Format( _T(" *** Reset Statics: CC - %u, TS - %lld, TR - %lld"), + m_lClientCount, m_llTotalSent, m_llTotalReceived); + + ::LogMsg(strMsg); + } + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CServerDlg::OnPrepareListen(SOCKET soListen) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Server->GetListenAddress(szAddress, iAddressLen, usPort); + ::PostOnPrepareListen(szAddress, usPort); + return HR_OK; +} + +EnHandleResult CServerDlg::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG + ::PostOnSend(dwConnID, pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalSent, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalSent, iLength); +#endif + + return HR_OK; +} + +EnHandleResult CServerDlg::OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) +{ +#ifdef _DEBUG + ::PostOnReceive(dwConnID, pData, iLength); +#endif + +#if (_WIN32_WINNT <= _WIN32_WINNT_WS03) + ::InterlockedExchangeAdd((volatile LONG*)&m_llTotalReceived, iLength); +#else + ::InterlockedExchangeAdd64(&m_llTotalReceived, iLength); +#endif + + if(m_Server->Send(dwConnID, pData, iLength)) + return HR_OK; + else + return HR_ERROR; +} + +EnHandleResult CServerDlg::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(dwConnID) : + ::PostOnError(dwConnID, enOperation, iErrorCode); + + Statistics(); + + return HR_OK; +} + +EnHandleResult CServerDlg::OnAccept(CONNID dwConnID, const SOCKADDR_IN* pSockAddr) +{ + if(m_lClientCount == 0) + { + CCriSecLock lock(m_cs); + + if(m_lClientCount == 0) + { + Reset(FALSE); + } + } + + ::InterlockedIncrement(&m_lClientCount); + ::PostOnAccept2(dwConnID); + + return HR_OK; +} + +EnHandleResult CServerDlg::OnShutdown() +{ + ::PostOnShutdown(); + return HR_OK; +} + +void CServerDlg::Statistics() +{ + if(m_lClientCount > 0) + { + CCriSecLock lock(m_cs); + + if(m_lClientCount > 0) + { + ::InterlockedDecrement(&m_lClientCount); + + if(m_lClientCount == 0) + { + ::WaitWithMessageLoop(600L); + ::PostServerStatics((LONGLONG)m_llTotalSent, (LONGLONG)m_llTotalReceived); + } + } + } +} + +void CServerDlg::Reset(BOOL bResetClientCount) +{ + if(bResetClientCount) + m_lClientCount = 0L; + + m_llTotalSent = 0L; + m_llTotalReceived = 0L; +} diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ServerDlg.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ServerDlg.h new file mode 100644 index 000000000..dc9e27b61 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/ServerDlg.h @@ -0,0 +1,69 @@ + +// ServerDlg.h : header file +// + +#pragma once +#include "afxwin.h" + +#include "../../../Src/HPSocket.h" +#include "../../Global/helper.h" + +// CServerDlg dialog +class CServerDlg : public CDialogEx, public CUdpServerListener +{ +// Construction +public: + CServerDlg(CWnd* pParent = nullptr); // standard constructor + +// Dialog Data + enum { IDD = IDD_SERVER_DIALOG }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg void OnBnClickedStatistics(); + afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + afx_msg void OnClose(); + + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); + void Statistics(); + void Reset(BOOL bResetClientCount = TRUE); +private: + virtual EnHandleResult OnPrepareListen(SOCKET soListen); + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnAccept(CONNID dwConnID, const SOCKADDR_IN* pSockAddr); + virtual EnHandleResult OnShutdown(); + +private: + CListBox m_Info; + CEdit m_Port; + CComboBox m_SendPolicy; + CComboBox m_RecvCount; + CButton m_Start; + CButton m_Stop; + CButton m_Statistics; + EnAppState m_enState; + + volatile LONGLONG m_llTotalReceived; + volatile LONGLONG m_llTotalSent; + volatile LONG m_lClientCount; + + CCriSec m_cs; + CUdpServerPtr m_Server; +}; diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/res/Server.ico b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/res/Server.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/res/Server.ico differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/res/Server.rc2 b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/res/Server.rc2 new file mode 100644 index 000000000..b77c9d1c1 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/res/Server.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/resource.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/resource.h new file mode 100644 index 000000000..9b008091e Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/stdafx.cpp b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/stdafx.cpp new file mode 100644 index 000000000..22d19927c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/stdafx.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/stdafx.h new file mode 100644 index 000000000..dc0a47732 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/stdafx.h @@ -0,0 +1,14 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/Server/targetver.h b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/TestEcho-UDP-PFM.sln b/HP-Socket/Demo/TestEcho-UDP-PFM/TestEcho-UDP-PFM.sln new file mode 100644 index 000000000..755ee99c6 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP-PFM/TestEcho-UDP-PFM.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C878}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87E8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.Build.0 = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.Build.0 = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.Build.0 = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.ActiveCfg = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.Build.0 = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestEcho-UDP-PFM/TestEcho-UDP-PFM.suo b/HP-Socket/Demo/TestEcho-UDP-PFM/TestEcho-UDP-PFM.suo new file mode 100644 index 000000000..586beb5b6 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP-PFM/TestEcho-UDP-PFM.suo differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/Client.cpp b/HP-Socket/Demo/TestEcho-UDP/Client/Client.cpp new file mode 100644 index 000000000..a67fe0573 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/Client.h b/HP-Socket/Demo/TestEcho-UDP/Client/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/Client.rc b/HP-Socket/Demo/TestEcho-UDP/Client/Client.rc new file mode 100644 index 000000000..365ccd1f1 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/Client/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj b/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj new file mode 100644 index 000000000..0873fb579 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj @@ -0,0 +1,243 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87E9} + Client + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj.filters b/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj.filters new file mode 100644 index 000000000..6908d9c04 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj.filters @@ -0,0 +1,137 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {9c762074-3907-4325-a740-4126dc320d82} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj.user b/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/Client.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/ClientDlg.cpp b/HP-Socket/Demo/TestEcho-UDP/Client/ClientDlg.cpp new file mode 100644 index 000000000..562b37ed4 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/ClientDlg.cpp @@ -0,0 +1,253 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" + + +// CClientDlg dialog + +#define DEFAULT_CONTENT _T("text to be sent") +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") + + +CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CClientDlg::IDD, pParent), m_Client(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_CONTENT, m_Content); + DDX_Control(pDX, IDC_SEND, m_Send); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_ASYNC, m_Async); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_EN_CHANGE(IDC_CONTENT, &CClientDlg::OnEnChangeContent) + ON_BN_CLICKED(IDC_SEND, &CClientDlg::OnBnClickedSend) + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_Content.SetWindowText(DEFAULT_CONTENT); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + m_Async.SetCheck(BST_CHECKED); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + m_bAsyncConn = FALSE; + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Async.EnableWindow(m_enState == ST_STOPPED); + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Send.EnableWindow(m_enState == ST_STARTED && m_Content.GetWindowTextLength() > 0); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); +} + +void CClientDlg::OnEnChangeContent() +{ + m_Send.EnableWindow(m_enState == ST_STARTED && m_Content.GetWindowTextLength() > 0); +} + + +void CClientDlg::OnBnClickedSend() +{ + USES_CONVERSION; + + CString strContent; + m_Content.GetWindowText(strContent); + + LPSTR lpszContent = T2A((LPTSTR)(LPCTSTR)strContent); + int iLen = (int)strlen(lpszContent); + + if(m_Client.Send((LPBYTE)lpszContent, iLen)) + ::LogSend(m_Client.GetConnectionID(), strContent); + else + ::LogSendFail(m_Client.GetConnectionID(), ::GetLastError(), ::GetSocketErrorDesc(SE_DATA_SEND)); +} + + +void CClientDlg::OnBnClickedStart() +{ + SetAppState(ST_STARTING); + + CString strAddress; + CString strPort; + + m_Address.GetWindowText(strAddress); + m_Port.GetWindowText(strPort); + + USHORT usPort = (USHORT)_ttoi(strPort); + m_bAsyncConn = m_Async.GetCheck(); + + ::LogClientStarting(strAddress, usPort); + + //m_Client.SetDetectAttempts(0); + + if(m_Client.Start(strAddress, usPort, m_bAsyncConn)) + { + + } + else + { + ::LogClientStartFail(m_Client.GetLastError(), m_Client.GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Client.Stop()) + ::LogClientStopping(m_Client.GetConnectionID()); + else + ASSERT(FALSE); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnConnect(IClient* pClient) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + pClient->GetLocalAddress(szAddress, iAddressLen, usPort); + + ::PostOnConnect(pClient->GetConnectionID(), szAddress, usPort); + SetAppState(ST_STARTED); + + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(IClient* pClient, const BYTE* pData, int iLength) +{ + ::PostOnSend(pClient->GetConnectionID(), pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(IClient* pClient, const BYTE* pData, int iLength) +{ + ::PostOnReceive(pClient->GetConnectionID(), pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(pClient->GetConnectionID()) : + ::PostOnError(pClient->GetConnectionID(), enOperation, iErrorCode) ; + + SetAppState(ST_STOPPED); + + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/ClientDlg.h b/HP-Socket/Demo/TestEcho-UDP/Client/ClientDlg.h new file mode 100644 index 000000000..40854d76f --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/ClientDlg.h @@ -0,0 +1,60 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/UdpClient.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CUdpClientListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnEnChangeContent(); + afx_msg void OnBnClickedSend(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(IClient* pClient); +private: + CEdit m_Content; + CButton m_Send; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Async; + CButton m_Start; + CButton m_Stop; + + BOOL m_bAsyncConn; + EnAppState m_enState; + CUdpClient m_Client; +}; diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/ReadMe.txt b/HP-Socket/Demo/TestEcho-UDP/Client/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/res/Client.ico b/HP-Socket/Demo/TestEcho-UDP/Client/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/Client/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/res/Client.rc2 b/HP-Socket/Demo/TestEcho-UDP/Client/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/Client/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/resource.h b/HP-Socket/Demo/TestEcho-UDP/Client/resource.h new file mode 100644 index 000000000..0ec41406f Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/Client/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/stdafx.cpp b/HP-Socket/Demo/TestEcho-UDP/Client/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/stdafx.h b/HP-Socket/Demo/TestEcho-UDP/Client/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-UDP/Client/targetver.h b/HP-Socket/Demo/TestEcho-UDP/Client/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Client/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/ReadMe.txt b/HP-Socket/Demo/TestEcho-UDP/Server/ReadMe.txt new file mode 100644 index 000000000..d97be25bf --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Server Project Overview +=============================================================================== + +The application wizard has created this Server application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Server application. + +Server.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Server.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CServerApp application class. + +Server.cpp + This is the main application source file that contains the application + class CServerApp. + +Server.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Server.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Server.rc. + +res\Server.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ServerDlg.h, ServerDlg.cpp - the dialog + These files contain your CServerDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Server.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Server.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Server.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/Server.cpp b/HP-Socket/Demo/TestEcho-UDP/Server/Server.cpp new file mode 100644 index 000000000..578f1d755 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/Server.cpp @@ -0,0 +1,87 @@ + +// Server.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" + + +// CServerApp + +BEGIN_MESSAGE_MAP(CServerApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CServerApp construction + +CServerApp::CServerApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CServerApp object + +CServerApp theApp; + + +// CServerApp initialization + +BOOL CServerApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CServerDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/Server.h b/HP-Socket/Demo/TestEcho-UDP/Server/Server.h new file mode 100644 index 000000000..df6a5f075 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/Server.h @@ -0,0 +1,32 @@ + +// Server.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CServerApp: +// See Server.cpp for the implementation of this class +// + +class CServerApp : public CWinApp +{ +public: + CServerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CServerApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/Server.rc b/HP-Socket/Demo/TestEcho-UDP/Server/Server.rc new file mode 100644 index 000000000..c6261eb0d Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/Server/Server.rc differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj b/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj new file mode 100644 index 000000000..aa4a453ab --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj @@ -0,0 +1,243 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5A2EE763-53B1-462E-AE9F-7CC58436C879} + Server + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj.filters b/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj.filters new file mode 100644 index 000000000..914bf9699 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj.filters @@ -0,0 +1,137 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {48c55559-451a-4f0d-9cb2-884503406307} + + + {f57bc1d3-66f4-49c0-b1c8-c7e5d163de15} + + + {355f64e5-73ec-4ca8-944d-8a3ca91a7cbb} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj.user b/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/Server.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/ServerDlg.cpp b/HP-Socket/Demo/TestEcho-UDP/Server/ServerDlg.cpp new file mode 100644 index 000000000..efa7707f0 --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/ServerDlg.cpp @@ -0,0 +1,276 @@ + +// ServerDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" +#include "afxdialogex.h" + + +// CServerDlg dialog + +const LPCTSTR CServerDlg::ADDRESS = _T("0.0.0.0"); +const USHORT CServerDlg::PORT = 5555; + +CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CServerDlg::IDD, pParent), m_Server(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CServerDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_CONN_ID, m_ConnID); + DDX_Control(pDX, IDC_DISCONNECT, m_DisConn); +} + +BEGIN_MESSAGE_MAP(CServerDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CServerDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CServerDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_BN_CLICKED(IDC_DISCONNECT, &CServerDlg::OnBnClickedDisconnect) + ON_EN_CHANGE(IDC_CONN_ID, &CServerDlg::OnEnChangeConnId) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CServerDlg message handlers + +BOOL CServerDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + CString strTitle; + CString strOriginTitle; + GetWindowText(strOriginTitle); + strTitle.Format(_T("%s - (%s:%d)"), strOriginTitle, ADDRESS, PORT); + SetWindowText(strTitle); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CServerDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CServerDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CServerDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_ConnID.GetWindowTextLength() > 0); +} + +void CServerDlg::OnBnClickedStart() +{ + //m_Server.SetWorkerThreadCount(2); + //m_Server.SetMaxShutdownWaitTime(100000000); + //m_Server.SetMaxDatagramSize(50); + //m_Server.SetDetectAttempts(0); + + //m_Server.SetDetectAttempts(0); + //m_Server.SetDetectInterval(0); + + //m_Server.SetSendPolicy(SP_SAFE); + + m_Address.GetWindowText(m_strAddress); + m_strAddress.Trim(); + + SetAppState(ST_STARTING); + + if(m_Server.Start(ADDRESS, PORT)) + { + ::LogServerStart(ADDRESS, PORT); + SetAppState(ST_STARTED); + } + else + { + ::LogServerStartFail(m_Server.GetLastError(), m_Server.GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + +void CServerDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Server.Stop()) + { + ::LogServerStop(); + SetAppState(ST_STOPPED); + } + else + { + ASSERT(FALSE); + } +} + +void CServerDlg::OnBnClickedDisconnect() +{ + CString strConnID; + m_ConnID.GetWindowText(strConnID); + CONNID dwConnID = (CONNID)_ttoi(strConnID); + + if(m_Server.Disconnect(dwConnID)) + ::LogDisconnect(dwConnID); + else + ::LogDisconnectFail(dwConnID); +} + +void CServerDlg::OnEnChangeConnId() +{ + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_ConnID.GetWindowTextLength() > 0); +} + +int CServerDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CServerDlg::OnPrepareListen(SOCKET soListen) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Server.GetListenAddress(szAddress, iAddressLen, usPort); + ::PostOnPrepareListen(szAddress, usPort); + return HR_OK; +} + +EnHandleResult CServerDlg::OnAccept(CONNID dwConnID, const SOCKADDR_IN* pSockAddr) +{ + BOOL bPass = TRUE; + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Server.GetRemoteAddress(dwConnID, szAddress, iAddressLen, usPort); + + if(!m_strAddress.IsEmpty()) + { + if(m_strAddress.CompareNoCase(szAddress) == 0) + bPass = FALSE; + } + + ::PostOnAccept(dwConnID, szAddress, usPort, bPass); + + return bPass ? HR_OK : HR_ERROR; +} + +EnHandleResult CServerDlg::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ + //static int t = 0; + //if(++t % 3 == 0) return HR_ERROR; + + ::PostOnSend(dwConnID, pData, iLength); + return HR_OK; +} + +EnHandleResult CServerDlg::OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) +{ + //static int t = 0; + //if(++t % 3 == 0) return HR_ERROR; + + ::PostOnReceive(dwConnID, pData, iLength); + + if(m_Server.Send(dwConnID, pData, iLength)) + return HR_OK; + else + return HR_ERROR; +} + +EnHandleResult CServerDlg::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(dwConnID) : + ::PostOnError(dwConnID, enOperation, iErrorCode); + + return HR_OK; +} + +EnHandleResult CServerDlg::OnShutdown() +{ + ::PostOnShutdown(); + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/ServerDlg.h b/HP-Socket/Demo/TestEcho-UDP/Server/ServerDlg.h new file mode 100644 index 000000000..7a1782d3a --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/ServerDlg.h @@ -0,0 +1,65 @@ + +// ServerDlg.h : header file +// + +#pragma once +#include "afxwin.h" + +#include "../../../Src/UdpServer.h" +#include "../../Global/helper.h" + +// CServerDlg dialog +class CServerDlg : public CDialogEx, public CUdpServerListener +{ +// Construction +public: + CServerDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_SERVER_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg void OnBnClickedDisconnect(); + afx_msg void OnEnChangeConnId(); + afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnPrepareListen(SOCKET soListen); + virtual EnHandleResult OnAccept(CONNID dwConnID, const SOCKADDR_IN* pSockAddr); + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnShutdown(); + +private: + CListBox m_Info; + CButton m_Start; + CButton m_Stop; + CEdit m_Address; + CEdit m_ConnID; + CButton m_DisConn; + +private: + static const USHORT PORT; + static const LPCTSTR ADDRESS; + + CString m_strAddress; + EnAppState m_enState; + CUdpServer m_Server; +}; diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/res/Server.ico b/HP-Socket/Demo/TestEcho-UDP/Server/res/Server.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/Server/res/Server.ico differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/res/Server.rc2 b/HP-Socket/Demo/TestEcho-UDP/Server/res/Server.rc2 new file mode 100644 index 000000000..b77c9d1c1 Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/Server/res/Server.rc2 differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/resource.h b/HP-Socket/Demo/TestEcho-UDP/Server/resource.h new file mode 100644 index 000000000..05b67af2d Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/Server/resource.h differ diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/stdafx.cpp b/HP-Socket/Demo/TestEcho-UDP/Server/stdafx.cpp new file mode 100644 index 000000000..22d19927c --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/stdafx.h b/HP-Socket/Demo/TestEcho-UDP/Server/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho-UDP/Server/targetver.h b/HP-Socket/Demo/TestEcho-UDP/Server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho-UDP/TestEcho-UDP.sln b/HP-Socket/Demo/TestEcho-UDP/TestEcho-UDP.sln new file mode 100644 index 000000000..2aca7374a --- /dev/null +++ b/HP-Socket/Demo/TestEcho-UDP/TestEcho-UDP.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87E9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C879}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E9}.Release|x64.Build.0 = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|Win32.Build.0 = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Debug|x64.Build.0 = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|Win32.Build.0 = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|x64.ActiveCfg = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C879}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestEcho-UDP/TestEcho-UDP.suo b/HP-Socket/Demo/TestEcho-UDP/TestEcho-UDP.suo new file mode 100644 index 000000000..f679f783c Binary files /dev/null and b/HP-Socket/Demo/TestEcho-UDP/TestEcho-UDP.suo differ diff --git a/HP-Socket/Demo/TestEcho/Client/Client.cpp b/HP-Socket/Demo/TestEcho/Client/Client.cpp new file mode 100644 index 000000000..a67fe0573 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho/Client/Client.h b/HP-Socket/Demo/TestEcho/Client/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho/Client/Client.rc b/HP-Socket/Demo/TestEcho/Client/Client.rc new file mode 100644 index 000000000..aedc5bb04 Binary files /dev/null and b/HP-Socket/Demo/TestEcho/Client/Client.rc differ diff --git a/HP-Socket/Demo/TestEcho/Client/Client.vcxproj b/HP-Socket/Demo/TestEcho/Client/Client.vcxproj new file mode 100644 index 000000000..8933a316d --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/Client.vcxproj @@ -0,0 +1,245 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87E8} + Client + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho/Client/Client.vcxproj.filters b/HP-Socket/Demo/TestEcho/Client/Client.vcxproj.filters new file mode 100644 index 000000000..d71f1b0d9 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/Client.vcxproj.filters @@ -0,0 +1,137 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {384036c9-f332-4983-9783-c5f08964d609} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho/Client/Client.vcxproj.user b/HP-Socket/Demo/TestEcho/Client/Client.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/Client.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho/Client/ClientDlg.cpp b/HP-Socket/Demo/TestEcho/Client/ClientDlg.cpp new file mode 100644 index 000000000..6a414e221 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/ClientDlg.cpp @@ -0,0 +1,250 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" + + +// CClientDlg dialog + +#define DEFAULT_CONTENT _T("text to be sent") +#define DEFAULT_ADDRESS _T("127.0.0.1") +#define DEFAULT_PORT _T("5555") + + +CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CClientDlg::IDD, pParent), m_Client(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_CONTENT, m_Content); + DDX_Control(pDX, IDC_SEND, m_Send); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_ASYNC, m_Async); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_EN_CHANGE(IDC_CONTENT, &CClientDlg::OnEnChangeContent) + ON_BN_CLICKED(IDC_SEND, &CClientDlg::OnBnClickedSend) + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_Content.SetWindowText(DEFAULT_CONTENT); + m_Address.SetWindowText(DEFAULT_ADDRESS); + m_Port.SetWindowText(DEFAULT_PORT); + m_Async.SetCheck(BST_CHECKED); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + m_bAsyncConn = FALSE; + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Async.EnableWindow(m_enState == ST_STOPPED); + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Send.EnableWindow(m_enState == ST_STARTED && m_Content.GetWindowTextLength() > 0); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); +} + +void CClientDlg::OnEnChangeContent() +{ + m_Send.EnableWindow(m_enState == ST_STARTED && m_Content.GetWindowTextLength() > 0); +} + + +void CClientDlg::OnBnClickedSend() +{ + USES_CONVERSION; + + CString strContent; + m_Content.GetWindowText(strContent); + + LPSTR lpszContent = T2A((LPTSTR)(LPCTSTR)strContent); + int iLen = (int)strlen(lpszContent); + + if(m_Client.Send((LPBYTE)lpszContent, iLen)) + ::LogSend(m_Client.GetConnectionID(), strContent); + else + ::LogSendFail(m_Client.GetConnectionID(), ::GetLastError(), ::GetSocketErrorDesc(SE_DATA_SEND)); +} + + +void CClientDlg::OnBnClickedStart() +{ + SetAppState(ST_STARTING); + + CString strAddress; + CString strPort; + + m_Address.GetWindowText(strAddress); + m_Port.GetWindowText(strPort); + + USHORT usPort = (USHORT)_ttoi(strPort); + m_bAsyncConn = m_Async.GetCheck(); + + ::LogClientStarting(strAddress, usPort); + + if(m_Client.Start(strAddress, usPort, m_bAsyncConn)) + { + + } + else + { + ::LogClientStartFail(m_Client.GetLastError(), m_Client.GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Client.Stop()) + ::LogClientStopping(m_Client.GetConnectionID()); + else + ASSERT(FALSE); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnConnect(IClient* pClient) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + pClient->GetLocalAddress(szAddress, iAddressLen, usPort); + + ::PostOnConnect(pClient->GetConnectionID(), szAddress, usPort); + SetAppState(ST_STARTED); + + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(IClient* pClient, const BYTE* pData, int iLength) +{ + ::PostOnSend(pClient->GetConnectionID(), pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(IClient* pClient, const BYTE* pData, int iLength) +{ + ::PostOnReceive(pClient->GetConnectionID(), pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(pClient->GetConnectionID()) : + ::PostOnError(pClient->GetConnectionID(), enOperation, iErrorCode) ; + + SetAppState(ST_STOPPED); + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho/Client/ClientDlg.h b/HP-Socket/Demo/TestEcho/Client/ClientDlg.h new file mode 100644 index 000000000..88dda4ae3 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/ClientDlg.h @@ -0,0 +1,60 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/TcpClient.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CTcpClientListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnEnChangeContent(); + afx_msg void OnBnClickedSend(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(IClient* pClient); +private: + CEdit m_Content; + CButton m_Send; + CListBox m_Info; + CEdit m_Address; + CEdit m_Port; + CButton m_Async; + CButton m_Start; + CButton m_Stop; + + BOOL m_bAsyncConn; + EnAppState m_enState; + CTcpClient m_Client; +}; diff --git a/HP-Socket/Demo/TestEcho/Client/ReadMe.txt b/HP-Socket/Demo/TestEcho/Client/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho/Client/res/Client.ico b/HP-Socket/Demo/TestEcho/Client/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho/Client/res/Client.ico differ diff --git a/HP-Socket/Demo/TestEcho/Client/res/Client.rc2 b/HP-Socket/Demo/TestEcho/Client/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestEcho/Client/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestEcho/Client/resource.h b/HP-Socket/Demo/TestEcho/Client/resource.h new file mode 100644 index 000000000..82642c470 Binary files /dev/null and b/HP-Socket/Demo/TestEcho/Client/resource.h differ diff --git a/HP-Socket/Demo/TestEcho/Client/stdafx.cpp b/HP-Socket/Demo/TestEcho/Client/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho/Client/stdafx.h b/HP-Socket/Demo/TestEcho/Client/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho/Client/targetver.h b/HP-Socket/Demo/TestEcho/Client/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Client/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho/Server/ReadMe.txt b/HP-Socket/Demo/TestEcho/Server/ReadMe.txt new file mode 100644 index 000000000..d97be25bf --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Server Project Overview +=============================================================================== + +The application wizard has created this Server application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Server application. + +Server.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Server.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CServerApp application class. + +Server.cpp + This is the main application source file that contains the application + class CServerApp. + +Server.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Server.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Server.rc. + +res\Server.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ServerDlg.h, ServerDlg.cpp - the dialog + These files contain your CServerDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Server.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Server.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Server.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestEcho/Server/Server.cpp b/HP-Socket/Demo/TestEcho/Server/Server.cpp new file mode 100644 index 000000000..578f1d755 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/Server.cpp @@ -0,0 +1,87 @@ + +// Server.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" + + +// CServerApp + +BEGIN_MESSAGE_MAP(CServerApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CServerApp construction + +CServerApp::CServerApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CServerApp object + +CServerApp theApp; + + +// CServerApp initialization + +BOOL CServerApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CServerDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestEcho/Server/Server.h b/HP-Socket/Demo/TestEcho/Server/Server.h new file mode 100644 index 000000000..df6a5f075 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/Server.h @@ -0,0 +1,32 @@ + +// Server.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CServerApp: +// See Server.cpp for the implementation of this class +// + +class CServerApp : public CWinApp +{ +public: + CServerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CServerApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho/Server/Server.rc b/HP-Socket/Demo/TestEcho/Server/Server.rc new file mode 100644 index 000000000..21b8c4b1f Binary files /dev/null and b/HP-Socket/Demo/TestEcho/Server/Server.rc differ diff --git a/HP-Socket/Demo/TestEcho/Server/Server.vcxproj b/HP-Socket/Demo/TestEcho/Server/Server.vcxproj new file mode 100644 index 000000000..82b3dbb38 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/Server.vcxproj @@ -0,0 +1,245 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5A2EE763-53B1-462E-AE9F-7CC58436C878} + Server + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho/Server/Server.vcxproj.filters b/HP-Socket/Demo/TestEcho/Server/Server.vcxproj.filters new file mode 100644 index 000000000..5ac60f33d --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/Server.vcxproj.filters @@ -0,0 +1,137 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {48c55559-451a-4f0d-9cb2-884503406307} + + + {f57bc1d3-66f4-49c0-b1c8-c7e5d163de15} + + + {f91de9d1-99d3-4318-8989-0a58646693cc} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho/Server/Server.vcxproj.user b/HP-Socket/Demo/TestEcho/Server/Server.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/Server.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestEcho/Server/ServerDlg.cpp b/HP-Socket/Demo/TestEcho/Server/ServerDlg.cpp new file mode 100644 index 000000000..ed52cb1ac --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/ServerDlg.cpp @@ -0,0 +1,266 @@ + +// ServerDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Server.h" +#include "ServerDlg.h" +#include "afxdialogex.h" + + +// CServerDlg dialog + +const LPCTSTR CServerDlg::ADDRESS = _T("0.0.0.0"); +const USHORT CServerDlg::PORT = 5555; + +CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CServerDlg::IDD, pParent), m_Server(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CServerDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_ADDRESS, m_Address); + DDX_Control(pDX, IDC_CONN_ID, m_ConnID); + DDX_Control(pDX, IDC_DISCONNECT, m_DisConn); +} + +BEGIN_MESSAGE_MAP(CServerDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_START, &CServerDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CServerDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_BN_CLICKED(IDC_DISCONNECT, &CServerDlg::OnBnClickedDisconnect) + ON_EN_CHANGE(IDC_CONN_ID, &CServerDlg::OnEnChangeConnId) + ON_WM_VKEYTOITEM() +END_MESSAGE_MAP() + + +// CServerDlg message handlers + +BOOL CServerDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + CString strTitle; + CString strOriginTitle; + GetWindowText(strOriginTitle); + strTitle.Format(_T("%s - (%s:%d)"), strOriginTitle, ADDRESS, PORT); + SetWindowText(strTitle); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CServerDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CServerDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CServerDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Address.EnableWindow(m_enState == ST_STOPPED); + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_ConnID.GetWindowTextLength() > 0); +} + +void CServerDlg::OnBnClickedStart() +{ + m_Address.GetWindowText(m_strAddress); + m_strAddress.Trim(); + + SetAppState(ST_STARTING); + + if(m_Server.Start(ADDRESS, PORT)) + { + ::LogServerStart(ADDRESS, PORT); + SetAppState(ST_STARTED); + } + else + { + ::LogServerStartFail(m_Server.GetLastError(), m_Server.GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + +void CServerDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Server.Stop()) + { + ::LogServerStop(); + SetAppState(ST_STOPPED); + } + else + { + ASSERT(FALSE); + } +} + +void CServerDlg::OnBnClickedDisconnect() +{ + CString strConnID; + m_ConnID.GetWindowText(strConnID); + CONNID dwConnID = (CONNID)_ttoi(strConnID); + + if(m_Server.Disconnect(dwConnID)) + ::LogDisconnect(dwConnID); + else + ::LogDisconnectFail(dwConnID); +} + +void CServerDlg::OnEnChangeConnId() +{ + m_DisConn.EnableWindow(m_enState == ST_STARTED && m_ConnID.GetWindowTextLength() > 0); +} + +int CServerDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CServerDlg::OnPrepareListen(SOCKET soListen) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Server.GetListenAddress(szAddress, iAddressLen, usPort); + ::PostOnPrepareListen(szAddress, usPort); + return HR_OK; +} + +EnHandleResult CServerDlg::OnAccept(CONNID dwConnID, SOCKET soClient) +{ + BOOL bPass = TRUE; + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + m_Server.GetRemoteAddress(dwConnID, szAddress, iAddressLen, usPort); + + if(!m_strAddress.IsEmpty()) + { + if(m_strAddress.CompareNoCase(szAddress) == 0) + bPass = FALSE; + } + + ::PostOnAccept(dwConnID, szAddress, usPort, bPass); + + return bPass ? HR_OK : HR_ERROR; +} + +EnHandleResult CServerDlg::OnSend(CONNID dwConnID, const BYTE* pData, int iLength) +{ + //static int t = 0; + //if(++t % 3 == 0) return HR_ERROR; + + ::PostOnSend(dwConnID, pData, iLength); + return HR_OK; +} + +EnHandleResult CServerDlg::OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) +{ + //static int t = 0; + //if(++t % 3 == 0) return HR_ERROR; + + ::PostOnReceive(dwConnID, pData, iLength); + + if(m_Server.Send(dwConnID, pData, iLength)) + return HR_OK; + else + return HR_ERROR; +} + +EnHandleResult CServerDlg::OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(dwConnID) : + ::PostOnError(dwConnID, enOperation, iErrorCode); + + return HR_OK; +} + +EnHandleResult CServerDlg::OnShutdown() +{ + ::PostOnShutdown(); + return HR_OK; +} diff --git a/HP-Socket/Demo/TestEcho/Server/ServerDlg.h b/HP-Socket/Demo/TestEcho/Server/ServerDlg.h new file mode 100644 index 000000000..183e47ff3 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/ServerDlg.h @@ -0,0 +1,65 @@ + +// ServerDlg.h : header file +// + +#pragma once +#include "afxwin.h" + +#include "../../../Src/TcpServer.h" +#include "../../Global/helper.h" + +// CServerDlg dialog +class CServerDlg : public CDialogEx, public CTcpServerListener +{ +// Construction +public: + CServerDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_SERVER_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg void OnBnClickedDisconnect(); + afx_msg void OnEnChangeConnId(); + afx_msg LRESULT CServerDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnPrepareListen(SOCKET soListen); + virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient); + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnShutdown(); + +private: + CListBox m_Info; + CButton m_Start; + CButton m_Stop; + CEdit m_Address; + CEdit m_ConnID; + CButton m_DisConn; + EnAppState m_enState; + +private: + static const USHORT PORT; + static const LPCTSTR ADDRESS; + + CString m_strAddress; + CTcpServer m_Server; +}; diff --git a/HP-Socket/Demo/TestEcho/Server/res/Server.ico b/HP-Socket/Demo/TestEcho/Server/res/Server.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestEcho/Server/res/Server.ico differ diff --git a/HP-Socket/Demo/TestEcho/Server/res/Server.rc2 b/HP-Socket/Demo/TestEcho/Server/res/Server.rc2 new file mode 100644 index 000000000..b77c9d1c1 Binary files /dev/null and b/HP-Socket/Demo/TestEcho/Server/res/Server.rc2 differ diff --git a/HP-Socket/Demo/TestEcho/Server/resource.h b/HP-Socket/Demo/TestEcho/Server/resource.h new file mode 100644 index 000000000..9791a41d9 Binary files /dev/null and b/HP-Socket/Demo/TestEcho/Server/resource.h differ diff --git a/HP-Socket/Demo/TestEcho/Server/stdafx.cpp b/HP-Socket/Demo/TestEcho/Server/stdafx.cpp new file mode 100644 index 000000000..22d19927c --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestEcho/Server/stdafx.h b/HP-Socket/Demo/TestEcho/Server/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestEcho/Server/targetver.h b/HP-Socket/Demo/TestEcho/Server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestEcho/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestEcho/TestEcho.sln b/HP-Socket/Demo/TestEcho/TestEcho.sln new file mode 100644 index 000000000..755ee99c6 --- /dev/null +++ b/HP-Socket/Demo/TestEcho/TestEcho.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{5A2EE763-53B1-462E-AE9F-7CC58436C878}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87E8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|Win32.Build.0 = Debug|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.ActiveCfg = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Debug|x64.Build.0 = Debug|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.ActiveCfg = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|Win32.Build.0 = Release|Win32 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.ActiveCfg = Release|x64 + {5A2EE763-53B1-462E-AE9F-7CC58436C878}.Release|x64.Build.0 = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87E8}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestEcho/TestEcho.suo b/HP-Socket/Demo/TestEcho/TestEcho.suo new file mode 100644 index 000000000..339580c86 Binary files /dev/null and b/HP-Socket/Demo/TestEcho/TestEcho.suo differ diff --git a/HP-Socket/Demo/TestUDPCast/Member/Client.cpp b/HP-Socket/Demo/TestUDPCast/Member/Client.cpp new file mode 100644 index 000000000..a67fe0573 --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/Client.cpp @@ -0,0 +1,87 @@ + +// Client.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" + + +// CClientApp + +BEGIN_MESSAGE_MAP(CClientApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CClientApp construction + +CClientApp::CClientApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CClientApp object + +CClientApp theApp; + + +// CClientApp initialization + +BOOL CClientApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CClientDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HP-Socket/Demo/TestUDPCast/Member/Client.h b/HP-Socket/Demo/TestUDPCast/Member/Client.h new file mode 100644 index 000000000..22d35bfeb --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/Client.h @@ -0,0 +1,32 @@ + +// Client.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CClientApp: +// See Client.cpp for the implementation of this class +// + +class CClientApp : public CWinApp +{ +public: + CClientApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CClientApp theApp; \ No newline at end of file diff --git a/HP-Socket/Demo/TestUDPCast/Member/Client.rc b/HP-Socket/Demo/TestUDPCast/Member/Client.rc new file mode 100644 index 000000000..60856314f Binary files /dev/null and b/HP-Socket/Demo/TestUDPCast/Member/Client.rc differ diff --git a/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj b/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj new file mode 100644 index 000000000..d3f12c7de --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj @@ -0,0 +1,243 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E3791685-9CC8-426B-811C-FEBA775F87EA} + Client + MFCProj + Member + + + + Application + true + Unicode + Dynamic + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + true + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x86\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + false + ..\..\$(Configuration)\x64\ + $(OutDir)obj\$(SolutionName)\$(ProjectName)\ + $(SolutionName)-$(ProjectName) + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj.filters b/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj.filters new file mode 100644 index 000000000..7a7e250fa --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj.filters @@ -0,0 +1,134 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {89058252-93cb-4ab6-a586-ad80c94ab5aa} + + + {d9d5fe43-fc80-4741-bcea-684280ad841b} + + + {9c762074-3907-4325-a740-4126dc320d82} + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Source Files + + + Source Files + + + Source Files + + + Global + + + Common + + + Common + + + Common + + + Common + + + HPSocket + + + HPSocket + + + + + Resource Files + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj.user b/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj.user new file mode 100644 index 000000000..ace9a86ac --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/Client.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/HP-Socket/Demo/TestUDPCast/Member/ClientDlg.cpp b/HP-Socket/Demo/TestUDPCast/Member/ClientDlg.cpp new file mode 100644 index 000000000..a746fe6e2 --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/ClientDlg.cpp @@ -0,0 +1,302 @@ + +// ClientDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "Client.h" +#include "ClientDlg.h" +#include "afxdialogex.h" + + +// CClientDlg dialog + +#define DEFAULT_CONTENT _T("text to be sent") +#define DEFAULT_CAST_ADDR _T("233.0.0.1") +#define DEFAULT_BIND_ADDR _T("0.0.0.0") +#define DEFAULT_PORT _T("5555") +#define DEFAULT_TTL _T("1") + + +CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CClientDlg::IDD, pParent), m_Cast(this) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CClientDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_CONTENT, m_Content); + DDX_Control(pDX, IDC_SEND, m_Send); + DDX_Control(pDX, IDC_INFO, m_Info); + DDX_Control(pDX, IDC_PORT, m_Port); + DDX_Control(pDX, IDC_START, m_Start); + DDX_Control(pDX, IDC_STOP, m_Stop); + DDX_Control(pDX, IDC_CAST_ADDRESS, m_CastAddr); + DDX_Control(pDX, IDC_BIND_ADDRESS, m_BindAddr); + DDX_Control(pDX, IDC_TTL, m_TTL); + DDX_Control(pDX, IDC_IP_LOOP, m_IPLoop); + DDX_Control(pDX, IDC_REUSE_ADDR, m_ReuseAddr); + DDX_Control(pDX, IDC_MULTI_MODE, m_CastMode); + DDX_Control(pDX, IDC_BROAD_MODE, m_CastMode2); +} + +BEGIN_MESSAGE_MAP(CClientDlg, CDialogEx) + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_EN_CHANGE(IDC_CONTENT, &CClientDlg::OnEnChangeContent) + ON_BN_CLICKED(IDC_SEND, &CClientDlg::OnBnClickedSend) + ON_BN_CLICKED(IDC_START, &CClientDlg::OnBnClickedStart) + ON_BN_CLICKED(IDC_STOP, &CClientDlg::OnBnClickedStop) + ON_MESSAGE(USER_INFO_MSG, OnUserInfoMsg) + ON_WM_VKEYTOITEM() + ON_BN_CLICKED(IDC_MULTI_MODE, &CClientDlg::OnBnClickedMultiMode) + ON_BN_CLICKED(IDC_BROAD_MODE, &CClientDlg::OnBnClickedBroadMode) +END_MESSAGE_MAP() + + +// CClientDlg message handlers + +BOOL CClientDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here + + m_Content.SetWindowText(DEFAULT_CONTENT); + m_CastAddr.SetWindowText(DEFAULT_CAST_ADDR); + m_BindAddr.SetWindowText(DEFAULT_BIND_ADDR); + m_Port.SetWindowText(DEFAULT_PORT); + m_TTL.SetWindowText(DEFAULT_TTL); + m_CastMode.SetCheck(BST_CHECKED); + m_IPLoop.SetCheck(BST_CHECKED); + m_ReuseAddr.SetCheck(BST_UNCHECKED); + + ::SetMainWnd(this); + ::SetInfoList(&m_Info); + SetAppState(ST_STOPPED); + + return TRUE; // return TRUE unless you set the focus to a control +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CClientDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CClientDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) +{ + if ( + pMsg->message == WM_KEYDOWN + &&( pMsg->wParam == VK_ESCAPE + || pMsg->wParam == VK_CANCEL + || pMsg->wParam == VK_RETURN + )) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + +void CClientDlg::SetAppState(EnAppState state) +{ + m_enState = state; + + if(this->GetSafeHwnd() == nullptr) + return; + + m_Start.EnableWindow(m_enState == ST_STOPPED); + m_Stop.EnableWindow(m_enState == ST_STARTED); + m_Send.EnableWindow(m_enState == ST_STARTED && m_Content.GetWindowTextLength() > 0); + m_CastAddr.EnableWindow(m_enState == ST_STOPPED && m_CastMode.GetCheck() == BST_CHECKED); + m_BindAddr.EnableWindow(m_enState == ST_STOPPED); + m_Port.EnableWindow(m_enState == ST_STOPPED); + m_TTL.EnableWindow(m_enState == ST_STOPPED); + m_CastMode.EnableWindow(m_enState == ST_STOPPED); + m_CastMode2.EnableWindow(m_enState == ST_STOPPED); + m_IPLoop.EnableWindow(m_enState == ST_STOPPED); + m_ReuseAddr.EnableWindow(m_enState == ST_STOPPED); +} + +void CClientDlg::OnEnChangeContent() +{ + m_Send.EnableWindow(m_enState == ST_STARTED && m_Content.GetWindowTextLength() > 0); +} + +void CClientDlg::OnBnClickedMultiMode() +{ + m_CastAddr.EnableWindow(m_enState == ST_STOPPED && m_CastMode.GetCheck() == BST_CHECKED); +} + +void CClientDlg::OnBnClickedBroadMode() +{ + m_CastAddr.EnableWindow(m_enState == ST_STOPPED && m_CastMode.GetCheck() == BST_CHECKED); +} + +void CClientDlg::OnBnClickedSend() +{ + USES_CONVERSION; + + CString strContent; + m_Content.GetWindowText(strContent); + + LPSTR lpszContent = T2A((LPTSTR)(LPCTSTR)strContent); + int iLen = (int)strlen(lpszContent); + + if(m_Cast.Send((LPBYTE)lpszContent, iLen)) + ::LogSend(m_Cast.GetConnectionID(), strContent); + else + ::LogSendFail(m_Cast.GetConnectionID(), ::GetLastError(), ::GetSocketErrorDesc(SE_DATA_SEND)); +} + + +void CClientDlg::OnBnClickedStart() +{ + SetAppState(ST_STARTING); + + + CString strCastAddress; + CString strBindAddress; + CString strPort; + CString strTTL; + + m_CastAddr.GetWindowText(strCastAddress); + m_BindAddr.GetWindowText(strBindAddress); + m_Port.GetWindowText(strPort); + m_TTL.GetWindowText(strTTL); + + USHORT usPort = (USHORT)_ttoi(strPort); + int iTTL = _ttoi(strTTL); + EnCastMode enMode = (m_CastMode.GetCheck() == BST_CHECKED) ? CM_MULTICAST : CM_BROADCAST; + BOOL bIPLoop = (m_IPLoop.GetCheck() == BST_CHECKED) ? TRUE : FALSE; + BOOL bReuseAddr = (m_ReuseAddr.GetCheck() == BST_CHECKED) ? TRUE : FALSE; + + // OPTIONS ... + m_Cast.SetCastMode(enMode); + m_Cast.SetMultiCastLoop(bIPLoop); + m_Cast.SetReuseAddress(bReuseAddr); + m_Cast.SetMultiCastTtl(iTTL); + m_Cast.SetBindAdddress(strBindAddress); + + ::LogClientStarting(strCastAddress, usPort); + + if(m_Cast.Start(strCastAddress, usPort, FALSE)) + { + + } + else + { + ::LogClientStartFail(m_Cast.GetLastError(), m_Cast.GetLastErrorDesc()); + SetAppState(ST_STOPPED); + } +} + + +void CClientDlg::OnBnClickedStop() +{ + SetAppState(ST_STOPPING); + + if(m_Cast.Stop()) + ::LogClientStopping(m_Cast.GetConnectionID()); + else + ASSERT(FALSE); +} + +int CClientDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) +{ + if(nKey == 'C') + pListBox->ResetContent(); + + return __super::OnVKeyToItem(nKey, pListBox, nIndex); +} + +LRESULT CClientDlg::OnUserInfoMsg(WPARAM wp, LPARAM lp) +{ + info_msg* msg = (info_msg*)wp; + + ::LogInfoMsg(msg); + + return 0; +} + +EnHandleResult CClientDlg::OnPrepareConnect(IClient* pClient, SOCKET socket) +{ + return HR_OK; +} + +EnHandleResult CClientDlg::OnConnect(IClient* pClient) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + pClient->GetLocalAddress(szAddress, iAddressLen, usPort); + + ::PostOnConnect(pClient->GetConnectionID(), szAddress, usPort); + SetAppState(ST_STARTED); + + return HR_OK; +} + +EnHandleResult CClientDlg::OnSend(IClient* pClient, const BYTE* pData, int iLength) +{ + ::PostOnSend(pClient->GetConnectionID(), pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnReceive(IClient* pClient, const BYTE* pData, int iLength) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + USHORT usPort; + + ((IUdpCast*)pClient)->GetRemoteAddress(szAddress, iAddressLen, usPort); + + ::PostOnReceiveCast(pClient->GetConnectionID(), szAddress, usPort, pData, iLength); + return HR_OK; +} + +EnHandleResult CClientDlg::OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) +{ + iErrorCode == SE_OK ? ::PostOnClose(pClient->GetConnectionID()) : + ::PostOnError(pClient->GetConnectionID(), enOperation, iErrorCode) ; + + SetAppState(ST_STOPPED); + + return HR_OK; +} diff --git a/HP-Socket/Demo/TestUDPCast/Member/ClientDlg.h b/HP-Socket/Demo/TestUDPCast/Member/ClientDlg.h new file mode 100644 index 000000000..fcfe84828 --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/ClientDlg.h @@ -0,0 +1,67 @@ + +// ClientDlg.h : header file +// + +#pragma once +#include "afxwin.h" +#include "../../../Src/UdpCast.h" +#include "../../Global/helper.h" + + +// CClientDlg dialog +class CClientDlg : public CDialogEx, public CUdpCastListener +{ +// Construction +public: + CClientDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_CLIENT_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL PreTranslateMessage(MSG* pMsg); + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnEnChangeContent(); + afx_msg void OnBnClickedMultiMode(); + afx_msg void OnBnClickedBroadMode(); + afx_msg void OnBnClickedSend(); + afx_msg void OnBnClickedStart(); + afx_msg void OnBnClickedStop(); + afx_msg LRESULT OnUserInfoMsg(WPARAM wp, LPARAM lp); + afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex); + DECLARE_MESSAGE_MAP() +public: + void SetAppState(EnAppState state); +private: + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket); + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength); + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult OnConnect(IClient* pClient); +private: + CEdit m_Content; + CButton m_Send; + CListBox m_Info; + CEdit m_CastAddr; + CEdit m_Port; + CEdit m_BindAddr; + CEdit m_TTL; + CButton m_IPLoop; + CButton m_ReuseAddr; + CButton m_CastMode; + CButton m_CastMode2; + CButton m_Start; + CButton m_Stop; + + EnAppState m_enState; + CUdpCast m_Cast; +}; diff --git a/HP-Socket/Demo/TestUDPCast/Member/ReadMe.txt b/HP-Socket/Demo/TestUDPCast/Member/ReadMe.txt new file mode 100644 index 000000000..5a8cb0ad2 --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/ReadMe.txt @@ -0,0 +1,100 @@ +================================================================================ + MICROSOFT FOUNDATION CLASS LIBRARY : Client Project Overview +=============================================================================== + +The application wizard has created this Client application for +you. This application not only demonstrates the basics of using the Microsoft +Foundation Classes but is also a starting point for writing your application. + +This file contains a summary of what you will find in each of the files that +make up your Client application. + +Client.vcxproj + This is the main project file for VC++ projects generated using an application wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + application wizard. + +Client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Client.h + This is the main header file for the application. It includes other + project specific headers (including Resource.h) and declares the + CClientApp application class. + +Client.cpp + This is the main application source file that contains the application + class CClientApp. + +Client.rc + This is a listing of all of the Microsoft Windows resources that the + program uses. It includes the icons, bitmaps, and cursors that are stored + in the RES subdirectory. This file can be directly edited in Microsoft + Visual C++. Your project resources are in 1033. + +res\Client.ico + This is an icon file, which is used as the application's icon. This + icon is included by the main resource file Client.rc. + +res\Client.rc2 + This file contains resources that are not edited by Microsoft + Visual C++. You should place all resources not editable by + the resource editor in this file. + + +///////////////////////////////////////////////////////////////////////////// + +The application wizard creates one dialog class: + +ClientDlg.h, ClientDlg.cpp - the dialog + These files contain your CClientDlg class. This class defines + the behavior of your application's main dialog. The dialog's template is + in Client.rc, which can be edited in Microsoft Visual C++. + + +///////////////////////////////////////////////////////////////////////////// + +Other Features: + +ActiveX Controls + The application includes support to use ActiveX controls. + +///////////////////////////////////////////////////////////////////////////// + +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named Client.pch and a precompiled types file named StdAfx.obj. + +Resource.h + This is the standard header file, which defines new resource IDs. + Microsoft Visual C++ reads and updates this file. + +Client.manifest + Application manifest files are used by Windows XP to describe an applications + dependency on specific versions of Side-by-Side assemblies. The loader uses this + information to load the appropriate assembly from the assembly cache or private + from the application. The Application manifest maybe included for redistribution + as an external .manifest file that is installed in the same folder as the application + executable or it may be included in the executable in the form of a resource. +///////////////////////////////////////////////////////////////////////////// + +Other notes: + +The application wizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +If your application uses MFC in a shared DLL, you will need +to redistribute the MFC DLLs. If your application is in a language +other than the operating system's locale, you will also have to +redistribute the corresponding localized resources MFC100XXX.DLL. +For more information on both of these topics, please see the section on +redistributing Visual C++ applications in MSDN documentation. + +///////////////////////////////////////////////////////////////////////////// diff --git a/HP-Socket/Demo/TestUDPCast/Member/res/Client.ico b/HP-Socket/Demo/TestUDPCast/Member/res/Client.ico new file mode 100644 index 000000000..45535c16a Binary files /dev/null and b/HP-Socket/Demo/TestUDPCast/Member/res/Client.ico differ diff --git a/HP-Socket/Demo/TestUDPCast/Member/res/Client.rc2 b/HP-Socket/Demo/TestUDPCast/Member/res/Client.rc2 new file mode 100644 index 000000000..c6c40d0ac Binary files /dev/null and b/HP-Socket/Demo/TestUDPCast/Member/res/Client.rc2 differ diff --git a/HP-Socket/Demo/TestUDPCast/Member/resource.h b/HP-Socket/Demo/TestUDPCast/Member/resource.h new file mode 100644 index 000000000..9bd02e93d Binary files /dev/null and b/HP-Socket/Demo/TestUDPCast/Member/resource.h differ diff --git a/HP-Socket/Demo/TestUDPCast/Member/stdafx.cpp b/HP-Socket/Demo/TestUDPCast/Member/stdafx.cpp new file mode 100644 index 000000000..d74b4fb31 --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/HP-Socket/Demo/TestUDPCast/Member/stdafx.h b/HP-Socket/Demo/TestUDPCast/Member/stdafx.h new file mode 100644 index 000000000..2ff86ca3b --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/stdafx.h @@ -0,0 +1,15 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +//#define _WIN32_WINNT _WIN32_WINNT_WINXP +//#define _WIN32_WINNT _WIN32_WINNT_WIN7 + +#define _USE_MFC +#define _DETECT_MEMORY_LEAK + +#include "../../../../Common/Src/GeneralHelper.h" + diff --git a/HP-Socket/Demo/TestUDPCast/Member/targetver.h b/HP-Socket/Demo/TestUDPCast/Member/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/Member/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HP-Socket/Demo/TestUDPCast/TestUDPCast.sln b/HP-Socket/Demo/TestUDPCast/TestUDPCast.sln new file mode 100644 index 000000000..d37db95c3 --- /dev/null +++ b/HP-Socket/Demo/TestUDPCast/TestUDPCast.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Member", "Member\Client.vcxproj", "{E3791685-9CC8-426B-811C-FEBA775F87EA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E3791685-9CC8-426B-811C-FEBA775F87EA}.Debug|Win32.ActiveCfg = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87EA}.Debug|Win32.Build.0 = Debug|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87EA}.Debug|x64.ActiveCfg = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87EA}.Debug|x64.Build.0 = Debug|x64 + {E3791685-9CC8-426B-811C-FEBA775F87EA}.Release|Win32.ActiveCfg = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87EA}.Release|Win32.Build.0 = Release|Win32 + {E3791685-9CC8-426B-811C-FEBA775F87EA}.Release|x64.ActiveCfg = Release|x64 + {E3791685-9CC8-426B-811C-FEBA775F87EA}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HP-Socket/Demo/TestUDPCast/TestUDPCast.suo b/HP-Socket/Demo/TestUDPCast/TestUDPCast.suo new file mode 100644 index 000000000..842181354 Binary files /dev/null and b/HP-Socket/Demo/TestUDPCast/TestUDPCast.suo differ diff --git a/HP-Socket/Src/HPSocket.cpp b/HP-Socket/Src/HPSocket.cpp new file mode 100644 index 000000000..f7dce2fa7 --- /dev/null +++ b/HP-Socket/Src/HPSocket.cpp @@ -0,0 +1,229 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "HPSocket.h" +#include "TcpServer.h" +#include "TcpAgent.h" +#include "TcpClient.h" +#include "TcpPullServer.h" +#include "TcpPullClient.h" +#include "TcpPullAgent.h" +#include "TcpPackServer.h" +#include "TcpPackClient.h" +#include "TcpPackAgent.h" +#include "UdpServer.h" +#include "UdpClient.h" +#include "UdpCast.h" + +/* +#if !defined(_WIN64) + #pragma comment(linker, "/EXPORT:HP_Create_TcpServer=_HP_Create_TcpServer") + #pragma comment(linker, "/EXPORT:HP_Create_TcpAgent=_HP_Create_TcpAgent") + #pragma comment(linker, "/EXPORT:HP_Create_TcpClient=_HP_Create_TcpClient") + #pragma comment(linker, "/EXPORT:HP_Create_TcpPullServer=_HP_Create_TcpPullServer") + #pragma comment(linker, "/EXPORT:HP_Create_TcpPullAgent=_HP_Create_TcpPullAgent") + #pragma comment(linker, "/EXPORT:HP_Create_TcpPullClient=_HP_Create_TcpPullClient") + #pragma comment(linker, "/EXPORT:HP_Create_TcpPackServer=_HP_Create_TcpPackServer") + #pragma comment(linker, "/EXPORT:HP_Create_TcpPackAgent=_HP_Create_TcpPackAgent") + #pragma comment(linker, "/EXPORT:HP_Create_TcpPackClient=_HP_Create_TcpPackClient") + #pragma comment(linker, "/EXPORT:HP_Create_UdpServer=_HP_Create_UdpServer") + #pragma comment(linker, "/EXPORT:HP_Create_UdpClient=_HP_Create_UdpClient") + #pragma comment(linker, "/EXPORT:HP_Create_UdpCast=_HP_Create_UdpCast") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpServer=_HP_Destroy_TcpServer") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpAgent=_HP_Destroy_TcpAgent") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpClient=_HP_Destroy_TcpClient") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpPullServer=_HP_Destroy_TcpPullServer") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpPullAgent=_HP_Destroy_TcpPullAgent") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpPullClient=_HP_Destroy_TcpPullClient") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpPackServer=_HP_Destroy_TcpPackServer") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpPackAgent=_HP_Destroy_TcpPackAgent") + #pragma comment(linker, "/EXPORT:HP_Destroy_TcpPackClient=_HP_Destroy_TcpPackClient") + #pragma comment(linker, "/EXPORT:HP_Destroy_UdpServer=_HP_Destroy_UdpServer") + #pragma comment(linker, "/EXPORT:HP_Destroy_UdpClient=_HP_Destroy_UdpClient") + #pragma comment(linker, "/EXPORT:HP_Destroy_UdpCast=_HP_Destroy_UdpCast") + #pragma comment(linker, "/EXPORT:HP_GetSocketErrorDesc=_HP_GetSocketErrorDesc") + #pragma comment(linker, "/EXPORT:SYS_GetLastError=_SYS_GetLastError") + #pragma comment(linker, "/EXPORT:SYS_WSAGetLastError=_SYS_WSAGetLastError") + #pragma comment(linker, "/EXPORT:SYS_SetSocketOption=_SYS_SetSocketOption") + #pragma comment(linker, "/EXPORT:SYS_GetSocketOption=_SYS_GetSocketOption") + #pragma comment(linker, "/EXPORT:SYS_IoctlSocket=_SYS_IoctlSocket") + #pragma comment(linker, "/EXPORT:SYS_WSAIoctl=_SYS_WSAIoctl") +#endif +*/ + +HPSOCKET_API ITcpServer* HP_Create_TcpServer(ITcpServerListener* pListener) +{ + return new CTcpServer(pListener); +} + +HPSOCKET_API ITcpAgent* HP_Create_TcpAgent(ITcpAgentListener* pListener) +{ + return new CTcpAgent(pListener); +} + +HPSOCKET_API ITcpClient* HP_Create_TcpClient(ITcpClientListener* pListener) +{ + return new CTcpClient(pListener); +} + +HPSOCKET_API ITcpPullServer* HP_Create_TcpPullServer(ITcpServerListener* pListener) +{ + return (ITcpPullServer*)(new CTcpPullServer(pListener)); +} + +HPSOCKET_API ITcpPullAgent* HP_Create_TcpPullAgent(ITcpAgentListener* pListener) +{ + return (ITcpPullAgent*)(new CTcpPullAgent(pListener)); +} + +HPSOCKET_API ITcpPullClient* HP_Create_TcpPullClient(ITcpClientListener* pListener) +{ + return (ITcpPullClient*)(new CTcpPullClient(pListener)); +} + +HPSOCKET_API ITcpPackServer* HP_Create_TcpPackServer(ITcpServerListener* pListener) +{ + return (ITcpPackServer*)(new CTcpPackServer(pListener)); +} + +HPSOCKET_API ITcpPackAgent* HP_Create_TcpPackAgent(ITcpAgentListener* pListener) +{ + return (ITcpPackAgent*)(new CTcpPackAgent(pListener)); +} + +HPSOCKET_API ITcpPackClient* HP_Create_TcpPackClient(ITcpClientListener* pListener) +{ + return (ITcpPackClient*)(new CTcpPackClient(pListener)); +} + +HPSOCKET_API IUdpServer* HP_Create_UdpServer(IUdpServerListener* pListener) +{ + return new CUdpServer(pListener); +} + +HPSOCKET_API IUdpClient* HP_Create_UdpClient(IUdpClientListener* pListener) +{ + return new CUdpClient(pListener); +} + +HPSOCKET_API IUdpCast* HP_Create_UdpCast(IUdpCastListener* pListener) +{ + return new CUdpCast(pListener); +} + +HPSOCKET_API void HP_Destroy_TcpServer(ITcpServer* pServer) +{ + delete pServer; +} + +HPSOCKET_API void HP_Destroy_TcpAgent(ITcpAgent* pAgent) +{ + delete pAgent; +} + +HPSOCKET_API void HP_Destroy_TcpClient(ITcpClient* pClient) +{ + delete pClient; +} + +HPSOCKET_API void HP_Destroy_TcpPullServer(ITcpPullServer* pServer) +{ + delete pServer; +} + +HPSOCKET_API void HP_Destroy_TcpPullAgent(ITcpPullAgent* pAgent) +{ + delete pAgent; +} + +HPSOCKET_API void HP_Destroy_TcpPullClient(ITcpPullClient* pClient) +{ + delete pClient; +} + +HPSOCKET_API void HP_Destroy_TcpPackServer(ITcpPackServer* pServer) +{ + delete pServer; +} + +HPSOCKET_API void HP_Destroy_TcpPackAgent(ITcpPackAgent* pAgent) +{ + delete pAgent; +} + +HPSOCKET_API void HP_Destroy_TcpPackClient(ITcpPackClient* pClient) +{ + delete pClient; +} + +HPSOCKET_API void HP_Destroy_UdpServer(IUdpServer* pServer) +{ + delete pServer; +} + +HPSOCKET_API void HP_Destroy_UdpClient(IUdpClient* pClient) +{ + delete pClient; +} + +HPSOCKET_API void HP_Destroy_UdpCast(IUdpCast* pCast) +{ + delete pCast; +} + +HPSOCKET_API LPCTSTR HP_GetSocketErrorDesc(EnSocketError enCode) +{ + return ::GetSocketErrorDesc(enCode); +} + +HPSOCKET_API DWORD SYS_GetLastError() +{ + return ::GetLastError(); +} + +HPSOCKET_API int SYS_WSAGetLastError() +{ + return ::WSAGetLastError(); +} + +HPSOCKET_API int SYS_SetSocketOption(SOCKET sock, int level, int name, LPVOID val, int len) +{ + return ::SSO_SetSocketOption(sock, level, name, val, len); +} + +HPSOCKET_API int SYS_GetSocketOption(SOCKET sock, int level, int name, LPVOID val, int* len) +{ + return ::SSO_GetSocketOption(sock, level, name, val, len); +} + +HPSOCKET_API int SYS_IoctlSocket(SOCKET sock, long cmd, u_long* arg) +{ + return ::SSO_IoctlSocket(sock, cmd, arg); +} + +HPSOCKET_API int SYS_WSAIoctl(SOCKET sock, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned) +{ + return ::SSO_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, lpvOutBuffer, cbOutBuffer, lpcbBytesReturned); +} diff --git a/HP-Socket/Src/HPSocket.h b/HP-Socket/Src/HPSocket.h new file mode 100644 index 000000000..7511710e4 --- /dev/null +++ b/HP-Socket/Src/HPSocket.h @@ -0,0 +1,389 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: HPSocket DLL + +Usage: + һ + -------------------------------------------------------------------------------------- + 0. Ӧó SocketInterface.h HPSocket.h ͷļ + 1. HP_Create_Xxx() HPSocket + 2. ʹϺ HP_Destroy_Xxx() HPSocket + + + -------------------------------------------------------------------------------------- + 0. Ӧó SocketInterface.h HPSocket.h ͷļ + 1. CXxxPtr ָ룬ָͨʹ HPSocket + +Release: + 1. x86/HPSocket.dll - (32λ/MBCS/Release) + 2. x86/HPSocket_D.dll - (32λ/MBCS/DeBug) + 3. x86/HPSocket_U.dll - (32λ/UNICODE/Release) + 4. x86/HPSocket_UD.dll - (32λ/UNICODE/DeBug) + 5. x64/HPSocket.dll - (64λ/MBCS/Release) + 6. x64/HPSocket_D.dll - (64λ/MBCS/DeBug) + 7. x64/HPSocket_U.dll - (64λ/UNICODE/Release) + 8. x64/HPSocket_UD.dll - (64λ/UNICODE/DeBug) + +******************************************************************************/ + +#pragma once + +/**************************************************/ +/********* imports / exports HPSocket.dll *********/ + +#ifdef HPSOCKET_STATIC_LIB + #define HPSOCKET_API EXTERN_C +#else + #ifdef HPSOCKET_EXPORTS + #define HPSOCKET_API EXTERN_C __declspec(dllexport) + #else + #define HPSOCKET_API EXTERN_C __declspec(dllimport) + #endif +#endif + +#include "SocketInterface.h" + +/**************************************************/ +/************** HPSocket.dll **************/ + +// ITcpServer +HPSOCKET_API ITcpServer* HP_Create_TcpServer(ITcpServerListener* pListener); +// ITcpAgent +HPSOCKET_API ITcpAgent* HP_Create_TcpAgent(ITcpAgentListener* pListener); +// ITcpClient +HPSOCKET_API ITcpClient* HP_Create_TcpClient(ITcpClientListener* pListener); +// ITcpPullServer +HPSOCKET_API ITcpPullServer* HP_Create_TcpPullServer(ITcpServerListener* pListener); +// ITcpPullAgent +HPSOCKET_API ITcpPullAgent* HP_Create_TcpPullAgent(ITcpAgentListener* pListener); +// ITcpPullClient +HPSOCKET_API ITcpPullClient* HP_Create_TcpPullClient(ITcpClientListener* pListener); +// ITcpPackServer +HPSOCKET_API ITcpPackServer* HP_Create_TcpPackServer(ITcpServerListener* pListener); +// ITcpPackAgent +HPSOCKET_API ITcpPackAgent* HP_Create_TcpPackAgent(ITcpAgentListener* pListener); +// ITcpPackClient +HPSOCKET_API ITcpPackClient* HP_Create_TcpPackClient(ITcpClientListener* pListener); +// IUdpServer +HPSOCKET_API IUdpServer* HP_Create_UdpServer(IUdpServerListener* pListener); +// IUdpClient +HPSOCKET_API IUdpClient* HP_Create_UdpClient(IUdpClientListener* pListener); +// IUdpCast +HPSOCKET_API IUdpCast* HP_Create_UdpCast(IUdpCastListener* pListener); + +// ITcpServer +HPSOCKET_API void HP_Destroy_TcpServer(ITcpServer* pServer); +// ITcpAgent +HPSOCKET_API void HP_Destroy_TcpAgent(ITcpAgent* pAgent); +// ITcpClient +HPSOCKET_API void HP_Destroy_TcpClient(ITcpClient* pClient); +// ITcpPullServer +HPSOCKET_API void HP_Destroy_TcpPullServer(ITcpPullServer* pServer); +// ITcpPullAgent +HPSOCKET_API void HP_Destroy_TcpPullAgent(ITcpPullAgent* pAgent); +// ITcpPullClient +HPSOCKET_API void HP_Destroy_TcpPullClient(ITcpPullClient* pClient); +// ITcpPackServer +HPSOCKET_API void HP_Destroy_TcpPackServer(ITcpPackServer* pServer); +// ITcpPackAgent +HPSOCKET_API void HP_Destroy_TcpPackAgent(ITcpPackAgent* pAgent); +// ITcpPackClient +HPSOCKET_API void HP_Destroy_TcpPackClient(ITcpPackClient* pClient); +// IUdpServer +HPSOCKET_API void HP_Destroy_UdpServer(IUdpServer* pServer); +// IUdpClient +HPSOCKET_API void HP_Destroy_UdpClient(IUdpClient* pClient); +// IUdpCast +HPSOCKET_API void HP_Destroy_UdpCast(IUdpCast* pCast); + +// ȡı +HPSOCKET_API LPCTSTR HP_GetSocketErrorDesc(EnSocketError enCode); +// ϵͳ ::GetLastError() ȡϵͳ +HPSOCKET_API DWORD SYS_GetLastError (); +// ϵͳ ::WSAGetLastError() ȡͨŴ +HPSOCKET_API int SYS_WSAGetLastError(); +// ϵͳ setsockopt() +HPSOCKET_API int SYS_SetSocketOption(SOCKET sock, int level, int name, LPVOID val, int len); +// ϵͳ getsockopt() +HPSOCKET_API int SYS_GetSocketOption(SOCKET sock, int level, int name, LPVOID val, int* len); +// ϵͳ ioctlsocket() +HPSOCKET_API int SYS_IoctlSocket(SOCKET sock, long cmd, u_long* arg); +// ϵͳ ::WSAIoctl() +HPSOCKET_API int SYS_WSAIoctl(SOCKET sock, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned); + +// ITcpServer 󴴽 +struct TcpServer_Creator +{ + static ITcpServer* Create(ITcpServerListener* pListener) + { + return HP_Create_TcpServer(pListener); + } + + static void Destroy(ITcpServer* pServer) + { + HP_Destroy_TcpServer(pServer); + } +}; + +// ITcpAgent 󴴽 +struct TcpAgent_Creator +{ + static ITcpAgent* Create(ITcpAgentListener* pListener) + { + return HP_Create_TcpAgent(pListener); + } + + static void Destroy(ITcpAgent* pAgent) + { + HP_Destroy_TcpAgent(pAgent); + } +}; + +// ITcpClient 󴴽 +struct TcpClient_Creator +{ + static ITcpClient* Create(ITcpClientListener* pListener) + { + return HP_Create_TcpClient(pListener); + } + + static void Destroy(ITcpClient* pClient) + { + HP_Destroy_TcpClient(pClient); + } +}; + +// ITcpPullServer 󴴽 +struct TcpPullServer_Creator +{ + static ITcpPullServer* Create(ITcpServerListener* pListener) + { + return HP_Create_TcpPullServer(pListener); + } + + static void Destroy(ITcpPullServer* pServer) + { + HP_Destroy_TcpPullServer(pServer); + } +}; + +// ITcpPullAgent 󴴽 +struct TcpPullAgent_Creator +{ + static ITcpPullAgent* Create(ITcpAgentListener* pListener) + { + return HP_Create_TcpPullAgent(pListener); + } + + static void Destroy(ITcpPullAgent* pAgent) + { + HP_Destroy_TcpPullAgent(pAgent); + } +}; + +// ITcpPullClient 󴴽 +struct TcpPullClient_Creator +{ + static ITcpPullClient* Create(ITcpClientListener* pListener) + { + return HP_Create_TcpPullClient(pListener); + } + + static void Destroy(ITcpPullClient* pClient) + { + HP_Destroy_TcpPullClient(pClient); + } +}; + +// ITcpPackServer 󴴽 +struct TcpPackServer_Creator +{ + static ITcpPackServer* Create(ITcpServerListener* pListener) + { + return HP_Create_TcpPackServer(pListener); + } + + static void Destroy(ITcpPackServer* pServer) + { + HP_Destroy_TcpPackServer(pServer); + } +}; + +// ITcpPackAgent 󴴽 +struct TcpPackAgent_Creator +{ + static ITcpPackAgent* Create(ITcpAgentListener* pListener) + { + return HP_Create_TcpPackAgent(pListener); + } + + static void Destroy(ITcpPackAgent* pAgent) + { + HP_Destroy_TcpPackAgent(pAgent); + } +}; + +// ITcpPackClient 󴴽 +struct TcpPackClient_Creator +{ + static ITcpPackClient* Create(ITcpClientListener* pListener) + { + return HP_Create_TcpPackClient(pListener); + } + + static void Destroy(ITcpPackClient* pClient) + { + HP_Destroy_TcpPackClient(pClient); + } +}; + +// IUdpServer 󴴽 +struct UdpServer_Creator +{ + static IUdpServer* Create(IUdpServerListener* pListener) + { + return HP_Create_UdpServer(pListener); + } + + static void Destroy(IUdpServer* pServer) + { + HP_Destroy_UdpServer(pServer); + } +}; + +// IUdpClient 󴴽 +struct UdpClient_Creator +{ + static IUdpClient* Create(IUdpClientListener* pListener) + { + return HP_Create_UdpClient(pListener); + } + + static void Destroy(IUdpClient* pClient) + { + HP_Destroy_UdpClient(pClient); + } +}; + +// IUdpClient 󴴽 +struct UdpCast_Creator +{ + static IUdpCast* Create(IUdpCastListener* pListener) + { + return HP_Create_UdpCast(pListener); + } + + static void Destroy(IUdpCast* pCast) + { + HP_Destroy_UdpCast(pCast); + } +}; + +/**************************************************/ +/************** HPSocket ָ **************/ + +template class CHPSocketPtr +{ +public: + CHPSocketPtr(_Listener* pListener = nullptr) + { + if(pListener) + m_pObj = _Creator::Create(pListener); + else + m_pObj = nullptr; + } + + ~CHPSocketPtr() + { + Reset(); + } + +public: + CHPSocketPtr& Reset(T* pObj = nullptr) + { + if(pObj != m_pObj) + { + if(m_pObj) + _Creator::Destroy(m_pObj); + + m_pObj = pObj; + } + + return *this; + } + + CHPSocketPtr& Attach(T* pObj) + { + return Reset(pObj); + } + + T* Detach() + { + T* pObj = m_pObj; + m_pObj = nullptr; + + return pObj; + } + + BOOL IsValid () const {return m_pObj != nullptr ;} + T* Get () const {return m_pObj ;} + T* operator -> () const {return m_pObj ;} + operator T* () const {return m_pObj ;} + + CHPSocketPtr& operator = (T* pObj) {return Reset(pObj) ;} + +private: + CHPSocketPtr(const CHPSocketPtr&); + CHPSocketPtr& operator = (const CHPSocketPtr&); + +private: + T* m_pObj; +}; + +// ITcpServer ָ +typedef CHPSocketPtr CTcpServerPtr; +// ITcpAgent ָ +typedef CHPSocketPtr CTcpAgentPtr; +// ITcpClient ָ +typedef CHPSocketPtr CTcpClientPtr; +// ITcpPullServer ָ +typedef CHPSocketPtr CTcpPullServerPtr; +// ITcpPullAgent ָ +typedef CHPSocketPtr CTcpPullAgentPtr; +// ITcpPullClient ָ +typedef CHPSocketPtr CTcpPullClientPtr; +// ITcpPackServer ָ +typedef CHPSocketPtr CTcpPackServerPtr; +// ITcpPackAgent ָ +typedef CHPSocketPtr CTcpPackAgentPtr; +// ITcpPackClient ָ +typedef CHPSocketPtr CTcpPackClientPtr; +// IUdpServer ָ +typedef CHPSocketPtr CUdpServerPtr; +// IUdpClient ָ +typedef CHPSocketPtr CUdpClientPtr; +// IUdpCast ָ +typedef CHPSocketPtr CUdpCastPtr; diff --git a/HP-Socket/Src/HPSocket4C.cpp b/HP-Socket/Src/HPSocket4C.cpp new file mode 100644 index 000000000..4217b2e65 --- /dev/null +++ b/HP-Socket/Src/HPSocket4C.cpp @@ -0,0 +1,2048 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "HPSocket4C.h" +#include "TcpServer.h" +#include "TcpClient.h" +#include "TcpAgent.h" +#include "UdpAgent.h" +#include "TcpPullServer.h" +#include "TcpPullClient.h" +#include "TcpPullAgent.h" +#include "TcpPackServer.h" +#include "TcpPackClient.h" +#include "TcpPackAgent.h" +#include "UdpServer.h" +#include "UdpClient.h" +#include "UdpCast.h" + +#if !defined(_WIN64) + #pragma comment(linker, "/EXPORT:Create_HP_TcpAgent=_Create_HP_TcpAgent@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpAgentListener=_Create_HP_TcpAgentListener@0") + #pragma comment(linker, "/EXPORT:Create_HP_TcpClient=_Create_HP_TcpClient@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpClientListener=_Create_HP_TcpClientListener@0") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPullAgent=_Create_HP_TcpPullAgent@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPullAgentListener=_Create_HP_TcpPullAgentListener@0") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPullClient=_Create_HP_TcpPullClient@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPullClientListener=_Create_HP_TcpPullClientListener@0") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPullServer=_Create_HP_TcpPullServer@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPullServerListener=_Create_HP_TcpPullServerListener@0") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPackAgent=_Create_HP_TcpPackAgent@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPackClient=_Create_HP_TcpPackClient@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpPackServer=_Create_HP_TcpPackServer@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpServer=_Create_HP_TcpServer@4") + #pragma comment(linker, "/EXPORT:Create_HP_TcpServerListener=_Create_HP_TcpServerListener@0") + #pragma comment(linker, "/EXPORT:Create_HP_UdpCast=_Create_HP_UdpCast@4") + #pragma comment(linker, "/EXPORT:Create_HP_UdpCastListener=_Create_HP_UdpCastListener@0") + #pragma comment(linker, "/EXPORT:Create_HP_UdpClient=_Create_HP_UdpClient@4") + #pragma comment(linker, "/EXPORT:Create_HP_UdpClientListener=_Create_HP_UdpClientListener@0") + #pragma comment(linker, "/EXPORT:Create_HP_UdpServer=_Create_HP_UdpServer@4") + #pragma comment(linker, "/EXPORT:Create_HP_UdpServerListener=_Create_HP_UdpServerListener@0") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpAgent=_Destroy_HP_TcpAgent@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpAgentListener=_Destroy_HP_TcpAgentListener@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpClient=_Destroy_HP_TcpClient@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpClientListener=_Destroy_HP_TcpClientListener@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPullAgent=_Destroy_HP_TcpPullAgent@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPullAgentListener=_Destroy_HP_TcpPullAgentListener@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPullClient=_Destroy_HP_TcpPullClient@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPullClientListener=_Destroy_HP_TcpPullClientListener@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPullServer=_Destroy_HP_TcpPullServer@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPullServerListener=_Destroy_HP_TcpPullServerListener@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPackAgent=_Destroy_HP_TcpPackAgent@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPackClient=_Destroy_HP_TcpPackClient@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpPackServer=_Destroy_HP_TcpPackServer@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpServer=_Destroy_HP_TcpServer@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_TcpServerListener=_Destroy_HP_TcpServerListener@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_UdpCast=_Destroy_HP_UdpCast@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_UdpCastListener=_Destroy_HP_UdpCastListener@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_UdpClient=_Destroy_HP_UdpClient@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_UdpClientListener=_Destroy_HP_UdpClientListener@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_UdpServer=_Destroy_HP_UdpServer@4") + #pragma comment(linker, "/EXPORT:Destroy_HP_UdpServerListener=_Destroy_HP_UdpServerListener@4") + #pragma comment(linker, "/EXPORT:HP_Agent_Connect=_HP_Agent_Connect@16") + #pragma comment(linker, "/EXPORT:HP_Agent_Disconnect=_HP_Agent_Disconnect@12") + #pragma comment(linker, "/EXPORT:HP_Agent_DisconnectLongConnections=_HP_Agent_DisconnectLongConnections@12") + #pragma comment(linker, "/EXPORT:HP_Agent_DisconnectSilenceConnections=_HP_Agent_DisconnectSilenceConnections@12") + #pragma comment(linker, "/EXPORT:HP_Agent_GetAllConnectionIDs=_HP_Agent_GetAllConnectionIDs@12") + #pragma comment(linker, "/EXPORT:HP_Agent_GetConnectPeriod=_HP_Agent_GetConnectPeriod@12") + #pragma comment(linker, "/EXPORT:HP_Agent_GetSilencePeriod=_HP_Agent_GetSilencePeriod@12") + #pragma comment(linker, "/EXPORT:HP_Agent_GetConnectionCount=_HP_Agent_GetConnectionCount@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetConnectionExtra=_HP_Agent_GetConnectionExtra@12") + #pragma comment(linker, "/EXPORT:HP_Agent_GetFreeBufferObjHold=_HP_Agent_GetFreeBufferObjHold@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetFreeBufferObjPool=_HP_Agent_GetFreeBufferObjPool@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetFreeSocketObjHold=_HP_Agent_GetFreeSocketObjHold@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetFreeSocketObjLockTime=_HP_Agent_GetFreeSocketObjLockTime@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetFreeSocketObjPool=_HP_Agent_GetFreeSocketObjPool@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetLastError=_HP_Agent_GetLastError@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetLastErrorDesc=_HP_Agent_GetLastErrorDesc@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetLocalAddress=_HP_Agent_GetLocalAddress@20") + #pragma comment(linker, "/EXPORT:HP_Agent_IsMarkSilence=_HP_Agent_IsMarkSilence@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetPendingDataLength=_HP_Agent_GetPendingDataLength@12") + #pragma comment(linker, "/EXPORT:HP_Agent_GetRemoteAddress=_HP_Agent_GetRemoteAddress@20") + #pragma comment(linker, "/EXPORT:HP_Agent_GetSendPolicy=_HP_Agent_GetSendPolicy@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetState=_HP_Agent_GetState@4") + #pragma comment(linker, "/EXPORT:HP_Agent_GetWorkerThreadCount=_HP_Agent_GetWorkerThreadCount@4") + #pragma comment(linker, "/EXPORT:HP_Agent_HasStarted=_HP_Agent_HasStarted@4") + #pragma comment(linker, "/EXPORT:HP_Agent_Send=_HP_Agent_Send@16") + #pragma comment(linker, "/EXPORT:HP_Agent_SendPackets=_HP_Agent_SendPackets@16") + #pragma comment(linker, "/EXPORT:HP_Agent_SendPart=_HP_Agent_SendPart@20") + #pragma comment(linker, "/EXPORT:HP_Agent_SetConnectionExtra=_HP_Agent_SetConnectionExtra@12") + #pragma comment(linker, "/EXPORT:HP_Agent_SetFreeBufferObjHold=_HP_Agent_SetFreeBufferObjHold@8") + #pragma comment(linker, "/EXPORT:HP_Agent_SetFreeBufferObjPool=_HP_Agent_SetFreeBufferObjPool@8") + #pragma comment(linker, "/EXPORT:HP_Agent_SetFreeSocketObjHold=_HP_Agent_SetFreeSocketObjHold@8") + #pragma comment(linker, "/EXPORT:HP_Agent_SetFreeSocketObjLockTime=_HP_Agent_SetFreeSocketObjLockTime@8") + #pragma comment(linker, "/EXPORT:HP_Agent_SetFreeSocketObjPool=_HP_Agent_SetFreeSocketObjPool@8") + #pragma comment(linker, "/EXPORT:HP_Agent_SetMarkSilence=_HP_Agent_SetMarkSilence@8") + #pragma comment(linker, "/EXPORT:HP_Agent_SetSendPolicy=_HP_Agent_SetSendPolicy@8") + #pragma comment(linker, "/EXPORT:HP_Agent_SetWorkerThreadCount=_HP_Agent_SetWorkerThreadCount@8") + #pragma comment(linker, "/EXPORT:HP_Agent_Start=_HP_Agent_Start@12") + #pragma comment(linker, "/EXPORT:HP_Agent_Stop=_HP_Agent_Stop@4") + #pragma comment(linker, "/EXPORT:HP_Client_GetConnectionID=_HP_Client_GetConnectionID@4") + #pragma comment(linker, "/EXPORT:HP_Client_GetExtra=_HP_Client_GetExtra@4") + #pragma comment(linker, "/EXPORT:HP_Client_GetFreeBufferPoolHold=_HP_Client_GetFreeBufferPoolHold@4") + #pragma comment(linker, "/EXPORT:HP_Client_GetFreeBufferPoolSize=_HP_Client_GetFreeBufferPoolSize@4") + #pragma comment(linker, "/EXPORT:HP_Client_GetLastError=_HP_Client_GetLastError@4") + #pragma comment(linker, "/EXPORT:HP_Client_GetLastErrorDesc=_HP_Client_GetLastErrorDesc@4") + #pragma comment(linker, "/EXPORT:HP_Client_GetLocalAddress=_HP_Client_GetLocalAddress@16") + #pragma comment(linker, "/EXPORT:HP_Client_GetPendingDataLength=_HP_Client_GetPendingDataLength@8") + #pragma comment(linker, "/EXPORT:HP_Client_GetState=_HP_Client_GetState@4") + #pragma comment(linker, "/EXPORT:HP_Client_HasStarted=_HP_Client_HasStarted@4") + #pragma comment(linker, "/EXPORT:HP_Client_Send=_HP_Client_Send@12") + #pragma comment(linker, "/EXPORT:HP_Client_SendPackets=_HP_Client_SendPackets@12") + #pragma comment(linker, "/EXPORT:HP_Client_SendPart=_HP_Client_SendPart@16") + #pragma comment(linker, "/EXPORT:HP_Client_SetExtra=_HP_Client_SetExtra@8") + #pragma comment(linker, "/EXPORT:HP_Client_SetFreeBufferPoolHold=_HP_Client_SetFreeBufferPoolHold@8") + #pragma comment(linker, "/EXPORT:HP_Client_SetFreeBufferPoolSize=_HP_Client_SetFreeBufferPoolSize@8") + #pragma comment(linker, "/EXPORT:HP_Client_Start=_HP_Client_Start@16") + #pragma comment(linker, "/EXPORT:HP_Client_Stop=_HP_Client_Stop@4") + #pragma comment(linker, "/EXPORT:HP_Server_Disconnect=_HP_Server_Disconnect@12") + #pragma comment(linker, "/EXPORT:HP_Server_DisconnectLongConnections=_HP_Server_DisconnectLongConnections@12") + #pragma comment(linker, "/EXPORT:HP_Server_DisconnectSilenceConnections=_HP_Server_DisconnectSilenceConnections@12") + #pragma comment(linker, "/EXPORT:HP_Server_GetAllConnectionIDs=_HP_Server_GetAllConnectionIDs@12") + #pragma comment(linker, "/EXPORT:HP_Server_GetConnectPeriod=_HP_Server_GetConnectPeriod@12") + #pragma comment(linker, "/EXPORT:HP_Server_GetSilencePeriod=_HP_Server_GetSilencePeriod@12") + #pragma comment(linker, "/EXPORT:HP_Server_GetConnectionCount=_HP_Server_GetConnectionCount@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetConnectionExtra=_HP_Server_GetConnectionExtra@12") + #pragma comment(linker, "/EXPORT:HP_Server_GetFreeBufferObjHold=_HP_Server_GetFreeBufferObjHold@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetFreeBufferObjPool=_HP_Server_GetFreeBufferObjPool@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetFreeSocketObjHold=_HP_Server_GetFreeSocketObjHold@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetFreeSocketObjLockTime=_HP_Server_GetFreeSocketObjLockTime@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetFreeSocketObjPool=_HP_Server_GetFreeSocketObjPool@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetLastError=_HP_Server_GetLastError@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetLastErrorDesc=_HP_Server_GetLastErrorDesc@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetListenAddress=_HP_Server_GetListenAddress@16") + #pragma comment(linker, "/EXPORT:HP_Server_IsMarkSilence=_HP_Server_IsMarkSilence@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetPendingDataLength=_HP_Server_GetPendingDataLength@12") + #pragma comment(linker, "/EXPORT:HP_Server_GetRemoteAddress=_HP_Server_GetRemoteAddress@20") + #pragma comment(linker, "/EXPORT:HP_Server_GetSendPolicy=_HP_Server_GetSendPolicy@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetState=_HP_Server_GetState@4") + #pragma comment(linker, "/EXPORT:HP_Server_GetWorkerThreadCount=_HP_Server_GetWorkerThreadCount@4") + #pragma comment(linker, "/EXPORT:HP_Server_HasStarted=_HP_Server_HasStarted@4") + #pragma comment(linker, "/EXPORT:HP_Server_Send=_HP_Server_Send@16") + #pragma comment(linker, "/EXPORT:HP_Server_SendPackets=_HP_Server_SendPackets@16") + #pragma comment(linker, "/EXPORT:HP_Server_SendPart=_HP_Server_SendPart@20") + #pragma comment(linker, "/EXPORT:HP_Server_SetConnectionExtra=_HP_Server_SetConnectionExtra@12") + #pragma comment(linker, "/EXPORT:HP_Server_SetFreeBufferObjHold=_HP_Server_SetFreeBufferObjHold@8") + #pragma comment(linker, "/EXPORT:HP_Server_SetFreeBufferObjPool=_HP_Server_SetFreeBufferObjPool@8") + #pragma comment(linker, "/EXPORT:HP_Server_SetFreeSocketObjHold=_HP_Server_SetFreeSocketObjHold@8") + #pragma comment(linker, "/EXPORT:HP_Server_SetFreeSocketObjLockTime=_HP_Server_SetFreeSocketObjLockTime@8") + #pragma comment(linker, "/EXPORT:HP_Server_SetFreeSocketObjPool=_HP_Server_SetFreeSocketObjPool@8") + #pragma comment(linker, "/EXPORT:HP_Server_SetMarkSilence=_HP_Server_SetMarkSilence@8") + #pragma comment(linker, "/EXPORT:HP_Server_SetSendPolicy=_HP_Server_SetSendPolicy@8") + #pragma comment(linker, "/EXPORT:HP_Server_SetWorkerThreadCount=_HP_Server_SetWorkerThreadCount@8") + #pragma comment(linker, "/EXPORT:HP_Server_Start=_HP_Server_Start@12") + #pragma comment(linker, "/EXPORT:HP_Server_Stop=_HP_Server_Stop@4") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Agent_OnConnect=_HP_Set_FN_Agent_OnConnect@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Agent_OnClose=_HP_Set_FN_Agent_OnClose@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Agent_OnPrepareConnect=_HP_Set_FN_Agent_OnPrepareConnect@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Agent_OnPullReceive=_HP_Set_FN_Agent_OnPullReceive@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Agent_OnReceive=_HP_Set_FN_Agent_OnReceive@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Agent_OnSend=_HP_Set_FN_Agent_OnSend@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Agent_OnShutdown=_HP_Set_FN_Agent_OnShutdown@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Client_OnConnect=_HP_Set_FN_Client_OnConnect@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Client_OnClose=_HP_Set_FN_Client_OnClose@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Client_OnPrepareConnect=_HP_Set_FN_Client_OnPrepareConnect@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Client_OnPullReceive=_HP_Set_FN_Client_OnPullReceive@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Client_OnReceive=_HP_Set_FN_Client_OnReceive@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Client_OnSend=_HP_Set_FN_Client_OnSend@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Server_OnAccept=_HP_Set_FN_Server_OnAccept@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Server_OnClose=_HP_Set_FN_Server_OnClose@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Server_OnPrepareListen=_HP_Set_FN_Server_OnPrepareListen@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Server_OnPullReceive=_HP_Set_FN_Server_OnPullReceive@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Server_OnReceive=_HP_Set_FN_Server_OnReceive@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Server_OnSend=_HP_Set_FN_Server_OnSend@8") + #pragma comment(linker, "/EXPORT:HP_Set_FN_Server_OnShutdown=_HP_Set_FN_Server_OnShutdown@8") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_GetKeepAliveInterval=_HP_TcpAgent_GetKeepAliveInterval@4") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_GetKeepAliveTime=_HP_TcpAgent_GetKeepAliveTime@4") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_GetSocketBufferSize=_HP_TcpAgent_GetSocketBufferSize@4") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_IsReuseAddress=_HP_TcpAgent_IsReuseAddress@4") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_SendSmallFile=_HP_TcpAgent_SendSmallFile@20") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_SetKeepAliveInterval=_HP_TcpAgent_SetKeepAliveInterval@8") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_SetKeepAliveTime=_HP_TcpAgent_SetKeepAliveTime@8") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_SetReuseAddress=_HP_TcpAgent_SetReuseAddress@8") + #pragma comment(linker, "/EXPORT:HP_TcpAgent_SetSocketBufferSize=_HP_TcpAgent_SetSocketBufferSize@8") + #pragma comment(linker, "/EXPORT:HP_TcpClient_GetKeepAliveInterval=_HP_TcpClient_GetKeepAliveInterval@4") + #pragma comment(linker, "/EXPORT:HP_TcpClient_GetKeepAliveTime=_HP_TcpClient_GetKeepAliveTime@4") + #pragma comment(linker, "/EXPORT:HP_TcpClient_GetSocketBufferSize=_HP_TcpClient_GetSocketBufferSize@4") + #pragma comment(linker, "/EXPORT:HP_TcpClient_SendSmallFile=_HP_TcpClient_SendSmallFile@16") + #pragma comment(linker, "/EXPORT:HP_TcpClient_SetKeepAliveInterval=_HP_TcpClient_SetKeepAliveInterval@8") + #pragma comment(linker, "/EXPORT:HP_TcpClient_SetKeepAliveTime=_HP_TcpClient_SetKeepAliveTime@8") + #pragma comment(linker, "/EXPORT:HP_TcpClient_SetSocketBufferSize=_HP_TcpClient_SetSocketBufferSize@8") + #pragma comment(linker, "/EXPORT:HP_TcpPullAgent_Fetch=_HP_TcpPullAgent_Fetch@16") + #pragma comment(linker, "/EXPORT:HP_TcpPullAgent_Peek=_HP_TcpPullAgent_Peek@16") + #pragma comment(linker, "/EXPORT:HP_TcpPullClient_Fetch=_HP_TcpPullClient_Fetch@12") + #pragma comment(linker, "/EXPORT:HP_TcpPullClient_Peek=_HP_TcpPullClient_Peek@12") + #pragma comment(linker, "/EXPORT:HP_TcpPullServer_Fetch=_HP_TcpPullServer_Fetch@16") + #pragma comment(linker, "/EXPORT:HP_TcpPullServer_Peek=_HP_TcpPullServer_Peek@16") + #pragma comment(linker, "/EXPORT:HP_TcpPackServer_SetMaxPackSize=_HP_TcpPackServer_SetMaxPackSize@8") + #pragma comment(linker, "/EXPORT:HP_TcpPackServer_SetPackHeaderFlag=_HP_TcpPackServer_SetPackHeaderFlag@8") + #pragma comment(linker, "/EXPORT:HP_TcpPackServer_GetMaxPackSize=_HP_TcpPackServer_GetMaxPackSize@4") + #pragma comment(linker, "/EXPORT:HP_TcpPackServer_GetPackHeaderFlag=_HP_TcpPackServer_GetPackHeaderFlag@4") + #pragma comment(linker, "/EXPORT:HP_TcpPackAgent_SetMaxPackSize=_HP_TcpPackAgent_SetMaxPackSize@8") + #pragma comment(linker, "/EXPORT:HP_TcpPackAgent_SetPackHeaderFlag=_HP_TcpPackAgent_SetPackHeaderFlag@8") + #pragma comment(linker, "/EXPORT:HP_TcpPackAgent_GetMaxPackSize=_HP_TcpPackAgent_GetMaxPackSize@4") + #pragma comment(linker, "/EXPORT:HP_TcpPackAgent_GetPackHeaderFlag=_HP_TcpPackAgent_GetPackHeaderFlag@4") + #pragma comment(linker, "/EXPORT:HP_TcpPackClient_SetMaxPackSize=_HP_TcpPackClient_SetMaxPackSize@8") + #pragma comment(linker, "/EXPORT:HP_TcpPackClient_SetPackHeaderFlag=_HP_TcpPackClient_SetPackHeaderFlag@8") + #pragma comment(linker, "/EXPORT:HP_TcpPackClient_GetMaxPackSize=_HP_TcpPackClient_GetMaxPackSize@4") + #pragma comment(linker, "/EXPORT:HP_TcpPackClient_GetPackHeaderFlag=_HP_TcpPackClient_GetPackHeaderFlag@4") + #pragma comment(linker, "/EXPORT:HP_TcpServer_GetAcceptSocketCount=_HP_TcpServer_GetAcceptSocketCount@4") + #pragma comment(linker, "/EXPORT:HP_TcpServer_GetKeepAliveInterval=_HP_TcpServer_GetKeepAliveInterval@4") + #pragma comment(linker, "/EXPORT:HP_TcpServer_GetKeepAliveTime=_HP_TcpServer_GetKeepAliveTime@4") + #pragma comment(linker, "/EXPORT:HP_TcpServer_GetSocketBufferSize=_HP_TcpServer_GetSocketBufferSize@4") + #pragma comment(linker, "/EXPORT:HP_TcpServer_GetSocketListenQueue=_HP_TcpServer_GetSocketListenQueue@4") + #pragma comment(linker, "/EXPORT:HP_TcpServer_SendSmallFile=_HP_TcpServer_SendSmallFile@20") + #pragma comment(linker, "/EXPORT:HP_TcpServer_SetAcceptSocketCount=_HP_TcpServer_SetAcceptSocketCount@8") + #pragma comment(linker, "/EXPORT:HP_TcpServer_SetKeepAliveInterval=_HP_TcpServer_SetKeepAliveInterval@8") + #pragma comment(linker, "/EXPORT:HP_TcpServer_SetKeepAliveTime=_HP_TcpServer_SetKeepAliveTime@8") + #pragma comment(linker, "/EXPORT:HP_TcpServer_SetSocketBufferSize=_HP_TcpServer_SetSocketBufferSize@8") + #pragma comment(linker, "/EXPORT:HP_TcpServer_SetSocketListenQueue=_HP_TcpServer_SetSocketListenQueue@8") + #pragma comment(linker, "/EXPORT:HP_UdpCast_GetBindAdddress=_HP_UdpCast_GetBindAdddress@4") + #pragma comment(linker, "/EXPORT:HP_UdpCast_GetCastMode=_HP_UdpCast_GetCastMode@4") + #pragma comment(linker, "/EXPORT:HP_UdpCast_GetMaxDatagramSize=_HP_UdpCast_GetMaxDatagramSize@4") + #pragma comment(linker, "/EXPORT:HP_UdpCast_GetMultiCastTtl=_HP_UdpCast_GetMultiCastTtl@4") + #pragma comment(linker, "/EXPORT:HP_UdpCast_GetRemoteAddress=_HP_UdpCast_GetRemoteAddress@16") + #pragma comment(linker, "/EXPORT:HP_UdpCast_IsMultiCastLoop=_HP_UdpCast_IsMultiCastLoop@4") + #pragma comment(linker, "/EXPORT:HP_UdpCast_IsReuseAddress=_HP_UdpCast_IsReuseAddress@4") + #pragma comment(linker, "/EXPORT:HP_UdpCast_SetBindAdddress=_HP_UdpCast_SetBindAdddress@8") + #pragma comment(linker, "/EXPORT:HP_UdpCast_SetCastMode=_HP_UdpCast_SetCastMode@8") + #pragma comment(linker, "/EXPORT:HP_UdpCast_SetMaxDatagramSize=_HP_UdpCast_SetMaxDatagramSize@8") + #pragma comment(linker, "/EXPORT:HP_UdpCast_SetMultiCastLoop=_HP_UdpCast_SetMultiCastLoop@8") + #pragma comment(linker, "/EXPORT:HP_UdpCast_SetMultiCastTtl=_HP_UdpCast_SetMultiCastTtl@8") + #pragma comment(linker, "/EXPORT:HP_UdpCast_SetReuseAddress=_HP_UdpCast_SetReuseAddress@8") + #pragma comment(linker, "/EXPORT:HP_UdpClient_GetDetectAttempts=_HP_UdpClient_GetDetectAttempts@4") + #pragma comment(linker, "/EXPORT:HP_UdpClient_GetDetectInterval=_HP_UdpClient_GetDetectInterval@4") + #pragma comment(linker, "/EXPORT:HP_UdpClient_GetMaxDatagramSize=_HP_UdpClient_GetMaxDatagramSize@4") + #pragma comment(linker, "/EXPORT:HP_UdpClient_SetDetectAttempts=_HP_UdpClient_SetDetectAttempts@8") + #pragma comment(linker, "/EXPORT:HP_UdpClient_SetDetectInterval=_HP_UdpClient_SetDetectInterval@8") + #pragma comment(linker, "/EXPORT:HP_UdpClient_SetMaxDatagramSize=_HP_UdpClient_SetMaxDatagramSize@8") + #pragma comment(linker, "/EXPORT:HP_UdpServer_GetDetectAttempts=_HP_UdpServer_GetDetectAttempts@4") + #pragma comment(linker, "/EXPORT:HP_UdpServer_GetDetectInterval=_HP_UdpServer_GetDetectInterval@4") + #pragma comment(linker, "/EXPORT:HP_UdpServer_GetMaxDatagramSize=_HP_UdpServer_GetMaxDatagramSize@4") + #pragma comment(linker, "/EXPORT:HP_UdpServer_GetPostReceiveCount=_HP_UdpServer_GetPostReceiveCount@4") + #pragma comment(linker, "/EXPORT:HP_UdpServer_SetDetectAttempts=_HP_UdpServer_SetDetectAttempts@8") + #pragma comment(linker, "/EXPORT:HP_UdpServer_SetDetectInterval=_HP_UdpServer_SetDetectInterval@8") + #pragma comment(linker, "/EXPORT:HP_UdpServer_SetMaxDatagramSize=_HP_UdpServer_SetMaxDatagramSize@8") + #pragma comment(linker, "/EXPORT:HP_UdpServer_SetPostReceiveCount=_HP_UdpServer_SetPostReceiveCount@8") + #pragma comment(linker, "/EXPORT:HP_GetSocketErrorDesc=_HP_GetSocketErrorDesc@4") + #pragma comment(linker, "/EXPORT:SYS_GetLastError=_SYS_GetLastError@0") + #pragma comment(linker, "/EXPORT:SYS_GetSocketOption=_SYS_GetSocketOption@20") + #pragma comment(linker, "/EXPORT:SYS_IoctlSocket=_SYS_IoctlSocket@12") + #pragma comment(linker, "/EXPORT:SYS_SetSocketOption=_SYS_SetSocketOption@20") + #pragma comment(linker, "/EXPORT:SYS_WSAGetLastError=_SYS_WSAGetLastError@0") + #pragma comment(linker, "/EXPORT:SYS_WSAIoctl=_SYS_WSAIoctl@28") +#endif + +class C_HP_Object +{ +public: + + inline static IServer* ToServer(HP_Server pServer) + { + return (IServer*)((char*)pServer + ((C_HP_Object*)pServer)->offset); + } + + inline static IAgent* ToAgent(HP_Agent pAgent) + { + return (IAgent*)((char*)pAgent + ((C_HP_Object*)pAgent)->offset); + } + + inline static IClient* ToClient(HP_Client pClient) + { + return (IClient*)((char*)pClient + ((C_HP_Object*)pClient)->offset); + } + + inline static IPullSocket* ToPullSocket(HP_PullSocket pPullSocket) + { + return (IPullSocket*)((char*)pPullSocket + sizeof(C_HP_Object)); + } + + inline static IPullClient* ToPullClient(HP_PullClient pPullClient) + { + return (IPullClient*)((char*)pPullClient + sizeof(C_HP_Object)); + } + + inline static IPackSocket* ToPackSocket(HP_PackSocket pPackSocket) + { + return (IPackSocket*)((char*)pPackSocket + sizeof(C_HP_Object)); + } + + inline static IPackClient* ToPackClient(HP_PackClient pPackClient) + { + return (IPackClient*)((char*)pPackClient + sizeof(C_HP_Object)); + } + + inline static HP_Server FromServer(IServer* pServer) + { + C_HP_Object* pResult = (C_HP_Object*)((char*)pServer - sizeof(C_HP_Object)); + + if(pResult->offset != sizeof(C_HP_Object)) + pResult = (C_HP_Object*)((char*)pResult - sizeof(HP_Object)); + + return (HP_Object)pResult; + } + + inline static HP_Agent FromAgent(IAgent* pAgent) + { + C_HP_Object* pResult = (C_HP_Object*)((char*)pAgent - sizeof(C_HP_Object)); + + if(pResult->offset != sizeof(C_HP_Object)) + pResult = (C_HP_Object*)((char*)pResult - sizeof(HP_Object)); + + return (HP_Object)pResult; + } + + inline static HP_Client FromClient(IClient* pClient) + { + C_HP_Object* pResult = (C_HP_Object*)((char*)pClient - sizeof(C_HP_Object)); + + if(pResult->offset != sizeof(C_HP_Object)) + pResult = (C_HP_Object*)((char*)pResult - sizeof(HP_Object)); + + return (HP_Object)pResult; + } + + inline static HP_PullSocket FromPullSocket(IPullSocket* pPullSocket) + { + return (HP_PullSocket)((char*)pPullSocket - sizeof(IPullSocket)); + } + + inline static HP_PullClient FromPullClient(IPullClient* pPullClient) + { + return (HP_PullClient)((char*)pPullClient - sizeof(IPullClient)); + } + + inline static HP_PackSocket FromPackSocket(IPackSocket* pPackSocket) + { + return (HP_PackSocket)((char*)pPackSocket - sizeof(IPackSocket)); + } + + inline static HP_PackClient FromPackClient(IPackClient* pPackClient) + { + return (HP_PackClient)((char*)pPackClient - sizeof(IPackClient)); + } + +public: + + inline static ITcpServer* ToTcpServer(HP_TcpServer pServer) + { + return (ITcpServer*)ToServer(pServer); + } + + inline static IUdpServer* ToUdpServer(HP_UdpServer pServer) + { + return (IUdpServer*)ToServer(pServer); + } + + inline static ITcpAgent* ToTcpAgent(HP_TcpAgent pAgent) + { + return (ITcpAgent*)ToAgent(pAgent); + } + + inline static IUdpAgent* ToUdpAgent(HP_UdpAgent pAgent) + { + return (IUdpAgent*)ToAgent(pAgent); + } + + inline static ITcpClient* ToTcpClient(HP_TcpClient pClient) + { + return (ITcpClient*)ToClient(pClient); + } + + inline static IUdpClient* ToUdpClient(HP_UdpClient pClient) + { + return (IUdpClient*)ToClient(pClient); + } + + inline static IUdpCast* ToUdpCast(HP_UdpCast pCast) + { + return (IUdpCast*)ToClient(pCast); + } + +protected: + + C_HP_Object(int k = 0) : offset(k + sizeof(C_HP_Object)) {} + + virtual ~C_HP_Object() {} + +private: + + size_t offset; +}; + +class C_HP_ServerListener : public IServerListener +{ +public: + virtual EnHandleResult OnPrepareListen(UINT_PTR soListen) + { + return (m_fnOnPrepareListen) + ? (EnHandleResult)m_fnOnPrepareListen(soListen) + : HR_IGNORE; + } + + virtual EnHandleResult OnAccept(CONNID dwConnID, UINT_PTR soClient) + { + ASSERT(m_fnOnAccept); + + return (m_fnOnAccept) + ? (EnHandleResult)m_fnOnAccept(dwConnID, soClient) + : HR_IGNORE; + } + + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) + { + return (m_fnOnSend) + ? (EnHandleResult)m_fnOnSend(dwConnID, pData, iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) + { + ASSERT(m_fnOnReceive); + + return (m_fnOnReceive) + ? (EnHandleResult)m_fnOnReceive(dwConnID, pData, iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) + { + ASSERT(m_fnOnPullReceive); + + return (m_fnOnPullReceive) + ? (EnHandleResult)m_fnOnPullReceive(dwConnID, iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) + { + ASSERT(m_fnOnClose); + + return (m_fnOnClose) + ? (EnHandleResult)m_fnOnClose(dwConnID, (En_HP_SocketOperation)enOperation, iErrorCode) + : HR_IGNORE; + } + + virtual EnHandleResult OnShutdown() + { + return (m_fnOnShutdown) + ? (EnHandleResult)m_fnOnShutdown() + : HR_IGNORE; + } + +public: + C_HP_ServerListener() + : m_fnOnPrepareListen (nullptr) + , m_fnOnAccept (nullptr) + , m_fnOnSend (nullptr) + , m_fnOnReceive (nullptr) + , m_fnOnPullReceive (nullptr) + , m_fnOnClose (nullptr) + , m_fnOnShutdown (nullptr) + { + } + +public: + HP_FN_Server_OnPrepareListen m_fnOnPrepareListen ; + HP_FN_Server_OnAccept m_fnOnAccept ; + HP_FN_Server_OnSend m_fnOnSend ; + HP_FN_Server_OnReceive m_fnOnReceive ; + HP_FN_Server_OnPullReceive m_fnOnPullReceive ; + HP_FN_Server_OnClose m_fnOnClose ; + HP_FN_Server_OnShutdown m_fnOnShutdown ; +}; + +class C_HP_AgentListener : public IAgentListener +{ +public: + virtual EnHandleResult OnPrepareConnect(CONNID dwConnID, UINT_PTR socket) + { + return (m_fnOnPrepareConnect) + ? (EnHandleResult)m_fnOnPrepareConnect(dwConnID, socket) + : HR_IGNORE; + } + + virtual EnHandleResult OnConnect(CONNID dwConnID) + { + ASSERT(m_fnOnConnect); + + return (m_fnOnConnect) + ? (EnHandleResult)m_fnOnConnect(dwConnID) + : HR_IGNORE; + } + + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) + { + return (m_fnOnSend) + ? (EnHandleResult)m_fnOnSend(dwConnID, pData, iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) + { + ASSERT(m_fnOnReceive); + + return (m_fnOnReceive) + ? (EnHandleResult)m_fnOnReceive(dwConnID, pData, iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) + { + ASSERT(m_fnOnPullReceive); + + return (m_fnOnPullReceive) + ? (EnHandleResult)m_fnOnPullReceive(dwConnID, iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) + { + ASSERT(m_fnOnClose); + + return (m_fnOnClose) + ? (EnHandleResult)m_fnOnClose(dwConnID, (En_HP_SocketOperation)enOperation, iErrorCode) + : HR_IGNORE; + } + + virtual EnHandleResult OnShutdown() + { + return (m_fnOnShutdown) + ? (EnHandleResult)m_fnOnShutdown() + : HR_IGNORE; + } + +public: + C_HP_AgentListener() + : m_fnOnPrepareConnect (nullptr) + , m_fnOnConnect (nullptr) + , m_fnOnSend (nullptr) + , m_fnOnReceive (nullptr) + , m_fnOnPullReceive (nullptr) + , m_fnOnClose (nullptr) + , m_fnOnShutdown (nullptr) + { + } + +public: + HP_FN_Agent_OnPrepareConnect m_fnOnPrepareConnect; + HP_FN_Agent_OnConnect m_fnOnConnect ; + HP_FN_Agent_OnSend m_fnOnSend ; + HP_FN_Agent_OnReceive m_fnOnReceive ; + HP_FN_Agent_OnPullReceive m_fnOnPullReceive ; + HP_FN_Agent_OnClose m_fnOnClose ; + HP_FN_Agent_OnShutdown m_fnOnShutdown ; +}; + +class C_HP_ClientListener : public IClientListener +{ +public: + virtual EnHandleResult OnPrepareConnect(IClient* pClient, UINT_PTR socket) + { + return (m_fnOnPrepareConnect) + ? (EnHandleResult)m_fnOnPrepareConnect(C_HP_Object::FromClient(pClient), socket) + : HR_IGNORE; + } + + virtual EnHandleResult OnConnect(IClient* pClient) + { + ASSERT(m_fnOnConnect); + + return (m_fnOnConnect) + ? (EnHandleResult)m_fnOnConnect(C_HP_Object::FromClient(pClient)) + : HR_IGNORE; + } + + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) + { + return (m_fnOnSend) + ? (EnHandleResult)m_fnOnSend(C_HP_Object::FromClient(pClient), pData, iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength) + { + ASSERT(m_fnOnReceive); + + return (m_fnOnReceive) + ? (EnHandleResult)m_fnOnReceive(C_HP_Object::FromClient(pClient), pData, iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) + { + ASSERT(m_fnOnPullReceive); + + return (m_fnOnPullReceive) + ? (EnHandleResult)m_fnOnPullReceive(C_HP_Object::FromClient(pClient), iLength) + : HR_IGNORE; + } + + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) + { + ASSERT(m_fnOnClose); + + return (m_fnOnClose) + ? (EnHandleResult)m_fnOnClose(C_HP_Object::FromClient(pClient), (En_HP_SocketOperation)enOperation, iErrorCode) + : HR_IGNORE; + } + +public: + C_HP_ClientListener() + : m_fnOnPrepareConnect (nullptr) + , m_fnOnConnect (nullptr) + , m_fnOnSend (nullptr) + , m_fnOnReceive (nullptr) + , m_fnOnPullReceive (nullptr) + , m_fnOnClose (nullptr) + { + } + +public: + HP_FN_Client_OnPrepareConnect m_fnOnPrepareConnect; + HP_FN_Client_OnConnect m_fnOnConnect ; + HP_FN_Client_OnSend m_fnOnSend ; + HP_FN_Client_OnReceive m_fnOnReceive ; + HP_FN_Client_OnPullReceive m_fnOnPullReceive ; + HP_FN_Client_OnClose m_fnOnClose ; +}; + +class C_HP_TcpServer : public C_HP_Object, public CTcpServer +{ +public: + C_HP_TcpServer(ITcpServerListener* pListener) : CTcpServer(pListener) {} +}; + +class C_HP_TcpPullServer : public C_HP_Object, public CTcpPullServer +{ +public: + C_HP_TcpPullServer(ITcpServerListener* pListener) : C_HP_Object(sizeof(IPullSocket)), CTcpPullServer(pListener) {} +}; + +class C_HP_TcpPackServer : public C_HP_Object, public CTcpPackServer +{ +public: + C_HP_TcpPackServer(ITcpServerListener* pListener) : C_HP_Object(sizeof(IPackSocket)), CTcpPackServer(pListener) {} +}; + +class C_HP_UdpServer : public C_HP_Object, public CUdpServer +{ +public: + C_HP_UdpServer(IUdpServerListener* pListener) : CUdpServer(pListener) {} +}; + +class C_HP_TcpAgent : public C_HP_Object, public CTcpAgent +{ +public: + C_HP_TcpAgent(ITcpAgentListener* pListener) : CTcpAgent(pListener) {} +}; + +class C_HP_TcpPullAgent : public C_HP_Object, public CTcpPullAgent +{ +public: + C_HP_TcpPullAgent(ITcpAgentListener* pListener) : C_HP_Object(sizeof(IPullSocket)), CTcpPullAgent(pListener) {} +}; + +class C_HP_TcpPackAgent : public C_HP_Object, public CTcpPackAgent +{ +public: + C_HP_TcpPackAgent(ITcpAgentListener* pListener) : C_HP_Object(sizeof(IPackSocket)), CTcpPackAgent(pListener) {} +}; + +class C_HP_UdpAgent : public C_HP_Object, public CUdpAgent +{ +public: + C_HP_UdpAgent(IUdpAgentListener* pListener) : CUdpAgent(pListener) {} +}; + +class C_HP_TcpClient : public C_HP_Object, public CTcpClient +{ +public: + C_HP_TcpClient(ITcpClientListener* pListener) : CTcpClient(pListener) {} +}; + +class C_HP_TcpPullClient : public C_HP_Object, public CTcpPullClient +{ +public: + C_HP_TcpPullClient(ITcpClientListener* pListener) : C_HP_Object(sizeof(IPullClient)), CTcpPullClient(pListener) {} +}; + +class C_HP_TcpPackClient : public C_HP_Object, public CTcpPackClient +{ +public: + C_HP_TcpPackClient(ITcpClientListener* pListener) : C_HP_Object(sizeof(IPackClient)), CTcpPackClient(pListener) {} +}; + +class C_HP_UdpClient : public C_HP_Object, public CUdpClient +{ +public: + C_HP_UdpClient(IUdpClientListener* pListener) : CUdpClient(pListener) {} +}; + +class C_HP_UdpCast : public C_HP_Object, public CUdpCast +{ +public: + C_HP_UdpCast(IUdpCastListener* pListener) : CUdpCast(pListener) {} +}; + +/****************************************************/ +/************** HPSocket4C.dll **************/ + +HPSOCKET_API HP_TcpServer __stdcall Create_HP_TcpServer(HP_TcpServerListener pListener) +{ + return (HP_TcpServer)(new C_HP_TcpServer((ITcpServerListener*)pListener)); +} + +HPSOCKET_API HP_TcpAgent __stdcall Create_HP_TcpAgent(HP_TcpAgentListener pListener) +{ + return (HP_TcpAgent)(new C_HP_TcpAgent((ITcpAgentListener*)pListener)); +} + +HPSOCKET_API HP_TcpClient __stdcall Create_HP_TcpClient(HP_TcpClientListener pListener) +{ + return (HP_TcpClient)(new C_HP_TcpClient((ITcpClientListener*)pListener)); +} + +HPSOCKET_API HP_TcpPullServer __stdcall Create_HP_TcpPullServer(HP_TcpPullServerListener pListener) +{ + return (HP_TcpPullServer)(new C_HP_TcpPullServer((ITcpServerListener*)pListener)); +} + +HPSOCKET_API HP_TcpPullAgent __stdcall Create_HP_TcpPullAgent(HP_TcpPullAgentListener pListener) +{ + return (HP_TcpPullAgent)(new C_HP_TcpPullAgent((ITcpAgentListener*)pListener)); +} + +HPSOCKET_API HP_TcpPullClient __stdcall Create_HP_TcpPullClient(HP_TcpPullClientListener pListener) +{ + return (HP_TcpPullClient)(new C_HP_TcpPullClient((ITcpClientListener*)pListener)); +} + +HPSOCKET_API HP_TcpPackServer __stdcall Create_HP_TcpPackServer(HP_TcpServerListener pListener) +{ + return (HP_TcpPackServer)(new C_HP_TcpPackServer((ITcpServerListener*)pListener)); +} + +HPSOCKET_API HP_TcpPackAgent __stdcall Create_HP_TcpPackAgent(HP_TcpAgentListener pListener) +{ + return (HP_TcpPackAgent)(new C_HP_TcpPackAgent((ITcpAgentListener*)pListener)); +} + +HPSOCKET_API HP_TcpPackClient __stdcall Create_HP_TcpPackClient(HP_TcpClientListener pListener) +{ + return (HP_TcpPackClient)(new C_HP_TcpPackClient((ITcpClientListener*)pListener)); +} + +HPSOCKET_API HP_UdpServer __stdcall Create_HP_UdpServer(HP_UdpServerListener pListener) +{ + return (HP_UdpServer)(new C_HP_UdpServer((IUdpServerListener*)pListener)); +} + +HPSOCKET_API HP_UdpAgent __stdcall Create_HP_UdpAgent(HP_UdpAgentListener pListener) +{ + return (HP_UdpAgent)(new C_HP_UdpAgent((IUdpAgentListener*)pListener)); +} + +HPSOCKET_API HP_UdpClient __stdcall Create_HP_UdpClient(HP_UdpClientListener pListener) +{ + return (HP_UdpClient)(new C_HP_UdpClient((IUdpClientListener*)pListener)); +} + +HPSOCKET_API HP_UdpCast __stdcall Create_HP_UdpCast(HP_UdpCastListener pListener) +{ + return (HP_UdpCast)(new C_HP_UdpCast((IUdpCastListener*)pListener)); +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpServer(HP_TcpServer pServer) +{ + delete (C_HP_TcpServer*)pServer; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpAgent(HP_TcpAgent pAgent) +{ + delete (C_HP_TcpAgent*)pAgent; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpClient(HP_TcpClient pClient) +{ + delete (C_HP_TcpClient*)pClient; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPullServer(HP_TcpPullServer pServer) +{ + delete (C_HP_TcpPullServer*)pServer; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPullAgent(HP_TcpPullAgent pAgent) +{ + delete (C_HP_TcpPullAgent*)pAgent; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPullClient(HP_TcpPullClient pClient) +{ + delete (C_HP_TcpPullClient*)pClient; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPackServer(HP_TcpPackServer pServer) +{ + delete (C_HP_TcpPackServer*)pServer; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPackAgent(HP_TcpPackAgent pAgent) +{ + delete (C_HP_TcpPackAgent*)pAgent; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPackClient(HP_TcpPackClient pClient) +{ + delete (C_HP_TcpPackClient*)pClient; +} + +HPSOCKET_API void __stdcall Destroy_HP_UdpServer(HP_UdpServer pServer) +{ + delete (C_HP_UdpServer*)pServer; +} + +HPSOCKET_API void __stdcall Destroy_HP_UdpAgent(HP_UdpAgent pAgent) +{ + delete (C_HP_UdpAgent*)pAgent; +} + +HPSOCKET_API void __stdcall Destroy_HP_UdpClient(HP_UdpClient pClient) +{ + delete (C_HP_UdpClient*)pClient; +} + +HPSOCKET_API void __stdcall Destroy_HP_UdpCast(HP_UdpCast pCast) +{ + delete (C_HP_UdpCast*)pCast; +} + +HPSOCKET_API HP_TcpServerListener __stdcall Create_HP_TcpServerListener() +{ + return (HP_TcpServerListener)(new C_HP_ServerListener); +} + +HPSOCKET_API HP_TcpAgentListener __stdcall Create_HP_TcpAgentListener() +{ + return (HP_TcpAgentListener)(new C_HP_AgentListener); +} + +HPSOCKET_API HP_TcpClientListener __stdcall Create_HP_TcpClientListener() +{ + return (HP_TcpClientListener)(new C_HP_ClientListener); +} + +HPSOCKET_API HP_TcpPullServerListener __stdcall Create_HP_TcpPullServerListener() +{ + return (HP_TcpPullServerListener)(new C_HP_ServerListener); +} + +HPSOCKET_API HP_TcpPullAgentListener __stdcall Create_HP_TcpPullAgentListener() +{ + return (HP_TcpPullAgentListener)(new C_HP_AgentListener); +} + +HPSOCKET_API HP_TcpPullClientListener __stdcall Create_HP_TcpPullClientListener() +{ + return (HP_TcpPullClientListener)(new C_HP_ClientListener); +} + +HPSOCKET_API HP_UdpServerListener __stdcall Create_HP_UdpServerListener() +{ + return (HP_UdpServerListener)(new C_HP_ServerListener); +} + +HPSOCKET_API HP_UdpAgentListener __stdcall Create_HP_UdpAgentListener() +{ + return (HP_UdpAgentListener)(new C_HP_AgentListener); +} + + +HPSOCKET_API HP_UdpClientListener __stdcall Create_HP_UdpClientListener() +{ + return (HP_UdpClientListener)(new C_HP_ClientListener); +} + +HPSOCKET_API HP_UdpCastListener __stdcall Create_HP_UdpCastListener() +{ + return (HP_UdpCastListener)(new C_HP_ClientListener); +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpServerListener(HP_TcpServerListener pListener) +{ + delete (C_HP_ServerListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpAgentListener(HP_TcpAgentListener pListener) +{ + delete (C_HP_AgentListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpClientListener(HP_TcpClientListener pListener) +{ + delete (C_HP_ClientListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPullServerListener(HP_TcpPullServerListener pListener) +{ + delete (C_HP_ServerListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPullAgentListener(HP_TcpPullAgentListener pListener) +{ + delete (C_HP_AgentListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_TcpPullClientListener(HP_TcpPullClientListener pListener) +{ + delete (C_HP_ClientListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_UdpServerListener(HP_UdpServerListener pListener) +{ + delete (C_HP_ServerListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_UdpAgentListener(HP_UdpAgentListener pListener) +{ + delete (C_HP_AgentListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_UdpClientListener(HP_UdpClientListener pListener) +{ + delete (C_HP_ClientListener*)pListener; +} + +HPSOCKET_API void __stdcall Destroy_HP_UdpCastListener(HP_UdpCastListener pListener) +{ + delete (C_HP_ClientListener*)pListener; +} + +/**********************************************************************************/ +/***************************** Server ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnPrepareListen(HP_ServerListener pListener, HP_FN_Server_OnPrepareListen fn) +{ + ((C_HP_ServerListener*)pListener)->m_fnOnPrepareListen = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnAccept(HP_ServerListener pListener, HP_FN_Server_OnAccept fn) +{ + ((C_HP_ServerListener*)pListener)->m_fnOnAccept = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnSend(HP_ServerListener pListener, HP_FN_Server_OnSend fn) +{ + ((C_HP_ServerListener*)pListener)->m_fnOnSend = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnReceive(HP_ServerListener pListener, HP_FN_Server_OnReceive fn) +{ + ((C_HP_ServerListener*)pListener)->m_fnOnReceive = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnPullReceive(HP_ServerListener pListener, HP_FN_Server_OnPullReceive fn) +{ + ((C_HP_ServerListener*)pListener)->m_fnOnPullReceive = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnClose(HP_ServerListener pListener, HP_FN_Server_OnClose fn) +{ + ((C_HP_ServerListener*)pListener)->m_fnOnClose = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnShutdown(HP_ServerListener pListener, HP_FN_Server_OnShutdown fn) +{ + ((C_HP_ServerListener*)pListener)->m_fnOnShutdown = fn; +} + +/**********************************************************************************/ +/***************************** Agent ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnPrepareConnect(HP_AgentListener pListener, HP_FN_Agent_OnPrepareConnect fn) +{ + ((C_HP_AgentListener*)pListener)->m_fnOnPrepareConnect = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnConnect(HP_AgentListener pListener, HP_FN_Agent_OnConnect fn) +{ + ((C_HP_AgentListener*)pListener)->m_fnOnConnect = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnSend(HP_AgentListener pListener, HP_FN_Agent_OnSend fn) +{ + ((C_HP_AgentListener*)pListener)->m_fnOnSend = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnReceive(HP_AgentListener pListener, HP_FN_Agent_OnReceive fn) +{ + ((C_HP_AgentListener*)pListener)->m_fnOnReceive = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnPullReceive(HP_AgentListener pListener, HP_FN_Agent_OnPullReceive fn) +{ + ((C_HP_AgentListener*)pListener)->m_fnOnPullReceive = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnClose(HP_AgentListener pListener, HP_FN_Agent_OnClose fn) +{ + ((C_HP_AgentListener*)pListener)->m_fnOnClose = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnShutdown(HP_AgentListener pListener, HP_FN_Agent_OnShutdown fn) +{ + ((C_HP_AgentListener*)pListener)->m_fnOnShutdown = fn; +} + +/**********************************************************************************/ +/***************************** Client ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnPrepareConnect(HP_ClientListener pListener, HP_FN_Client_OnPrepareConnect fn) +{ + ((C_HP_ClientListener*)pListener)->m_fnOnPrepareConnect = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnConnect(HP_ClientListener pListener, HP_FN_Client_OnConnect fn) +{ + ((C_HP_ClientListener*)pListener)->m_fnOnConnect = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnSend(HP_ClientListener pListener, HP_FN_Client_OnSend fn) +{ + ((C_HP_ClientListener*)pListener)->m_fnOnSend = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnReceive(HP_ClientListener pListener, HP_FN_Client_OnReceive fn) +{ + ((C_HP_ClientListener*)pListener)->m_fnOnReceive = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnPullReceive(HP_ClientListener pListener, HP_FN_Client_OnPullReceive fn) +{ + ((C_HP_ClientListener*)pListener)->m_fnOnPullReceive = fn; +} + +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnClose(HP_ClientListener pListener, HP_FN_Client_OnClose fn) +{ + ((C_HP_ClientListener*)pListener)->m_fnOnClose = fn; +} + +/**************************************************************************/ +/***************************** Server *****************************/ + +HPSOCKET_API BOOL __stdcall HP_Server_Start(HP_Server pServer, LPCTSTR pszBindAddress, USHORT usPort) +{ + return C_HP_Object::ToServer(pServer)->Start(pszBindAddress, usPort); +} + +HPSOCKET_API BOOL __stdcall HP_Server_Stop(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->Stop(); +} + +HPSOCKET_API BOOL __stdcall HP_Server_Send(HP_Server pServer, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength) +{ + return C_HP_Object::ToServer(pServer)->Send(dwConnID, pBuffer, iLength); +} + +HPSOCKET_API BOOL __stdcall HP_Server_SendPart(HP_Server pServer, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset) +{ + return C_HP_Object::ToServer(pServer)->Send(dwConnID, pBuffer, iLength, iOffset); +} + +HPSOCKET_API BOOL __stdcall HP_Server_SendPackets(HP_Server pServer, HP_CONNID dwConnID, const WSABUF pBuffers[], int iCount) +{ + return C_HP_Object::ToServer(pServer)->SendPackets(dwConnID, pBuffers, iCount); +} + +HPSOCKET_API BOOL __stdcall HP_Server_Disconnect(HP_Server pServer, HP_CONNID dwConnID, BOOL bForce) +{ + return C_HP_Object::ToServer(pServer)->Disconnect(dwConnID, bForce); +} + +HPSOCKET_API BOOL __stdcall HP_Server_DisconnectLongConnections(HP_Server pServer, DWORD dwPeriod, BOOL bForce) +{ + return C_HP_Object::ToServer(pServer)->DisconnectLongConnections(dwPeriod, bForce); +} + +HPSOCKET_API BOOL __stdcall HP_Server_DisconnectSilenceConnections(HP_Server pServer, DWORD dwPeriod, BOOL bForce) +{ + return C_HP_Object::ToServer(pServer)->DisconnectSilenceConnections(dwPeriod, bForce); +} + +/******************************************************************************/ +/***************************** Server Էʷ *****************************/ + +HPSOCKET_API BOOL __stdcall HP_Server_SetConnectionExtra(HP_Server pServer, HP_CONNID dwConnID, PVOID pExtra) +{ + return C_HP_Object::ToServer(pServer)->SetConnectionExtra(dwConnID, pExtra); +} + +HPSOCKET_API BOOL __stdcall HP_Server_GetConnectionExtra(HP_Server pServer, HP_CONNID dwConnID, PVOID* ppExtra) +{ + return C_HP_Object::ToServer(pServer)->GetConnectionExtra(dwConnID, ppExtra); +} + +HPSOCKET_API BOOL __stdcall HP_Server_HasStarted(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->HasStarted(); +} + +HPSOCKET_API En_HP_ServiceState __stdcall HP_Server_GetState(HP_Server pServer) +{ + return (En_HP_ServiceState)C_HP_Object::ToServer(pServer)->GetState(); +} + +HPSOCKET_API En_HP_SocketError __stdcall HP_Server_GetLastError(HP_Server pServer) +{ + return (En_HP_SocketError)C_HP_Object::ToServer(pServer)->GetLastError(); +} + +HPSOCKET_API LPCTSTR __stdcall HP_Server_GetLastErrorDesc(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->GetLastErrorDesc(); +} + +HPSOCKET_API BOOL __stdcall HP_Server_GetPendingDataLength(HP_Server pServer, HP_CONNID dwConnID, int* piPending) +{ + return C_HP_Object::ToServer(pServer)->GetPendingDataLength(dwConnID, *piPending); +} + +HPSOCKET_API DWORD __stdcall HP_Server_GetConnectionCount(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->GetConnectionCount(); +} + +HPSOCKET_API BOOL __stdcall HP_Server_GetAllConnectionIDs(HP_Server pServer, HP_CONNID pIDs[], DWORD* pdwCount) +{ + return C_HP_Object::ToServer(pServer)->GetAllConnectionIDs(pIDs, *pdwCount); +} + +HPSOCKET_API BOOL __stdcall HP_Server_GetConnectPeriod(HP_Server pServer, HP_CONNID dwConnID, DWORD* pdwPeriod) +{ + return C_HP_Object::ToServer(pServer)->GetConnectPeriod(dwConnID, *pdwPeriod); +} + +HPSOCKET_API BOOL __stdcall HP_Server_GetSilencePeriod(HP_Server pServer, HP_CONNID dwConnID, DWORD* pdwPeriod) +{ + return C_HP_Object::ToServer(pServer)->GetSilencePeriod(dwConnID, *pdwPeriod); +} + +HPSOCKET_API BOOL __stdcall HP_Server_GetListenAddress(HP_Server pServer, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort) +{ + return C_HP_Object::ToServer(pServer)->GetListenAddress(lpszAddress, *piAddressLen, *pusPort); +} + +HPSOCKET_API BOOL __stdcall HP_Server_GetRemoteAddress(HP_Server pServer, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort) +{ + return C_HP_Object::ToServer(pServer)->GetRemoteAddress(dwConnID, lpszAddress, *piAddressLen, *pusPort); +} + +HPSOCKET_API void __stdcall HP_Server_SetSendPolicy(HP_Server pServer, En_HP_SendPolicy enSendPolicy) +{ + C_HP_Object::ToServer(pServer)->SetSendPolicy((EnSendPolicy)enSendPolicy); +} + +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjLockTime(HP_Server pServer, DWORD dwFreeSocketObjLockTime) +{ + C_HP_Object::ToServer(pServer)->SetFreeSocketObjLockTime(dwFreeSocketObjLockTime); +} + +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjPool(HP_Server pServer, DWORD dwFreeSocketObjPool) +{ + C_HP_Object::ToServer(pServer)->SetFreeSocketObjPool(dwFreeSocketObjPool); +} + +HPSOCKET_API void __stdcall HP_Server_SetFreeBufferObjPool(HP_Server pServer, DWORD dwFreeBufferObjPool) +{ + C_HP_Object::ToServer(pServer)->SetFreeBufferObjPool(dwFreeBufferObjPool); +} + +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjHold(HP_Server pServer, DWORD dwFreeSocketObjHold) +{ + C_HP_Object::ToServer(pServer)->SetFreeSocketObjHold(dwFreeSocketObjHold); +} + +HPSOCKET_API void __stdcall HP_Server_SetFreeBufferObjHold(HP_Server pServer, DWORD dwFreeBufferObjHold) +{ + C_HP_Object::ToServer(pServer)->SetFreeBufferObjHold(dwFreeBufferObjHold); +} + +HPSOCKET_API void __stdcall HP_Server_SetWorkerThreadCount(HP_Server pServer, DWORD dwWorkerThreadCount) +{ + C_HP_Object::ToServer(pServer)->SetWorkerThreadCount(dwWorkerThreadCount); +} + +HPSOCKET_API void __stdcall HP_Server_SetMarkSilence(HP_Server pServer, BOOL bMarkSilence) +{ + C_HP_Object::ToServer(pServer)->SetMarkSilence(bMarkSilence); +} + +HPSOCKET_API En_HP_SendPolicy __stdcall HP_Server_GetSendPolicy(HP_Server pServer) +{ + return (En_HP_SendPolicy)C_HP_Object::ToServer(pServer)->GetSendPolicy(); +} + +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjLockTime(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->GetFreeSocketObjLockTime(); +} + +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjPool(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->GetFreeSocketObjPool(); +} + +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeBufferObjPool(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->GetFreeBufferObjPool(); +} + +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjHold(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->GetFreeSocketObjHold(); +} + +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeBufferObjHold(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->GetFreeBufferObjHold(); +} + +HPSOCKET_API DWORD __stdcall HP_Server_GetWorkerThreadCount(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->GetWorkerThreadCount(); +} + +HPSOCKET_API BOOL __stdcall HP_Server_IsMarkSilence(HP_Server pServer) +{ + return C_HP_Object::ToServer(pServer)->IsMarkSilence(); +} + +/**********************************************************************************/ +/******************************* TCP Server *******************************/ + +HPSOCKET_API BOOL __stdcall HP_TcpServer_SendSmallFile(HP_Server pServer, HP_CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail) +{ + return C_HP_Object::ToTcpServer(pServer)->SendSmallFile(dwConnID, lpszFileName, pHead, pTail); +} + +/**********************************************************************************/ +/***************************** TCP Server Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_TcpServer_SetAcceptSocketCount(HP_TcpServer pServer, DWORD dwAcceptSocketCount) +{ + C_HP_Object::ToTcpServer(pServer)->SetAcceptSocketCount(dwAcceptSocketCount); +} + +HPSOCKET_API void __stdcall HP_TcpServer_SetSocketBufferSize(HP_TcpServer pServer, DWORD dwSocketBufferSize) +{ + C_HP_Object::ToTcpServer(pServer)->SetSocketBufferSize(dwSocketBufferSize); +} + +HPSOCKET_API void __stdcall HP_TcpServer_SetSocketListenQueue(HP_TcpServer pServer, DWORD dwSocketListenQueue) +{ + C_HP_Object::ToTcpServer(pServer)->SetSocketListenQueue(dwSocketListenQueue); +} + +HPSOCKET_API void __stdcall HP_TcpServer_SetKeepAliveTime(HP_TcpServer pServer, DWORD dwKeepAliveTime) +{ + C_HP_Object::ToTcpServer(pServer)->SetKeepAliveTime(dwKeepAliveTime); +} + +HPSOCKET_API void __stdcall HP_TcpServer_SetKeepAliveInterval(HP_TcpServer pServer, DWORD dwKeepAliveInterval) +{ + C_HP_Object::ToTcpServer(pServer)->SetKeepAliveInterval(dwKeepAliveInterval); +} + +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetAcceptSocketCount(HP_TcpServer pServer) +{ + return C_HP_Object::ToTcpServer(pServer)->GetAcceptSocketCount(); +} + +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetSocketBufferSize(HP_TcpServer pServer) +{ + return C_HP_Object::ToTcpServer(pServer)->GetSocketBufferSize(); +} + +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetSocketListenQueue(HP_TcpServer pServer) +{ + return C_HP_Object::ToTcpServer(pServer)->GetSocketListenQueue(); +} + +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetKeepAliveTime(HP_TcpServer pServer) +{ + return C_HP_Object::ToTcpServer(pServer)->GetKeepAliveTime(); +} + +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetKeepAliveInterval(HP_TcpServer pServer) +{ + return C_HP_Object::ToTcpServer(pServer)->GetKeepAliveInterval(); +} + +/**********************************************************************************/ +/***************************** UDP Server Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_UdpServer_SetMaxDatagramSize(HP_UdpServer pServer, DWORD dwMaxDatagramSize) +{ + C_HP_Object::ToUdpServer(pServer)->SetMaxDatagramSize(dwMaxDatagramSize); +} + +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetMaxDatagramSize(HP_UdpServer pServer) +{ + return C_HP_Object::ToUdpServer(pServer)->GetMaxDatagramSize(); +} + +HPSOCKET_API void __stdcall HP_UdpServer_SetPostReceiveCount(HP_UdpServer pServer, DWORD dwPostReceiveCount) +{ + C_HP_Object::ToUdpServer(pServer)->SetPostReceiveCount(dwPostReceiveCount); +} + +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetPostReceiveCount(HP_UdpServer pServer) +{ + return C_HP_Object::ToUdpServer(pServer)->GetPostReceiveCount(); +} + +HPSOCKET_API void __stdcall HP_UdpServer_SetDetectAttempts(HP_UdpServer pServer, DWORD dwDetectAttempts) +{ + C_HP_Object::ToUdpServer(pServer)->SetDetectAttempts(dwDetectAttempts); +} + +HPSOCKET_API void __stdcall HP_UdpServer_SetDetectInterval(HP_UdpServer pServer, DWORD dwDetectInterval) +{ + C_HP_Object::ToUdpServer(pServer)->SetDetectInterval(dwDetectInterval); +} + +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetDetectAttempts(HP_UdpServer pServer) +{ + return C_HP_Object::ToUdpServer(pServer)->GetDetectAttempts(); +} + +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetDetectInterval(HP_UdpServer pServer) +{ + return C_HP_Object::ToUdpServer(pServer)->GetDetectInterval(); +} + +/**************************************************************************/ +/***************************** Agent *****************************/ + +HPSOCKET_API BOOL __stdcall HP_Agent_Start(HP_Agent pAgent, LPCTSTR pszBindAddress, BOOL bAsyncConnect) +{ + return C_HP_Object::ToAgent(pAgent)->Start(pszBindAddress, bAsyncConnect); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_Stop(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->Stop(); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_Connect(HP_Agent pAgent, LPCTSTR pszRemoteAddress, USHORT usPort, HP_CONNID* pdwConnID) +{ + return C_HP_Object::ToAgent(pAgent)->Connect(pszRemoteAddress, usPort, pdwConnID); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_Send(HP_Agent pAgent, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength) +{ + return C_HP_Object::ToAgent(pAgent)->Send(dwConnID, pBuffer, iLength); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_SendPart(HP_Agent pAgent, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset) +{ + return C_HP_Object::ToAgent(pAgent)->Send(dwConnID, pBuffer, iLength, iOffset); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_SendPackets(HP_Agent pAgent, HP_CONNID dwConnID, const WSABUF pBuffers[], int iCount) +{ + return C_HP_Object::ToAgent(pAgent)->SendPackets(dwConnID, pBuffers, iCount); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_Disconnect(HP_Agent pAgent, HP_CONNID dwConnID, BOOL bForce) +{ + return C_HP_Object::ToAgent(pAgent)->Disconnect(dwConnID, bForce); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_DisconnectLongConnections(HP_Agent pAgent, DWORD dwPeriod, BOOL bForce) +{ + return C_HP_Object::ToAgent(pAgent)->DisconnectLongConnections(dwPeriod, bForce); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_DisconnectSilenceConnections(HP_Agent pAgent, DWORD dwPeriod, BOOL bForce) +{ + return C_HP_Object::ToAgent(pAgent)->DisconnectSilenceConnections(dwPeriod, bForce); +} + +/******************************************************************************/ +/***************************** Agent Էʷ *****************************/ + +HPSOCKET_API BOOL __stdcall HP_Agent_SetConnectionExtra(HP_Agent pAgent, HP_CONNID dwConnID, PVOID pExtra) +{ + return C_HP_Object::ToAgent(pAgent)->SetConnectionExtra(dwConnID, pExtra); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_GetConnectionExtra(HP_Agent pAgent, HP_CONNID dwConnID, PVOID* ppExtra) +{ + return C_HP_Object::ToAgent(pAgent)->GetConnectionExtra(dwConnID, ppExtra); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_HasStarted(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->HasStarted(); +} + +HPSOCKET_API En_HP_ServiceState __stdcall HP_Agent_GetState(HP_Agent pAgent) +{ + return (En_HP_ServiceState)C_HP_Object::ToAgent(pAgent)->GetState(); +} + +HPSOCKET_API En_HP_SocketError __stdcall HP_Agent_GetLastError(HP_Agent pAgent) +{ + return (En_HP_SocketError)C_HP_Object::ToAgent(pAgent)->GetLastError(); +} + +HPSOCKET_API LPCTSTR __stdcall HP_Agent_GetLastErrorDesc(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->GetLastErrorDesc(); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_GetPendingDataLength(HP_Agent pAgent, HP_CONNID dwConnID, int* piPending) +{ + return C_HP_Object::ToAgent(pAgent)->GetPendingDataLength(dwConnID, *piPending); +} + +HPSOCKET_API DWORD __stdcall HP_Agent_GetConnectionCount(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->GetConnectionCount(); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_GetAllConnectionIDs(HP_Agent pAgent, HP_CONNID pIDs[], DWORD* pdwCount) +{ + return C_HP_Object::ToAgent(pAgent)->GetAllConnectionIDs(pIDs, *pdwCount); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_GetConnectPeriod(HP_Agent pAgent, HP_CONNID dwConnID, DWORD* pdwPeriod) +{ + return C_HP_Object::ToAgent(pAgent)->GetConnectPeriod(dwConnID, *pdwPeriod); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_GetSilencePeriod(HP_Agent pAgent, HP_CONNID dwConnID, DWORD* pdwPeriod) +{ + return C_HP_Object::ToAgent(pAgent)->GetSilencePeriod(dwConnID, *pdwPeriod); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_GetLocalAddress(HP_Agent pAgent, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort) +{ + return C_HP_Object::ToAgent(pAgent)->GetLocalAddress(dwConnID, lpszAddress, *piAddressLen, *pusPort); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_GetRemoteAddress(HP_Agent pAgent, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort) +{ + return C_HP_Object::ToAgent(pAgent)->GetRemoteAddress(dwConnID, lpszAddress, *piAddressLen, *pusPort); +} + +HPSOCKET_API void __stdcall HP_Agent_SetSendPolicy(HP_Agent pAgent, En_HP_SendPolicy enSendPolicy) +{ + C_HP_Object::ToAgent(pAgent)->SetSendPolicy((EnSendPolicy)enSendPolicy); +} + +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjLockTime(HP_Agent pAgent, DWORD dwFreeSocketObjLockTime) +{ + C_HP_Object::ToAgent(pAgent)->SetFreeSocketObjLockTime(dwFreeSocketObjLockTime); +} + +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjPool(HP_Agent pAgent, DWORD dwFreeSocketObjPool) +{ + C_HP_Object::ToAgent(pAgent)->SetFreeSocketObjPool(dwFreeSocketObjPool); +} + +HPSOCKET_API void __stdcall HP_Agent_SetFreeBufferObjPool(HP_Agent pAgent, DWORD dwFreeBufferObjPool) +{ + C_HP_Object::ToAgent(pAgent)->SetFreeBufferObjPool(dwFreeBufferObjPool); +} + +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjHold(HP_Agent pAgent, DWORD dwFreeSocketObjHold) +{ + C_HP_Object::ToAgent(pAgent)->SetFreeSocketObjHold(dwFreeSocketObjHold); +} + +HPSOCKET_API void __stdcall HP_Agent_SetFreeBufferObjHold(HP_Agent pAgent, DWORD dwFreeBufferObjHold) +{ + C_HP_Object::ToAgent(pAgent)->SetFreeBufferObjHold(dwFreeBufferObjHold); +} + +HPSOCKET_API void __stdcall HP_Agent_SetWorkerThreadCount(HP_Agent pAgent, DWORD dwWorkerThreadCount) +{ + C_HP_Object::ToAgent(pAgent)->SetWorkerThreadCount(dwWorkerThreadCount); +} + +HPSOCKET_API void __stdcall HP_Agent_SetMarkSilence(HP_Agent pAgent, BOOL bMarkSilence) +{ + C_HP_Object::ToAgent(pAgent)->SetMarkSilence(bMarkSilence); +} + +HPSOCKET_API En_HP_SendPolicy __stdcall HP_Agent_GetSendPolicy(HP_Agent pAgent) +{ + return (En_HP_SendPolicy)C_HP_Object::ToAgent(pAgent)->GetSendPolicy(); +} + +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjLockTime(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->GetFreeSocketObjLockTime(); +} + +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjPool(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->GetFreeSocketObjPool(); +} + +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeBufferObjPool(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->GetFreeBufferObjPool(); +} + +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjHold(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->GetFreeSocketObjHold(); +} + +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeBufferObjHold(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->GetFreeBufferObjHold(); +} + +HPSOCKET_API DWORD __stdcall HP_Agent_GetWorkerThreadCount(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->GetWorkerThreadCount(); +} + +HPSOCKET_API BOOL __stdcall HP_Agent_IsMarkSilence(HP_Agent pAgent) +{ + return C_HP_Object::ToAgent(pAgent)->IsMarkSilence(); +} + +/**********************************************************************************/ +/******************************* TCP Agent *******************************/ + +HPSOCKET_API BOOL __stdcall HP_TcpAgent_SendSmallFile(HP_Agent pAgent, HP_CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail) +{ + return C_HP_Object::ToTcpAgent(pAgent)->SendSmallFile(dwConnID, lpszFileName, pHead, pTail); +} + +/**********************************************************************************/ +/***************************** TCP Agent Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_TcpAgent_SetReuseAddress(HP_TcpAgent pAgent, BOOL bReuseAddress) +{ + C_HP_Object::ToTcpAgent(pAgent)->SetReuseAddress(bReuseAddress); +} + +HPSOCKET_API BOOL __stdcall HP_TcpAgent_IsReuseAddress(HP_TcpAgent pAgent) +{ + return C_HP_Object::ToTcpAgent(pAgent)->IsReuseAddress(); +} + +HPSOCKET_API void __stdcall HP_TcpAgent_SetSocketBufferSize(HP_TcpAgent pAgent, DWORD dwSocketBufferSize) +{ + C_HP_Object::ToTcpAgent(pAgent)->SetSocketBufferSize(dwSocketBufferSize); +} + +HPSOCKET_API void __stdcall HP_TcpAgent_SetKeepAliveTime(HP_TcpAgent pAgent, DWORD dwKeepAliveTime) +{ + C_HP_Object::ToTcpAgent(pAgent)->SetKeepAliveTime(dwKeepAliveTime); +} + +HPSOCKET_API void __stdcall HP_TcpAgent_SetKeepAliveInterval(HP_TcpAgent pAgent, DWORD dwKeepAliveInterval) +{ + C_HP_Object::ToTcpAgent(pAgent)->SetKeepAliveInterval(dwKeepAliveInterval); +} + +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetSocketBufferSize(HP_TcpAgent pAgent) +{ + return C_HP_Object::ToTcpAgent(pAgent)->GetSocketBufferSize(); +} + +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetKeepAliveTime(HP_TcpAgent pAgent) +{ + return C_HP_Object::ToTcpAgent(pAgent)->GetKeepAliveTime(); +} + +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetKeepAliveInterval(HP_TcpAgent pAgent) +{ + return C_HP_Object::ToTcpAgent(pAgent)->GetKeepAliveInterval(); +} + +/**********************************************************************************/ +/***************************** UDP Agent Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_UdpAgent_SetMaxDatagramSize(HP_UdpAgent pAgent, DWORD dwMaxDatagramSize) +{ + C_HP_Object::ToUdpAgent(pAgent)->SetMaxDatagramSize(dwMaxDatagramSize); +} + +HPSOCKET_API void __stdcall HP_UdpAgent_SetDetectAttempts(HP_UdpAgent pAgent, DWORD dwDetectAttempts) +{ + C_HP_Object::ToUdpAgent(pAgent)->SetDetectAttempts(dwDetectAttempts); +} + +HPSOCKET_API void __stdcall HP_UdpAgent_SetDetectInterval(HP_UdpAgent pAgent, DWORD dwDetectInterval) +{ + C_HP_Object::ToUdpAgent(pAgent)->SetDetectInterval(dwDetectInterval); +} + +HPSOCKET_API DWORD __stdcall HP_UdpAgent_GetMaxDatagramSize(HP_UdpAgent pAgent) +{ + return C_HP_Object::ToUdpAgent(pAgent)->GetMaxDatagramSize(); +} + +HPSOCKET_API DWORD __stdcall HP_UdpAgent_GetDetectAttempts(HP_UdpAgent pAgent) +{ + return C_HP_Object::ToUdpAgent(pAgent)->GetDetectAttempts(); +} + +HPSOCKET_API DWORD __stdcall HP_UdpAgent_GetDetectInterval(HP_UdpAgent pAgent) +{ + return C_HP_Object::ToUdpAgent(pAgent)->GetDetectInterval(); +} + +/******************************************************************************/ +/***************************** Client *****************************/ + +HPSOCKET_API BOOL __stdcall HP_Client_Start(HP_Client pClient, LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect) +{ + return C_HP_Object::ToClient(pClient)->Start(pszRemoteAddress, usPort, bAsyncConnect); +} + +HPSOCKET_API BOOL __stdcall HP_Client_Stop(HP_Client pClient) +{ + return C_HP_Object::ToClient(pClient)->Stop(); +} + +HPSOCKET_API BOOL __stdcall HP_Client_Send(HP_Client pClient, const BYTE* pBuffer, int iLength) +{ + return C_HP_Object::ToClient(pClient)->Send(pBuffer, iLength); +} + +HPSOCKET_API BOOL __stdcall HP_Client_SendPart(HP_Client pClient, const BYTE* pBuffer, int iLength, int iOffset) +{ + return C_HP_Object::ToClient(pClient)->Send(pBuffer, iLength, iOffset); +} + +HPSOCKET_API BOOL __stdcall HP_Client_SendPackets(HP_Client pClient, const WSABUF pBuffers[], int iCount) +{ + return C_HP_Object::ToClient(pClient)->SendPackets(pBuffers, iCount); +} + +/******************************************************************************/ +/***************************** Client Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_Client_SetExtra(HP_Client pClient, PVOID pExtra) +{ + C_HP_Object::ToClient(pClient)->SetExtra(pExtra); +} + +HPSOCKET_API PVOID __stdcall HP_Client_GetExtra(HP_Client pClient) +{ + return C_HP_Object::ToClient(pClient)->GetExtra(); +} + +HPSOCKET_API BOOL __stdcall HP_Client_HasStarted(HP_Client pClient) +{ + return C_HP_Object::ToClient(pClient)->HasStarted(); +} + +HPSOCKET_API En_HP_ServiceState __stdcall HP_Client_GetState(HP_Client pClient) +{ + return (En_HP_ServiceState)C_HP_Object::ToClient(pClient)->GetState(); +} + +HPSOCKET_API En_HP_SocketError __stdcall HP_Client_GetLastError(HP_Client pClient) +{ + return (En_HP_SocketError)C_HP_Object::ToClient(pClient)->GetLastError(); +} + +HPSOCKET_API LPCTSTR __stdcall HP_Client_GetLastErrorDesc(HP_Client pClient) +{ + return C_HP_Object::ToClient(pClient)->GetLastErrorDesc(); +} + +HPSOCKET_API HP_CONNID __stdcall HP_Client_GetConnectionID(HP_Client pClient) +{ + return C_HP_Object::ToClient(pClient)->GetConnectionID(); +} + +HPSOCKET_API BOOL __stdcall HP_Client_GetLocalAddress(HP_Client pClient, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort) +{ + return C_HP_Object::ToClient(pClient)->GetLocalAddress(lpszAddress, *piAddressLen, *pusPort); +} + +HPSOCKET_API BOOL __stdcall HP_Client_GetPendingDataLength(HP_Client pClient, int* piPending) +{ + return C_HP_Object::ToClient(pClient)->GetPendingDataLength(*piPending); +} + +HPSOCKET_API void __stdcall HP_Client_SetFreeBufferPoolSize(HP_Client pClient, DWORD dwFreeBufferPoolSize) +{ + C_HP_Object::ToClient(pClient)->SetFreeBufferPoolSize(dwFreeBufferPoolSize); +} + +HPSOCKET_API void __stdcall HP_Client_SetFreeBufferPoolHold(HP_Client pClient, DWORD dwFreeBufferPoolHold) +{ + C_HP_Object::ToClient(pClient)->SetFreeBufferPoolHold(dwFreeBufferPoolHold); +} + +HPSOCKET_API DWORD __stdcall HP_Client_GetFreeBufferPoolSize(HP_Client pClient) +{ + return C_HP_Object::ToClient(pClient)->GetFreeBufferPoolSize(); +} + +HPSOCKET_API DWORD __stdcall HP_Client_GetFreeBufferPoolHold(HP_Client pClient) +{ + return C_HP_Object::ToClient(pClient)->GetFreeBufferPoolHold(); +} + +/**********************************************************************************/ +/******************************* TCP Client *******************************/ + +HPSOCKET_API BOOL __stdcall HP_TcpClient_SendSmallFile(HP_Client pClient, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail) +{ + return C_HP_Object::ToTcpClient(pClient)->SendSmallFile(lpszFileName, pHead, pTail); +} + +/**********************************************************************************/ +/***************************** TCP Client Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_TcpClient_SetSocketBufferSize(HP_TcpClient pClient, DWORD dwSocketBufferSize) +{ + C_HP_Object::ToTcpClient(pClient)->SetSocketBufferSize(dwSocketBufferSize); +} + +HPSOCKET_API void __stdcall HP_TcpClient_SetKeepAliveTime(HP_TcpClient pClient, DWORD dwKeepAliveTime) +{ + C_HP_Object::ToTcpClient(pClient)->SetKeepAliveTime(dwKeepAliveTime); +} + +HPSOCKET_API void __stdcall HP_TcpClient_SetKeepAliveInterval(HP_TcpClient pClient, DWORD dwKeepAliveInterval) +{ + C_HP_Object::ToTcpClient(pClient)->SetKeepAliveInterval(dwKeepAliveInterval); +} + +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetSocketBufferSize(HP_TcpClient pClient) +{ + return C_HP_Object::ToTcpClient(pClient)->GetSocketBufferSize(); +} + +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetKeepAliveTime(HP_TcpClient pClient) +{ + return C_HP_Object::ToTcpClient(pClient)->GetKeepAliveTime(); +} + +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetKeepAliveInterval(HP_TcpClient pClient) +{ + return C_HP_Object::ToTcpClient(pClient)->GetKeepAliveInterval(); +} + +/**********************************************************************************/ +/***************************** UDP Client Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_UdpClient_SetMaxDatagramSize(HP_UdpClient pClient, DWORD dwMaxDatagramSize) +{ + C_HP_Object::ToUdpClient(pClient)->SetMaxDatagramSize(dwMaxDatagramSize); +} + +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetMaxDatagramSize(HP_UdpClient pClient) +{ + return C_HP_Object::ToUdpClient(pClient)->GetMaxDatagramSize(); +} + +HPSOCKET_API void __stdcall HP_UdpClient_SetDetectAttempts(HP_UdpClient pClient, DWORD dwDetectAttempts) +{ + C_HP_Object::ToUdpClient(pClient)->SetDetectAttempts(dwDetectAttempts); +} + +HPSOCKET_API void __stdcall HP_UdpClient_SetDetectInterval(HP_UdpClient pClient, DWORD dwDetectInterval) +{ + C_HP_Object::ToUdpClient(pClient)->SetDetectInterval(dwDetectInterval); +} + +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetDetectAttempts(HP_UdpClient pClient) +{ + return C_HP_Object::ToUdpClient(pClient)->GetDetectAttempts(); +} + +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetDetectInterval(HP_UdpClient pClient) +{ + return C_HP_Object::ToUdpClient(pClient)->GetDetectInterval(); +} + +/**********************************************************************************/ +/****************************** UDP Cast Էʷ ******************************/ + +HPSOCKET_API void __stdcall HP_UdpCast_SetMaxDatagramSize(HP_UdpCast pCast, DWORD dwMaxDatagramSize) +{ + C_HP_Object::ToUdpCast(pCast)->SetMaxDatagramSize(dwMaxDatagramSize); +} + +HPSOCKET_API DWORD __stdcall HP_UdpCast_GetMaxDatagramSize(HP_UdpCast pCast) +{ + return C_HP_Object::ToUdpCast(pCast)->GetMaxDatagramSize(); +} + +HPSOCKET_API BOOL __stdcall HP_UdpCast_GetRemoteAddress(HP_UdpCast pCast, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort) +{ + return C_HP_Object::ToUdpCast(pCast)->GetRemoteAddress(lpszAddress, *piAddressLen, *pusPort); +} + +HPSOCKET_API void __stdcall HP_UdpCast_SetBindAdddress(HP_UdpCast pCast, LPCTSTR pszBindAddress) +{ + C_HP_Object::ToUdpCast(pCast)->SetBindAdddress(pszBindAddress); +} + +HPSOCKET_API LPCTSTR __stdcall HP_UdpCast_GetBindAdddress(HP_UdpCast pCast) +{ + return C_HP_Object::ToUdpCast(pCast)->GetBindAdddress(); +} + +HPSOCKET_API void __stdcall HP_UdpCast_SetReuseAddress(HP_UdpCast pCast, BOOL bReuseAddress) +{ + C_HP_Object::ToUdpCast(pCast)->SetReuseAddress(bReuseAddress); +} + +HPSOCKET_API BOOL __stdcall HP_UdpCast_IsReuseAddress(HP_UdpCast pCast) +{ + return C_HP_Object::ToUdpCast(pCast)->IsReuseAddress(); +} + +HPSOCKET_API void __stdcall HP_UdpCast_SetCastMode(HP_UdpCast pCast, En_HP_CastMode enCastMode) +{ + C_HP_Object::ToUdpCast(pCast)->SetCastMode((EnCastMode)enCastMode); +} + +HPSOCKET_API En_HP_CastMode __stdcall HP_UdpCast_GetCastMode(HP_UdpCast pCast) +{ + return (En_HP_CastMode)C_HP_Object::ToUdpCast(pCast)->GetCastMode(); +} + +HPSOCKET_API void __stdcall HP_UdpCast_SetMultiCastTtl(HP_UdpCast pCast, int iMCTtl) +{ + C_HP_Object::ToUdpCast(pCast)->SetMultiCastTtl(iMCTtl); +} + +HPSOCKET_API int __stdcall HP_UdpCast_GetMultiCastTtl(HP_UdpCast pCast) +{ + return C_HP_Object::ToUdpCast(pCast)->GetMultiCastTtl(); +} + +HPSOCKET_API void __stdcall HP_UdpCast_SetMultiCastLoop(HP_UdpCast pCast, BOOL bMCLoop) +{ + C_HP_Object::ToUdpCast(pCast)->SetMultiCastLoop(bMCLoop); +} + +HPSOCKET_API BOOL __stdcall HP_UdpCast_IsMultiCastLoop(HP_UdpCast pCast) +{ + return C_HP_Object::ToUdpCast(pCast)->IsMultiCastLoop(); +} + +/***************************************************************************************/ +/***************************** TCP Pull Server *****************************/ + +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullServer_Fetch(HP_TcpPullServer pServer, HP_CONNID dwConnID, BYTE* pData, int iLength) +{ + return (En_HP_FetchResult)C_HP_Object::ToPullSocket(pServer)->Fetch(dwConnID, pData, iLength); +} + +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullServer_Peek(HP_TcpPullServer pServer, HP_CONNID dwConnID, BYTE* pData, int iLength) +{ + return (En_HP_FetchResult)C_HP_Object::ToPullSocket(pServer)->Peek(dwConnID, pData, iLength); +} + +/***************************************************************************************/ +/***************************** TCP Pull Server Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pull Agent *****************************/ + +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullAgent_Fetch(HP_TcpPullAgent pAgent, HP_CONNID dwConnID, BYTE* pData, int iLength) +{ + return (En_HP_FetchResult)C_HP_Object::ToPullSocket(pAgent)->Fetch(dwConnID, pData, iLength); +} + +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullAgent_Peek(HP_TcpPullAgent pAgent, HP_CONNID dwConnID, BYTE* pData, int iLength) +{ + return (En_HP_FetchResult)C_HP_Object::ToPullSocket(pAgent)->Peek(dwConnID, pData, iLength); +} + +/***************************************************************************************/ +/***************************** TCP Pull Agent Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pull Client *****************************/ + +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullClient_Fetch(HP_TcpPullClient pClient, BYTE* pData, int iLength) +{ + return (En_HP_FetchResult)C_HP_Object::ToPullClient(pClient)->Fetch(pData, iLength); +} + +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullClient_Peek(HP_TcpPullClient pClient, BYTE* pData, int iLength) +{ + return (En_HP_FetchResult)C_HP_Object::ToPullClient(pClient)->Peek(pData, iLength); +} + +/***************************************************************************************/ +/***************************** TCP Pull Client Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Server *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Server Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_TcpPackServer_SetMaxPackSize(HP_TcpPackServer pServer, DWORD dwMaxPackSize) +{ + C_HP_Object::ToPackSocket(pServer)->SetMaxPackSize(dwMaxPackSize); +} + +HPSOCKET_API void __stdcall HP_TcpPackServer_SetPackHeaderFlag(HP_TcpPackServer pServer, USHORT usPackHeaderFlag) +{ + C_HP_Object::ToPackSocket(pServer)->SetPackHeaderFlag(usPackHeaderFlag); +} + +HPSOCKET_API DWORD __stdcall HP_TcpPackServer_GetMaxPackSize(HP_TcpPackServer pServer) +{ + return C_HP_Object::ToPackSocket(pServer)->GetMaxPackSize(); +} + +HPSOCKET_API USHORT __stdcall HP_TcpPackServer_GetPackHeaderFlag(HP_TcpPackServer pServer) +{ + return C_HP_Object::ToPackSocket(pServer)->GetPackHeaderFlag(); +} + +/***************************************************************************************/ +/***************************** TCP Pack Agent *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Agent Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_TcpPackAgent_SetMaxPackSize(HP_TcpPackAgent pAgent, DWORD dwMaxPackSize) +{ + C_HP_Object::ToPackSocket(pAgent)->SetMaxPackSize(dwMaxPackSize); +} + +HPSOCKET_API void __stdcall HP_TcpPackAgent_SetPackHeaderFlag(HP_TcpPackAgent pAgent, USHORT usPackHeaderFlag) +{ + C_HP_Object::ToPackSocket(pAgent)->SetPackHeaderFlag(usPackHeaderFlag); +} + +HPSOCKET_API DWORD __stdcall HP_TcpPackAgent_GetMaxPackSize(HP_TcpPackAgent pAgent) +{ + return C_HP_Object::ToPackSocket(pAgent)->GetMaxPackSize(); +} + +HPSOCKET_API USHORT __stdcall HP_TcpPackAgent_GetPackHeaderFlag(HP_TcpPackAgent pAgent) +{ + return C_HP_Object::ToPackSocket(pAgent)->GetPackHeaderFlag(); +} + +/***************************************************************************************/ +/***************************** TCP Pack Client *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Client Էʷ *****************************/ + +HPSOCKET_API void __stdcall HP_TcpPackClient_SetMaxPackSize(HP_TcpPackClient pClient, DWORD dwMaxPackSize) +{ + C_HP_Object::ToPackClient(pClient)->SetMaxPackSize(dwMaxPackSize); +} + +HPSOCKET_API void __stdcall HP_TcpPackClient_SetPackHeaderFlag(HP_TcpPackClient pClient, USHORT usPackHeaderFlag) +{ + C_HP_Object::ToPackClient(pClient)->SetPackHeaderFlag(usPackHeaderFlag); +} + +HPSOCKET_API DWORD __stdcall HP_TcpPackClient_GetMaxPackSize(HP_TcpPackClient pClient) +{ + return C_HP_Object::ToPackClient(pClient)->GetMaxPackSize(); +} + +HPSOCKET_API USHORT __stdcall HP_TcpPackClient_GetPackHeaderFlag(HP_TcpPackClient pClient) +{ + return C_HP_Object::ToPackClient(pClient)->GetPackHeaderFlag(); +} + +/***************************************************************************************/ +/*************************************** ***************************************/ + +HPSOCKET_API LPCTSTR __stdcall HP_GetSocketErrorDesc(En_HP_SocketError enCode) +{ + return ::GetSocketErrorDesc((EnSocketError)enCode); +} + +HPSOCKET_API DWORD __stdcall SYS_GetLastError() +{ + return ::GetLastError(); +} + +HPSOCKET_API int __stdcall SYS_WSAGetLastError() +{ + return ::WSAGetLastError(); +} + +HPSOCKET_API int __stdcall SYS_SetSocketOption(SOCKET sock, int level, int name, LPVOID val, int len) +{ + return ::SSO_SetSocketOption(sock, level, name, val, len); +} + +HPSOCKET_API int __stdcall SYS_GetSocketOption(SOCKET sock, int level, int name, LPVOID val, int* len) +{ + return ::SSO_GetSocketOption(sock, level, name, val, len); +} + +HPSOCKET_API int __stdcall SYS_IoctlSocket(SOCKET sock, long cmd, u_long* arg) +{ + return ::SSO_IoctlSocket(sock, cmd, arg); +} + +HPSOCKET_API int __stdcall SYS_WSAIoctl(SOCKET sock, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned) +{ + return ::SSO_WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, lpvOutBuffer, cbOutBuffer, lpcbBytesReturned); +} diff --git a/HP-Socket/Src/HPSocket4C.h b/HP-Socket/Src/HPSocket4C.h new file mode 100644 index 000000000..89edde3f3 --- /dev/null +++ b/HP-Socket/Src/HPSocket4C.h @@ -0,0 +1,1193 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/****************************************************************************** +Module: HPSocket for C DLL + +Desc: C ԣ磺C / C# / Delphi ȣܷʹ HPSocket + +Usage: + һ + -------------------------------------------------------------------------------------- + 0. C/C++ 򣩰 HPSocket4C.h ͷļ + 1. ::Create_HP_XxxListener() + 2. ::Create_HP_Xxx(pListener) HPSocket + 3. ::HP_Set_FN_Xxx_OnYyy(pListener, ...) üĻص + 4. ص HPSocket + 5. ...... ...... + 6. ::Destroy_HP_Xxx(pSocket) HPSocket + 7. ::Destroy_HP_XxxListener(pListener) ټ + + + -------------------------------------------------------------------------------------- + 1. ӦóҪõĵװضԵİװ + 2. ͨװװķʽʹ HPSocket + +Release: + 1. x86/HPSocket4C.dll - (32λ/MBCS/Release) + 2. x86/HPSocket4C_D.dll - (32λ/MBCS/DeBug) + 3. x86/HPSocket4C_U.dll - (32λ/UNICODE/Release) + 4. x86/HPSocket4C_UD.dll - (32λ/UNICODE/DeBug) + 5. x64/HPSocket4C.dll - (64λ/MBCS/Release) + 6. x64/HPSocket4C_D.dll - (64λ/MBCS/DeBug) + 7. x64/HPSocket4C_U.dll - (64λ/UNICODE/Release) + 8. x64/HPSocket4C_UD.dll - (64λ/UNICODE/DeBug) + +******************************************************************************/ + +#pragma once + +#include + +/**************************************************/ +/********* imports / exports HPSocket.dll *********/ + +#ifdef HPSOCKET_STATIC_LIB + #define HPSOCKET_API EXTERN_C +#else + #ifdef HPSOCKET_EXPORTS + #define HPSOCKET_API EXTERN_C __declspec(dllexport) + #else + #define HPSOCKET_API EXTERN_C __declspec(dllimport) + #endif +#endif + +/************************************************************************ +ƣ ID + ID +************************************************************************/ +typedef ULONG_PTR HP_CONNID; + +/************************************************************************ +ƣ Socket ָͱ + Socket ָ붨Ϊֱ۵ı +************************************************************************/ + +typedef PVOID HP_Object; + +typedef HP_Object HP_Server; +typedef HP_Object HP_Agent; +typedef HP_Object HP_Client; +typedef HP_Object HP_TcpServer; +typedef HP_Object HP_TcpAgent; +typedef HP_Object HP_TcpClient; +typedef HP_Object HP_PullSocket; +typedef HP_Object HP_PullClient; +typedef HP_Object HP_TcpPullServer; +typedef HP_Object HP_TcpPullAgent; +typedef HP_Object HP_TcpPullClient; +typedef HP_Object HP_PackSocket; +typedef HP_Object HP_PackClient; +typedef HP_Object HP_TcpPackServer; +typedef HP_Object HP_TcpPackAgent; +typedef HP_Object HP_TcpPackClient; +typedef HP_Object HP_UdpServer; +typedef HP_Object HP_UdpAgent; +typedef HP_Object HP_UdpClient; +typedef HP_Object HP_UdpCast; + +typedef HP_Object HP_Listener; +typedef HP_Object HP_ServerListener; +typedef HP_Object HP_AgentListener; +typedef HP_Object HP_ClientListener; +typedef HP_Object HP_TcpServerListener; +typedef HP_Object HP_TcpAgentListener; +typedef HP_Object HP_TcpClientListener; +typedef HP_Object HP_PullSocketListener; +typedef HP_Object HP_PullClientListener; +typedef HP_Object HP_TcpPullServerListener; +typedef HP_Object HP_TcpPullAgentListener; +typedef HP_Object HP_TcpPullClientListener; +typedef HP_Object HP_UdpServerListener; +typedef HP_Object HP_UdpAgentListener; +typedef HP_Object HP_UdpClientListener; +typedef HP_Object HP_UdpCastListener; + +/*****************************************************************************************************/ +/******************************************** ࡢӿ ********************************************/ +/*****************************************************************************************************/ + +/************************************************************************ +ƣͨ״̬ +Ӧóͨͨ GetState() ȡǰ״̬ +************************************************************************/ +enum En_HP_ServiceState +{ + HP_SS_STARTING = 0, // + HP_SS_STARTED = 1, // Ѿ + HP_SS_STOPPING = 2, // ֹͣ + HP_SS_STOPPED = 3, // Ѿֹͣ +}; + +/************************************************************************ +ƣSocket +Ӧó OnErrror() ¼ͨòʶֲµĴ +************************************************************************/ +enum En_HP_SocketOperation +{ + HP_SO_UNKNOWN = 0, // Unknown + HP_SO_ACCEPT = 1, // Acccept + HP_SO_CONNECT = 2, // Connect + HP_SO_SEND = 3, // Send + HP_SO_RECEIVE = 4, // Receive + HP_SO_CLOSE = 5, // Close +}; + +/************************************************************************ +ƣ¼֪ͨ +¼֪ͨķֵͬķֵӰͨĺΪ +************************************************************************/ +enum En_HP_HandleResult +{ + HP_HR_OK = 0, // ɹ + HP_HR_IGNORE = 1, // + HP_HR_ERROR = 2, // +}; + +/************************************************************************ +ƣץȡ +ץȡķֵ +************************************************************************/ +enum En_HP_FetchResult +{ + HP_FR_OK = 0, // ɹ + HP_FR_LENGTH_TOO_LONG = 1, // ץȡȹ + HP_FR_DATA_NOT_FOUND = 2, // Ҳ ConnID Ӧ +}; + +/************************************************************************ +ƣݷͲ +Server Agent ݷͲ + +* ģʽĬϣ ѶͲһͣӴЧ +* ȫģʽ ѶͲһͣƴٶȣ⻺ +* ֱģʽ ÿһͲֱͶݣڸزߵҪʵʱԽϸߵij + +************************************************************************/ +enum En_HP_SendPolicy +{ + HP_SP_PACK = 0, // ģʽĬϣ + HP_SP_SAFE = 1, // ȫģʽ + HP_SP_DIRECT = 2, // ֱģʽ +}; + +/************************************************************************ +ƣ + Start() / Stop() ִʧʱͨ GetLastError() ȡ +************************************************************************/ +enum En_HP_SocketError +{ + HP_SE_OK = NO_ERROR, // ɹ + HP_SE_ILLEGAL_STATE = 1, // ǰ״̬ + HP_SE_INVALID_PARAM = 2, // Ƿ + HP_SE_SOCKET_CREATE = 3, // SOCKET ʧ + HP_SE_SOCKET_BIND = 4, // SOCKET ʧ + HP_SE_SOCKET_PREPARE = 5, // SOCKET ʧ + HP_SE_SOCKET_LISTEN = 6, // SOCKET ʧ + HP_SE_CP_CREATE = 7, // ɶ˿ʧ + HP_SE_WORKER_THREAD_CREATE = 8, // ߳ʧ + HP_SE_DETECT_THREAD_CREATE = 9, // ߳ʧ + HP_SE_SOCKE_ATTACH_TO_CP = 10, // ɶ˿ʧ + HP_SE_CONNECT_SERVER = 11, // ӷʧ + HP_SE_NETWORK = 12, // + HP_SE_DATA_PROC = 13, // ݴ + HP_SE_DATA_SEND = 14, // ݷʧ +}; + +/************************************************************************ +ƣģʽ +UDP IJģʽ鲥㲥 +************************************************************************/ +enum En_HP_CastMode +{ + HP_CM_MULTICAST = 0, // 鲥 + HP_CM_BROADCAST = 1, // 㲥 +}; + +/****************************************************/ +/************** HPSocket4C.dll ص **************/ + +/* Server ص */ +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnPrepareListen) (UINT_PTR soListen); +// Ϊ TCP ӣpClientΪ SOCKET Ϊ UDP ӣpClientΪ SOCKADDR_IN ָ룻 +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnAccept) (HP_CONNID dwConnID, UINT_PTR pClient); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnSend) (HP_CONNID dwConnID, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnReceive) (HP_CONNID dwConnID, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnPullReceive) (HP_CONNID dwConnID, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnClose) (HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode); +typedef En_HP_HandleResult (__stdcall *HP_FN_Server_OnShutdown) (); + +/* Agent ص */ +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnPrepareConnect) (HP_CONNID dwConnID, UINT_PTR socket); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnConnect) (HP_CONNID dwConnID); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnSend) (HP_CONNID dwConnID, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnReceive) (HP_CONNID dwConnID, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnPullReceive) (HP_CONNID dwConnID, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnClose) (HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode); +typedef En_HP_HandleResult (__stdcall *HP_FN_Agent_OnShutdown) (); + +/* Client ص */ +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnPrepareConnect) (HP_Client pClient, UINT_PTR socket); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnConnect) (HP_Client pClient); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnSend) (HP_Client pClient, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnReceive) (HP_Client pClient, const BYTE* pData, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnPullReceive) (HP_Client pClient, int iLength); +typedef En_HP_HandleResult (__stdcall *HP_FN_Client_OnClose) (HP_Client pClient, En_HP_SocketOperation enOperation, int iErrorCode); + +/****************************************************/ +/************** HPSocket4C.dll **************/ + +// HP_TcpServer +HPSOCKET_API HP_TcpServer __stdcall Create_HP_TcpServer(HP_TcpServerListener pListener); +// HP_TcpAgent +HPSOCKET_API HP_TcpAgent __stdcall Create_HP_TcpAgent(HP_TcpAgentListener pListener); +// HP_TcpClient +HPSOCKET_API HP_TcpClient __stdcall Create_HP_TcpClient(HP_TcpClientListener pListener); +// HP_TcpPullServer +HPSOCKET_API HP_TcpPullServer __stdcall Create_HP_TcpPullServer(HP_TcpPullServerListener pListener); +// HP_TcpPullAgent +HPSOCKET_API HP_TcpPullAgent __stdcall Create_HP_TcpPullAgent(HP_TcpPullAgentListener pListener); +// HP_TcpPullClient +HPSOCKET_API HP_TcpPullClient __stdcall Create_HP_TcpPullClient(HP_TcpPullClientListener pListener); +// HP_TcpPackServer +HPSOCKET_API HP_TcpPackServer __stdcall Create_HP_TcpPackServer(HP_TcpServerListener pListener); +// HP_TcpPackAgent +HPSOCKET_API HP_TcpPackAgent __stdcall Create_HP_TcpPackAgent(HP_TcpAgentListener pListener); +// HP_TcpPackClient +HPSOCKET_API HP_TcpPackClient __stdcall Create_HP_TcpPackClient(HP_TcpClientListener pListener); +// HP_UdpServer +HPSOCKET_API HP_UdpServer __stdcall Create_HP_UdpServer(HP_UdpServerListener pListener); +// HP_UdpAgent +HPSOCKET_API HP_UdpAgent __stdcall Create_HP_UdpAgent(HP_UdpAgentListener pListener); +// HP_UdpClient +HPSOCKET_API HP_UdpClient __stdcall Create_HP_UdpClient(HP_UdpClientListener pListener); +// HP_UdpCast +HPSOCKET_API HP_UdpCast __stdcall Create_HP_UdpCast(HP_UdpCastListener pListener); + +// HP_TcpServer +HPSOCKET_API void __stdcall Destroy_HP_TcpServer(HP_TcpServer pServer); +// HP_TcpAgent +HPSOCKET_API void __stdcall Destroy_HP_TcpAgent(HP_TcpAgent pAgent); +// HP_TcpClient +HPSOCKET_API void __stdcall Destroy_HP_TcpClient(HP_TcpClient pClient); +// HP_TcpPullServer +HPSOCKET_API void __stdcall Destroy_HP_TcpPullServer(HP_TcpPullServer pServer); +// HP_TcpPullAgent +HPSOCKET_API void __stdcall Destroy_HP_TcpPullAgent(HP_TcpPullAgent pAgent); +// HP_TcpPullClient +HPSOCKET_API void __stdcall Destroy_HP_TcpPullClient(HP_TcpPullClient pClient); +// HP_TcpPackServer +HPSOCKET_API void __stdcall Destroy_HP_TcpPackServer(HP_TcpPackServer pServer); +// HP_TcpPackAgent +HPSOCKET_API void __stdcall Destroy_HP_TcpPackAgent(HP_TcpPackAgent pAgent); +// HP_TcpPackClient +HPSOCKET_API void __stdcall Destroy_HP_TcpPackClient(HP_TcpPackClient pClient); +// HP_UdpServer +HPSOCKET_API void __stdcall Destroy_HP_UdpServer(HP_UdpServer pServer); +// HP_UdpAgent +HPSOCKET_API void __stdcall Destroy_HP_UdpAgent(HP_UdpAgent pAgent); +// HP_UdpClient +HPSOCKET_API void __stdcall Destroy_HP_UdpClient(HP_UdpClient pClient); +// HP_UdpCast +HPSOCKET_API void __stdcall Destroy_HP_UdpCast(HP_UdpCast pCast); + +// HP_TcpServerListener +HPSOCKET_API HP_TcpServerListener __stdcall Create_HP_TcpServerListener(); +// HP_TcpAgentListener +HPSOCKET_API HP_TcpAgentListener __stdcall Create_HP_TcpAgentListener(); +// HP_TcpClientListener +HPSOCKET_API HP_TcpClientListener __stdcall Create_HP_TcpClientListener(); +// HP_TcpPullServerListener +HPSOCKET_API HP_TcpPullServerListener __stdcall Create_HP_TcpPullServerListener(); +// HP_TcpPullAgentListener +HPSOCKET_API HP_TcpPullAgentListener __stdcall Create_HP_TcpPullAgentListener(); +// HP_TcpPullClientListener +HPSOCKET_API HP_TcpPullClientListener __stdcall Create_HP_TcpPullClientListener(); +// HP_UdpServerListener +HPSOCKET_API HP_UdpServerListener __stdcall Create_HP_UdpServerListener(); +// HP_UdpAgentListener +HPSOCKET_API HP_TcpAgentListener __stdcall Create_HP_UdpAgentListener(); +// HP_UdpClientListener +HPSOCKET_API HP_UdpClientListener __stdcall Create_HP_UdpClientListener(); +// HP_UdpCastListener +HPSOCKET_API HP_UdpCastListener __stdcall Create_HP_UdpCastListener(); + +// HP_TcpServerListener +HPSOCKET_API void __stdcall Destroy_HP_TcpServerListener(HP_TcpServerListener pListener); +// HP_TcpAgentListener +HPSOCKET_API void __stdcall Destroy_HP_TcpAgentListener(HP_TcpAgentListener pListener); +// HP_TcpClientListener +HPSOCKET_API void __stdcall Destroy_HP_TcpClientListener(HP_TcpClientListener pListener); +// HP_TcpPullServerListener +HPSOCKET_API void __stdcall Destroy_HP_TcpPullServerListener(HP_TcpPullServerListener pListener); +// HP_TcpPullAgentListener +HPSOCKET_API void __stdcall Destroy_HP_TcpPullAgentListener(HP_TcpPullAgentListener pListener); +// HP_TcpPullClientListener +HPSOCKET_API void __stdcall Destroy_HP_TcpPullClientListener(HP_TcpPullClientListener pListener); +// HP_UdpServerListener +HPSOCKET_API void __stdcall Destroy_HP_UdpServerListener(HP_UdpServerListener pListener); +// HP_UdpAgentListener +HPSOCKET_API void __stdcall Destroy_HP_UdpAgentListener(HP_UdpAgentListener pListener); +// HP_UdpClientListener +HPSOCKET_API void __stdcall Destroy_HP_UdpClientListener(HP_UdpClientListener pListener); +// HP_UdpCastListener +HPSOCKET_API void __stdcall Destroy_HP_UdpCastListener(HP_UdpCastListener pListener); + +/**********************************************************************************/ +/***************************** Server ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnPrepareListen(HP_ServerListener pListener , HP_FN_Server_OnPrepareListen fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnAccept(HP_ServerListener pListener , HP_FN_Server_OnAccept fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnSend(HP_ServerListener pListener , HP_FN_Server_OnSend fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnReceive(HP_ServerListener pListener , HP_FN_Server_OnReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnPullReceive(HP_ServerListener pListener , HP_FN_Server_OnPullReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnClose(HP_ServerListener pListener , HP_FN_Server_OnClose fn); +HPSOCKET_API void __stdcall HP_Set_FN_Server_OnShutdown(HP_ServerListener pListener , HP_FN_Server_OnShutdown fn); + +/**********************************************************************************/ +/****************************** Agent ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnPrepareConnect(HP_AgentListener pListener , HP_FN_Agent_OnPrepareConnect fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnConnect(HP_AgentListener pListener , HP_FN_Agent_OnConnect fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnSend(HP_AgentListener pListener , HP_FN_Agent_OnSend fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnReceive(HP_AgentListener pListener , HP_FN_Agent_OnReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnPullReceive(HP_AgentListener pListener , HP_FN_Agent_OnPullReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnClose(HP_AgentListener pListener , HP_FN_Agent_OnClose fn); +HPSOCKET_API void __stdcall HP_Set_FN_Agent_OnShutdown(HP_AgentListener pListener , HP_FN_Agent_OnShutdown fn); + +/**********************************************************************************/ +/***************************** Client ص÷ *****************************/ + +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnPrepareConnect(HP_ClientListener pListener , HP_FN_Client_OnPrepareConnect fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnConnect(HP_ClientListener pListener , HP_FN_Client_OnConnect fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnSend(HP_ClientListener pListener , HP_FN_Client_OnSend fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnReceive(HP_ClientListener pListener , HP_FN_Client_OnReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnPullReceive(HP_ClientListener pListener , HP_FN_Client_OnPullReceive fn); +HPSOCKET_API void __stdcall HP_Set_FN_Client_OnClose(HP_ClientListener pListener , HP_FN_Client_OnClose fn); + +/**************************************************************************/ +/***************************** Server *****************************/ + +/* +* ƣͨ +* ͨɺɿʼտͻӲշ +* +* pszBindAddress -- ַ +* usPort -- ˿ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_Start(HP_Server pServer, LPCTSTR pszBindAddress, USHORT usPort); + +/* +* ƣرͨ +* رշͨرɺϿпͻӲͷԴ +* +* +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_Stop(HP_Server pServer); + +/* +* ƣ +* ָӷ +* +* dwConnID -- ID +* pBuffer -- ͻ +* iLength -- ͻ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Server_Send(HP_Server pServer, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength); + +/* +* ƣ +* ָӷ +* +* dwConnID -- ID +* pBuffer -- ͻ +* iLength -- ͻ +* iOffset -- ͻָƫ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Server_SendPart(HP_Server pServer, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset); + +/* +* ƣͶ +* ָӷͶ +* TCP - ˳ݰ +* UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ +* +* dwConnID -- ID +* pBuffers -- ͻ +* iCount -- ͻĿ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Server_SendPackets(HP_Server pServer, HP_CONNID dwConnID, const WSABUF pBuffers[], int iCount); + +/* +* ƣϿ +* Ͽijͻ˵ +* +* dwConnID -- ID +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_Disconnect(HP_Server pServer, HP_CONNID dwConnID, BOOL bForce); + +/* +* ƣϿʱ +* Ͽָʱ +* +* dwPeriod -- ʱ룩 +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_DisconnectLongConnections(HP_Server pServer, DWORD dwPeriod, BOOL bForce); + +/* +* ƣϿĬ +* ϿָʱľĬ +* +* dwPeriod -- ʱ룩 +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Server_DisconnectSilenceConnections(HP_Server pServer, DWORD dwPeriod, BOOL bForce); + +/******************************************************************************/ +/***************************** Server Էʷ *****************************/ + +/* +* ƣӵĸ +* ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ +* +* dwConnID -- ID +* pv -- +* ֵ TRUE -- ɹ +* FALSE -- ʧܣЧ ID +*/ +HPSOCKET_API BOOL __stdcall HP_Server_SetConnectionExtra(HP_Server pServer, HP_CONNID dwConnID, PVOID pExtra); + +/* +* ƣȡӵĸ +* ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ +* +* dwConnID -- ID +* ppv -- ָ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣЧ ID +*/ +HPSOCKET_API BOOL __stdcall HP_Server_GetConnectionExtra(HP_Server pServer, HP_CONNID dwConnID, PVOID* ppExtra); + +/* ͨǷ */ +HPSOCKET_API BOOL __stdcall HP_Server_HasStarted(HP_Server pServer); +/* 鿴ͨǰ״̬ */ +HPSOCKET_API En_HP_ServiceState __stdcall HP_Server_GetState(HP_Server pServer); +/* ȡһʧܲĴ */ +HPSOCKET_API En_HP_SocketError __stdcall HP_Server_GetLastError(HP_Server pServer); +/* ȡһʧܲĴ */ +HPSOCKET_API LPCTSTR __stdcall HP_Server_GetLastErrorDesc(HP_Server pServer); +/* ȡδݵij */ +HPSOCKET_API BOOL __stdcall HP_Server_GetPendingDataLength(HP_Server pServer, HP_CONNID dwConnID, int* piPending); +/* ȡͻ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetConnectionCount(HP_Server pServer); +/* ȡӵ CONNID */ +HPSOCKET_API BOOL __stdcall HP_Server_GetAllConnectionIDs(HP_Server pServer, HP_CONNID pIDs[], DWORD* pdwCount); +/* ȡijͻʱ룩 */ +HPSOCKET_API BOOL __stdcall HP_Server_GetConnectPeriod(HP_Server pServer, HP_CONNID dwConnID, DWORD* pdwPeriod); +/* ȡijӾĬʱ䣨룩 */ +HPSOCKET_API BOOL __stdcall HP_Server_GetSilencePeriod(HP_Server pServer, HP_CONNID dwConnID, DWORD* pdwPeriod); +/* ȡ Socket ĵַϢ */ +HPSOCKET_API BOOL __stdcall HP_Server_GetListenAddress(HP_Server pServer, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ȡijӵԶ̵ַϢ */ +HPSOCKET_API BOOL __stdcall HP_Server_GetRemoteAddress(HP_Server pServer, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); + +/* ݷͲ */ +HPSOCKET_API void __stdcall HP_Server_SetSendPolicy(HP_Server pServer, En_HP_SendPolicy enSendPolicy); +/* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjLockTime(HP_Server pServer, DWORD dwFreeSocketObjLockTime); +/* Socket شСͨΪƽ 1/3 - 1/2 */ +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjPool(HP_Server pServer, DWORD dwFreeSocketObjPool); +/* ڴ黺شСͨΪ Socket شС 2 - 3 */ +HPSOCKET_API void __stdcall HP_Server_SetFreeBufferObjPool(HP_Server pServer, DWORD dwFreeBufferObjPool); +/* Socket ػշֵͨΪ Socket شС 3 */ +HPSOCKET_API void __stdcall HP_Server_SetFreeSocketObjHold(HP_Server pServer, DWORD dwFreeSocketObjHold); +/* ڴ黺ػշֵͨΪڴ黺شС 3 */ +HPSOCKET_API void __stdcall HP_Server_SetFreeBufferObjHold(HP_Server pServer, DWORD dwFreeBufferObjHold); +/* ù߳ͨΪ 2 * CPU + 2 */ +HPSOCKET_API void __stdcall HP_Server_SetWorkerThreadCount(HP_Server pServer, DWORD dwWorkerThreadCount); +/* ǷǾĬʱ䣨Ϊ TRUE ʱ DisconnectSilenceConnections() GetSilencePeriod() ЧĬϣFALSE */ +HPSOCKET_API void __stdcall HP_Server_SetMarkSilence(HP_Server pServer, BOOL bMarkSilence); + +/* ȡݷͲ */ +HPSOCKET_API En_HP_SendPolicy __stdcall HP_Server_GetSendPolicy(HP_Server pServer); +/* ȡ Socket ʱ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjLockTime(HP_Server pServer); +/* ȡ Socket شС */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjPool(HP_Server pServer); +/* ȡڴ黺شС */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeBufferObjPool(HP_Server pServer); +/* ȡ Socket ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeSocketObjHold(HP_Server pServer); +/* ȡڴ黺ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetFreeBufferObjHold(HP_Server pServer); +/* ȡ߳ */ +HPSOCKET_API DWORD __stdcall HP_Server_GetWorkerThreadCount(HP_Server pServer); +/* ǷǾĬʱ */ +HPSOCKET_API BOOL __stdcall HP_Server_IsMarkSilence(HP_Server pServer); + +/**********************************************************************************/ +/******************************* TCP Server *******************************/ + +/* +* ƣСļ +* ָӷ 4096 KB µСļ +* +* dwConnID -- ID +* lpszFileName -- ļ· +* pHead -- ͷ +* pTail -- β +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_TcpServer_SendSmallFile(HP_Server pServer, HP_CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail); + +/**********************************************************************************/ +/***************************** TCP Server Էʷ *****************************/ + +/* ü Socket ĵȺдСݲã */ +HPSOCKET_API void __stdcall HP_TcpServer_SetSocketListenQueue(HP_TcpServer pServer, DWORD dwSocketListenQueue); +/* Accept ԤͶݸصãAccept ԤͶԽֵ֧IJԽࣩ */ +HPSOCKET_API void __stdcall HP_TcpServer_SetAcceptSocketCount(HP_TcpServer pServer, DWORD dwAcceptSocketCount); +/* ͨݻСƽͨݰСãͨΪ 1024 ı */ +HPSOCKET_API void __stdcall HP_TcpServer_SetSocketBufferSize(HP_TcpServer pServer, DWORD dwSocketBufferSize); +/* 룬0 򲻷Ĭϣ30 * 1000 */ +HPSOCKET_API void __stdcall HP_TcpServer_SetKeepAliveTime(HP_TcpServer pServer, DWORD dwKeepAliveTime); +/* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ +HPSOCKET_API void __stdcall HP_TcpServer_SetKeepAliveInterval(HP_TcpServer pServer, DWORD dwKeepAliveInterval); + +/* ȡ Accept ԤͶ */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetAcceptSocketCount(HP_TcpServer pServer); +/* ȡͨݻС */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetSocketBufferSize(HP_TcpServer pServer); +/* ȡ Socket ĵȺдС */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetSocketListenQueue(HP_TcpServer pServer); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetKeepAliveTime(HP_TcpServer pServer); +/* ȡ쳣 */ +HPSOCKET_API DWORD __stdcall HP_TcpServer_GetKeepAliveInterval(HP_TcpServer pServer); + +/**********************************************************************************/ +/***************************** UDP Server Էʷ *****************************/ + +/* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ +HPSOCKET_API void __stdcall HP_UdpServer_SetMaxDatagramSize(HP_UdpServer pServer, DWORD dwMaxDatagramSize); +/* ȡݱ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetMaxDatagramSize(HP_UdpServer pServer); + +/* Receive ԤͶݸصãReceive ԤͶԽ򶪰ԽС */ +HPSOCKET_API void __stdcall HP_UdpServer_SetPostReceiveCount(HP_UdpServer pServer, DWORD dwPostReceiveCount); +/* ȡ Receive ԤͶ */ +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetPostReceiveCount(HP_UdpServer pServer); + +/* üԴ0 򲻷ͼԴΪѶߣ */ +HPSOCKET_API void __stdcall HP_UdpServer_SetDetectAttempts(HP_UdpServer pServer, DWORD dwDetectAttempts); +/* üͼ룬0 ͼ */ +HPSOCKET_API void __stdcall HP_UdpServer_SetDetectInterval(HP_UdpServer pServer, DWORD dwDetectInterval); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetDetectAttempts(HP_UdpServer pServer); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpServer_GetDetectInterval(HP_UdpServer pServer); + +/**************************************************************************/ +/***************************** Agent *****************************/ + +/* +* ƣͨ +* ͨŴɺɿʼԶ̷ +* +* pszBindAddress -- ַ +* bAsyncConnect -- Ƿ첽 Connect +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Start(HP_Agent pAgent, LPCTSTR pszBindAddress, BOOL bAsyncConnect); + +/* +* ƣرͨ +* رͨرɺϿӲͷԴ +* +* +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Stop(HP_Agent pAgent); + +/* +* ƣӷ +* ӷӳɹ IAgentListener յ OnConnect() ¼ +* +* pszRemoteAddress -- ˵ַ +* usPort -- ˶˿ +* pdwConnID -- IDĬϣnullptrȡ ID +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ SYS_GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Connect(HP_Agent pAgent, LPCTSTR pszRemoteAddress, USHORT usPort, HP_CONNID* pdwConnID); + +/* +* ƣ +* ָӷ +* +* dwConnID -- ID +* pBuffer -- ͻ +* iLength -- ͻ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Send(HP_Agent pAgent, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength); + +/* +* ƣ +* ָӷ +* +* dwConnID -- ID +* pBuffer -- ͻ +* iLength -- ͻ +* iOffset -- ͻָƫ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_SendPart(HP_Agent pAgent, HP_CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset); + +/* +* ƣͶ +* ָӷͶ +* TCP - ˳ݰ +* UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ +* +* dwConnID -- ID +* pBuffers -- ͻ +* iCount -- ͻĿ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_SendPackets(HP_Agent pAgent, HP_CONNID dwConnID, const WSABUF pBuffers[], int iCount); + +/* +* ƣϿ +* Ͽij +* +* dwConnID -- ID +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_Disconnect(HP_Agent pAgent, HP_CONNID dwConnID, BOOL bForce); + +/* +* ƣϿʱ +* Ͽָʱ +* +* dwPeriod -- ʱ룩 +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_DisconnectLongConnections(HP_Agent pAgent, DWORD dwPeriod, BOOL bForce); + +/* +* ƣϿĬ +* ϿָʱľĬ +* +* dwPeriod -- ʱ룩 +* bForce -- ǷǿƶϿ +* ֵ TRUE -- ɹ +* FALSE -- ʧ +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_DisconnectSilenceConnections(HP_Agent pAgent, DWORD dwPeriod, BOOL bForce); + +/******************************************************************************/ +/***************************** Agent Էʷ *****************************/ + +/* +* ƣӵĸ +* ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ +* +* dwConnID -- ID +* pv -- +* ֵ TRUE -- ɹ +* FALSE -- ʧܣЧ ID +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_SetConnectionExtra(HP_Agent pAgent, HP_CONNID dwConnID, PVOID pExtra); + +/* +* ƣȡӵĸ +* ǷΪӰ󶨸ݻ߰ʲôݣӦóֻ +* +* dwConnID -- ID +* ppv -- ָ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣЧ ID +*/ +HPSOCKET_API BOOL __stdcall HP_Agent_GetConnectionExtra(HP_Agent pAgent, HP_CONNID dwConnID, PVOID* ppExtra); + +/* ͨǷ */ +HPSOCKET_API BOOL __stdcall HP_Agent_HasStarted(HP_Agent pAgent); +/* 鿴ͨǰ״̬ */ +HPSOCKET_API En_HP_ServiceState __stdcall HP_Agent_GetState(HP_Agent pAgent); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetConnectionCount(HP_Agent pAgent); +/* ȡӵ CONNID */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetAllConnectionIDs(HP_Agent pAgent, HP_CONNID pIDs[], DWORD* pdwCount); +/* ȡijʱ룩 */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetConnectPeriod(HP_Agent pAgent, HP_CONNID dwConnID, DWORD* pdwPeriod); +/* ȡijӾĬʱ䣨룩 */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetSilencePeriod(HP_Agent pAgent, HP_CONNID dwConnID, DWORD* pdwPeriod); +/* ȡijӵıصַϢ */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetLocalAddress(HP_Agent pAgent, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ȡijӵԶ̵ַϢ */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetRemoteAddress(HP_Agent pAgent, HP_CONNID dwConnID, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ȡһʧܲĴ */ +HPSOCKET_API En_HP_SocketError __stdcall HP_Agent_GetLastError(HP_Agent pAgent); +/* ȡһʧܲĴ */ +HPSOCKET_API LPCTSTR __stdcall HP_Agent_GetLastErrorDesc(HP_Agent pAgent); +/* ȡδݵij */ +HPSOCKET_API BOOL __stdcall HP_Agent_GetPendingDataLength(HP_Agent pAgent, HP_CONNID dwConnID, int* piPending); + +/* ݷͲ */ +HPSOCKET_API void __stdcall HP_Agent_SetSendPolicy(HP_Agent pAgent, En_HP_SendPolicy enSendPolicy); +/* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjLockTime(HP_Agent pAgent, DWORD dwFreeSocketObjLockTime); +/* Socket شСͨΪƽ 1/3 - 1/2 */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjPool(HP_Agent pAgent, DWORD dwFreeSocketObjPool); +/* ڴ黺شСͨΪ Socket شС 2 - 3 */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeBufferObjPool(HP_Agent pAgent, DWORD dwFreeBufferObjPool); +/* Socket ػշֵͨΪ Socket شС 3 */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeSocketObjHold(HP_Agent pAgent, DWORD dwFreeSocketObjHold); +/* ڴ黺ػշֵͨΪڴ黺شС 3 */ +HPSOCKET_API void __stdcall HP_Agent_SetFreeBufferObjHold(HP_Agent pAgent, DWORD dwFreeBufferObjHold); +/* ù߳ͨΪ 2 * CPU + 2 */ +HPSOCKET_API void __stdcall HP_Agent_SetWorkerThreadCount(HP_Agent pAgent, DWORD dwWorkerThreadCount); +/* ǷǾĬʱ䣨Ϊ TRUE ʱ DisconnectSilenceConnections() GetSilencePeriod() ЧĬϣFALSE */ +HPSOCKET_API void __stdcall HP_Agent_SetMarkSilence(HP_Agent pAgent, BOOL bMarkSilence); + +/* ȡݷͲ */ +HPSOCKET_API En_HP_SendPolicy __stdcall HP_Agent_GetSendPolicy(HP_Agent pAgent); +/* ȡ Socket ʱ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjLockTime(HP_Agent pAgent); +/* ȡ Socket شС */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjPool(HP_Agent pAgent); +/* ȡڴ黺شС */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeBufferObjPool(HP_Agent pAgent); +/* ȡ Socket ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeSocketObjHold(HP_Agent pAgent); +/* ȡڴ黺ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetFreeBufferObjHold(HP_Agent pAgent); +/* ȡ߳ */ +HPSOCKET_API DWORD __stdcall HP_Agent_GetWorkerThreadCount(HP_Agent pAgent); +/* ǷǾĬʱ */ +HPSOCKET_API BOOL __stdcall HP_Agent_IsMarkSilence(HP_Agent pAgent); + +/**********************************************************************************/ +/******************************* TCP Agent *******************************/ + +/* +* ƣСļ +* ָӷ 4096 KB µСļ +* +* dwConnID -- ID +* lpszFileName -- ļ· +* pHead -- ͷ +* pTail -- β +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_TcpAgent_SendSmallFile(HP_Agent pAgent, HP_CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail); + +/**********************************************************************************/ +/***************************** TCP Agent Էʷ *****************************/ + +/* ǷõַûƣĬϣã */ +HPSOCKET_API void __stdcall HP_TcpAgent_SetReuseAddress(HP_TcpAgent pAgent, BOOL bReuseAddress); +/* Ƿõַû */ +HPSOCKET_API BOOL __stdcall HP_TcpAgent_IsReuseAddress(HP_TcpAgent pAgent); + +/* ͨݻСƽͨݰСãͨΪ 1024 ı */ +HPSOCKET_API void __stdcall HP_TcpAgent_SetSocketBufferSize(HP_TcpAgent pAgent, DWORD dwSocketBufferSize); +/* 룬0 򲻷Ĭϣ30 * 1000 */ +HPSOCKET_API void __stdcall HP_TcpAgent_SetKeepAliveTime(HP_TcpAgent pAgent, DWORD dwKeepAliveTime); +/* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ +HPSOCKET_API void __stdcall HP_TcpAgent_SetKeepAliveInterval(HP_TcpAgent pAgent, DWORD dwKeepAliveInterval); + +/* ȡͨݻС */ +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetSocketBufferSize(HP_TcpAgent pAgent); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetKeepAliveTime(HP_TcpAgent pAgent); +/* ȡ쳣 */ +HPSOCKET_API DWORD __stdcall HP_TcpAgent_GetKeepAliveInterval(HP_TcpAgent pAgent); + +/**********************************************************************************/ +/***************************** UDP Agent Էʷ *****************************/ + +/* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ +HPSOCKET_API void __stdcall HP_UdpAgent_SetMaxDatagramSize(HP_UdpAgent pAgent, DWORD dwMaxDatagramSize); +/* üԴ0 򲻷ͼԴΪѶߣ */ +HPSOCKET_API void __stdcall HP_UdpAgent_SetDetectAttempts(HP_UdpAgent pAgent, DWORD dwDetectAttempts); +/* üͼ룬0 ͼ */ +HPSOCKET_API void __stdcall HP_UdpAgent_SetDetectInterval(HP_UdpAgent pAgent, DWORD dwDetectInterval); +/* ȡݱ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_UdpAgent_GetMaxDatagramSize(HP_UdpAgent pAgent); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpAgent_GetDetectAttempts(HP_UdpAgent pAgent); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpAgent_GetDetectInterval(HP_UdpAgent pAgent); + +/******************************************************************************/ +/***************************** Client *****************************/ + +/* +* ƣͨ +* ͻͨӷˣɺɿʼշ +* +* pszRemoteAddress -- ˵ַ +* usPort -- ˶˿ +* bAsyncConnect -- Ƿ첽 Connect +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Client_Start(HP_Client pClient, LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect); + +/* +* ƣرͨ +* رտͻͨرɺϿ˵ӲͷԴ +* +* +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ GetLastError() ȡ +*/ +HPSOCKET_API BOOL __stdcall HP_Client_Stop(HP_Client pClient); + +/* +* ƣ +* ˷ +* +* pBuffer -- ͻ +* iLength -- ͻ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Client_Send(HP_Client pClient, const BYTE* pBuffer, int iLength); + +/* +* ƣ +* ˷ +* +* pBuffer -- ͻ +* iLength -- ͻ +* iOffset -- ͻָƫ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Client_SendPart(HP_Client pClient, const BYTE* pBuffer, int iLength, int iOffset); + +/* +* ƣͶ +* ˷Ͷ +* TCP - ˳ݰ +* UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ +* +* pBuffers -- ͻ +* iCount -- ͻĿ +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_Client_SendPackets(HP_Client pClient, const WSABUF pBuffers[], int iCount); + +/******************************************************************************/ +/***************************** Client Էʷ *****************************/ + +/* ӵĸ */ +HPSOCKET_API void __stdcall HP_Client_SetExtra(HP_Client pClient, PVOID pExtra); +/* ȡӵĸ */ +HPSOCKET_API PVOID __stdcall HP_Client_GetExtra(HP_Client pClient); + +/* ͨǷ */ +HPSOCKET_API BOOL __stdcall HP_Client_HasStarted(HP_Client pClient); +/* 鿴ͨǰ״̬ */ +HPSOCKET_API En_HP_ServiceState __stdcall HP_Client_GetState(HP_Client pClient); +/* ȡһʧܲĴ */ +HPSOCKET_API En_HP_SocketError __stdcall HP_Client_GetLastError(HP_Client pClient); +/* ȡһʧܲĴ */ +HPSOCKET_API LPCTSTR __stdcall HP_Client_GetLastErrorDesc(HP_Client pClient); +/* ȡ ID */ +HPSOCKET_API HP_CONNID __stdcall HP_Client_GetConnectionID(HP_Client pClient); +/* ȡ Client Socket ĵַϢ */ +HPSOCKET_API BOOL __stdcall HP_Client_GetLocalAddress(HP_Client pClient, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ȡδݵij */ +HPSOCKET_API BOOL __stdcall HP_Client_GetPendingDataLength(HP_Client pClient, int* piPending); +/* ڴ黺شСͨΪ -> PUSH ģͣ5 - 10PULL ģͣ10 - 20 */ +HPSOCKET_API void __stdcall HP_Client_SetFreeBufferPoolSize(HP_Client pClient, DWORD dwFreeBufferPoolSize); +/* ڴ黺ػշֵͨΪڴ黺شС 3 */ +HPSOCKET_API void __stdcall HP_Client_SetFreeBufferPoolHold(HP_Client pClient, DWORD dwFreeBufferPoolHold); +/* ȡڴ黺شС */ +HPSOCKET_API DWORD __stdcall HP_Client_GetFreeBufferPoolSize(HP_Client pClient); +/* ȡڴ黺ػշֵ */ +HPSOCKET_API DWORD __stdcall HP_Client_GetFreeBufferPoolHold(HP_Client pClient); + +/**********************************************************************************/ +/******************************* TCP Client *******************************/ + +/* +* ƣСļ +* ˷ 4096 KB µСļ +* +* lpszFileName -- ļ· +* pHead -- ͷ +* pTail -- β +* ֵ TRUE -- ɹ +* FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows +*/ +HPSOCKET_API BOOL __stdcall HP_TcpClient_SendSmallFile(HP_Client pClient, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail); + +/**********************************************************************************/ +/***************************** TCP Client Էʷ *****************************/ + +/* ͨݻСƽͨݰСãͨΪ(N * 1024) - sizeof(TBufferObj) */ +HPSOCKET_API void __stdcall HP_TcpClient_SetSocketBufferSize(HP_TcpClient pClient, DWORD dwSocketBufferSize); +/* 룬0 򲻷Ĭϣ30 * 1000 */ +HPSOCKET_API void __stdcall HP_TcpClient_SetKeepAliveTime(HP_TcpClient pClient, DWORD dwKeepAliveTime); +/* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ +HPSOCKET_API void __stdcall HP_TcpClient_SetKeepAliveInterval(HP_TcpClient pClient, DWORD dwKeepAliveInterval); + +/* ȡͨݻС */ +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetSocketBufferSize(HP_TcpClient pClient); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetKeepAliveTime(HP_TcpClient pClient); +/* ȡ쳣 */ +HPSOCKET_API DWORD __stdcall HP_TcpClient_GetKeepAliveInterval(HP_TcpClient pClient); + +/**********************************************************************************/ +/***************************** UDP Client Էʷ *****************************/ + +/* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ +HPSOCKET_API void __stdcall HP_UdpClient_SetMaxDatagramSize(HP_UdpClient pClient, DWORD dwMaxDatagramSize); +/* ȡݱ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetMaxDatagramSize(HP_UdpClient pClient); + +/* üԴ0 򲻷ͼԴΪѶߣ */ +HPSOCKET_API void __stdcall HP_UdpClient_SetDetectAttempts(HP_UdpClient pClient, DWORD dwDetectAttempts); +/* üͼ룬0 ͼ */ +HPSOCKET_API void __stdcall HP_UdpClient_SetDetectInterval(HP_UdpClient pClient, DWORD dwDetectInterval); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetDetectAttempts(HP_UdpClient pClient); +/* ȡ */ +HPSOCKET_API DWORD __stdcall HP_UdpClient_GetDetectInterval(HP_UdpClient pClient); + +/**********************************************************************************/ +/****************************** UDP Cast Էʷ ******************************/ + +/* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ +HPSOCKET_API void __stdcall HP_UdpCast_SetMaxDatagramSize(HP_UdpCast pCast, DWORD dwMaxDatagramSize); +/* ȡݱ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_UdpCast_GetMaxDatagramSize(HP_UdpCast pCast); +/* ȡǰݱԶ̵ַϢͨ OnReceive ¼еã */ +HPSOCKET_API BOOL __stdcall HP_UdpCast_GetRemoteAddress(HP_UdpCast pCast, TCHAR lpszAddress[], int* piAddressLen, USHORT* pusPort); +/* ð󶨵ַ */ +HPSOCKET_API void __stdcall HP_UdpCast_SetBindAdddress(HP_UdpCast pCast, LPCTSTR pszBindAddress); +/* ȡ󶨵ַ */ +HPSOCKET_API LPCTSTR __stdcall HP_UdpCast_GetBindAdddress(HP_UdpCast pCast); +/* ǷõַûƣĬϣã */ +HPSOCKET_API void __stdcall HP_UdpCast_SetReuseAddress(HP_UdpCast pCast, BOOL bReuseAddress); +/* Ƿõַû */ +HPSOCKET_API BOOL __stdcall HP_UdpCast_IsReuseAddress(HP_UdpCast pCast); +/* ôģʽ鲥㲥 */ +HPSOCKET_API void __stdcall HP_UdpCast_SetCastMode(HP_UdpCast pCast, En_HP_CastMode enCastMode); +/* ȡģʽ */ +HPSOCKET_API En_HP_CastMode __stdcall HP_UdpCast_GetCastMode(HP_UdpCast pCast); +/* 鲥ĵ TTL0 - 255 */ +HPSOCKET_API void __stdcall HP_UdpCast_SetMultiCastTtl(HP_UdpCast pCast, int iMCTtl); +/* ȡ鲥ĵ TTL */ +HPSOCKET_API int __stdcall HP_UdpCast_GetMultiCastTtl(HP_UdpCast pCast); +/* Ƿ鲥·TRUE or FALSE */ +HPSOCKET_API void __stdcall HP_UdpCast_SetMultiCastLoop(HP_UdpCast pCast, BOOL bMCLoop); +/* Ƿ鲥· */ +HPSOCKET_API BOOL __stdcall HP_UdpCast_IsMultiCastLoop(HP_UdpCast pCast); + +/***************************************************************************************/ +/***************************** TCP Pull Server *****************************/ + +/* +* ƣץȡ +* ûͨ÷ Socket ץȡ +* +* dwConnID -- ID +* pData -- ץȡ +* iLength -- ץȡݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullServer_Fetch(HP_TcpPullServer pServer, HP_CONNID dwConnID, BYTE* pData, int iLength); + +/* +* ƣ̽ݣƳݣ +* ûͨ÷ Socket п̽ +* +* dwConnID -- ID +* pData -- ̽ +* iLength -- ̽ݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullServer_Peek(HP_TcpPullServer pServer, HP_CONNID dwConnID, BYTE* pData, int iLength); + +/***************************************************************************************/ +/***************************** TCP Pull Server Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pull Agent *****************************/ + +/* +* ƣץȡ +* ûͨ÷ Socket ץȡ +* +* dwConnID -- ID +* pData -- ץȡ +* iLength -- ץȡݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullAgent_Fetch(HP_TcpPullAgent pAgent, HP_CONNID dwConnID, BYTE* pData, int iLength); + +/* +* ƣ̽ݣƳݣ +* ûͨ÷ Socket п̽ +* +* dwConnID -- ID +* pData -- ̽ +* iLength -- ̽ݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullAgent_Peek(HP_TcpPullAgent pAgent, HP_CONNID dwConnID, BYTE* pData, int iLength); + +/***************************************************************************************/ +/***************************** TCP Pull Agent Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pull Client *****************************/ + +/* +* ƣץȡ +* ûͨ÷ Socket ץȡ +* +* dwConnID -- ID +* pData -- ץȡ +* iLength -- ץȡݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullClient_Fetch(HP_TcpPullClient pClient, BYTE* pData, int iLength); + +/* +* ƣ̽ݣƳݣ +* ûͨ÷ Socket п̽ +* +* dwConnID -- ID +* pData -- ̽ +* iLength -- ̽ݳ +* ֵ En_HP_FetchResult +*/ +HPSOCKET_API En_HP_FetchResult __stdcall HP_TcpPullClient_Peek(HP_TcpPullClient pClient, BYTE* pData, int iLength); + +/***************************************************************************************/ +/***************************** TCP Pull Client Էʷ *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Server *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Server Էʷ *****************************/ + +/* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ +HPSOCKET_API void __stdcall HP_TcpPackServer_SetMaxPackSize(HP_TcpPackServer pServer, DWORD dwMaxPackSize); +/* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ +HPSOCKET_API void __stdcall HP_TcpPackServer_SetPackHeaderFlag(HP_TcpPackServer pServer, USHORT usPackHeaderFlag); + +/* ȡݰ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_TcpPackServer_GetMaxPackSize(HP_TcpPackServer pServer); +/* ȡͷʶ */ +HPSOCKET_API USHORT __stdcall HP_TcpPackServer_GetPackHeaderFlag(HP_TcpPackServer pServer); + +/***************************************************************************************/ +/***************************** TCP Pack Agent *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Agent Էʷ *****************************/ + +/* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ +HPSOCKET_API void __stdcall HP_TcpPackAgent_SetMaxPackSize(HP_TcpPackAgent pAgent, DWORD dwMaxPackSize); +/* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ +HPSOCKET_API void __stdcall HP_TcpPackAgent_SetPackHeaderFlag(HP_TcpPackAgent pAgent, USHORT usPackHeaderFlag); + +/* ȡݰ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_TcpPackAgent_GetMaxPackSize(HP_TcpPackAgent pAgent); +/* ȡͷʶ */ +HPSOCKET_API USHORT __stdcall HP_TcpPackAgent_GetPackHeaderFlag(HP_TcpPackAgent pAgent); + +/***************************************************************************************/ +/***************************** TCP Pack Client *****************************/ + +/***************************************************************************************/ +/***************************** TCP Pack Client Էʷ *****************************/ + +/* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ +HPSOCKET_API void __stdcall HP_TcpPackClient_SetMaxPackSize(HP_TcpPackClient pClient, DWORD dwMaxPackSize); +/* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ +HPSOCKET_API void __stdcall HP_TcpPackClient_SetPackHeaderFlag(HP_TcpPackClient pClient, USHORT usPackHeaderFlag); + +/* ȡݰ󳤶 */ +HPSOCKET_API DWORD __stdcall HP_TcpPackClient_GetMaxPackSize(HP_TcpPackClient pClient); +/* ȡͷʶ */ +HPSOCKET_API USHORT __stdcall HP_TcpPackClient_GetPackHeaderFlag(HP_TcpPackClient pClient); + +/***************************************************************************************/ +/*************************************** ***************************************/ + +/* ȡı */ +HPSOCKET_API LPCTSTR __stdcall HP_GetSocketErrorDesc(En_HP_SocketError enCode); +/* ϵͳ ::GetLastError() ȡϵͳ */ +HPSOCKET_API DWORD __stdcall SYS_GetLastError(); +// ϵͳ ::WSAGetLastError() ȡͨŴ +HPSOCKET_API int __stdcall SYS_WSAGetLastError(); +// ϵͳ setsockopt() +HPSOCKET_API int __stdcall SYS_SetSocketOption(SOCKET sock, int level, int name, LPVOID val, int len); +// ϵͳ getsockopt() +HPSOCKET_API int __stdcall SYS_GetSocketOption(SOCKET sock, int level, int name, LPVOID val, int* len); +// ϵͳ ioctlsocket() +HPSOCKET_API int __stdcall SYS_IoctlSocket(SOCKET sock, long cmd, u_long* arg); +// ϵͳ ::WSAIoctl() +HPSOCKET_API int __stdcall SYS_WSAIoctl(SOCKET sock, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned); diff --git a/HP-Socket/Src/MiscHelper.cpp b/HP-Socket/Src/MiscHelper.cpp new file mode 100644 index 000000000..925100687 --- /dev/null +++ b/HP-Socket/Src/MiscHelper.cpp @@ -0,0 +1,53 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "MiscHelper.h" + +BOOL AddPackHeader(const WSABUF * pBuffers, int iCount, unique_ptr& buffers, DWORD dwMaxPackSize, USHORT usPackHeaderFlag, DWORD& header) +{ + ASSERT(pBuffers && iCount > 0); + + DWORD iLength = 0; + + for(int i = 0; i < iCount; i++) + { + const WSABUF& buf = pBuffers[i]; + buffers[i + 1] = buf; + iLength += buf.len; + } + + if(iLength == 0 || iLength > dwMaxPackSize) + { + ::SetLastError(ERROR_BAD_LENGTH); + return FALSE; + } + + header = (usPackHeaderFlag << 19) | iLength; + + buffers[0].len = sizeof(header); + buffers[0].buf = (char*)&header; + + return TRUE; +} diff --git a/HP-Socket/Src/MiscHelper.h b/HP-Socket/Src/MiscHelper.h new file mode 100644 index 000000000..57cb95285 --- /dev/null +++ b/HP-Socket/Src/MiscHelper.h @@ -0,0 +1,152 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "SocketHelper.h" + +/* Pack Data Info */ +template struct TPackInfo +{ + bool header; + DWORD length; + B* pBuffer; + + static TPackInfo* Construct(B* pbuf = nullptr, bool head = true, DWORD len = sizeof(DWORD)) + { + return new TPackInfo(pbuf, head, len); + } + + static void Destruct(TPackInfo* pPackInfo) + { + if(pPackInfo) + delete pPackInfo; + } + + TPackInfo(B* pbuf = nullptr, bool head = true, DWORD len = sizeof(DWORD)) + : header(head), length(len), pBuffer(pbuf) + { + } + + void Reset() + { + header = true; + length = sizeof(DWORD); + pBuffer = nullptr; + } +}; + +typedef TPackInfo TBufferPackInfo; + +BOOL AddPackHeader(const WSABUF * pBuffers, int iCount, unique_ptr& buffers, DWORD dwMaxPackSize, USHORT usPackHeaderFlag, DWORD& header); + +template EnFetchResult FetchBuffer(B* pBuffer, BYTE* pData, int iLength) +{ + ASSERT(pBuffer != nullptr); + ASSERT(pData != nullptr && iLength > 0); + + EnFetchResult result = FR_OK; + + if(pBuffer->Length() >= iLength) + pBuffer->Fetch(pData, iLength); + else + result = FR_LENGTH_TOO_LONG; + + return result; +} + +template EnFetchResult PeekBuffer(B* pBuffer, BYTE* pData, int iLength) +{ + ASSERT(pBuffer != nullptr); + ASSERT(pData != nullptr && iLength > 0); + + EnFetchResult result = FR_OK; + + if(pBuffer->Length() >= iLength) + pBuffer->Peek(pData, iLength); + else + result = FR_LENGTH_TOO_LONG; + + return result; +} + +template EnHandleResult ParsePack(T* pThis, TPackInfo* pInfo, B* pBuffer, S* pSocket, DWORD dwMaxPackSize, USHORT usPackHeaderFlag, const BYTE* pData, int iLength) +{ + EnHandleResult rs = HR_OK; + + pBuffer->Cat(pData, iLength); + iLength = pBuffer->Length(); + + int required = pInfo->length; + int remain = iLength; + + while(remain >= required) + { + remain -= required; + CBufferPtr buffer(required); + + pBuffer->Fetch(buffer, (int)buffer.Size()); + + if(pInfo->header) + { + DWORD header = *((DWORD*)(byte*)buffer); + + if(usPackHeaderFlag != 0) + { + USHORT flag = (USHORT)(header >> 19); + + if(flag != usPackHeaderFlag) + { + ::SetLastError(ERROR_INVALID_DATA); + return HR_ERROR; + } + } + + DWORD len = header & TCP_PACK_LENGTH_MASK; + + if(len > dwMaxPackSize) + { + ::SetLastError(ERROR_INVALID_DATA); + return HR_ERROR; + } + + required = len; + } + else + { + rs = pThis->FireSuperReceive(pSocket, (const BYTE*)buffer, (int)buffer.Size()); + + if(rs == HR_ERROR) + return rs; + + required = sizeof(DWORD); + } + + pInfo->header = !pInfo->header; + pInfo->length = required; + } + + return rs; +} + diff --git a/HP-Socket/Src/SocketHelper.cpp b/HP-Socket/Src/SocketHelper.cpp new file mode 100644 index 000000000..3c207b60d --- /dev/null +++ b/HP-Socket/Src/SocketHelper.cpp @@ -0,0 +1,694 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "../../Common/Src/GeneralHelper.h" +#include "../../Common/Src/SysHelper.h" +#include "SocketHelper.h" + +#include +#pragma comment(lib, "ws2_32") + +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +const DWORD MAX_WORKER_THREAD_COUNT = 500; +const DWORD MIN_SOCKET_BUFFER_SIZE = 64; +const DWORD MAX_SMALL_FILE_SIZE = 4096 * 1024; +const DWORD DEFAULT_WORKER_THREAD_COUNT = min((::SysGetNumberOfProcessors() * 2 + 2), MAX_WORKER_THREAD_COUNT); +const DWORD DEFAULT_FREE_SOCKETOBJ_LOCK_TIME = 10 * 1000; +const DWORD DEFAULT_FREE_SOCKETOBJ_POOL = 150; +const DWORD DEFAULT_FREE_SOCKETOBJ_HOLD = 600; +const DWORD DEFAULT_FREE_BUFFEROBJ_POOL = 300; +const DWORD DEFAULT_FREE_BUFFEROBJ_HOLD = 1200; +const DWORD DEFAULT_CLIENT_FREE_BUFFER_POOL_SIZE = 10; +const DWORD DEFAULT_CLIENT_FREE_BUFFER_POOL_HOLD = 40; +const DWORD DEFAULT_TCP_SOCKET_BUFFER_SIZE = ::SysGetPageSize(); +const DWORD DEFALUT_TCP_KEEPALIVE_TIME = 30 * 1000; +const DWORD DEFALUT_TCP_KEEPALIVE_INTERVAL = 10 * 1000; +const DWORD DEFAULT_TCP_SERVER_SOCKET_LISTEN_QUEUE = SOMAXCONN; +const DWORD DEFAULT_TCP_SERVER_ACCEPT_SOCKET_COUNT = 300; +const DWORD DEFAULT_UDP_MAX_DATAGRAM_SIZE = 1472; +const DWORD DEFAULT_UDP_POST_RECEIVE_COUNT = 300; +const DWORD DEFAULT_UDP_DETECT_ATTEMPTS = 3; +const DWORD DEFAULT_UDP_DETECT_INTERVAL = 20; +LPCTSTR DEFAULT_BIND_ADDRESS = _T("0.0.0.0"); + +const DWORD TCP_PACK_LENGTH_MASK = 0x7FFFF; +const DWORD TCP_PACK_MAX_SIZE_LIMIT = 0x7FFFF; +const DWORD TCP_PACK_DEFAULT_MAX_SIZE = 0x40000; +const USHORT TCP_PACK_HEADER_FLAG_LIMIT = 0x01FFF; +const USHORT TCP_PACK_DEFAULT_HEADER_FLAG = 0x00000; + +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +ULONG GetIPv4InAddr(LPCTSTR lpszAddress) +{ + if (!lpszAddress || lpszAddress[0] == '\0') + return INADDR_NONE; + +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA + IN_ADDR addr; + if (::InetPton(AF_INET, lpszAddress, &addr.s_addr) == 1) + return addr.s_addr; + + return INADDR_NONE; +#else + return ::inet_addr(CT2A(lpszAddress)); +#endif +} + +BOOL IsIPAddress(LPCTSTR lpszAddress) +{ + return GetIPv4InAddr(lpszAddress) != INADDR_NONE; +} + +BOOL GetIPAddress(LPCTSTR lpszHost, LPTSTR lpszIP, int& iIPLen) +{ + BOOL isOK = TRUE; + + if(IsIPAddress(lpszHost)) + { + int iHostLen = lstrlen(lpszHost); + + if(iHostLen > 0) + ++iHostLen; + + if(iHostLen > 0 && iIPLen >= iHostLen) + lstrcpy(lpszIP, lpszHost); + else + isOK = FALSE; + + iIPLen = iHostLen; + } + else + { + IN_ADDR addr; + + if(GetOptimalIPByHostName(lpszHost, addr)) + isOK = IN_ADDR_2_IP(addr, lpszIP, iIPLen); + else + isOK = FALSE; + } + + return isOK; +} + +BOOL GetOptimalIPByHostName(LPCTSTR lpszHost, IN_ADDR& addr) +{ + addr.s_addr = 0; + + addrinfo* pInfo = nullptr; + addrinfo hints = {0}; + + hints.ai_flags = AI_ALL; + hints.ai_family = AF_INET; + + int rs = ::getaddrinfo((CT2A)lpszHost, nullptr, &hints, &pInfo); + + if(rs == NO_ERROR) + { + IN_ADDR inAddr; + ULONG addrs[3] = {0}; + char** pptr = nullptr; + + for(addrinfo* pCur = pInfo; pCur != nullptr; pCur = pCur->ai_next) + { + if(pCur->ai_family == AF_INET) + { + inAddr = ((SOCKADDR_IN*)(pCur->ai_addr))->sin_addr; + UCHAR a = inAddr.s_net; + UCHAR b = inAddr.s_host; + + if(addrs[0] == 0 && a == 127) + { + addrs[0] = inAddr.s_addr; + break; + } + else if( addrs[1] == 0 && + ( + (a == 10) || + (a == 172 && b >= 16 && b <= 31) || + (a == 192 && b == 168) + ) + ) + addrs[1] = inAddr.s_addr; + else if(addrs[2] == 0) + addrs[2] = inAddr.s_addr; + } + } + + ::freeaddrinfo(pInfo); + + for(int i = 0; i < 3; i++) + { + if(addrs[i] != 0) + { + addr.s_addr = addrs[i]; + break; + } + } + } + + return addr.s_addr != 0; +} + +BOOL IN_ADDR_2_IP(const IN_ADDR& addr, LPTSTR lpszAddress, int& iAddressLen) +{ + BOOL isOK = TRUE; + + TCHAR szAddr[16]; + wsprintf(szAddr, _T("%hu.%hu.%hu.%hu"), addr.s_net, addr.s_host, addr.s_lh, addr.s_impno); + + int iIPLen = lstrlen(szAddr) + 1; + + if(iAddressLen >= iIPLen) + memcpy(lpszAddress, szAddr, iIPLen * sizeof(TCHAR)); + else + isOK = FALSE; + + iAddressLen = iIPLen; + + return isOK; +} + +BOOL sockaddr_IN_2_A(const SOCKADDR_IN& addr, ADDRESS_FAMILY& usFamily, LPTSTR lpszAddress, int& iAddressLen, USHORT& usPort) +{ + usFamily = addr.sin_family; + usPort = ntohs(addr.sin_port); + + return IN_ADDR_2_IP(addr.sin_addr, lpszAddress, iAddressLen); +} + +BOOL sockaddr_A_2_IN(ADDRESS_FAMILY usFamily, LPCTSTR pszAddress, USHORT usPort, SOCKADDR_IN& addr) +{ + ASSERT(usFamily == AF_INET); + + addr.sin_family = usFamily; + addr.sin_port = htons(usPort); + addr.sin_addr.s_addr = GetIPv4InAddr(pszAddress); + + return addr.sin_addr.s_addr != INADDR_NONE; +} + +BOOL GetSocketAddress(SOCKET socket, LPTSTR lpszAddress, int& iAddressLen, USHORT& usPort, BOOL bLocal) +{ + sockaddr addr; + + int addr_len = sizeof(addr); + int result = bLocal ? getsockname(socket, &addr, &addr_len) : getpeername(socket, &addr, &addr_len); + + if(result == NO_ERROR) + { + ADDRESS_FAMILY usFamily; + return sockaddr_IN_2_A((sockaddr_in&)addr, usFamily, lpszAddress, iAddressLen, usPort); + } + + return FALSE; +} + +BOOL GetSocketLocalAddress(SOCKET socket, LPTSTR lpszAddress, int& iAddressLen, USHORT& usPort) +{ + return GetSocketAddress(socket, lpszAddress, iAddressLen, usPort, TRUE); +} + +BOOL GetSocketRemoteAddress(SOCKET socket, LPTSTR lpszAddress, int& iAddressLen, USHORT& usPort) +{ + return GetSocketAddress(socket, lpszAddress, iAddressLen, usPort, FALSE); +} + +PVOID GetExtensionFuncPtr(SOCKET sock, GUID guid) +{ + DWORD dwBytes; + PVOID pfn = nullptr; + + ::WSAIoctl ( + sock, + SIO_GET_EXTENSION_FUNCTION_POINTER, + &guid, + sizeof(guid), + &pfn, + sizeof(pfn), + &dwBytes, + nullptr, + nullptr + ); + + return pfn; +} + +LPFN_ACCEPTEX Get_AcceptEx_FuncPtr(SOCKET sock) +{ + GUID guid = WSAID_ACCEPTEX; + return (LPFN_ACCEPTEX)GetExtensionFuncPtr(sock, guid); +} + +LPFN_GETACCEPTEXSOCKADDRS Get_GetAcceptExSockaddrs_FuncPtr(SOCKET sock) +{ + GUID guid = WSAID_GETACCEPTEXSOCKADDRS; + return (LPFN_GETACCEPTEXSOCKADDRS)GetExtensionFuncPtr(sock, guid); +} + +LPFN_CONNECTEX Get_ConnectEx_FuncPtr(SOCKET sock) +{ + GUID guid = WSAID_CONNECTEX; + return (LPFN_CONNECTEX)GetExtensionFuncPtr(sock, guid); +} + +LPFN_TRANSMITFILE Get_TransmitFile_FuncPtr(SOCKET sock) +{ + GUID guid = WSAID_TRANSMITFILE; + return (LPFN_TRANSMITFILE)GetExtensionFuncPtr(sock, guid); +} + +LPFN_DISCONNECTEX Get_DisconnectEx_FuncPtr (SOCKET sock) +{ + GUID guid = WSAID_DISCONNECTEX; + return (LPFN_DISCONNECTEX)GetExtensionFuncPtr(sock, guid); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +BOOL PostIocpCommand(HANDLE hIOCP, EnIocpCommand enCmd, ULONG_PTR ulParam) +{ + return ::PostQueuedCompletionStatus(hIOCP, enCmd, ulParam, nullptr); +} + +BOOL PostIocpExit(HANDLE hIOCP) +{ + return ::PostQueuedCompletionStatus(hIOCP, IOCP_CMD_EXIT, 0, nullptr); +} + +BOOL PostIocpAccept(HANDLE hIOCP) +{ + return ::PostQueuedCompletionStatus(hIOCP, IOCP_CMD_ACCEPT, 0, nullptr); +} + +BOOL PostIocpDisconnect(HANDLE hIOCP, CONNID dwConnID) +{ + return ::PostQueuedCompletionStatus(hIOCP, IOCP_CMD_DISCONNECT, dwConnID, nullptr); +} + +BOOL PostIocpSend(HANDLE hIOCP, CONNID dwConnID) +{ + return ::PostQueuedCompletionStatus(hIOCP, IOCP_CMD_SEND, dwConnID, nullptr); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +int SSO_SetSocketOption(SOCKET sock, int level, int name, LPVOID val, int len) +{ + return setsockopt(sock, level, name, (CHAR*)val, len); +} + +int SSO_GetSocketOption(SOCKET sock, int level, int name, LPVOID val, int* len) +{ + return getsockopt(sock, level, name, (CHAR*)val, len); +} + +int SSO_IoctlSocket(SOCKET sock, long cmd, u_long* arg) +{ + return ioctlsocket(sock, cmd, arg); +} + +int SSO_WSAIoctl(SOCKET sock, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned) +{ + return ::WSAIoctl(sock, dwIoControlCode, lpvInBuffer, cbInBuffer, lpvOutBuffer, cbOutBuffer, lpcbBytesReturned, nullptr, nullptr); +} + +int SSO_UpdateAcceptContext(SOCKET soClient, SOCKET soBind) +{ + return setsockopt(soClient, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (CHAR*)&soBind, sizeof(SOCKET)); +} + +int SSO_UpdateConnectContext(SOCKET soClient, int iOption) +{ + return setsockopt(soClient, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, (CHAR*)&iOption, sizeof(int)); +} + +int SSO_NoDelay(SOCKET sock, BOOL bNoDelay) +{ + return setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (CHAR*)&bNoDelay, sizeof(BOOL)); +} + +int SSO_DontLinger(SOCKET sock, BOOL bDont) +{ + return setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (CHAR*)&bDont, sizeof(BOOL)); +} + +int SSO_Linger(SOCKET sock, USHORT l_onoff, USHORT l_linger) +{ + linger ln = {l_onoff, l_linger}; + return setsockopt(sock, SOL_SOCKET, SO_LINGER, (CHAR*)&ln, sizeof(linger)); +} + +int SSO_KeepAlive(SOCKET sock, BOOL bKeepAlive) +{ + return setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (CHAR*)&bKeepAlive, sizeof(BOOL)); +} + +int SSO_KeepAliveVals(SOCKET sock, u_long onoff, u_long time, u_long interval) +{ + int result = NO_ERROR; + tcp_keepalive in = {onoff, time, interval}; + DWORD dwBytes; + + if(::WSAIoctl ( + sock, + SIO_KEEPALIVE_VALS, + (LPVOID)&in, + sizeof(in), + nullptr, + 0, + &dwBytes, + nullptr, + nullptr + ) == SOCKET_ERROR) + { + result = ::WSAGetLastError(); + if(result == WSAEWOULDBLOCK) + result = NO_ERROR; + } + + return result; +} + +int SSO_RecvBuffSize(SOCKET sock, int size) +{ + return setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (CHAR*)&size, sizeof(int)); +} + +int SSO_SendBuffSize(SOCKET sock, int size) +{ + return setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (CHAR*)&size, sizeof(int)); +} + +int SSO_ReuseAddress(SOCKET sock, BOOL bReuse) +{ + return setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (CHAR*)&bReuse, sizeof(BOOL)); +} + +int SSO_UDP_ConnReset(SOCKET sock, BOOL bNewBehavior) +{ + int result = NO_ERROR; + DWORD dwBytes; + + if(::WSAIoctl ( + sock, + SIO_UDP_CONNRESET, + (LPVOID)&bNewBehavior, + sizeof(bNewBehavior), + nullptr, + 0, + &dwBytes, + nullptr, + nullptr + ) == SOCKET_ERROR) + { + result = ::WSAGetLastError(); + if(result == WSAEWOULDBLOCK) + result = NO_ERROR; + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +CONNID GenerateConnectionID() +{ + static volatile CONNID s_dwConnID = 0; + + CONNID dwConnID = ::InterlockedIncrement(&s_dwConnID); + + if(dwConnID == 0) + dwConnID = ::InterlockedIncrement(&s_dwConnID); + + return dwConnID; +} + +int ManualCloseSocket(SOCKET sock, int iShutdownFlag, BOOL bGraceful, BOOL bReuseAddress) +{ + if(!bGraceful) + SSO_Linger(sock, 1, 0); + + if(bReuseAddress) + SSO_ReuseAddress(sock, bReuseAddress); + + if(iShutdownFlag != 0xFF) + shutdown(sock, iShutdownFlag); + + return closesocket(sock); +} + +int PostAccept(LPFN_ACCEPTEX pfnAcceptEx, SOCKET soListen, SOCKET soClient, TBufferObj* pBufferObj) +{ + int result = PostAcceptNotCheck(pfnAcceptEx, soListen, soClient, pBufferObj); + + if(result == WSA_IO_PENDING) + result = NO_ERROR; + + return result; +} + +int PostAcceptNotCheck(LPFN_ACCEPTEX pfnAcceptEx, SOCKET soListen, SOCKET soClient, TBufferObj* pBufferObj) +{ + int result = NO_ERROR; + pBufferObj->client = soClient; + pBufferObj->operation = SO_ACCEPT; + + if(!pfnAcceptEx ( + soListen, + pBufferObj->client, + pBufferObj->buff.buf, + 0, + sizeof(SOCKADDR_IN) + 16, + sizeof(SOCKADDR_IN) + 16, + nullptr, + &pBufferObj->ov + ) + ) + { + result = ::WSAGetLastError(); + } + + return result; +} + +int PostConnect(LPFN_CONNECTEX pfnConnectEx, SOCKET soClient, SOCKADDR_IN& soAddrIN, TBufferObj* pBufferObj) +{ + int result = PostConnectNotCheck(pfnConnectEx, soClient, soAddrIN, pBufferObj); + + if(result == WSA_IO_PENDING) + result = NO_ERROR; + + return result; +} + +int PostConnectNotCheck(LPFN_CONNECTEX pfnConnectEx, SOCKET soClient, SOCKADDR_IN& soAddrIN, TBufferObj* pBufferObj) +{ + int result = NO_ERROR; + pBufferObj->client = soClient; + pBufferObj->operation = SO_CONNECT; + + if(!pfnConnectEx ( + soClient, + (SOCKADDR*)&soAddrIN, + sizeof(SOCKADDR_IN), + nullptr, + 0, + nullptr, + &pBufferObj->ov + ) + ) + { + result = ::WSAGetLastError(); + } + + return result; +} + +int PostSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + int result = PostSendNotCheck(pSocketObj, pBufferObj); + + if(result == WSA_IO_PENDING) + result = NO_ERROR; + + return result; +} + +int PostSendNotCheck(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + int result = NO_ERROR; + DWORD dwBytes = 0; + pBufferObj->client = pSocketObj->socket; + pBufferObj->operation = SO_SEND; + + if(::WSASend( + pBufferObj->client, + &pBufferObj->buff, + 1, + &dwBytes, + 0, + &pBufferObj->ov, + nullptr + ) == SOCKET_ERROR) + { + result = ::WSAGetLastError(); + } + + return result; +} + +int PostReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + int result = PostReceiveNotCheck(pSocketObj, pBufferObj); + + if(result == WSA_IO_PENDING) + result = NO_ERROR; + + return result; +} + +int PostReceiveNotCheck(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + int result = NO_ERROR; + DWORD dwFlag = 0; + DWORD dwBytes = 0; + pBufferObj->client = pSocketObj->socket; + pBufferObj->operation = SO_RECEIVE; + + if(::WSARecv( + pBufferObj->client, + &pBufferObj->buff, + 1, + &dwBytes, + &dwFlag, + &pBufferObj->ov, + nullptr + ) == SOCKET_ERROR) + { + result = ::WSAGetLastError(); + } + + return result; +} + +int PostSendTo(SOCKET sock, TUdpBufferObj* pBufferObj) +{ + int result = PostSendToNotCheck(sock, pBufferObj); + + if(result == WSA_IO_PENDING) + result = NO_ERROR; + + return result; +} + +int PostSendToNotCheck(SOCKET sock, TUdpBufferObj* pBufferObj) +{ + int result = NO_ERROR; + DWORD dwBytes = 0; + pBufferObj->operation = SO_SEND; + pBufferObj->addrLen = sizeof(SOCKADDR_IN); + + if(::WSASendTo ( + sock, + &pBufferObj->buff, + 1, + &dwBytes, + 0, + (sockaddr*)&pBufferObj->remoteAddr, + pBufferObj->addrLen, + &pBufferObj->ov, + nullptr + ) == SOCKET_ERROR) + { + result = ::WSAGetLastError(); + } + + return result; +} + +int PostReceiveFrom(SOCKET sock, TUdpBufferObj* pBufferObj) +{ + int result = PostReceiveFromNotCheck(sock, pBufferObj); + + if(result == WSA_IO_PENDING) + result = NO_ERROR; + + return result; +} + +int PostReceiveFromNotCheck(SOCKET sock, TUdpBufferObj* pBufferObj) +{ + int result = NO_ERROR; + DWORD dwFlag = 0; + DWORD dwBytes = 0; + pBufferObj->operation = SO_RECEIVE; + pBufferObj->addrLen = sizeof(SOCKADDR_IN); + + ::ZeroMemory(&pBufferObj->remoteAddr, pBufferObj->addrLen); + + if(::WSARecvFrom( + sock, + &pBufferObj->buff, + 1, + &dwBytes, + &dwFlag, + (sockaddr*)&pBufferObj->remoteAddr, + &pBufferObj->addrLen, + &pBufferObj->ov, + nullptr + ) == SOCKET_ERROR) + { + result = ::WSAGetLastError(); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +LPCTSTR GetSocketErrorDesc(EnSocketError enCode) +{ + switch(enCode) + { + case SE_OK: return _T("SUCCESS"); + case SE_ILLEGAL_STATE: return _T("Illegal State"); + case SE_INVALID_PARAM: return _T("Invalid Parameter"); + case SE_SOCKET_CREATE: return _T("Create SOCKET Fail"); + case SE_SOCKET_BIND: return _T("Bind SOCKET Fail"); + case SE_SOCKET_PREPARE: return _T("Prepare SOCKET Fail"); + case SE_SOCKET_LISTEN: return _T("Listen SOCKET Fail"); + case SE_CP_CREATE: return _T("Create IOCP Fail"); + case SE_WORKER_THREAD_CREATE: return _T("Create Worker Thread Fail"); + case SE_DETECT_THREAD_CREATE: return _T("Create Detector Thread Fail"); + case SE_SOCKE_ATTACH_TO_CP: return _T("Attach SOCKET to IOCP Fail"); + case SE_CONNECT_SERVER: return _T("Connect to Server Fail"); + case SE_NETWORK: return _T("Network Error"); + case SE_DATA_PROC: return _T("Process Data Error"); + case SE_DATA_SEND: return _T("Send Data Error"); + default: ASSERT(FALSE); return _T("UNKNOWN ERROR"); + } +} diff --git a/HP-Socket/Src/SocketHelper.h b/HP-Socket/Src/SocketHelper.h new file mode 100644 index 000000000..4f153f443 --- /dev/null +++ b/HP-Socket/Src/SocketHelper.h @@ -0,0 +1,452 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +#include "SocketInterface.h" +#include "../../Common/Src/WaitFor.h" +#include "../../Common/Src/bufferpool.h" +#include "../../Common//Src/RingBuffer.h" + +/************************************************************************ +ƣȫֳ +Ĺȫֳ +************************************************************************/ + +/* IOCP ߳ */ +extern const DWORD MAX_WORKER_THREAD_COUNT; +/* IOCP Socket Сֵ */ +extern const DWORD MIN_SOCKET_BUFFER_SIZE; +/* Сļֽ */ +extern const DWORD MAX_SMALL_FILE_SIZE; + +/* IOCP ĬϹ߳ */ +extern const DWORD DEFAULT_WORKER_THREAD_COUNT; +/* Server/Agent Ĭ Socket ʱ */ +extern const DWORD DEFAULT_FREE_SOCKETOBJ_LOCK_TIME; +/* Server/Agent Ĭ Socket شС */ +extern const DWORD DEFAULT_FREE_SOCKETOBJ_POOL; +/* Server/Agent Ĭ Socket ػշֵ */ +extern const DWORD DEFAULT_FREE_SOCKETOBJ_HOLD; +/* Server/Agent Ĭڴ黺شС */ +extern const DWORD DEFAULT_FREE_BUFFEROBJ_POOL; +/* Server/Agent Ĭڴ黺ػշֵ */ +extern const DWORD DEFAULT_FREE_BUFFEROBJ_HOLD; +/* Client Ĭڴ黺شС */ +extern const DWORD DEFAULT_CLIENT_FREE_BUFFER_POOL_SIZE; +/* Client Ĭڴ黺ػշֵ */ +extern const DWORD DEFAULT_CLIENT_FREE_BUFFER_POOL_HOLD; +/* Agent Ĭϰ󶨵ַ */ +extern LPCTSTR DEFAULT_BIND_ADDRESS; + +/* TCP ĬͨݻС */ +extern const DWORD DEFAULT_TCP_SOCKET_BUFFER_SIZE; +/* TCP Ĭ */ +extern const DWORD DEFALUT_TCP_KEEPALIVE_TIME; +/* TCP Ĭȷϰ */ +extern const DWORD DEFALUT_TCP_KEEPALIVE_INTERVAL; +/* TCP Server Ĭ Listen дС */ +extern const DWORD DEFAULT_TCP_SERVER_SOCKET_LISTEN_QUEUE; +/* TCP Server ĬԤͶ Accept */ +extern const DWORD DEFAULT_TCP_SERVER_ACCEPT_SOCKET_COUNT; + +/* UDP Ĭݱ󳤶 */ +extern const DWORD DEFAULT_UDP_MAX_DATAGRAM_SIZE; +/* UDP Ĭ Receive ԤͶ */ +extern const DWORD DEFAULT_UDP_POST_RECEIVE_COUNT; +/* UDP ĬϼԴ */ +extern const DWORD DEFAULT_UDP_DETECT_ATTEMPTS; +/* UDP Ĭϼͼ */ +extern const DWORD DEFAULT_UDP_DETECT_INTERVAL; + +/* TCP Pack */ +extern const DWORD TCP_PACK_LENGTH_MASK; +/* TCP Pack 󳤶Ӳ */ +extern const DWORD TCP_PACK_MAX_SIZE_LIMIT; +/* TCP Pack Ĭ󳤶 */ +extern const DWORD TCP_PACK_DEFAULT_MAX_SIZE; +/* TCP Pack ͷʶֵӲ */ +extern const USHORT TCP_PACK_HEADER_FLAG_LIMIT; +/* TCP Pack ͷĬϱʶֵ */ +extern const USHORT TCP_PACK_DEFAULT_HEADER_FLAG; + +/************************************************************************ +ƣWindows Socket ʼ +Զغж Windows Socket +************************************************************************/ +class CInitSocket +{ +public: + CInitSocket(LPWSADATA lpWSAData = nullptr, BYTE minorVersion = 2, BYTE majorVersion = 2) + { + LPWSADATA lpTemp = lpWSAData; + if(!lpTemp) + lpTemp = (LPWSADATA)_alloca(sizeof(WSADATA)); + + m_iResult = ::WSAStartup(MAKEWORD(minorVersion, majorVersion), lpTemp); + } + + ~CInitSocket() + { + if(IsValid()) + ::WSACleanup(); + } + + int GetResult() {return m_iResult;} + BOOL IsValid() {return m_iResult == 0;} + +private: + int m_iResult; +}; + +/* Server Agent ڲʹõ¼ */ + +// ѹر +#define HR_CLOSED 0xFF + +/* رӱʶ */ +enum EnSocketCloseFlag +{ + SCF_NONE = 0, // ¼ + SCF_CLOSE = 1, // ر OnClose ¼ + SCF_ERROR = 2 // 쳣ر OnClose ¼ +}; + +/* ݻṹ */ +struct TBufferObjBase +{ + WSAOVERLAPPED ov; + EnSocketOperation operation; + WSABUF buff; +}; + +/* ݻṹ */ +struct TBufferObj : public TBufferObjBase +{ + SOCKET client; +}; + +/* UDP ݻṹ */ +struct TUdpBufferObj : public TBufferObjBase +{ + SOCKADDR_IN remoteAddr; + int addrLen; +}; + +/* ݻṹ */ +typedef CRingPool TBufferObjPtrList; + +/* Udp ݻṹ */ +typedef CRingPool TUdpBufferObjPtrList; + +/* Socket ṹ */ +struct TSocketObjBase +{ + CONNID connID; + SOCKADDR_IN remoteAddr; + PVOID extra; + PVOID reserved; + BOOL valid; + + union + { + DWORD freeTime; + DWORD connTime; + }; + + DWORD activeTime; + + CCriSec csSend; + TItemList sndBuff; + + volatile BOOL smooth; + volatile long pending; + volatile long sndCount; + + CReentrantSpinGuard csRecv; + + TSocketObjBase(CItemPool& itPool) + : sndBuff(itPool) + { + + } + + static BOOL IsExist(TSocketObjBase* pSocketObj) + {return pSocketObj != nullptr;} + + static BOOL IsValid(TSocketObjBase* pSocketObj) + {return pSocketObj != nullptr && pSocketObj->valid;} + + static void Invalid(TSocketObjBase* pSocketObj) + {ASSERT(IsExist(pSocketObj)); pSocketObj->valid = FALSE;} + + static BOOL IsSmooth(TSocketObjBase* pSocketObj) + {ASSERT(IsExist(pSocketObj)); return pSocketObj->valid && pSocketObj->smooth;} + + static BOOL IsPending(TSocketObjBase* pSocketObj) + {ASSERT(IsExist(pSocketObj)); return pSocketObj->valid && pSocketObj->pending > 0;} + + static void Release(TSocketObjBase* pSocketObj) + { + ASSERT(IsExist(pSocketObj)); + + pSocketObj->sndBuff.Release(); + pSocketObj->freeTime = ::TimeGetTime(); + } + + int Pending() {return pending;} + + void Reset(CONNID dwConnID) + { + connID = dwConnID; + valid = TRUE; + smooth = TRUE; + pending = 0; + sndCount = 0; + extra = nullptr; + reserved = nullptr; + } +}; + +/* ݻṹ */ +struct TSocketObj : public TSocketObjBase +{ + SOCKET socket; + + TSocketObj(CItemPool& itPool) + : TSocketObjBase(itPool) + { + + } + + void Reset(CONNID dwConnID, SOCKET soClient) + { + __super::Reset(dwConnID); + socket = soClient; + } +}; + +/* UDP ݻṹ */ +struct TUdpSocketObj : public TSocketObjBase +{ + volatile DWORD detectFails; + + TUdpSocketObj(CItemPool& itPool) + : TSocketObjBase(itPool) + { + + } + + void Reset(CONNID dwConnID) + { + __super::Reset(dwConnID); + detectFails = 0; + } +}; + +/* ݻṹ */ +typedef CRingPool TSocketObjPtrList; +/* ݻսṹ */ +typedef CCASQueue TSocketObjPtrQueue; +/* ݻṹϣ */ +typedef unordered_map TSocketObjPtrMap; +/* ݻṹϣ */ +typedef TSocketObjPtrMap::iterator TSocketObjPtrMapI; +/* ݻṹϣ const */ +typedef TSocketObjPtrMap::const_iterator TSocketObjPtrMapCI; + +/* UDP ݻṹ */ +typedef CRingPool TUdpSocketObjPtrList; +/* ݻսṹ */ +typedef CCASQueue TUdpSocketObjPtrQueue; +/* UDP ݻṹϣ */ +typedef unordered_map TUdpSocketObjPtrMap; +/* UDP ݻṹϣ */ +typedef TUdpSocketObjPtrMap::iterator TUdpSocketObjPtrMapI; +/* UDP ݻṹϣ const */ +typedef TUdpSocketObjPtrMap::const_iterator TUdpSocketObjPtrMapCI; + +/* SOCKADDR_IN Ƚ */ +struct sockaddr_func +{ + struct hash + { + size_t operator() (const SOCKADDR_IN* pA) const + { + return ((pA->sin_family << 16) | ntohs(pA->sin_port)) ^ pA->sin_addr.s_addr; + } + }; + + struct equal_to + { + bool operator () (const SOCKADDR_IN* pA, const SOCKADDR_IN* pB) const + { + return memcmp(pA, pB, offsetof(SOCKADDR_IN, sin_zero)) == 0; + } + }; + +}; + +/* ַ- ID ϣ */ +typedef unordered_map + TSockAddrMap; +/* ַ- ID ϣ */ +typedef TSockAddrMap::iterator TSockAddrMapI; +/* ַ- ID ϣ const */ +typedef TSockAddrMap::const_iterator TSockAddrMapCI; + +/*****************************************************************************************************/ +/******************************************** ********************************************/ +/*****************************************************************************************************/ + +/* ȡı */ +LPCTSTR GetSocketErrorDesc(EnSocketError enCode); +/* ȡ IPv4 ַ */ +ULONG GetIPv4InAddr(LPCTSTR lpszAddress); +/* ַǷ IP ַʽ */ +BOOL IsIPAddress(LPCTSTR lpszAddress); +/* ͨȡ IP ַ */ +BOOL GetIPAddress(LPCTSTR lpszHost, __out LPTSTR lpszIP, __inout int& iIPLenth); +/* ͨȡŵ IP ַ */ +BOOL GetOptimalIPByHostName(LPCTSTR lpszHost, __out IN_ADDR& addr); +/* ȡ IN_ADDR ṹ IP ַ */ +BOOL IN_ADDR_2_IP(const IN_ADDR& addr, __out LPTSTR lpszAddress, __inout int& iAddressLen); +/* SOCKADDR_IN ṹתΪַ */ +BOOL sockaddr_IN_2_A(const SOCKADDR_IN& addr, __out ADDRESS_FAMILY& usFamily, __out LPTSTR lpszAddress, __inout int& iAddressLen, __out USHORT& usPort); +/* ѵַתΪ SOCKADDR_IN ṹ */ +BOOL sockaddr_A_2_IN(ADDRESS_FAMILY usFamily, LPCTSTR pszAddress, USHORT usPort, __out SOCKADDR_IN& addr); +/* ȡ Socket ıػԶ̵ַϢ */ +BOOL GetSocketAddress(SOCKET socket, __out LPTSTR lpszAddress, __inout int& iAddressLen, __out USHORT& usPort, BOOL bLocal = TRUE); +/* ȡ Socket ıصַϢ */ +BOOL GetSocketLocalAddress(SOCKET socket, __out LPTSTR lpszAddress, __inout int& iAddressLen, __out USHORT& usPort); +/* ȡ Socket Զ̵ַϢ */ +BOOL GetSocketRemoteAddress(SOCKET socket, __out LPTSTR lpszAddress, __inout int& iAddressLen, __out USHORT& usPort); + +/* ȡ Socket ijչָ */ +PVOID GetExtensionFuncPtr (SOCKET sock, GUID guid); +/* ȡ AcceptEx չָ */ +LPFN_ACCEPTEX Get_AcceptEx_FuncPtr (SOCKET sock); +/* ȡ GetAcceptExSockaddrs չָ */ +LPFN_GETACCEPTEXSOCKADDRS Get_GetAcceptExSockaddrs_FuncPtr(SOCKET sock); +/* ȡ ConnectEx չָ */ +LPFN_CONNECTEX Get_ConnectEx_FuncPtr (SOCKET sock); +/* ȡ TransmitFile չָ */ +LPFN_TRANSMITFILE Get_TransmitFile_FuncPtr (SOCKET sock); +/* ȡ DisconnectEx չָ */ +LPFN_DISCONNECTEX Get_DisconnectEx_FuncPtr (SOCKET sock); + +/************************************************************************ +ƣIOCP ָͶݰ + IOCP ָͶ +************************************************************************/ + +/* IOCP */ +enum EnIocpCommand +{ + IOCP_CMD_EXIT = 0x00000000, // ˳ + IOCP_CMD_ACCEPT = 0xFFFFFFF1, // + IOCP_CMD_DISCONNECT = 0xFFFFFFF2, // Ͽ + IOCP_CMD_SEND = 0xFFFFFFF3 // +}; + +/* IOCP  */ +enum EnIocpAction +{ + IOCP_ACT_GOON = 0, // ִ + IOCP_ACT_CONTINUE = 1, // ִ + IOCP_ACT_BREAK = 2 // жִ +}; + +BOOL PostIocpCommand(HANDLE hIOCP, EnIocpCommand enCmd, ULONG_PTR ulParam); +BOOL PostIocpExit(HANDLE hIOCP); +BOOL PostIocpAccept(HANDLE hIOCP); +BOOL PostIocpDisconnect(HANDLE hIOCP, CONNID dwConnID); +BOOL PostIocpSend(HANDLE hIOCP, CONNID dwConnID); + +/************************************************************************ +ƣsetsockopt() +򻯳õ setsockopt() +************************************************************************/ + +int SSO_SetSocketOption (SOCKET sock, int level, int name, LPVOID val, int len); +int SSO_GetSocketOption (SOCKET sock, int level, int name, LPVOID val, int* len); +int SSO_IoctlSocket (SOCKET sock, long cmd, u_long* arg); +int SSO_WSAIoctl (SOCKET sock, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned); + +int SSO_UpdateAcceptContext (SOCKET soClient, SOCKET soBind); +int SSO_UpdateConnectContext(SOCKET soClient, int iOption); +int SSO_NoDelay (SOCKET sock, BOOL bNoDelay = TRUE); +int SSO_DontLinger (SOCKET sock, BOOL bDont = TRUE); +int SSO_Linger (SOCKET sock, USHORT l_onoff, USHORT l_linger); +int SSO_KeepAlive (SOCKET sock, BOOL bKeepAlive = TRUE); +int SSO_KeepAliveVals (SOCKET sock, u_long onoff, u_long time, u_long interval); +int SSO_RecvBuffSize (SOCKET sock, int size); +int SSO_SendBuffSize (SOCKET sock, int size); +int SSO_ReuseAddress (SOCKET sock, BOOL bReuse = TRUE); +int SSO_UDP_ConnReset (SOCKET sock, BOOL bNewBehavior = TRUE); + +/************************************************************************ +ƣSocket +Socket װ +************************************************************************/ + +/* IOCP ֵNO_ERROR 򷵻 TRUE */ +#define IOCP_NO_ERROR(result) (result == NO_ERROR) +/* IOCP ֵWSA_IO_PENDING 򷵻 TRUE */ +#define IOCP_PENDING(result) (result == WSA_IO_PENDING) +/* IOCP ֵNO_ERROR WSA_IO_PENDING 򷵻 TRUE */ +#define IOCP_SUCCESS(result) (IOCP_NO_ERROR(result) || IOCP_PENDING(result)) + +/* Connection ID */ +CONNID GenerateConnectionID (); +/* ر Socket */ +int ManualCloseSocket (SOCKET sock, int iShutdownFlag = 0xFF, BOOL bGraceful = TRUE, BOOL bReuseAddress = FALSE); +/* Ͷ AccceptEx() WSA_IO_PENDING תΪ NO_ERROR */ +int PostAccept (LPFN_ACCEPTEX pfnAcceptEx, SOCKET soListen, SOCKET soClient, TBufferObj* pBufferObj); +/* Ͷ AccceptEx() */ +int PostAcceptNotCheck (LPFN_ACCEPTEX pfnAcceptEx, SOCKET soListen, SOCKET soClient, TBufferObj* pBufferObj); +/* Ͷ ConnectEx() WSA_IO_PENDING תΪ NO_ERROR */ +int PostConnect (LPFN_CONNECTEX pfnConnectEx, SOCKET soClient, SOCKADDR_IN& soAddrIN, TBufferObj* pBufferObj); +/* Ͷ ConnectEx() */ +int PostConnectNotCheck (LPFN_CONNECTEX pfnConnectEx, SOCKET soClient, SOCKADDR_IN& soAddrIN, TBufferObj* pBufferObj); +/* Ͷ WSASend() WSA_IO_PENDING תΪ NO_ERROR */ +int PostSend (TSocketObj* pSocketObj, TBufferObj* pBufferObj); +/* Ͷ WSASend() */ +int PostSendNotCheck (TSocketObj* pSocketObj, TBufferObj* pBufferObj); +/* Ͷ WSARecv() WSA_IO_PENDING תΪ NO_ERROR*/ +int PostReceive (TSocketObj* pSocketObj, TBufferObj* pBufferObj); +/* Ͷ WSARecv() */ +int PostReceiveNotCheck (TSocketObj* pSocketObj, TBufferObj* pBufferObj); +/* Ͷ WSASendTo() WSA_IO_PENDING תΪ NO_ERROR*/ +int PostSendTo (SOCKET sock, TUdpBufferObj* pBufferObj); +/* Ͷ WSASendTo() */ +int PostSendToNotCheck (SOCKET sock, TUdpBufferObj* pBufferObj); +/* Ͷ WSARecvFrom() WSA_IO_PENDING תΪ NO_ERROR*/ +int PostReceiveFrom (SOCKET sock, TUdpBufferObj* pBufferObj); +/* Ͷ WSARecvFrom() */ +int PostReceiveFromNotCheck (SOCKET sock, TUdpBufferObj* pBufferObj); diff --git a/HP-Socket/Src/SocketInterface.h b/HP-Socket/Src/SocketInterface.h new file mode 100644 index 000000000..d6c3e4be4 --- /dev/null +++ b/HP-Socket/Src/SocketInterface.h @@ -0,0 +1,1414 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +/************************************************************************ +ƣ ID +Ӧó԰ CONNID ΪҪͣ磺ULONG / ULONGLONG +************************************************************************/ +typedef ULONG_PTR CONNID; + +/*****************************************************************************************************/ +/******************************************** ࡢӿ ********************************************/ +/*****************************************************************************************************/ + +/************************************************************************ +ƣͨ״̬ +Ӧóͨͨ GetState() ȡǰ״̬ +************************************************************************/ +enum EnServiceState +{ + SS_STARTING = 0, // + SS_STARTED = 1, // Ѿ + SS_STOPPING = 2, // ֹͣ + SS_STOPPED = 3, // Ѿֹͣ +}; + +/************************************************************************ +ƣSocket +Ӧó OnClose() ¼ͨòʶֲµĴ +************************************************************************/ +enum EnSocketOperation +{ + SO_UNKNOWN = 0, // Unknown + SO_ACCEPT = 1, // Acccept + SO_CONNECT = 2, // Connect + SO_SEND = 3, // Send + SO_RECEIVE = 4, // Receive + SO_CLOSE = 5, // Close +}; + +/************************************************************************ +ƣ¼ +¼ķֵͬķֵӰͨĺΪ +************************************************************************/ +enum EnHandleResult +{ + HR_OK = 0, // ɹ + HR_IGNORE = 1, // + HR_ERROR = 2, // +}; + +/************************************************************************ +ƣץȡ +ץȡķֵ +************************************************************************/ +enum EnFetchResult +{ + FR_OK = 0, // ɹ + FR_LENGTH_TOO_LONG = 1, // ץȡȹ + FR_DATA_NOT_FOUND = 2, // Ҳ ConnID Ӧ +}; + +/************************************************************************ +ƣݷͲ +Server Agent ݷͲ + +* ģʽĬϣ ѶͲһͣӴЧ +* ȫģʽ ѶͲһͣƴٶȣ⻺ +* ֱģʽ ÿһͲֱͶݣڸزߵҪʵʱԽϸߵij + +************************************************************************/ +enum EnSendPolicy +{ + SP_PACK = 0, // ģʽĬϣ + SP_SAFE = 1, // ȫģʽ + SP_DIRECT = 2, // ֱģʽ +}; + +/************************************************************************ +ƣ + Start() / Stop() ִʧʱͨ GetLastError() ȡ +************************************************************************/ +enum EnSocketError +{ + SE_OK = NO_ERROR, // ɹ + SE_ILLEGAL_STATE = 1, // ǰ״̬ + SE_INVALID_PARAM = 2, // Ƿ + SE_SOCKET_CREATE = 3, // SOCKET ʧ + SE_SOCKET_BIND = 4, // SOCKET ʧ + SE_SOCKET_PREPARE = 5, // SOCKET ʧ + SE_SOCKET_LISTEN = 6, // SOCKET ʧ + SE_CP_CREATE = 7, // ɶ˿ʧ + SE_WORKER_THREAD_CREATE = 8, // ߳ʧ + SE_DETECT_THREAD_CREATE = 9, // ߳ʧ + SE_SOCKE_ATTACH_TO_CP = 10, // ɶ˿ʧ + SE_CONNECT_SERVER = 11, // ӷʧ + SE_NETWORK = 12, // + SE_DATA_PROC = 13, // ݴ + SE_DATA_SEND = 14, // ݷʧ +}; + +/************************************************************************ +ƣģʽ +UDP IJģʽ鲥㲥 +************************************************************************/ +enum EnCastMode +{ + CM_MULTICAST = 0, // 鲥 + CM_BROADCAST = 1, // 㲥 +}; + +/************************************************************************ +ƣSocket ӿ +˺Ϳͻ Socket ĹϢ +************************************************************************/ +class IComplexSocketListener +{ +public: + + /* + * ƣѷ֪ͨ + * ɹݺSocket յ֪ͨ + * + * dwConnID -- ID + * pData -- ѷݻ + * iLength -- ѷݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֪ͨ HR_ERRORģʽԴ + */ + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) = 0; + + /* + * ƣݵ֪ͨPUSH ģͣ + * PUSH ģ͵ Socket ͨɹݺ Socket ͸֪ͨ + * + * dwConnID -- ID + * pData -- ѽݻ + * iLength -- ѽݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- OnClose() ¼ʱ䲢ر + */ + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) = 0; + + /* + * ƣݵ֪ͨPULL ģͣ + * PULL ģ͵ Socket ͨɹݺ Socket ͸֪ͨ + * + * dwConnID -- ID + * iLength -- ѽݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- OnClose() ¼ʱ䲢ر + */ + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) = 0; + + /* + * ƣͨŴ֪ͨ + * ͨŷSocket յ֪ͨر + * + * dwConnID -- ID + * enOperation -- Socket + * iErrorCode -- + * ֵ Էֵ + */ + virtual EnHandleResult OnClose(CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode) = 0; + + /* + * ƣر֪ͨͨ + * ͨرʱSocket յ֪ͨ + * + * + * ֵԷֵ + */ + virtual EnHandleResult OnShutdown() = 0; + +public: + virtual ~IComplexSocketListener() {} +}; + +/************************************************************************ +ƣ Socket ӿ + Socket ¼ +************************************************************************/ +class IServerListener : public IComplexSocketListener +{ +public: + + /* + * ƣ׼֪ͨ + * ͨŷʱڼ Socket ɲʼִмǰSocket + * յִ֪֪ͨͨ Socket ѡõȶ⹤ + * + * soListen -- Socket + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֹͨŷ + */ + virtual EnHandleResult OnPrepareListen(SOCKET soListen) = 0; +}; + +/************************************************************************ +ƣTCP Socket ӿ + TCP Socket ¼ +************************************************************************/ +class ITcpServerListener : public IServerListener +{ +public: + + /* + * ƣ֪ͨ + * յͻʱSocket յ֪֪ͨͨ + * ִ Socket ѡûܾͻӵȶ⹤ + * + * dwConnID -- ID + * soClient -- ͻ Socket + * ֵ HR_OK / HR_IGNORE -- + * HR_ERROR -- ܾ + */ + virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient) = 0; +}; + +/************************************************************************ +ƣPUSH ģͷ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpServerListener : public ITcpServerListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareListen(SOCKET soListen) {return HR_IGNORE;} + virtual EnHandleResult OnAccept(CONNID dwConnID, SOCKET soClient) {return HR_IGNORE;} + virtual EnHandleResult OnShutdown() {return HR_IGNORE;} +}; + +/************************************************************************ +ƣPULL ģͷ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpPullServerListener : public CTcpServerListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) = 0; + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣUDP Socket ӿ + UDP Socket ¼ +************************************************************************/ +class IUdpServerListener : public IServerListener +{ +public: + + /* + * ƣ֪ͨ + * յͻʱSocket յ֪֪ͨͨ + * ִ Socket ѡûܾͻӵȶ⹤ + * + * dwConnID -- ID + * soClient -- ͻ Socket + * ֵ HR_OK / HR_IGNORE -- + * HR_ERROR -- ܾ + */ + virtual EnHandleResult OnAccept(CONNID dwConnID, const SOCKADDR_IN* pSockAddr) = 0; +}; + +/************************************************************************ +ƣUDP Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CUdpServerListener : public IUdpServerListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareListen(SOCKET soListen) {return HR_IGNORE;} + virtual EnHandleResult OnAccept(CONNID dwConnID, const SOCKADDR_IN* pSockAddr) {return HR_IGNORE;} + virtual EnHandleResult OnShutdown() {return HR_IGNORE;} +}; + +/************************************************************************ +ƣͨŴ Socket ӿ + ͨŴ Socket ¼ +************************************************************************/ +class IAgentListener : public IComplexSocketListener +{ +public: + + /* + * ƣ׼֪ͨ + * ͨſͻʱڿͻ Socket ɲʼִǰSocket + * յִ֪֪ͨͨ Socket ѡõȶ⹤ + * + * dwConnID -- ID + * socket -- ͻ Socket + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֹͨſͻ + */ + virtual EnHandleResult OnPrepareConnect(CONNID dwConnID, SOCKET socket) = 0; + + /* + * ƣ֪ͨ + * ˳ɹʱSocket յ֪ͨ + * + * dwConnID -- ID + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ͬӣֹͨſͻ + * 첽ӣر + */ + virtual EnHandleResult OnConnect(CONNID dwConnID) = 0; +}; + +/************************************************************************ +ƣTCP ͨŴ Socket ӿ + TCP ͨŴ Socket ¼ +************************************************************************/ +class ITcpAgentListener : public IAgentListener +{ +}; + +/************************************************************************ +ƣPUSH ģͨŴ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpAgentListener : public ITcpAgentListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(CONNID dwConnID, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(CONNID dwConnID) {return HR_IGNORE;} + virtual EnHandleResult OnShutdown() {return HR_IGNORE;} +}; + +/************************************************************************ +ƣPULL ͨŴ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpPullAgentListener : public CTcpAgentListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) = 0; + virtual EnHandleResult OnReceive(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣUDP ͨŴ Socket ӿ + UDP ͨŴ Socket ¼ +************************************************************************/ +class IUdpAgentListener : public IAgentListener +{ +}; + +/************************************************************************ +ƣPUSH ģͨŴ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CUdpAgentListener : public IUdpAgentListener +{ +public: + virtual EnHandleResult OnReceive(CONNID dwConnID, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(CONNID dwConnID, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(CONNID dwConnID, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(CONNID dwConnID) {return HR_IGNORE;} + virtual EnHandleResult OnShutdown() {return HR_IGNORE;} +}; + + +class IClient; + +/************************************************************************ +ƣͻ Socket ӿ +ͻ Socket ¼ +************************************************************************/ +class IClientListener +{ +public: + + /* + * ƣ׼֪ͨ + * ͨſͻʱڿͻ Socket ɲʼִǰSocket + * յִ֪֪ͨͨ Socket ѡõȶ⹤ + * + * pClient -- Ӷ + * socket -- ͻ Socket + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֹͨſͻ + */ + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket) = 0; + + /* + * ƣ֪ͨ + * ˳ɹʱSocket յ֪ͨ + * + * pClient -- Ӷ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ͬӣֹͨſͻ + * 첽ӣر + */ + virtual EnHandleResult OnConnect(IClient* pClient) = 0; + + /* + * ƣѷ֪ͨ + * ɹݺSocket յ֪ͨ + * + * pClient -- Ӷ + * pData -- ѷݻ + * iLength -- ѷݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- ֪ͨ HR_ERRORģʽԴ + */ + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) = 0; + + /* + * ƣݵ֪ͨPUSH ģͣ + * PUSH ģ͵ Socket ͨɹݺ Socket ͸֪ͨ + * + * pClient -- Ӷ + * pData -- ѽݻ + * iLength -- ѽݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- OnClose() ¼ʱ䲢ر + */ + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength) = 0; + + /* + * ƣݵ֪ͨPULL ģͣ + * PULL ģ͵ Socket ͨɹݺ Socket ͸֪ͨ + * + * pClient -- Ӷ + * iLength -- ѽݳ + * ֵ HR_OK / HR_IGNORE -- ִ + * HR_ERROR -- OnClose() ¼ʱ䲢ر + */ + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) = 0; + + /* + * ƣͨŴ֪ͨ + * ͨŷSocket յ֪ͨر + * + * pClient -- Ӷ + * enOperation -- Socket + * iErrorCode -- + * ֵ Էֵ + */ + virtual EnHandleResult OnClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) = 0; + +public: + virtual ~IClientListener() {} +}; + +/************************************************************************ +ƣTCP ͻ Socket ӿ + TCP ͻ Socket ¼ +************************************************************************/ +class ITcpClientListener : public IClientListener +{ +}; + +/************************************************************************ +ƣPUSH ģͿͻ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpClientListener : public ITcpClientListener +{ +public: + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(IClient* pClient) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣPULL ͻ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CTcpPullClientListener : public CTcpClientListener +{ +public: + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) = 0; + virtual EnHandleResult OnReceive(IClient* pClient, const BYTE* pData, int iLength) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣUDP ͻ Socket ӿ + UDP ͻ Socket ¼ +************************************************************************/ +class IUdpClientListener : public IClientListener +{ +}; + +/************************************************************************ +ƣUDP ͻ Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CUdpClientListener : public IUdpClientListener +{ +public: + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(IClient* pClient) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣUDP Socket ӿ + UDP Socket ¼ +************************************************************************/ +class IUdpCastListener : public IClientListener +{ +}; + +/************************************************************************ +ƣUDP Socket +ijЩ¼Ĭϴ¼ +************************************************************************/ +class CUdpCastListener : public IUdpCastListener +{ +public: + virtual EnHandleResult OnReceive(IClient* pClient, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnSend(IClient* pClient, const BYTE* pData, int iLength) {return HR_IGNORE;} + virtual EnHandleResult OnPrepareConnect(IClient* pClient, SOCKET socket) {return HR_IGNORE;} + virtual EnHandleResult OnConnect(IClient* pClient) {return HR_IGNORE;} +}; + +/************************************************************************ +ƣ Socket ӿ +帴 Socket вԷʷ Socket ͬʱ Socket +************************************************************************/ +class IComplexSocket +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣرͨ + * رͨرɺϿӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Stop () = 0; + + /* + * ƣ + * ָӷ + * + * dwConnID -- ID + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL Send (CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0) = 0; + + /* + * ƣͶ + * ָӷͶ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * dwConnID -- ID + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount) = 0; + + /* + * ƣϿ + * Ͽij + * + * dwConnID -- ID + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ + virtual BOOL Disconnect(CONNID dwConnID, BOOL bForce = TRUE) = 0; + + /* + * ƣϿʱ + * Ͽָʱ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ + virtual BOOL DisconnectLongConnections(DWORD dwPeriod, BOOL bForce = TRUE) = 0; + + /* + * ƣϿĬ + * ϿָʱľĬ + * + * dwPeriod -- ʱ룩 + * bForce -- ǷǿƶϿ + * ֵ TRUE -- ɹ + * FALSE -- ʧ + */ + virtual BOOL DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce = TRUE) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* + * ƣӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦó + * + * dwConnID -- ID + * pv -- + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ + virtual BOOL SetConnectionExtra (CONNID dwConnID, PVOID pExtra) = 0; + + /* + * ƣȡӵĸ + * ǷΪӰ󶨸ݻ߰ʲôݣӦó + * + * dwConnID -- ID + * ppv -- ָ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣЧ ID + */ + virtual BOOL GetConnectionExtra (CONNID dwConnID, PVOID* ppExtra) = 0; + + /* ͨǷ */ + virtual BOOL HasStarted () = 0; + /* 鿴ͨǰ״̬ */ + virtual EnServiceState GetState () = 0; + /* ȡ */ + virtual DWORD GetConnectionCount () = 0; + /* ȡӵ CONNID */ + virtual BOOL GetAllConnectionIDs (CONNID pIDs[], DWORD& dwCount) = 0; + /* ȡijʱ룩 */ + virtual BOOL GetConnectPeriod (CONNID dwConnID, DWORD& dwPeriod) = 0; + /* ȡijӾĬʱ䣨룩 */ + virtual BOOL GetSilencePeriod (CONNID dwConnID, DWORD& dwPeriod) = 0; + /* ȡijӵԶ̵ַϢ */ + virtual BOOL GetRemoteAddress (CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; + /* ȡһʧܲĴ */ + virtual EnSocketError GetLastError () = 0; + /* ȡһʧܲĴ */ + virtual LPCTSTR GetLastErrorDesc () = 0; + /* ȡδݵij */ + virtual BOOL GetPendingDataLength (CONNID dwConnID, int& iPending) = 0; + + /* ݷͲ */ + virtual void SetSendPolicy (EnSendPolicy enSendPolicy) = 0; + /* Socket ʱ䣨룬ڼ Socket ܱȡʹã */ + virtual void SetFreeSocketObjLockTime (DWORD dwFreeSocketObjLockTime) = 0; + /* Socket شСͨΪƽ 1/3 - 1/2 */ + virtual void SetFreeSocketObjPool (DWORD dwFreeSocketObjPool) = 0; + /* ڴ黺شСͨΪ Socket شС 2 - 3 */ + virtual void SetFreeBufferObjPool (DWORD dwFreeBufferObjPool) = 0; + /* Socket ػշֵͨΪ Socket شС 3 */ + virtual void SetFreeSocketObjHold (DWORD dwFreeSocketObjHold) = 0; + /* ڴ黺ػշֵͨΪڴ黺شС 3 */ + virtual void SetFreeBufferObjHold (DWORD dwFreeBufferObjHold) = 0; + /* ù߳ͨΪ 2 * CPU + 2 */ + virtual void SetWorkerThreadCount (DWORD dwWorkerThreadCount) = 0; + /* ǷǾĬʱ䣨Ϊ TRUE ʱ DisconnectSilenceConnections() GetSilencePeriod() ЧĬϣFALSE */ + virtual void SetMarkSilence (BOOL bMarkSilence) = 0; + + /* ȡݷͲ */ + virtual EnSendPolicy GetSendPolicy () = 0; + /* ȡ Socket ʱ */ + virtual DWORD GetFreeSocketObjLockTime () = 0; + /* ȡ Socket شС */ + virtual DWORD GetFreeSocketObjPool () = 0; + /* ȡڴ黺شС */ + virtual DWORD GetFreeBufferObjPool () = 0; + /* ȡ Socket ػշֵ */ + virtual DWORD GetFreeSocketObjHold () = 0; + /* ȡڴ黺ػշֵ */ + virtual DWORD GetFreeBufferObjHold () = 0; + /* ȡ߳ */ + virtual DWORD GetWorkerThreadCount () = 0; + /* ǷǾĬʱ */ + virtual BOOL IsMarkSilence () = 0; + +public: + virtual ~IComplexSocket() {} +}; + +/************************************************************************ +ƣͨŷӿ +ͨŷвԷʷ +************************************************************************/ +class IServer : public IComplexSocket +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣͨ + * ͨɺɿʼտͻӲշ + * + * pszBindAddress -- ַ + * usPort -- ˿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Start (LPCTSTR pszBindAddress, USHORT usPort) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ȡ Socket ĵַϢ */ + virtual BOOL GetListenAddress(TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; +}; + +/************************************************************************ +ƣTCP ͨŷӿ + TCP ͨŷвԷʷ +************************************************************************/ +class ITcpServer : public IServer +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendSmallFile (CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* Accept ԤͶݸصãAccept ԤͶԽֵ֧IJԽࣩ */ + virtual void SetAcceptSocketCount (DWORD dwAcceptSocketCount) = 0; + /* ͨݻСƽͨݰСãͨΪ 1024 ı */ + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) = 0; + /* ü Socket ĵȺдСݲã */ + virtual void SetSocketListenQueue (DWORD dwSocketListenQueue) = 0; + /* 룬0 򲻷Ĭϣ30 * 1000 */ + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) = 0; + /* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) = 0; + + /* ȡ Accept ԤͶ */ + virtual DWORD GetAcceptSocketCount () = 0; + /* ȡͨݻС */ + virtual DWORD GetSocketBufferSize () = 0; + /* ȡ Socket ĵȺдС */ + virtual DWORD GetSocketListenQueue () = 0; + /* ȡ */ + virtual DWORD GetKeepAliveTime () = 0; + /* ȡ쳣 */ + virtual DWORD GetKeepAliveInterval () = 0; +}; + +/************************************************************************ +ƣUDP ͨŷӿ + UDP ͨŷвԷʷ +************************************************************************/ +class IUdpServer : public IServer +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) = 0; + /* ȡݱ󳤶 */ + virtual DWORD GetMaxDatagramSize () = 0; + + /* Receive ԤͶݸصãReceive ԤͶԽ򶪰ԽС */ + virtual void SetPostReceiveCount (DWORD dwPostReceiveCount) = 0; + /* ȡ Receive ԤͶ */ + virtual DWORD GetPostReceiveCount () = 0; + + /* üԴ0 򲻷ͼԴΪѶߣ */ + virtual void SetDetectAttempts (DWORD dwDetectAttempts) = 0; + /* üͼ룬0 ͼ */ + virtual void SetDetectInterval (DWORD dwDetectInterval) = 0; + /* ȡ */ + virtual DWORD GetDetectAttempts () = 0; + /* ȡ */ + virtual DWORD GetDetectInterval () = 0; +}; + +/************************************************************************ +ƣͨŴӿ +ͨŴвԷʷһͬʱӶĿͻ +************************************************************************/ +class IAgent : public IComplexSocket +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣͨ + * ͨŴɺɿʼԶ̷ + * + * pszBindAddress -- ַ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Start (LPCTSTR pszBindAddress = nullptr, BOOL bAsyncConnect = TRUE) = 0; + + /* + * ƣӷ + * ӷӳɹ IAgentListener յ OnConnect() ¼ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * pdwConnID -- IDĬϣnullptrȡ ID + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID = nullptr) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ȡijӵıصַϢ */ + virtual BOOL GetLocalAddress(CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; +}; + +/************************************************************************ +ƣTCP ͨŴӿ + TCP ͨŴвԷʷ +************************************************************************/ +class ITcpAgent : public IAgent +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣСļ + * ָӷ 4096 KB µСļ + * + * dwConnID -- ID + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendSmallFile (CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ǷõַûƣĬϣã */ + virtual void SetReuseAddress (BOOL bReuseAddress) = 0; + /* Ƿõַû */ + virtual BOOL IsReuseAddress () = 0; + + /* ͨݻСƽͨݰСãͨΪ 1024 ı */ + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) = 0; + /* 룬0 򲻷Ĭϣ30 * 1000 */ + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) = 0; + /* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) = 0; + + /* ȡͨݻС */ + virtual DWORD GetSocketBufferSize () = 0; + /* ȡ */ + virtual DWORD GetKeepAliveTime () = 0; + /* ȡ쳣 */ + virtual DWORD GetKeepAliveInterval () = 0; +}; + +/************************************************************************ +ƣUDP ͨŴӿ + UDP ͨŴвԷʷ +************************************************************************/ +class IUdpAgent : public IAgent +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) = 0; + /* ȡݱ󳤶 */ + virtual DWORD GetMaxDatagramSize() = 0; + + /* üԴ0 򲻷ͼԴΪѶߣ */ + virtual void SetDetectAttempts (DWORD dwDetectAttempts) = 0; + /* üͼ룬0 ͼ */ + virtual void SetDetectInterval (DWORD dwDetectInterval) = 0; + /* ȡ */ + virtual DWORD GetDetectAttempts () = 0; + /* ȡ */ + virtual DWORD GetDetectInterval () = 0; +}; + +/************************************************************************ +ƣͨſͻӿ +ͨſͻвԷʷ +************************************************************************/ +class IClient +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣͨ + * ͻͨӷˣɺɿʼշ + * + * pszRemoteAddress -- ˵ַ + * usPort -- ˶˿ + * bAsyncConnect -- Ƿ첽 Connect + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Start (LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect = FALSE) = 0; + + /* + * ƣرͨ + * رտͻͨرɺϿ˵ӲͷԴ + * + * + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ GetLastError() ȡ + */ + virtual BOOL Stop () = 0; + + /* + * ƣ + * ˷ + * + * pBuffer -- ͻ + * iLength -- ͻ + * iOffset -- ͻָƫ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL Send (const BYTE* pBuffer, int iLength, int iOffset = 0) = 0; + + /* + * ƣͶ + * ˷Ͷ + * TCP - ˳ݰ + * UDP - ݰϳһݰͣݰܳȲܴõ UDP 󳤶ȣ + * + * pBuffers -- ͻ + * iCount -- ͻĿ + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendPackets(const WSABUF pBuffers[], int iCount) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ӵĸ */ + virtual void SetExtra (PVOID pExtra) = 0; + + /* ȡӵĸ */ + virtual PVOID GetExtra () = 0; + + /* ͨǷ */ + virtual BOOL HasStarted () = 0; + /* 鿴ͨǰ״̬ */ + virtual EnServiceState GetState () = 0; + /* ȡһʧܲĴ */ + virtual EnSocketError GetLastError () = 0; + /* ȡһʧܲĴ */ + virtual LPCTSTR GetLastErrorDesc() = 0; + /* ȡ ID */ + virtual CONNID GetConnectionID () = 0; + /* ȡ Client Socket ĵַϢ */ + virtual BOOL GetLocalAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; + /* ȡδݵij */ + virtual BOOL GetPendingDataLength (int& iPending) = 0; + + /* ڴ黺شСͨΪ -> PUSH ģͣ5 - 10PULL ģͣ10 - 20 */ + virtual void SetFreeBufferPoolSize (DWORD dwFreeBufferPoolSize) = 0; + /* ڴ黺ػշֵͨΪڴ黺شС 3 */ + virtual void SetFreeBufferPoolHold (DWORD dwFreeBufferPoolHold) = 0; + + /* ȡڴ黺شС */ + virtual DWORD GetFreeBufferPoolSize () = 0; + /* ȡڴ黺ػշֵ */ + virtual DWORD GetFreeBufferPoolHold () = 0; + +public: + virtual ~IClient() {} +}; + +/************************************************************************ +ƣTCP ͨſͻӿ + TCP ͨſͻвԷʷ +************************************************************************/ +class ITcpClient : public IClient +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + + /* + * ƣСļ + * ˷ 4096 KB µСļ + * + * lpszFileName -- ļ· + * pHead -- ͷ + * pTail -- β + * ֵ TRUE -- ɹ + * FALSE -- ʧܣͨ Windows API ::GetLastError() ȡ Windows + */ + virtual BOOL SendSmallFile (LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr) = 0; + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ͨݻСƽͨݰСãͨΪ(N * 1024) - sizeof(TBufferObj) */ + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) = 0; + /* 룬0 򲻷Ĭϣ30 * 1000 */ + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) = 0; + /* 쳣룬0 Ĭϣ10 * 1000ɴ [ĬϣWinXP 5 , Win7 10 ] ⲻȷϰΪѶߣ */ + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) = 0; + + /* ȡͨݻС */ + virtual DWORD GetSocketBufferSize () = 0; + /* ȡ */ + virtual DWORD GetKeepAliveTime () = 0; + /* ȡ쳣 */ + virtual DWORD GetKeepAliveInterval () = 0; +}; + +/************************************************************************ +ƣUDP ͨſͻӿ + UDP ͨſͻвԷʷ +************************************************************************/ +class IUdpClient : public IClient +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) = 0; + /* ȡݱ󳤶 */ + virtual DWORD GetMaxDatagramSize() = 0; + + /* üԴ0 򲻷ͼԴΪѶߣ */ + virtual void SetDetectAttempts (DWORD dwDetectAttempts) = 0; + /* üͼ룬0 ͼ */ + virtual void SetDetectInterval (DWORD dwDetectInterval) = 0; + /* ȡ */ + virtual DWORD GetDetectAttempts () = 0; + /* ȡ */ + virtual DWORD GetDetectInterval () = 0; +}; + +/************************************************************************ +ƣUDP ӿ + UDP 鲥㲥вԷʷ +************************************************************************/ +class IUdpCast : public IClient +{ +public: + + /***********************************************************************/ + /***************************** *****************************/ + +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ð󶨵ַ */ + virtual void SetBindAdddress (LPCTSTR pszBindAddress) = 0; + /* ȡ󶨵ַ */ + virtual LPCTSTR GetBindAdddress () = 0; + + /* ݱ󳤶ȣھ² 1472 ֽڣڹ² 548 ֽڣ */ + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) = 0; + /* ȡݱ󳤶 */ + virtual DWORD GetMaxDatagramSize() = 0; + + /* ǷõַûƣĬϣã */ + virtual void SetReuseAddress (BOOL bReuseAddress) = 0; + /* Ƿõַû */ + virtual BOOL IsReuseAddress () = 0; + + /* ôģʽ鲥㲥 */ + virtual void SetCastMode (EnCastMode enCastMode) = 0; + /* ȡģʽ */ + virtual EnCastMode GetCastMode () = 0; + + /* 鲥ĵ TTL0 - 255 */ + virtual void SetMultiCastTtl (int iMCTtl) = 0; + /* ȡ鲥ĵ TTL */ + virtual int GetMultiCastTtl () = 0; + + /* Ƿ鲥·TRUE or FALSE */ + virtual void SetMultiCastLoop (BOOL bMCLoop) = 0; + /* Ƿ鲥· */ + virtual BOOL IsMultiCastLoop () = 0; + + /* ȡǰݱԶ̵ַϢͨ OnReceive ¼еã */ + virtual BOOL GetRemoteAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) = 0; +}; + +/************************************************************************ +ƣServer/Agent PULL ģӿ + Server/Agent PULL ģв +************************************************************************/ +class IPullSocket +{ +public: + + /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * dwConnID -- ID + * pData -- ץȡ + * iLength -- ץȡݳ + * ֵ EnFetchResult + */ + virtual EnFetchResult Fetch (CONNID dwConnID, BYTE* pData, int iLength) = 0; + + /* + * ƣ̽ݣƳݣ + * ûͨ÷ Socket п̽ + * + * dwConnID -- ID + * pData -- ̽ + * iLength -- ̽ݳ + * ֵ EnFetchResult + */ + virtual EnFetchResult Peek (CONNID dwConnID, BYTE* pData, int iLength) = 0; + +public: + virtual ~IPullSocket() {} +}; + +/************************************************************************ +ƣClient PULL ģӿ + Client PULL ģв +************************************************************************/ +class IPullClient +{ +public: + + /* + * ƣץȡ + * ûͨ÷ Socket ץȡ + * + * pData -- ץȡ + * iLength -- ץȡݳ + * ֵ EnFetchResult + */ + virtual EnFetchResult Fetch (BYTE* pData, int iLength) = 0; + + /* + * ƣ̽ݣƳݣ + * ûͨ÷ Socket п̽ + * + * pData -- ̽ + * iLength -- ̽ݳ + * ֵ EnFetchResult + */ + virtual EnFetchResult Peek (BYTE* pData, int iLength) = 0; + +public: + virtual ~IPullClient() {} +}; + +/************************************************************************ +ƣTCP Server PULL ģӿ +̳ ITcpServer IPullSocket +************************************************************************/ +class ITcpPullServer : public IPullSocket, public ITcpServer +{ +public: + /* IServer* תΪ IPullSocket* */ + inline static IPullSocket* ToPull(IServer* pServer) + { + return (IPullSocket*)((char*)pServer - sizeof(IPullSocket)); + } + + /* IPullSocket* תΪ ITcpServer* */ + inline static ITcpServer* ToServer(IPullSocket* pPullSocket) + { + return (ITcpServer*)((char*)pPullSocket + sizeof(IPullSocket)); + } +}; + +/************************************************************************ +ƣTCP Agent PULL ģӿ +̳ ITcpAgent IPullSocket +************************************************************************/ +class ITcpPullAgent : public IPullSocket, public ITcpAgent +{ +public: + /* IAgent* תΪ IPullSocket* */ + inline static IPullSocket* ToPull(IAgent* pAgent) + { + return (IPullSocket*)((char*)pAgent - sizeof(IPullSocket)); + } + + /* IPullSocket* תΪ ITcpAgent* */ + inline static ITcpAgent* ToAgent(IPullSocket* pPullSocket) + { + return (ITcpAgent*)((char*)pPullSocket + sizeof(IPullSocket)); + } +}; + +/************************************************************************ +ƣTCP Client PULL ģӿ +̳ ITcpClient IPullClient +************************************************************************/ +class ITcpPullClient : public IPullClient, public ITcpClient +{ +public: + /* IClient* תΪ IPullClient* */ + inline static IPullClient* ToPull(IClient* pClient) + { + return (IPullClient*)((char*)pClient - sizeof(IPullClient)); + } + + /* IPullClient* תΪ ITcpClient* */ + inline static ITcpClient* ToClient(IPullClient* pPullClient) + { + return (ITcpClient*)((char*)pPullClient + sizeof(IPullClient)); + } +}; + +/************************************************************************ +ƣServer/Agent PACK ģӿ + Server/Agent PACK ģв +************************************************************************/ +class IPackSocket +{ +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ + virtual void SetMaxPackSize (DWORD dwMaxPackSize) = 0; + /* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ + virtual void SetPackHeaderFlag (USHORT usPackHeaderFlag) = 0; + + /* ȡݰ󳤶 */ + virtual DWORD GetMaxPackSize () = 0; + /* ȡͷʶ */ + virtual USHORT GetPackHeaderFlag() = 0; + +public: + virtual ~IPackSocket() {} +}; + +/************************************************************************ +ƣClient PACK ģӿ + Client PACK ģв +************************************************************************/ +class IPackClient +{ +public: + + /***********************************************************************/ + /***************************** Էʷ *****************************/ + + /* ݰ󳤶ȣЧݰ󳤶Ȳܳ 524287/0x7FFFF ֽڣĬϣ262144/0x40000 */ + virtual void SetMaxPackSize (DWORD dwMaxPackSize) = 0; + /* ðͷʶЧͷʶȡֵΧ 0 ~ 8191/0x1FFFͷʶΪ 0 ʱУͷĬϣ0 */ + virtual void SetPackHeaderFlag (USHORT usPackHeaderFlag) = 0; + + /* ȡݰ󳤶 */ + virtual DWORD GetMaxPackSize () = 0; + /* ȡͷʶ */ + virtual USHORT GetPackHeaderFlag() = 0; + +public: + virtual ~IPackClient() {} +}; + +/************************************************************************ +ƣTCP Server PACK ģӿ +̳ ITcpServer IPackSocket +************************************************************************/ +class ITcpPackServer : public IPackSocket, public ITcpServer +{ +public: + /* IServer* תΪ IPackSocket* */ + inline static IPackSocket* ToPack(IServer* pServer) + { + return (IPackSocket*)((char*)pServer - sizeof(IPackSocket)); + } + + /* IPackSocket* תΪ ITcpServer* */ + inline static ITcpServer* ToServer(IPackSocket* pPackSocket) + { + return (ITcpServer*)((char*)pPackSocket + sizeof(IPackSocket)); + } +}; + +/************************************************************************ +ƣTCP Agent PACK ģӿ +̳ ITcpAgent IPackSocket +************************************************************************/ +class ITcpPackAgent : public IPackSocket, public ITcpAgent +{ +public: + /* IAgent* תΪ IPackSocket* */ + inline static IPackSocket* ToPack(IAgent* pAgent) + { + return (IPackSocket*)((char*)pAgent - sizeof(IPackSocket)); + } + + /* IPackSocket* תΪ ITcpAgent* */ + inline static ITcpAgent* ToAgent(IPackSocket* pPackSocket) + { + return (ITcpAgent*)((char*)pPackSocket + sizeof(IPackSocket)); + } +}; + +/************************************************************************ +ƣTCP Client PACK ģӿ +̳ ITcpClient IPackClient +************************************************************************/ +class ITcpPackClient : public IPackClient, public ITcpClient +{ +public: + /* IClient* תΪ IPackClient* */ + inline static IPackClient* ToPack(IClient* pClient) + { + return (IPackClient*)((char*)pClient - sizeof(IPackClient)); + } + + /* IPackClient* תΪ ITcpClient* */ + inline static ITcpClient* ToClient(IPackClient* pPackClient) + { + return (ITcpClient*)((char*)pPackClient + sizeof(IPackClient)); + } +}; diff --git a/HP-Socket/Src/TcpAgent.cpp b/HP-Socket/Src/TcpAgent.cpp new file mode 100644 index 000000000..15acd9718 --- /dev/null +++ b/HP-Socket/Src/TcpAgent.cpp @@ -0,0 +1,1406 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include +#include "TcpAgent.h" +#include "../../Common/Src/WaitFor.h" + +#include +#include + +EnHandleResult CTcpAgent::TriggerFireConnect(TSocketObj* pSocketObj) +{ + CReentrantSpinLock locallock(pSocketObj->csRecv); + return FireConnect(pSocketObj); +} + +EnHandleResult CTcpAgent::TriggerFireReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + EnHandleResult rs = (EnHandleResult)HR_CLOSED; + + if(TSocketObj::IsValid(pSocketObj)) + { + CReentrantSpinLock locallock(pSocketObj->csRecv); + + if(TSocketObj::IsValid(pSocketObj)) + { + rs = FireReceive(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len); + } + } + + return rs; +} + +EnHandleResult CTcpAgent::TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + EnHandleResult rs = FireSend(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len); + + if(rs == HR_ERROR) + { + TRACE(" OnSend() event should not return 'HR_ERROR' !!\n", pSocketObj->connID); + ASSERT(FALSE); + } + + AddFreeBufferObj(pBufferObj); + + return rs; +} + +EnHandleResult CTcpAgent::TriggerFireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + CReentrantSpinLock locallock(pSocketObj->csRecv); + return FireClose(pSocketObj, enOperation, iErrorCode); +} + +void CTcpAgent::SetLastError(EnSocketError code, LPCSTR func, int ec) +{ + m_enLastError = code; + + TRACE("%s --> Error: %d, EC: %d\n", func, code, ec); +} + +BOOL CTcpAgent::Start(LPCTSTR pszBindAddress, BOOL bAsyncConnect) +{ + if(!CheckParams() || !CheckStarting()) + return FALSE; + + PrepareStart(); + + if(ParseBindAddress(pszBindAddress, bAsyncConnect)) + if(CreateCompletePort()) + if(CreateWorkerThreads()) + { + m_bAsyncConnect = bAsyncConnect; + m_enState = SS_STARTED; + + return TRUE; + } + + Stop(); + + return FALSE; +} + +BOOL CTcpAgent::CheckParams() +{ + if(m_enSendPolicy >= SP_PACK && m_enSendPolicy <= SP_DIRECT) + if((int)m_dwWorkerThreadCount > 0 && m_dwWorkerThreadCount <= MAX_WORKER_THREAD_COUNT) + if((int)m_dwSocketBufferSize >= MIN_SOCKET_BUFFER_SIZE) + if((int)m_dwFreeSocketObjLockTime >= 0) + if((int)m_dwFreeSocketObjPool >= 0) + if((int)m_dwFreeBufferObjPool >= 0) + if((int)m_dwFreeSocketObjHold >= m_dwFreeSocketObjPool) + if((int)m_dwFreeBufferObjHold >= m_dwFreeBufferObjPool) + if((int)m_dwKeepAliveTime >= 1000 || m_dwKeepAliveTime == 0) + if((int)m_dwKeepAliveInterval >= 1000 || m_dwKeepAliveInterval == 0) + return TRUE; + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CTcpAgent::PrepareStart() +{ + m_lsFreeSocket.Reset(m_dwFreeSocketObjHold); + m_lsFreeBuffer.Reset(m_dwFreeBufferObjHold); + + m_itPool.SetItemCapacity((int)m_dwSocketBufferSize); + m_itPool.SetPoolSize((int)m_dwFreeBufferObjPool); + m_itPool.SetPoolHold((int)m_dwFreeBufferObjHold); + + m_itPool.Prepare(); +} + +BOOL CTcpAgent::CheckStarting() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STOPPED) + m_enState = SS_STARTING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CTcpAgent::CheckStoping() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STARTED || m_enState == SS_STARTING) + m_enState = SS_STOPPING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CTcpAgent::ParseBindAddress(LPCTSTR pszBindAddress, BOOL bAsyncConnect) +{ + BOOL isOK = FALSE; + SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if(sock != INVALID_SOCKET) + { + if(!pszBindAddress) + pszBindAddress = DEFAULT_BIND_ADDRESS; + + ::sockaddr_A_2_IN(AF_INET, pszBindAddress, 0, m_soAddrIN); + + if(!bAsyncConnect || ::bind(sock, (SOCKADDR*)&m_soAddrIN, sizeof(SOCKADDR_IN)) != SOCKET_ERROR) + { + m_pfnConnectEx = ::Get_ConnectEx_FuncPtr(sock); + m_pfnDisconnectEx = ::Get_DisconnectEx_FuncPtr(sock); + + ASSERT(m_pfnConnectEx); + ASSERT(m_pfnDisconnectEx); + + isOK = TRUE; + } + else + SetLastError(SE_SOCKET_BIND, __FUNCTION__, ::WSAGetLastError()); + + ::ManualCloseSocket(sock); + } + else + SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError()); + + return isOK; +} + +BOOL CTcpAgent::CreateCompletePort() +{ + m_hCompletePort = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 0); + if(m_hCompletePort == nullptr) + SetLastError(SE_CP_CREATE, __FUNCTION__, ::GetLastError()); + + return (m_hCompletePort != nullptr); +} + +BOOL CTcpAgent::CreateWorkerThreads() +{ + BOOL isOK = TRUE; + + for(DWORD i = 0; i < m_dwWorkerThreadCount; i++) + { + HANDLE hThread = (HANDLE)_beginthreadex(nullptr, 0, WorkerThreadProc, (LPVOID)this, 0, nullptr); + if(hThread) + m_vtWorkerThreads.push_back(hThread); + else + { + SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ::GetLastError()); + isOK = FALSE; + break; + } + } + + return isOK; +} + +BOOL CTcpAgent::Stop() +{ + if(!CheckStoping()) + return FALSE; + + ::WaitWithMessageLoop(150); + + DisconnectClientSocket(); + WaitForClientSocketClose(); + WaitForWorkerThreadEnd(); + + ReleaseClientSocket(); + + FireShutdown(); + + ReleaseFreeSocket(); + ReleaseFreeBuffer(); + + CloseCompletePort(); + + Reset(); + + return TRUE; +} + +void CTcpAgent::Reset(BOOL bAll) +{ + if(bAll) + { + m_phSocket.Reset(); + m_phBuffer.Reset(); + m_itPool.Clear(); + } + + ::ZeroMemory((void*)&m_soAddrIN, sizeof(SOCKADDR_IN)); + + m_pfnConnectEx = nullptr; + m_pfnDisconnectEx = nullptr; + m_enState = SS_STOPPED; +} + +void CTcpAgent::DisconnectClientSocket() +{ + CReentrantReadLock locallock(m_csClientSocket); + + for(TSocketObjPtrMapI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + Disconnect(it->first); +} + +void CTcpAgent::ReleaseClientSocket() +{ + CReentrantWriteLock locallock(m_csClientSocket); + + for(TSocketObjPtrMapI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + TSocketObj* pSocketObj = it->second; + + CloseClientSocketObj(pSocketObj); + DeleteSocketObj(pSocketObj); + } + + m_mpClientSocket.clear(); +} + +TSocketObj* CTcpAgent::GetFreeSocketObj(CONNID dwConnID, SOCKET soClient) +{ + DWORD dwIndex; + TSocketObj* pSocketObj = nullptr; + + if(m_lsFreeSocket.TryLock(&pSocketObj, dwIndex)) + { + if(::GetTimeGap32(pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) + m_lsFreeSocket.ReleaseLock(nullptr, dwIndex); + else + { + m_lsFreeSocket.ReleaseLock(pSocketObj, dwIndex); + pSocketObj = nullptr; + } + } + + if(!pSocketObj) pSocketObj = CreateSocketObj(); + pSocketObj->Reset(dwConnID, soClient); + + return pSocketObj; +} + +void CTcpAgent::AddFreeSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode) +{ + if(!InvalidSocketObj(pSocketObj)) + return; + + CloseClientSocketObj(pSocketObj, enFlag, enOperation, iErrorCode); + TSocketObj::Release(pSocketObj); + + { + CReentrantWriteLock locallock(m_csClientSocket); + m_mpClientSocket.erase(pSocketObj->connID); + } + + if(!m_lsFreeSocket.TryPut(pSocketObj)) + { + m_lsGCSocket.PushBack(pSocketObj); + + if(m_lsGCSocket.Size() > m_dwFreeSocketObjPool) + ReleaseGCSocketObj(); + } +} + +void CTcpAgent::ReleaseGCSocketObj(BOOL bForce) +{ + TSocketObj* pSocketObj = nullptr; + DWORD now = ::TimeGetTime(); + + while(m_lsGCSocket.PopFront(&pSocketObj)) + { + if(bForce || (now - pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) + DeleteSocketObj(pSocketObj); + else + { + m_lsGCSocket.PushBack(pSocketObj); + break; + } + } +} + +BOOL CTcpAgent::InvalidSocketObj(TSocketObj* pSocketObj) +{ + BOOL bDone = FALSE; + + if(TSocketObj::IsValid(pSocketObj)) + { + CReentrantSpinLock locallock(pSocketObj->csRecv); + CCriSecLock locallock2(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + { + TSocketObj::Invalid(pSocketObj); + bDone = TRUE; + } + } + + return bDone; +} + +void CTcpAgent::AddClientSocketObj(CONNID dwConnID, TSocketObj* pSocketObj) +{ + ASSERT(FindSocketObj(dwConnID) == nullptr); + + pSocketObj->connTime = ::TimeGetTime(); + pSocketObj->activeTime = pSocketObj->connTime; + + CReentrantWriteLock locallock(m_csClientSocket); + m_mpClientSocket[dwConnID] = pSocketObj; +} + +void CTcpAgent::ReleaseFreeSocket() +{ + TSocketObj* pSocketObj = nullptr; + + while(m_lsFreeSocket.TryGet(&pSocketObj)) + DeleteSocketObj(pSocketObj); + + VERIFY(m_lsFreeSocket.IsEmpty()); + m_lsFreeSocket.Reset(); + + ReleaseGCSocketObj(TRUE); + VERIFY(m_lsGCSocket.IsEmpty()); +} + +TSocketObj* CTcpAgent::CreateSocketObj() +{ + TSocketObj* pSocketObj = (TSocketObj*)m_phSocket.Alloc(sizeof(TSocketObj)); + ASSERT(pSocketObj); + + pSocketObj->TSocketObj::TSocketObj(m_itPool); + + return pSocketObj; +} + +void CTcpAgent::DeleteSocketObj(TSocketObj* pSocketObj) +{ + ASSERT(pSocketObj); + + pSocketObj->TSocketObj::~TSocketObj(); + m_phSocket.Free(pSocketObj); +} + +TBufferObj* CTcpAgent::GetFreeBufferObj(int iLen) +{ + ASSERT(iLen >= 0 && iLen <= (int)m_dwSocketBufferSize); + + TBufferObj* pBufferObj = nullptr; + + if(!m_lsFreeBuffer.TryGet(&pBufferObj)) + pBufferObj = CreateBufferObj(); + + if(iLen <= 0) iLen = m_dwSocketBufferSize; + pBufferObj->buff.len = iLen; + + return pBufferObj; +} + +void CTcpAgent::AddFreeBufferObj(TBufferObj* pBufferObj) +{ + if(!m_lsFreeBuffer.TryPut(pBufferObj)) + DeleteBufferObj(pBufferObj); +} + +void CTcpAgent::ReleaseFreeBuffer() +{ + TBufferObj* pBufferObj = nullptr; + + while(m_lsFreeBuffer.TryGet(&pBufferObj)) + DeleteBufferObj(pBufferObj); + + VERIFY(m_lsFreeBuffer.IsEmpty()); + m_lsFreeBuffer.Reset(); +} + +TBufferObj* CTcpAgent::CreateBufferObj() +{ + TBufferObj* pBufferObj = (TBufferObj*)m_phBuffer.Alloc(sizeof(TBufferObj) + m_dwSocketBufferSize); + ASSERT(pBufferObj); + + ::ZeroMemory(pBufferObj, sizeof(TBufferObj)); + pBufferObj->buff.buf = ((char*)pBufferObj) + sizeof(TBufferObj); + + return pBufferObj; +} + +void CTcpAgent::DeleteBufferObj(TBufferObj* pBufferObj) +{ + ASSERT(pBufferObj); + m_phBuffer.Free(pBufferObj); +} + +TSocketObj* CTcpAgent::FindSocketObj(CONNID dwConnID) +{ + TSocketObj* pSocketObj = nullptr; + + { + CReentrantReadLock locallock(m_csClientSocket); + + TSocketObjPtrMapCI it = m_mpClientSocket.find(dwConnID); + if(it != m_mpClientSocket.end()) + pSocketObj = it->second; + } + + return pSocketObj; +} + +void CTcpAgent::CloseClientSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode, int iShutdownFlag) +{ + ASSERT(TSocketObj::IsExist(pSocketObj)); + + if(enFlag == SCF_CLOSE) + TriggerFireClose(pSocketObj, SO_CLOSE, SE_OK); + else if(enFlag == SCF_ERROR) + TriggerFireClose(pSocketObj, enOperation, iErrorCode); + + SOCKET socket = pSocketObj->socket; + pSocketObj->socket = INVALID_SOCKET; + + ::ManualCloseSocket(socket, iShutdownFlag); +} + +BOOL CTcpAgent::GetLocalAddress(CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + return ::GetSocketLocalAddress(pSocketObj->socket, lpszAddress, iAddressLen, usPort); + + return FALSE; +} + +BOOL CTcpAgent::GetRemoteAddress(CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsExist(pSocketObj)) + { + ADDRESS_FAMILY usFamily; + return ::sockaddr_IN_2_A(pSocketObj->remoteAddr, usFamily, lpszAddress, iAddressLen, usPort); + } + + return FALSE; +} + +BOOL CTcpAgent::SetConnectionExtra(CONNID dwConnID, PVOID pExtra) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return SetConnectionExtra(pSocketObj, pExtra); +} + +BOOL CTcpAgent::SetConnectionExtra(TSocketObj* pSocketObj, PVOID pExtra) +{ + if(TSocketObj::IsExist(pSocketObj)) + { + pSocketObj->extra = pExtra; + return TRUE; + } + + return FALSE; +} + +BOOL CTcpAgent::GetConnectionExtra(CONNID dwConnID, PVOID* ppExtra) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return GetConnectionExtra(pSocketObj, ppExtra); +} + +BOOL CTcpAgent::GetConnectionExtra(TSocketObj* pSocketObj, PVOID* ppExtra) +{ + ASSERT(ppExtra != nullptr); + + if(TSocketObj::IsExist(pSocketObj)) + { + *ppExtra = pSocketObj->extra; + return TRUE; + } + + return FALSE; +} + +BOOL CTcpAgent::SetConnectionReserved(CONNID dwConnID, PVOID pReserved) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return SetConnectionReserved(pSocketObj, pReserved); +} + +BOOL CTcpAgent::SetConnectionReserved(TSocketObj* pSocketObj, PVOID pReserved) +{ + if(TSocketObj::IsExist(pSocketObj)) + { + pSocketObj->reserved = pReserved; + return TRUE; + } + + return FALSE; +} + +BOOL CTcpAgent::GetConnectionReserved(CONNID dwConnID, PVOID* ppReserved) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return GetConnectionReserved(pSocketObj, ppReserved); +} + +BOOL CTcpAgent::GetConnectionReserved(TSocketObj* pSocketObj, PVOID* ppReserved) +{ + ASSERT(ppReserved != nullptr); + + if(TSocketObj::IsExist(pSocketObj)) + { + *ppReserved = pSocketObj->reserved; + return TRUE; + } + + return FALSE; +} + +BOOL CTcpAgent::GetPendingDataLength(CONNID dwConnID, int& iPending) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + iPending = pSocketObj->Pending(); + return TRUE; + } + + return FALSE; +} + +DWORD CTcpAgent::GetConnectionCount() +{ + return (DWORD)m_mpClientSocket.size(); +} + +BOOL CTcpAgent::GetAllConnectionIDs(CONNID pIDs[], DWORD& dwCount) +{ + BOOL isOK = FALSE; + DWORD dwSize = 0; + + { + CReentrantReadLock locallock(m_csClientSocket); + + dwSize = (DWORD)m_mpClientSocket.size(); + + if(pIDs != nullptr && dwSize <= dwCount) + { + TSocketObjPtrMapCI it = m_mpClientSocket.begin(); + TSocketObjPtrMapCI end = m_mpClientSocket.end(); + + for(int i = 0; it != end; ++it, ++i) + pIDs[i] = it->first; + + isOK = TRUE; + } + } + + dwCount = dwSize; + return isOK; +} + +BOOL CTcpAgent::GetConnectPeriod(CONNID dwConnID, DWORD& dwPeriod) +{ + BOOL isOK = TRUE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + dwPeriod = ::GetTimeGap32(pSocketObj->connTime); + else + isOK = FALSE; + + return isOK; +} + +BOOL CTcpAgent::GetSilencePeriod(CONNID dwConnID, DWORD& dwPeriod) +{ + if(!m_bMarkSilence) + return FALSE; + + BOOL isOK = TRUE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + dwPeriod = ::GetTimeGap32(pSocketObj->activeTime); + else + isOK = FALSE; + + return isOK; +} + +BOOL CTcpAgent::Disconnect(CONNID dwConnID, BOOL bForce) +{ + BOOL isOK = FALSE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + if(bForce) + isOK = ::PostIocpDisconnect(m_hCompletePort, dwConnID); + else + isOK = m_pfnDisconnectEx(pSocketObj->socket, nullptr, 0, 0); + } + + return isOK; +} + +BOOL CTcpAgent::DisconnectLongConnections(DWORD dwPeriod, BOOL bForce) +{ + ulong_ptr_deque ls; + + { + CReentrantReadLock locallock(m_csClientSocket); + + DWORD now = ::TimeGetTime(); + + for(TSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(now - it->second->connTime >= dwPeriod) + ls.push_back(it->first); + } + } + + for(ulong_ptr_deque::const_iterator it = ls.begin(), end = ls.end(); it != end; ++it) + Disconnect(*it, bForce); + + return ls.size() > 0; +} + +BOOL CTcpAgent::DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce) +{ + if(!m_bMarkSilence) + return FALSE; + + ulong_ptr_deque ls; + + { + CReentrantReadLock locallock(m_csClientSocket); + + DWORD now = ::TimeGetTime(); + + for(TSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(now - it->second->activeTime >= dwPeriod) + ls.push_back(it->first); + } + } + + for(ulong_ptr_deque::const_iterator it = ls.begin(), end = ls.end(); it != end; ++it) + Disconnect(*it, bForce); + + return ls.size() > 0; +} + +void CTcpAgent::WaitForClientSocketClose() +{ + DWORD dwWait = 0; + DWORD dwOrig = ::TimeGetTime(); + + while(m_mpClientSocket.size() > 0) + { + ::WaitWithMessageLoop(100); + dwWait = ::GetTimeGap32(dwOrig); + } + + ASSERT(m_mpClientSocket.size() == 0); +} + +void CTcpAgent::WaitForWorkerThreadEnd() +{ + int count = (int)m_vtWorkerThreads.size(); + + for(int i = 0; i < count; i++) + ::PostIocpExit(m_hCompletePort); + + int remain = count; + int index = 0; + + while(remain > 0) + { + int wait = min(remain, MAXIMUM_WAIT_OBJECTS); + HANDLE* pHandles = (HANDLE*)_alloca(sizeof(HANDLE) * wait); + + for(int i = 0; i < wait; i++) + pHandles[i] = m_vtWorkerThreads[i + index]; + + VERIFY(::WaitForMultipleObjects((DWORD)wait, pHandles, TRUE, INFINITE) == WAIT_OBJECT_0); + + for(int i = 0; i < wait; i++) + ::CloseHandle(pHandles[i]); + + remain -= wait; + index += wait; + } + + m_vtWorkerThreads.clear(); +} + +void CTcpAgent::CloseCompletePort() +{ + if(m_hCompletePort != nullptr) + { + ::CloseHandle(m_hCompletePort); + m_hCompletePort = nullptr; + } +} + +UINT WINAPI CTcpAgent::WorkerThreadProc(LPVOID pv) +{ + CTcpAgent* pServer = (CTcpAgent*)pv; + + while(TRUE) + { + DWORD dwErrorCode = NO_ERROR; + + DWORD dwBytes; + OVERLAPPED* pOverlapped; + TSocketObj* pSocketObj; + + BOOL result = ::GetQueuedCompletionStatus + ( + pServer->m_hCompletePort, + &dwBytes, + (PULONG_PTR)&pSocketObj, + &pOverlapped, + INFINITE + ); + + if(pOverlapped == nullptr) + { + EnIocpAction action = pServer->CheckIocpCommand(pOverlapped, dwBytes, (ULONG_PTR)pSocketObj); + + if(action == IOCP_ACT_CONTINUE) + continue; + else if(action == IOCP_ACT_BREAK) + break; + } + + TBufferObj* pBufferObj = CONTAINING_RECORD(pOverlapped, TBufferObj, ov); + CONNID dwConnID = pSocketObj->connID; + + if (!result) + { + DWORD dwFlag = 0; + DWORD dwSysCode = ::GetLastError(); + + if(pServer->HasStarted()) + { + SOCKET sock = pBufferObj->client; + result = ::WSAGetOverlappedResult(sock, &pBufferObj->ov, &dwBytes, FALSE, &dwFlag); + + if (!result) + { + dwErrorCode = ::WSAGetLastError(); + TRACE("GetQueuedCompletionStatus error ( SYS: %d, SOCK: %d, FLAG: %d)\n", dwConnID, dwSysCode, dwErrorCode, dwFlag); + } + } + else + dwErrorCode = dwSysCode; + + ASSERT(dwSysCode != 0 && dwErrorCode != 0); + } + + pServer->HandleIo(dwConnID, pSocketObj, pBufferObj, dwBytes, dwErrorCode); + } + + return 0; +} + +EnIocpAction CTcpAgent::CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey) +{ + ASSERT(pOverlapped == nullptr); + + EnIocpAction action = IOCP_ACT_CONTINUE; + + if(dwBytes == IOCP_CMD_SEND) + DoSend((CONNID)ulCompKey); + else if(dwBytes == IOCP_CMD_DISCONNECT) + ForceDisconnect((CONNID)ulCompKey); + else if(dwBytes == IOCP_CMD_EXIT && ulCompKey == 0) + action = IOCP_ACT_BREAK; + else + VERIFY(FALSE); + + return action; +} + +void CTcpAgent::ForceDisconnect(CONNID dwConnID) +{ + AddFreeSocketObj(FindSocketObj(dwConnID), SCF_CLOSE); +} + +void CTcpAgent::HandleIo(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode) +{ + ASSERT(pBufferObj != nullptr); + ASSERT(pSocketObj != nullptr); + + if(dwErrorCode != NO_ERROR) + { + HandleError(dwConnID, pSocketObj, pBufferObj, dwErrorCode); + return; + } + + if(dwBytes == 0 && pBufferObj->operation != SO_CONNECT) + { + AddFreeSocketObj(pSocketObj, SCF_CLOSE); + AddFreeBufferObj(pBufferObj); + return; + } + + pBufferObj->buff.len = dwBytes; + + switch(pBufferObj->operation) + { + case SO_CONNECT: + HandleConnect(dwConnID, pSocketObj, pBufferObj); + break; + case SO_SEND: + HandleSend(dwConnID, pSocketObj, pBufferObj); + break; + case SO_RECEIVE: + HandleReceive(dwConnID, pSocketObj, pBufferObj); + break; + default: + ASSERT(FALSE); + } +} + +void CTcpAgent::HandleError(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwErrorCode) +{ + CheckError(pSocketObj, pBufferObj->operation, dwErrorCode); + AddFreeBufferObj(pBufferObj); +} + +void CTcpAgent::HandleConnect(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + ::SSO_UpdateConnectContext(pBufferObj->client, 0); + + if(TriggerFireConnect(pSocketObj) != HR_ERROR) + DoReceive(dwConnID, pSocketObj, pBufferObj); + else + { + AddFreeSocketObj(pSocketObj, SCF_NONE); + AddFreeBufferObj(pBufferObj); + } +} + +void CTcpAgent::HandleSend(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + switch(m_enSendPolicy) + { + case SP_PACK: + { + long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount); + + TriggerFireSend(pSocketObj, pBufferObj); + if(sndCount == 0) DoSendPack(pSocketObj); + } + + break; + case SP_SAFE: + { + long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount); + + if(sndCount == 0 && !pSocketObj->smooth) + { + CCriSecLock locallock(pSocketObj->csSend); + + if((sndCount = pSocketObj->sndCount) == 0) + pSocketObj->smooth = TRUE; + } + + TriggerFireSend(pSocketObj, pBufferObj); + if(sndCount == 0) DoSendSafe(pSocketObj); + } + + break; + case SP_DIRECT: + { + TriggerFireSend(pSocketObj, pBufferObj); + } + + break; + default: + ASSERT(FALSE); + } +} + +void CTcpAgent::HandleReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime(); + EnHandleResult hr = TriggerFireReceive(pSocketObj, pBufferObj); + + if(hr == HR_OK || hr == HR_IGNORE) + DoReceive(dwConnID, pSocketObj, pBufferObj); + else if(hr == HR_CLOSED) + { + AddFreeBufferObj(pBufferObj); + } + else + { + TRACE(" OnReceive() event return 'HR_ERROR', connection will be closed !\n", dwConnID); + AddFreeSocketObj(pSocketObj, SCF_ERROR, SO_RECEIVE, ERROR_CANCELLED); + AddFreeBufferObj(pBufferObj); + } +} + +int CTcpAgent::DoReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + pBufferObj->buff.len = m_dwSocketBufferSize; + int result =::PostReceive(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + CheckError(pSocketObj, SO_RECEIVE, result); + AddFreeBufferObj(pBufferObj); + } + + return result; +} + +BOOL CTcpAgent::Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID) +{ + ASSERT(pszRemoteAddress && usPort != 0); + + if(pdwConnID) *pdwConnID = 0; + + DWORD result = NO_ERROR; + SOCKET soClient = INVALID_SOCKET; + + if(!HasStarted()) + result = ERROR_INVALID_STATE; + else + { + result = CreateClientSocket(soClient); + + if(result == NO_ERROR) + { + CONNID dwConnID = ::GenerateConnectionID(); + if(pdwConnID) *pdwConnID = dwConnID; + + if(FirePrepareConnect(dwConnID, soClient) != HR_ERROR) + result = ConnectToServer(dwConnID, soClient, pszRemoteAddress, usPort); + else + result = ERROR_CANCELLED; + } + } + + if(result != NO_ERROR) + { + if(soClient != INVALID_SOCKET) + ::ManualCloseSocket(soClient); + + ::SetLastError(result); + } + + return (result == NO_ERROR); +} + +DWORD CTcpAgent::CreateClientSocket(SOCKET& soClient) +{ + DWORD result = NO_ERROR; + soClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if(soClient != INVALID_SOCKET) + { + VERIFY(::SSO_ReuseAddress(soClient, m_bReuseAddress) != SOCKET_ERROR); + + BOOL bOnOff = (m_dwKeepAliveTime > 0 && m_dwKeepAliveInterval > 0); + ::SSO_KeepAliveVals(soClient, bOnOff, m_dwKeepAliveTime, m_dwKeepAliveInterval); + + if(m_bAsyncConnect && ::bind(soClient, (SOCKADDR*)&m_soAddrIN, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) + result = ::WSAGetLastError(); + } + else + result = ::WSAGetLastError(); + + return result; +} + +DWORD CTcpAgent::ConnectToServer(CONNID dwConnID, SOCKET& soClient, LPCTSTR pszRemoteAddress, USHORT usPort) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + + if(!::GetIPAddress(pszRemoteAddress, szAddress, iAddressLen)) + return WSAEADDRNOTAVAIL; + + SOCKADDR_IN addr; + if(!::sockaddr_A_2_IN(AF_INET, szAddress, usPort, addr)) + return WSAEADDRNOTAVAIL; + + TBufferObj* pBufferObj = GetFreeBufferObj(); + TSocketObj* pSocketObj = GetFreeSocketObj(dwConnID, soClient); + + memcpy(&pSocketObj->remoteAddr, &addr, sizeof(SOCKADDR_IN)); + AddClientSocketObj(dwConnID, pSocketObj); + + DWORD result = NO_ERROR; + BOOL bNeedFree = TRUE; + + if(m_bAsyncConnect) + { + if(::CreateIoCompletionPort((HANDLE)soClient, m_hCompletePort, (ULONG_PTR)pSocketObj, 0)) + { + result = DoConnect(dwConnID, pSocketObj, pBufferObj); + bNeedFree = FALSE; + } + else + result = ::GetLastError(); + } + else + { + if(::connect(soClient, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)) != SOCKET_ERROR) + { + if(::CreateIoCompletionPort((HANDLE)soClient, m_hCompletePort, (ULONG_PTR)pSocketObj, 0)) + { + if(TriggerFireConnect(pSocketObj) != HR_ERROR) + { + result = DoReceive(dwConnID, pSocketObj, pBufferObj); + bNeedFree = FALSE; + } + else + result = ERROR_CANCELLED; + } + else + result = ::GetLastError(); + } + else + result = ::WSAGetLastError(); + } + + if(result != NO_ERROR) + { + if(bNeedFree) + { + AddFreeSocketObj(pSocketObj, SCF_NONE); + AddFreeBufferObj(pBufferObj); + } + + soClient = INVALID_SOCKET; + } + + return result; +} + +int CTcpAgent::DoConnect(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + int result = ::PostConnect(m_pfnConnectEx, pSocketObj->socket, pSocketObj->remoteAddr, pBufferObj); + + if(result != NO_ERROR) + { + CheckError(pSocketObj, SO_CONNECT, result); + AddFreeBufferObj(pBufferObj); + } + + return result; +} + +BOOL CTcpAgent::Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset) +{ + ASSERT(pBuffer && iLength > 0); + + if(iOffset != 0) pBuffer += iOffset; + + WSABUF buffer; + buffer.len = iLength; + buffer.buf = (char*)pBuffer; + + return SendPackets(dwConnID, &buffer, 1); +} + +BOOL CTcpAgent::SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + TSocketObj* pSocketObj = nullptr; + + ASSERT(pBuffers && iCount > 0); + + if(pBuffers && iCount > 0) + { + pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + result = SendInternal(pSocketObj, pBuffers, iCount); + else + result = ERROR_OBJECT_NOT_FOUND; + } + else + result = ERROR_OBJECT_NOT_FOUND; + } + else + result = ERROR_INVALID_PARAMETER; + + if(result != NO_ERROR) + { + if(m_enSendPolicy == SP_DIRECT && TSocketObj::IsValid(pSocketObj)) + CheckError(pSocketObj, SO_SEND, result); + + ::SetLastError(result); + } + + return (result == NO_ERROR); +} + +int CTcpAgent::SendInternal(TSocketObj* pSocketObj, const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + + for(int i = 0; i < iCount; i++) + { + int iBufLen = pBuffers[i].len; + + if(iBufLen > 0) + { + BYTE* pBuffer = (BYTE*)pBuffers[i].buf; + ASSERT(pBuffer); + + switch(m_enSendPolicy) + { + case SP_PACK: result = SendPack(pSocketObj, pBuffer, iBufLen); break; + case SP_SAFE: result = SendSafe(pSocketObj, pBuffer, iBufLen); break; + case SP_DIRECT: result = SendDirect(pSocketObj, pBuffer, iBufLen); break; + default: ASSERT(FALSE); result = ERROR_INVALID_INDEX; break; + } + + if(result != NO_ERROR) + break; + } + } + + return result; +} + +int CTcpAgent::SendPack(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + BOOL isPostSend = !TSocketObj::IsPending(pSocketObj); + return CatAndPost(pSocketObj, pBuffer, iLength, isPostSend); +} + +int CTcpAgent::SendSafe(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + BOOL isPostSend = !TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj); + return CatAndPost(pSocketObj, pBuffer, iLength, isPostSend); +} + +int CTcpAgent::SendDirect(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + int result = NO_ERROR; + int iRemain = iLength; + + while(iRemain > 0) + { + int iBufferSize = min(iRemain, (int)m_dwSocketBufferSize); + TBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize); + memcpy(pBufferObj->buff.buf, pBuffer, iBufferSize); + + result = ::PostSend(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + AddFreeBufferObj(pBufferObj); + break; + } + + iRemain -= iBufferSize; + pBuffer += iBufferSize; + } + + return result; +} + +int CTcpAgent::CatAndPost(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend) +{ + int result = NO_ERROR; + + pSocketObj->sndBuff.Cat(pBuffer, iLength); + pSocketObj->pending += iLength; + + if(isPostSend && !::PostIocpSend(m_hCompletePort, pSocketObj->connID)) + result = ::GetLastError(); + + return result; +} + +int CTcpAgent::DoSend(CONNID dwConnID) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + return DoSend(pSocketObj); + + return ERROR_OBJECT_NOT_FOUND; +} + +int CTcpAgent::DoSend(TSocketObj* pSocketObj) +{ + switch(m_enSendPolicy) + { + case SP_PACK: return DoSendPack(pSocketObj); + case SP_SAFE: return DoSendSafe(pSocketObj); + default: ASSERT(FALSE); return ERROR_INVALID_INDEX; + } +} + +int CTcpAgent::DoSendPack(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + if(TSocketObj::IsPending(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + result = SendItem(pSocketObj); + } + + if(!IOCP_SUCCESS(result)) + CheckError(pSocketObj, SO_SEND, result); + + return result; +} + +int CTcpAgent::DoSendSafe(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + if(TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj)) + { + pSocketObj->smooth = FALSE; + + result = SendItem(pSocketObj); + + if(result == NO_ERROR) + pSocketObj->smooth = TRUE; + } + } + + if(!IOCP_SUCCESS(result)) + CheckError(pSocketObj, SO_SEND, result); + + return result; +} + +int CTcpAgent::SendItem(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + while(pSocketObj->sndBuff.Size() > 0) + { + ::InterlockedIncrement(&pSocketObj->sndCount); + + TItemPtr itPtr(m_itPool, pSocketObj->sndBuff.PopFront()); + + int iBufferSize = itPtr->Size(); + ASSERT(iBufferSize > 0 && iBufferSize <= (int)m_dwSocketBufferSize); + + pSocketObj->pending -= iBufferSize; + TBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize); + memcpy(pBufferObj->buff.buf, itPtr->Ptr(), iBufferSize); + + result = ::PostSendNotCheck(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + if(result != WSA_IO_PENDING) + AddFreeBufferObj(pBufferObj); + + break; + } + } + + return result; +} + +BOOL CTcpAgent::SendSmallFile(CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail) +{ + ASSERT(lpszFileName != nullptr); + + CAtlFile file; + HRESULT hr = file.Create(lpszFileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); + + if(SUCCEEDED(hr)) + { + ULONGLONG ullLen; + hr = file.GetSize(ullLen); + + if(SUCCEEDED(hr)) + { + if(ullLen > 0 && ullLen <= MAX_SMALL_FILE_SIZE) + { + CAtlFileMapping<> fmap; + hr = fmap.MapFile(file); + + if(SUCCEEDED(hr)) + { + WSABUF bufs[3] = {0}; + + bufs[1].len = (ULONG)ullLen; + bufs[1].buf = fmap; + + if(pHead) memcpy(&bufs[0], pHead, sizeof(WSABUF)); + if(pTail) memcpy(&bufs[2], pTail, sizeof(WSABUF)); + + return SendPackets(dwConnID, bufs, 3); + } + } + else if(ullLen == 0) + hr = HRESULT_FROM_WIN32(ERROR_FILE_INVALID); + else + hr = HRESULT_FROM_WIN32(ERROR_FILE_TOO_LARGE); + } + } + + ::SetLastError(hr & 0x0000FFFF); + + return FALSE; +} + +void CTcpAgent::CheckError(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + if(iErrorCode != WSAENOTSOCK && iErrorCode != ERROR_OPERATION_ABORTED) + AddFreeSocketObj(pSocketObj, SCF_ERROR, enOperation, iErrorCode); +} diff --git a/HP-Socket/Src/TcpAgent.h b/HP-Socket/Src/TcpAgent.h new file mode 100644 index 000000000..300112a16 --- /dev/null +++ b/HP-Socket/Src/TcpAgent.h @@ -0,0 +1,260 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "SocketHelper.h" +#include "../../Common/Src/Event.h" +#include "../../Common/Src/RWLock.h" +#include "../../Common/Src/STLHelper.h" +#include "../../Common/Src/RingBuffer.h" +#include "../../Common/Src/PrivateHeap.h" + +class CTcpAgent : public ITcpAgent +{ +public: + CTcpAgent(ITcpAgentListener* psoListener) + : m_psoListener (psoListener) + , m_hCompletePort (nullptr) + , m_pfnConnectEx (nullptr) + , m_pfnDisconnectEx (nullptr) + , m_enLastError (SE_OK) + , m_enState (SS_STOPPED) + , m_bAsyncConnect (TRUE) + , m_enSendPolicy (SP_PACK) + , m_dwWorkerThreadCount (DEFAULT_WORKER_THREAD_COUNT) + , m_dwSocketBufferSize (DEFAULT_TCP_SOCKET_BUFFER_SIZE) + , m_dwFreeSocketObjLockTime (DEFAULT_FREE_SOCKETOBJ_LOCK_TIME) + , m_dwFreeSocketObjPool (DEFAULT_FREE_SOCKETOBJ_POOL) + , m_dwFreeBufferObjPool (DEFAULT_FREE_BUFFEROBJ_POOL) + , m_dwFreeSocketObjHold (DEFAULT_FREE_SOCKETOBJ_HOLD) + , m_dwFreeBufferObjHold (DEFAULT_FREE_BUFFEROBJ_HOLD) + , m_dwKeepAliveTime (DEFALUT_TCP_KEEPALIVE_TIME) + , m_dwKeepAliveInterval (DEFALUT_TCP_KEEPALIVE_INTERVAL) + , m_bReuseAddress (FALSE) + , m_bMarkSilence (FALSE) + { + ASSERT(m_wsSocket.IsValid()); + ASSERT(m_psoListener); + + Reset(FALSE); + } + + virtual ~CTcpAgent() + { + if(HasStarted()) + Stop(); + } + +public: + virtual BOOL Start (LPCTSTR pszBindAddress = nullptr, BOOL bAsyncConnect = TRUE); + virtual BOOL Stop (); + virtual BOOL Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID = nullptr); + virtual BOOL Send (CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0); + virtual BOOL SendPackets (CONNID dwConnID, const WSABUF pBuffers[], int iCount); + virtual BOOL SendSmallFile (CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr); + virtual BOOL HasStarted () {return m_enState == SS_STARTED || m_enState == SS_STARTING;} + virtual EnServiceState GetState () {return m_enState;} + virtual BOOL Disconnect (CONNID dwConnID, BOOL bForce = TRUE); + virtual BOOL DisconnectLongConnections (DWORD dwPeriod, BOOL bForce = TRUE); + virtual BOOL DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce = TRUE); + virtual BOOL GetLocalAddress (CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + virtual BOOL GetRemoteAddress (CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + + virtual BOOL GetPendingDataLength (CONNID dwConnID, int& iPending); + virtual DWORD GetConnectionCount (); + virtual BOOL GetAllConnectionIDs (CONNID pIDs[], DWORD& dwCount); + virtual BOOL GetConnectPeriod (CONNID dwConnID, DWORD& dwPeriod); + virtual BOOL GetSilencePeriod (CONNID dwConnID, DWORD& dwPeriod); + virtual EnSocketError GetLastError () {return m_enLastError;} + virtual LPCTSTR GetLastErrorDesc () {return ::GetSocketErrorDesc(m_enLastError);} + +public: + virtual BOOL SetConnectionExtra(CONNID dwConnID, PVOID pExtra); + virtual BOOL GetConnectionExtra(CONNID dwConnID, PVOID* ppExtra); + + virtual void SetSendPolicy (EnSendPolicy enSendPolicy) {m_enSendPolicy = enSendPolicy;} + virtual void SetWorkerThreadCount (DWORD dwWorkerThreadCount) {m_dwWorkerThreadCount = dwWorkerThreadCount;} + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) {m_dwSocketBufferSize = dwSocketBufferSize;} + virtual void SetFreeSocketObjLockTime (DWORD dwFreeSocketObjLockTime) {m_dwFreeSocketObjLockTime = dwFreeSocketObjLockTime;} + virtual void SetFreeSocketObjPool (DWORD dwFreeSocketObjPool) {m_dwFreeSocketObjPool = dwFreeSocketObjPool;} + virtual void SetFreeBufferObjPool (DWORD dwFreeBufferObjPool) {m_dwFreeBufferObjPool = dwFreeBufferObjPool;} + virtual void SetFreeSocketObjHold (DWORD dwFreeSocketObjHold) {m_dwFreeSocketObjHold = dwFreeSocketObjHold;} + virtual void SetFreeBufferObjHold (DWORD dwFreeBufferObjHold) {m_dwFreeBufferObjHold = dwFreeBufferObjHold;} + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) {m_dwKeepAliveTime = dwKeepAliveTime;} + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) {m_dwKeepAliveInterval = dwKeepAliveInterval;} + virtual void SetReuseAddress (BOOL bReuseAddress) {m_bReuseAddress = bReuseAddress;} + virtual void SetMarkSilence (BOOL bMarkSilence) {m_bMarkSilence = bMarkSilence;} + + virtual EnSendPolicy GetSendPolicy () {return m_enSendPolicy;} + virtual DWORD GetWorkerThreadCount () {return m_dwWorkerThreadCount;} + virtual DWORD GetSocketBufferSize () {return m_dwSocketBufferSize;} + virtual DWORD GetFreeSocketObjLockTime () {return m_dwFreeSocketObjLockTime;} + virtual DWORD GetFreeSocketObjPool () {return m_dwFreeSocketObjPool;} + virtual DWORD GetFreeBufferObjPool () {return m_dwFreeBufferObjPool;} + virtual DWORD GetFreeSocketObjHold () {return m_dwFreeSocketObjHold;} + virtual DWORD GetFreeBufferObjHold () {return m_dwFreeBufferObjHold;} + virtual DWORD GetKeepAliveTime () {return m_dwKeepAliveTime;} + virtual DWORD GetKeepAliveInterval () {return m_dwKeepAliveInterval;} + virtual BOOL IsReuseAddress () {return m_bReuseAddress;} + virtual BOOL IsMarkSilence () {return m_bMarkSilence;} + +protected: + virtual EnHandleResult FirePrepareConnect(CONNID dwConnID, SOCKET socket) + {return m_psoListener->OnPrepareConnect(dwConnID, socket);} + virtual EnHandleResult FireConnect(TSocketObj* pSocketObj) + {return m_psoListener->OnConnect(pSocketObj->connID);} + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return m_psoListener->OnReceive(pSocketObj->connID, pData, iLength);} + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, int iLength) + {return m_psoListener->OnReceive(pSocketObj->connID, iLength);} + virtual EnHandleResult FireSend(TSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return m_psoListener->OnSend(pSocketObj->connID, pData, iLength);} + virtual EnHandleResult FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) + {return m_psoListener->OnClose(pSocketObj->connID, enOperation, iErrorCode);} + virtual EnHandleResult FireShutdown() + {return m_psoListener->OnShutdown();} + + void SetLastError(EnSocketError code, LPCSTR func, int ec); + virtual BOOL CheckParams(); + virtual void PrepareStart(); + virtual void Reset(BOOL bAll = TRUE); + +private: + EnHandleResult TriggerFireConnect(TSocketObj* pSocketObj); + EnHandleResult TriggerFireReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj); + EnHandleResult TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj); + EnHandleResult TriggerFireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + +protected: + BOOL SetConnectionExtra(TSocketObj* pSocketObj, PVOID pExtra); + BOOL GetConnectionExtra(TSocketObj* pSocketObj, PVOID* ppExtra); + BOOL SetConnectionReserved(CONNID dwConnID, PVOID pReserved); + BOOL GetConnectionReserved(CONNID dwConnID, PVOID* ppReserved); + BOOL SetConnectionReserved(TSocketObj* pSocketObj, PVOID pReserved); + BOOL GetConnectionReserved(TSocketObj* pSocketObj, PVOID* ppReserved); + +private: + BOOL CheckStarting(); + BOOL CheckStoping(); + BOOL ParseBindAddress(LPCTSTR pszBindAddress, BOOL bAsyncConnect); + BOOL CreateCompletePort(); + BOOL CreateWorkerThreads(); + + void DisconnectClientSocket(); + void WaitForClientSocketClose(); + void ReleaseClientSocket(); + void ReleaseFreeSocket(); + void ReleaseFreeBuffer(); + void WaitForWorkerThreadEnd(); + void CloseCompletePort(); + + TBufferObj* GetFreeBufferObj(int iLen = 0); + TSocketObj* GetFreeSocketObj(CONNID dwConnID, SOCKET soClient); + void AddFreeBufferObj(TBufferObj* pBufferObj); + void AddFreeSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0); + TBufferObj* CreateBufferObj(); + TSocketObj* CreateSocketObj(); + void DeleteBufferObj(TBufferObj* pBufferObj); + void DeleteSocketObj(TSocketObj* pSocketObj); + BOOL InvalidSocketObj(TSocketObj* pSocketObj); + void ReleaseGCSocketObj(BOOL bForce = FALSE); + + void AddClientSocketObj(CONNID dwConnID, TSocketObj* pSocketObj); + void CloseClientSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0, int iShutdownFlag = SD_SEND); + TSocketObj* FindSocketObj(CONNID dwConnID); + +private: + static UINT WINAPI WorkerThreadProc(LPVOID pv); + + EnIocpAction CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey); + + DWORD CreateClientSocket(SOCKET& soClient); + DWORD ConnectToServer (CONNID dwConnID, SOCKET& soClient, LPCTSTR pszRemoteAddress, USHORT usPort); + void ForceDisconnect (CONNID dwConnID); + + void HandleIo (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode); + void HandleError (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwErrorCode); + void HandleConnect (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + void HandleSend (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + void HandleReceive (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + + int SendInternal(TSocketObj* pSocketObj, const WSABUF pBuffers[], int iCount); + int SendPack (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int SendSafe (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int SendDirect (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int CatAndPost (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend); + + int DoConnect (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + int DoReceive (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + + int DoSend (CONNID dwConnID); + int DoSend (TSocketObj* pSocketObj); + int DoSendPack (TSocketObj* pSocketObj); + int DoSendSafe (TSocketObj* pSocketObj); + int SendItem (TSocketObj* pSocketObj); + + void CheckError (TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + +private: + EnSendPolicy m_enSendPolicy; + DWORD m_dwWorkerThreadCount; + DWORD m_dwSocketBufferSize; + DWORD m_dwFreeSocketObjLockTime; + DWORD m_dwFreeSocketObjPool; + DWORD m_dwFreeBufferObjPool; + DWORD m_dwFreeSocketObjHold; + DWORD m_dwFreeBufferObjHold; + DWORD m_dwKeepAliveTime; + DWORD m_dwKeepAliveInterval; + BOOL m_bReuseAddress; + BOOL m_bMarkSilence; + +private: + CInitSocket m_wsSocket; + LPFN_CONNECTEX m_pfnConnectEx; + LPFN_DISCONNECTEX m_pfnDisconnectEx; + +private: + ITcpAgentListener* m_psoListener; + BOOL m_bAsyncConnect; + HANDLE m_hCompletePort; + EnServiceState m_enState; + EnSocketError m_enLastError; + SOCKADDR_IN m_soAddrIN; + vector m_vtWorkerThreads; + + CPrivateHeap m_phBuffer; + CPrivateHeap m_phSocket; + CItemPool m_itPool; + + CSpinGuard m_csState; + + CRWLock m_csClientSocket; + TSocketObjPtrMap m_mpClientSocket; + + TBufferObjPtrList m_lsFreeBuffer; + TSocketObjPtrList m_lsFreeSocket; + TSocketObjPtrQueue m_lsGCSocket; +}; diff --git a/HP-Socket/Src/TcpClient.cpp b/HP-Socket/Src/TcpClient.cpp new file mode 100644 index 000000000..1aa428fb5 --- /dev/null +++ b/HP-Socket/Src/TcpClient.cpp @@ -0,0 +1,688 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include +#include "TcpClient.h" +#include "../../Common/Src/WaitFor.h" + +#include + +BOOL CTcpClient::Start(LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect) +{ + if(!CheckParams() || !CheckStarting()) + return FALSE; + + PrepareStart(); + + BOOL isOK = FALSE; + m_bAsyncConnect = bAsyncConnect; + + if(CreateClientSocket()) + { + if(FirePrepareConnect(this, m_soClient) != HR_ERROR) + { + if(ConnectToServer(pszRemoteAddress, usPort)) + { + if(CreateWorkerThread()) + isOK = TRUE; + else + SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ERROR_CREATE_FAILED); + } + else + SetLastError(SE_CONNECT_SERVER, __FUNCTION__, ::WSAGetLastError()); + } + else + SetLastError(SE_SOCKET_PREPARE, __FUNCTION__, ERROR_CANCELLED); + } + else + SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError()); + + if(!isOK) Stop(); + + return isOK; +} + +BOOL CTcpClient::CheckParams() +{ + if((int)m_dwSocketBufferSize > 0) + if((int)m_dwFreeBufferPoolSize >= 0) + if((int)m_dwFreeBufferPoolHold >= 0) + if((int)m_dwKeepAliveTime >= 1000 || m_dwKeepAliveTime == 0) + if((int)m_dwKeepAliveInterval >= 1000 || m_dwKeepAliveInterval == 0) + return TRUE; + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CTcpClient::PrepareStart() +{ + m_itPool.SetItemCapacity((int)m_dwSocketBufferSize); + m_itPool.SetPoolSize((int)m_dwFreeBufferPoolSize); + m_itPool.SetPoolHold((int)m_dwFreeBufferPoolHold); + + m_itPool.Prepare(); +} + +BOOL CTcpClient::CheckStarting() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STOPPED) + m_enState = SS_STARTING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CTcpClient::CheckStoping() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STARTED || m_enState == SS_STARTING) + m_enState = SS_STOPPING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CTcpClient::CreateClientSocket() +{ + m_soClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if(m_soClient != INVALID_SOCKET) + { + BOOL bOnOff = (m_dwKeepAliveTime > 0 && m_dwKeepAliveInterval > 0); + VERIFY(::SSO_KeepAliveVals(m_soClient, bOnOff, m_dwKeepAliveTime, m_dwKeepAliveInterval) == NO_ERROR); + + m_evSocket = ::WSACreateEvent(); + ASSERT(m_evSocket != WSA_INVALID_EVENT); + + m_dwConnID = ::GenerateConnectionID(); + + return TRUE; + } + + return FALSE; +} + +BOOL CTcpClient::ConnectToServer(LPCTSTR pszRemoteAddress, USHORT usPort) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + + if(!::GetIPAddress(pszRemoteAddress, szAddress, iAddressLen)) + { + ::WSASetLastError(WSAEADDRNOTAVAIL); + return FALSE; + } + + SOCKADDR_IN addr; + if(!::sockaddr_A_2_IN(AF_INET, szAddress, usPort, addr)) + { + ::WSASetLastError(WSAEADDRNOTAVAIL); + return FALSE; + } + + BOOL isOK = FALSE; + + if(m_bAsyncConnect) + { + if(::WSAEventSelect(m_soClient, m_evSocket, FD_CONNECT | FD_CLOSE) != SOCKET_ERROR) + { + int rc = ::connect(m_soClient, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)); + isOK = (rc == NO_ERROR || (rc == SOCKET_ERROR && ::WSAGetLastError() == WSAEWOULDBLOCK)); + } + } + else + { + if(::connect(m_soClient, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)) != SOCKET_ERROR) + { + if(::WSAEventSelect(m_soClient, m_evSocket, FD_READ | FD_WRITE | FD_CLOSE) != SOCKET_ERROR) + { + if(FireConnect(this) != HR_ERROR) + { + m_enState = SS_STARTED; + isOK = TRUE; + } + } + } + } + + return isOK; +} + +BOOL CTcpClient::CreateWorkerThread() +{ + m_hWorker = (HANDLE)_beginthreadex(nullptr, 0, WorkerThreadProc, (LPVOID)this, 0, &m_dwWorkerID); + + return m_hWorker != nullptr; +} + +UINT WINAPI CTcpClient::WorkerThreadProc(LPVOID pv) +{ + TRACE("---------------> Client Worker Thread 0x%08X started <---------------\n", ::GetCurrentThreadId()); + + CTcpClient* pClient = (CTcpClient*)pv; + HANDLE hEvents[] = {pClient->m_evSocket, pClient->m_evBuffer, pClient->m_evWorker}; + + pClient->m_rcBuffer.Malloc(pClient->m_dwSocketBufferSize); + + while(pClient->HasStarted()) + { + DWORD retval = ::WSAWaitForMultipleEvents(3, hEvents, FALSE, WSA_INFINITE, FALSE); + + if(retval == WSA_WAIT_EVENT_0) + { + if(!pClient->ProcessNetworkEvent()) + { + if(pClient->HasStarted()) + pClient->Stop(); + + break; + } + } + else if(retval == WSA_WAIT_EVENT_0 + 1) + { + if(!pClient->SendData()) + { + if(pClient->HasStarted()) + pClient->Stop(); + + break; + } + } + else if(retval == WSA_WAIT_EVENT_0 + 2) + break; + else + ASSERT(FALSE); + } + + TRACE("---------------> Client Worker Thread 0x%08X stoped <---------------\n", ::GetCurrentThreadId()); + + return 0; +} + +BOOL CTcpClient::ProcessNetworkEvent() +{ + BOOL bContinue = TRUE; + WSANETWORKEVENTS events; + + int rc = ::WSAEnumNetworkEvents(m_soClient, m_evSocket, &events); + + if(rc == SOCKET_ERROR) + bContinue = HandleError(events); + + if(m_bAsyncConnect && bContinue && events.lNetworkEvents & FD_CONNECT) + bContinue = HandleConnect(events); + + if(bContinue && events.lNetworkEvents & FD_READ) + bContinue = HandleRead(events); + + if(bContinue && events.lNetworkEvents & FD_WRITE) + bContinue = HandleWrite(events); + + if(bContinue && events.lNetworkEvents & FD_CLOSE) + bContinue = HandleClose(events); + + return bContinue; +} + +BOOL CTcpClient::HandleError(WSANETWORKEVENTS& events) +{ + int iCode = ::WSAGetLastError(); + EnSocketOperation enOperation = SO_UNKNOWN; + + if(events.lNetworkEvents & FD_CONNECT) + enOperation = SO_CONNECT; + else if(events.lNetworkEvents & FD_CLOSE) + enOperation = SO_CLOSE; + else if(events.lNetworkEvents & FD_READ) + enOperation = SO_RECEIVE; + else if(events.lNetworkEvents & FD_WRITE) + enOperation = SO_SEND; + + VERIFY(::WSAResetEvent(m_evSocket)); + FireClose(this, enOperation, iCode); + + return FALSE; +} + +BOOL CTcpClient::HandleRead(WSANETWORKEVENTS& events) +{ + BOOL bContinue = TRUE; + int iCode = events.iErrorCode[FD_READ_BIT]; + + if(iCode == 0) + bContinue = ReadData(); + else + { + FireClose(this, SO_RECEIVE, iCode); + bContinue = FALSE; + } + + return bContinue; +} + +BOOL CTcpClient::HandleWrite(WSANETWORKEVENTS& events) +{ + BOOL bContinue = TRUE; + int iCode = events.iErrorCode[FD_WRITE_BIT]; + + if(iCode == 0) + bContinue = SendData(); + else + { + FireClose(this, SO_SEND, iCode); + bContinue = FALSE; + } + + return bContinue; +} + +BOOL CTcpClient::HandleConnect(WSANETWORKEVENTS& events) +{ + BOOL bContinue = TRUE; + int iCode = events.iErrorCode[FD_CONNECT_BIT]; + + if(iCode == 0) + { + if(::WSAEventSelect(m_soClient, m_evSocket, FD_READ | FD_WRITE | FD_CLOSE) != SOCKET_ERROR) + { + if(FireConnect(this) != HR_ERROR) + m_enState = SS_STARTED; + else + iCode = ERROR_CANCELLED; + } + else + iCode = ::WSAGetLastError(); + } + + if(iCode != 0) + { + if(iCode != ERROR_CANCELLED) + FireClose(this, SO_CONNECT, iCode); + + bContinue = FALSE; + } + + return bContinue; +} + +BOOL CTcpClient::HandleClose(WSANETWORKEVENTS& events) +{ + int iCode = events.iErrorCode[FD_CLOSE_BIT]; + + if(iCode == 0) + FireClose(this, SO_CLOSE, SE_OK); + else + FireClose(this, SO_CLOSE, iCode); + + return FALSE; +} + +BOOL CTcpClient::ReadData() +{ + while(TRUE) + { + int rc = recv(m_soClient, (char*)(BYTE*)m_rcBuffer, m_dwSocketBufferSize, 0); + + if(rc > 0) + { + if(FireReceive(this, m_rcBuffer, rc) == HR_ERROR) + { + TRACE(" OnReceive() event return 'HR_ERROR', connection will be closed !\n", m_dwConnID); + + FireClose(this, SO_RECEIVE, ERROR_CANCELLED); + return FALSE; + } + } + else if(rc == SOCKET_ERROR) + { + int code = ::WSAGetLastError(); + + if(code == WSAEWOULDBLOCK) + break; + else + { + FireClose(this, SO_RECEIVE, code); + return FALSE; + } + } + else if(rc == 0) + { + FireClose(this, SO_CLOSE, SE_OK); + return FALSE; + } + else + ASSERT(FALSE); + } + + return TRUE; +} + +BOOL CTcpClient::SendData() +{ + BOOL isOK = TRUE; + + while(TRUE) + { + TItemPtr itPtr(m_itPool, GetSendBuffer()); + + if(itPtr.IsValid()) + { + ASSERT(!itPtr->IsEmpty()); + + isOK = DoSendData(itPtr); + + if(isOK) + { + if(!itPtr->IsEmpty()) + { + CCriSecLock locallock(m_csSend); + m_lsSend.PushFront(itPtr.Detach()); + + break; + } + } + else + break; + } + else + break; + } + + return isOK; +} + +TItem* CTcpClient::GetSendBuffer() +{ + TItem* pItem = nullptr; + + if(m_lsSend.Size() > 0) + { + CCriSecLock locallock(m_csSend); + + if(m_lsSend.Size() > 0) + pItem = m_lsSend.PopFront(); + } + + return pItem; +} + +BOOL CTcpClient::DoSendData(TItem* pItem) +{ + while(!pItem->IsEmpty()) + { + int rc = 0; + + { + CCriSecLock locallock(m_csSend); + + rc = send(m_soClient, (char*)pItem->Ptr(), min(pItem->Size(), (int)m_dwSocketBufferSize), 0); + if(rc > 0) m_iPending -= rc; + } + + if(rc > 0) + { + if(FireSend(this, pItem->Ptr(), rc) == HR_ERROR) + { + TRACE(" OnSend() event should not return 'HR_ERROR' !!\n", m_dwConnID); + ASSERT(FALSE); + } + + pItem->Reduce(rc); + } + else if(rc == SOCKET_ERROR) + { + int code = ::WSAGetLastError(); + + if(code == WSAEWOULDBLOCK) + break; + else + { + FireClose(this, SO_SEND, code); + return FALSE; + } + } + else + ASSERT(FALSE); + } + + return TRUE; +} + +BOOL CTcpClient::Stop() +{ + BOOL bNeedFireClose = FALSE; + EnServiceState enCurState = m_enState; + DWORD dwCurrentThreadID = ::GetCurrentThreadId(); + + if(!CheckStoping()) + return FALSE; + + if(enCurState == SS_STARTED && dwCurrentThreadID != m_dwWorkerID) + bNeedFireClose = TRUE; + + WaitForWorkerThreadEnd(dwCurrentThreadID); + + if(bNeedFireClose) + FireClose(this, SO_CLOSE, SE_OK); + + if(m_evSocket != nullptr) + { + ::WSACloseEvent(m_evSocket); + m_evSocket = nullptr; + } + + if(m_soClient != INVALID_SOCKET) + { + shutdown(m_soClient, SD_SEND); + closesocket(m_soClient); + m_soClient = INVALID_SOCKET; + } + + Reset(); + + return TRUE; +} + +void CTcpClient::Reset(BOOL bAll) +{ + if(bAll) + { + m_rcBuffer.Free(); + m_evBuffer.Reset(); + m_evWorker.Reset(); + m_lsSend.Clear(); + m_itPool.Clear(); + } + + m_iPending = 0; + m_enState = SS_STOPPED; +} + +void CTcpClient::WaitForWorkerThreadEnd(DWORD dwCurrentThreadID) +{ + if(m_hWorker != nullptr) + { + if(dwCurrentThreadID != m_dwWorkerID) + { + m_evWorker.Set(); + VERIFY(::WaitForSingleObject(m_hWorker, INFINITE) == WAIT_OBJECT_0); + } + + ::CloseHandle(m_hWorker); + + m_hWorker = nullptr; + m_dwWorkerID = 0; + } +} + +BOOL CTcpClient::Send(const BYTE* pBuffer, int iLength, int iOffset) +{ + ASSERT(pBuffer && iLength > 0); + + if(iOffset != 0) pBuffer += iOffset; + + WSABUF buffer; + buffer.len = iLength; + buffer.buf = (char*)pBuffer; + + return SendPackets(&buffer, 1); +} + +BOOL CTcpClient::SendPackets(const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + EnSocketError enCode = SE_OK; + + ASSERT(pBuffers && iCount > 0); + + if(pBuffers && iCount > 0) + { + if(HasStarted()) + { + CCriSecLock locallock(m_csSend); + + if(HasStarted()) + result = SendInternal(pBuffers, iCount, enCode); + else + { + result = ERROR_INVALID_STATE; + enCode = SE_ILLEGAL_STATE; + } + } + else + { + result = ERROR_INVALID_STATE; + enCode = SE_ILLEGAL_STATE; + } + } + else + { + result = ERROR_INVALID_PARAMETER; + enCode = SE_INVALID_PARAM; + } + + if(result != NO_ERROR) + ::SetLastError(result); + + return (result == NO_ERROR); +} + +BOOL CTcpClient::SendInternal(const WSABUF pBuffers[], int iCount, EnSocketError& enCode) +{ + int result = NO_ERROR; + + ASSERT(m_iPending >= 0); + + int iPending = m_iPending; + BOOL isPending = m_iPending > 0; + + for(int i = 0; i < iCount; i++) + { + int iBufLen = pBuffers[i].len; + + if(iBufLen > 0) + { + BYTE* pBuffer = (BYTE*)pBuffers[i].buf; + ASSERT(pBuffer); + + m_lsSend.Cat(pBuffer, iBufLen); + m_iPending += iBufLen; + } + } + + if(!isPending && m_iPending > iPending) m_evBuffer.Set(); + + return result; +} + +BOOL CTcpClient::SendSmallFile(LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail) +{ + ASSERT(lpszFileName != nullptr); + + CAtlFile file; + HRESULT hr = file.Create(lpszFileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); + + if(SUCCEEDED(hr)) + { + ULONGLONG ullLen; + hr = file.GetSize(ullLen); + + if(SUCCEEDED(hr)) + { + if(ullLen > 0 && ullLen <= MAX_SMALL_FILE_SIZE) + { + CAtlFileMapping<> fmap; + hr = fmap.MapFile(file); + + if(SUCCEEDED(hr)) + { + WSABUF bufs[3] = {0}; + + bufs[1].len = (ULONG)ullLen; + bufs[1].buf = fmap; + + if(pHead) memcpy(&bufs[0], pHead, sizeof(WSABUF)); + if(pTail) memcpy(&bufs[2], pTail, sizeof(WSABUF)); + + return SendPackets(bufs, 3); + } + } + else if(ullLen == 0) + hr = HRESULT_FROM_WIN32(ERROR_FILE_INVALID); + else + hr = HRESULT_FROM_WIN32(ERROR_FILE_TOO_LARGE); + } + } + + ::SetLastError(hr & 0x0000FFFF); + + return FALSE; +} + +void CTcpClient::SetLastError(EnSocketError code, LPCSTR func, int ec) +{ + TRACE("%s --> Error: %d, EC: %d\n", func, code, ec); + + m_enLastError = code; + ::SetLastError(ec); +} + +BOOL CTcpClient::GetLocalAddress(TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + return ::GetSocketLocalAddress(m_soClient, lpszAddress, iAddressLen, usPort); +} diff --git a/HP-Socket/Src/TcpClient.h b/HP-Socket/Src/TcpClient.h new file mode 100644 index 000000000..705754da0 --- /dev/null +++ b/HP-Socket/Src/TcpClient.h @@ -0,0 +1,175 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "SocketHelper.h" +#include "../../Common/Src/Event.h" +#include "../../Common/Src/bufferptr.h" +#include "../../Common/Src/bufferpool.h" +#include "../../Common/Src/CriticalSection.h" + +class CTcpClient : public ITcpClient +{ +public: + virtual BOOL Start (LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect = FALSE); + virtual BOOL Stop (); + virtual BOOL Send (const BYTE* pBuffer, int iLength, int iOffset = 0); + virtual BOOL SendPackets (const WSABUF pBuffers[], int iCount); + virtual BOOL SendSmallFile (LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr); + virtual BOOL HasStarted () {return m_enState == SS_STARTED || m_enState == SS_STARTING;} + virtual EnServiceState GetState () {return m_enState;} + virtual CONNID GetConnectionID () {return m_dwConnID;}; + virtual BOOL GetLocalAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + virtual BOOL GetPendingDataLength (int& iPending) {iPending = m_iPending; return HasStarted();} + virtual EnSocketError GetLastError () {return m_enLastError;} + virtual LPCTSTR GetLastErrorDesc () {return ::GetSocketErrorDesc(m_enLastError);} + +public: + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) {m_dwSocketBufferSize = dwSocketBufferSize;} + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) {m_dwKeepAliveTime = dwKeepAliveTime;} + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) {m_dwKeepAliveInterval = dwKeepAliveInterval;} + virtual void SetFreeBufferPoolSize (DWORD dwFreeBufferPoolSize) {m_dwFreeBufferPoolSize = dwFreeBufferPoolSize;} + virtual void SetFreeBufferPoolHold (DWORD dwFreeBufferPoolHold) {m_dwFreeBufferPoolHold = dwFreeBufferPoolHold;} + virtual void SetExtra (PVOID pExtra) {m_pExtra = pExtra;} + + virtual DWORD GetSocketBufferSize () {return m_dwSocketBufferSize;} + virtual DWORD GetKeepAliveTime () {return m_dwKeepAliveTime;} + virtual DWORD GetKeepAliveInterval () {return m_dwKeepAliveInterval;} + virtual DWORD GetFreeBufferPoolSize () {return m_dwFreeBufferPoolSize;} + virtual DWORD GetFreeBufferPoolHold () {return m_dwFreeBufferPoolHold;} + virtual PVOID GetExtra () {return m_pExtra;} + +protected: + virtual EnHandleResult FirePrepareConnect(IClient* pClient, SOCKET socket) + {return m_psoListener->OnPrepareConnect(pClient, socket);} + virtual EnHandleResult FireConnect(IClient* pClient) + {return m_psoListener->OnConnect(pClient);} + virtual EnHandleResult FireSend(IClient* pClient, const BYTE* pData, int iLength) + {return m_psoListener->OnSend(pClient, pData, iLength);} + virtual EnHandleResult FireReceive(IClient* pClient, const BYTE* pData, int iLength) + {return m_psoListener->OnReceive(pClient, pData, iLength);} + virtual EnHandleResult FireReceive(IClient* pClient, int iLength) + {return m_psoListener->OnReceive(pClient, iLength);} + virtual EnHandleResult FireClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) + {return m_psoListener->OnClose(pClient, enOperation, iErrorCode);} + + void SetLastError(EnSocketError code, LPCSTR func, int ec); + virtual BOOL CheckParams(); + virtual void PrepareStart(); + virtual void Reset(BOOL bAll = TRUE); + +protected: + void SetReserved (PVOID pReserved) {m_pReserved = pReserved;} + PVOID GetReserved () {return m_pReserved;} + +private: + BOOL CheckStarting(); + BOOL CheckStoping(); + BOOL CreateClientSocket(); + BOOL ConnectToServer(LPCTSTR pszRemoteAddress, USHORT usPort); + BOOL CreateWorkerThread(); + BOOL ProcessNetworkEvent(); + BOOL ReadData(); + BOOL SendData(); + BOOL DoSendData(TItem* pItem); + TItem* GetSendBuffer(); + BOOL SendInternal(const WSABUF pBuffers[], int iCount, EnSocketError& enCode); + void WaitForWorkerThreadEnd(DWORD dwCurrentThreadID); + + BOOL HandleError (WSANETWORKEVENTS& events); + BOOL HandleRead (WSANETWORKEVENTS& events); + BOOL HandleWrite (WSANETWORKEVENTS& events); + BOOL HandleConnect (WSANETWORKEVENTS& events); + BOOL HandleClose (WSANETWORKEVENTS& events); + + static UINT WINAPI WorkerThreadProc(LPVOID pv); + +public: + CTcpClient(ITcpClientListener* psoListener) + : m_psoListener (psoListener) + , m_lsSend (m_itPool) + , m_soClient (INVALID_SOCKET) + , m_evSocket (nullptr) + , m_dwConnID (0) + , m_hWorker (nullptr) + , m_dwWorkerID (0) + , m_bAsyncConnect (FALSE) + , m_iPending (0) + , m_enState (SS_STOPPED) + , m_enLastError (SE_OK) + , m_pExtra (nullptr) + , m_pReserved (nullptr) + , m_dwSocketBufferSize (DEFAULT_TCP_SOCKET_BUFFER_SIZE) + , m_dwFreeBufferPoolSize(DEFAULT_CLIENT_FREE_BUFFER_POOL_SIZE) + , m_dwFreeBufferPoolHold(DEFAULT_CLIENT_FREE_BUFFER_POOL_HOLD) + , m_dwKeepAliveTime (DEFALUT_TCP_KEEPALIVE_TIME) + , m_dwKeepAliveInterval (DEFALUT_TCP_KEEPALIVE_INTERVAL) + { + ASSERT(m_psoListener); + } + + virtual ~CTcpClient() {if(HasStarted()) Stop();} + +private: + CInitSocket m_wsSocket; + +private: + ITcpClientListener* m_psoListener; + BOOL m_bAsyncConnect; + SOCKET m_soClient; + HANDLE m_evSocket; + CONNID m_dwConnID; + + DWORD m_dwSocketBufferSize; + DWORD m_dwFreeBufferPoolSize; + DWORD m_dwFreeBufferPoolHold; + DWORD m_dwKeepAliveTime; + DWORD m_dwKeepAliveInterval; + + HANDLE m_hWorker; + UINT m_dwWorkerID; + + EnServiceState m_enState; + EnSocketError m_enLastError; + + PVOID m_pExtra; + PVOID m_pReserved; + + CBufferPtr m_rcBuffer; + +protected: + CItemPool m_itPool; + + CSpinGuard m_csState; + +private: + CCriSec m_csSend; + TItemList m_lsSend; + + CEvt m_evBuffer; + CEvt m_evWorker; + + volatile int m_iPending; +}; diff --git a/HP-Socket/Src/TcpPackAgent.cpp b/HP-Socket/Src/TcpPackAgent.cpp new file mode 100644 index 000000000..dc6d101f8 --- /dev/null +++ b/HP-Socket/Src/TcpPackAgent.cpp @@ -0,0 +1,111 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "TcpPackAgent.h" +#include "MiscHelper.h" + +BOOL CTcpPackAgent::CheckParams() +{ + if(m_dwMaxPackSize > 0 && m_dwMaxPackSize <= TCP_PACK_MAX_SIZE_LIMIT) + if(m_usHeaderFlag >= 0 && m_usHeaderFlag <= TCP_PACK_HEADER_FLAG_LIMIT) + return __super::CheckParams(); + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CTcpPackAgent::PrepareStart() +{ + __super::PrepareStart(); + + m_bfPool.SetItemCapacity (GetSocketBufferSize()); + m_bfPool.SetItemPoolSize (GetFreeBufferObjPool()); + m_bfPool.SetItemPoolHold (GetFreeBufferObjHold()); + m_bfPool.SetBufferLockTime (GetFreeSocketObjLockTime()); + m_bfPool.SetBufferPoolSize (GetFreeSocketObjPool()); + m_bfPool.SetBufferPoolHold (GetFreeSocketObjHold()); + + m_bfPool.Prepare(); +} + +BOOL CTcpPackAgent::SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount) +{ + int iNewCount = iCount + 1; + unique_ptr buffers(new WSABUF[iNewCount]); + + DWORD header; + if(!::AddPackHeader(pBuffers, iCount, buffers, m_dwMaxPackSize, m_usHeaderFlag, header)) + return FALSE; + + return __super::SendPackets(dwConnID, buffers.get(), iNewCount); +} + +EnHandleResult CTcpPackAgent::FireConnect(TSocketObj* pSocketObj) +{ + EnHandleResult result = __super::FireConnect(pSocketObj); + + if(result != HR_ERROR) + { + TBuffer* pBuffer = m_bfPool.PickFreeBuffer(pSocketObj->connID); + VERIFY(SetConnectionReserved(pSocketObj, TBufferPackInfo::Construct(pBuffer))); + } + + return result; +} + +EnHandleResult CTcpPackAgent::FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) +{ + TBufferPackInfo* pInfo = nullptr; + GetConnectionReserved(pSocketObj, (PVOID*)&pInfo); + ASSERT(pInfo); + + TBuffer* pBuffer = (TBuffer*)pInfo->pBuffer; + ASSERT(pBuffer && pBuffer->IsValid()); + + return ParsePack(this, pInfo, pBuffer, pSocketObj, m_dwMaxPackSize, m_usHeaderFlag, pData, iLength); +} + +EnHandleResult CTcpPackAgent::FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + EnHandleResult result = __super::FireClose(pSocketObj, enOperation, iErrorCode); + + TBufferPackInfo* pInfo = nullptr; + GetConnectionReserved(pSocketObj, (PVOID*)&pInfo); + ASSERT(pInfo); + + m_bfPool.PutFreeBuffer(pInfo->pBuffer); + TBufferPackInfo::Destruct(pInfo); + + return result; +} + +EnHandleResult CTcpPackAgent::FireShutdown() +{ + EnHandleResult result = __super::FireShutdown(); + + m_bfPool.Clear(); + + return HR_OK; +} diff --git a/HP-Socket/Src/TcpPackAgent.h b/HP-Socket/Src/TcpPackAgent.h new file mode 100644 index 000000000..683495cc0 --- /dev/null +++ b/HP-Socket/Src/TcpPackAgent.h @@ -0,0 +1,77 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "TcpAgent.h" +#include "MiscHelper.h" +#include "../../Common/Src/bufferpool.h" + +class CTcpPackAgent : public IPackSocket, public CTcpAgent +{ +public: + virtual BOOL SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount); + +protected: + virtual EnHandleResult FireConnect(TSocketObj* pSocketObj); + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength); + virtual EnHandleResult FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult FireShutdown(); + + virtual BOOL CheckParams(); + virtual void PrepareStart(); + +public: + virtual void SetMaxPackSize (DWORD dwMaxPackSize) {m_dwMaxPackSize = dwMaxPackSize;} + virtual void SetPackHeaderFlag (USHORT usPackHeaderFlag) {m_usHeaderFlag = usPackHeaderFlag;} + virtual DWORD GetMaxPackSize () {return m_dwMaxPackSize;} + virtual USHORT GetPackHeaderFlag() {return m_usHeaderFlag;} + +private: + EnHandleResult FireSuperReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return __super::FireReceive(pSocketObj, pData, iLength);} + + friend EnHandleResult ParsePack<> (CTcpPackAgent* pThis, TBufferPackInfo* pInfo, TBuffer* pBuffer, TSocketObj* pSocket, + DWORD dwMaxPackSize, USHORT usPackHeaderFlag, const BYTE* pData, int iLength); + +public: + CTcpPackAgent(ITcpAgentListener* psoListener) : CTcpAgent(psoListener) + , m_dwMaxPackSize (TCP_PACK_DEFAULT_MAX_SIZE) + , m_usHeaderFlag (TCP_PACK_DEFAULT_HEADER_FLAG) + { + + } + + virtual ~CTcpPackAgent() + { + if(HasStarted()) + Stop(); + } + +private: + DWORD m_dwMaxPackSize; + USHORT m_usHeaderFlag; + + CBufferPool m_bfPool; +}; diff --git a/HP-Socket/Src/TcpPackClient.cpp b/HP-Socket/Src/TcpPackClient.cpp new file mode 100644 index 000000000..61d8af84d --- /dev/null +++ b/HP-Socket/Src/TcpPackClient.cpp @@ -0,0 +1,61 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "TcpPackClient.h" + +BOOL CTcpPackClient::CheckParams() +{ + if(m_dwMaxPackSize > 0 && m_dwMaxPackSize <= TCP_PACK_MAX_SIZE_LIMIT) + if(m_usHeaderFlag >= 0 && m_usHeaderFlag <= TCP_PACK_HEADER_FLAG_LIMIT) + return __super::CheckParams(); + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +BOOL CTcpPackClient::SendPackets(const WSABUF pBuffers[], int iCount) +{ + int iNewCount = iCount + 1; + unique_ptr buffers(new WSABUF[iNewCount]); + + DWORD header; + if(!::AddPackHeader(pBuffers, iCount, buffers, m_dwMaxPackSize, m_usHeaderFlag, header)) + return FALSE; + + return __super::SendPackets(buffers.get(), iNewCount); +} + +EnHandleResult CTcpPackClient::FireReceive(IClient* pClient, const BYTE* pData, int iLength) +{ + return ParsePack(this, &m_pkInfo, &m_lsBuffer, pClient, m_dwMaxPackSize, m_usHeaderFlag, pData, iLength); +} + +void CTcpPackClient::Reset(BOOL bAll) +{ + m_lsBuffer.Clear(); + m_pkInfo.Reset(); + + return __super::Reset(bAll); +} diff --git a/HP-Socket/Src/TcpPackClient.h b/HP-Socket/Src/TcpPackClient.h new file mode 100644 index 000000000..a746f516a --- /dev/null +++ b/HP-Socket/Src/TcpPackClient.h @@ -0,0 +1,72 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "TcpClient.h" +#include "MiscHelper.h" + +class CTcpPackClient : public IPackClient, public CTcpClient +{ +public: + virtual BOOL SendPackets(const WSABUF pBuffers[], int iCount); + +protected: + virtual EnHandleResult FireReceive(IClient* pClient, const BYTE* pData, int iLength); + + virtual BOOL CheckParams(); + virtual void Reset(BOOL bAll = TRUE); + +public: + virtual void SetMaxPackSize (DWORD dwMaxPackSize) {m_dwMaxPackSize = dwMaxPackSize;} + virtual void SetPackHeaderFlag (USHORT usPackHeaderFlag) {m_usHeaderFlag = usPackHeaderFlag;} + virtual DWORD GetMaxPackSize () {return m_dwMaxPackSize;} + virtual USHORT GetPackHeaderFlag() {return m_usHeaderFlag;} + +private: + EnHandleResult FireSuperReceive(IClient* pClient, const BYTE* pData, int iLength) + {return __super::FireReceive(pClient, pData, iLength);} + + friend EnHandleResult ParsePack<> (CTcpPackClient* pThis, TPackInfo* pInfo, TItemListEx* pBuffer, IClient* pSocket, + DWORD dwMaxPackSize, USHORT usPackHeaderFlag, const BYTE* pData, int iLength); + +public: + CTcpPackClient(ITcpClientListener* psoListener) : CTcpClient(psoListener) + , m_dwMaxPackSize (TCP_PACK_DEFAULT_MAX_SIZE) + , m_usHeaderFlag (TCP_PACK_DEFAULT_HEADER_FLAG) + , m_pkInfo (nullptr) + , m_lsBuffer (m_itPool) + { + + } + + virtual ~CTcpPackClient() {if(HasStarted()) Stop();} + +private: + DWORD m_dwMaxPackSize; + USHORT m_usHeaderFlag; + + TPackInfo m_pkInfo; + TItemListEx m_lsBuffer; +}; diff --git a/HP-Socket/Src/TcpPackServer.cpp b/HP-Socket/Src/TcpPackServer.cpp new file mode 100644 index 000000000..2c47a19af --- /dev/null +++ b/HP-Socket/Src/TcpPackServer.cpp @@ -0,0 +1,111 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "TcpPackServer.h" +#include "MiscHelper.h" + +BOOL CTcpPackServer::CheckParams() +{ + if(m_dwMaxPackSize > 0 && m_dwMaxPackSize <= TCP_PACK_MAX_SIZE_LIMIT) + if(m_usHeaderFlag >= 0 && m_usHeaderFlag <= TCP_PACK_HEADER_FLAG_LIMIT) + return __super::CheckParams(); + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CTcpPackServer::PrepareStart() +{ + __super::PrepareStart(); + + m_bfPool.SetItemCapacity (GetSocketBufferSize()); + m_bfPool.SetItemPoolSize (GetFreeBufferObjPool()); + m_bfPool.SetItemPoolHold (GetFreeBufferObjHold()); + m_bfPool.SetBufferLockTime (GetFreeSocketObjLockTime()); + m_bfPool.SetBufferPoolSize (GetFreeSocketObjPool()); + m_bfPool.SetBufferPoolHold (GetFreeSocketObjHold()); + + m_bfPool.Prepare(); +} + +BOOL CTcpPackServer::SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount) +{ + int iNewCount = iCount + 1; + unique_ptr buffers(new WSABUF[iNewCount]); + + DWORD header; + if(!::AddPackHeader(pBuffers, iCount, buffers, m_dwMaxPackSize, m_usHeaderFlag, header)) + return FALSE; + + return __super::SendPackets(dwConnID, buffers.get(), iNewCount); +} + +EnHandleResult CTcpPackServer::FireAccept(TSocketObj* pSocketObj) +{ + EnHandleResult result = __super::FireAccept(pSocketObj); + + if(result != HR_ERROR) + { + TBuffer* pBuffer = m_bfPool.PickFreeBuffer(pSocketObj->connID); + VERIFY(SetConnectionReserved(pSocketObj, TBufferPackInfo::Construct(pBuffer))); + } + + return result; +} + +EnHandleResult CTcpPackServer::FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) +{ + TBufferPackInfo* pInfo = nullptr; + GetConnectionReserved(pSocketObj, (PVOID*)&pInfo); + ASSERT(pInfo); + + TBuffer* pBuffer = (TBuffer*)pInfo->pBuffer; + ASSERT(pBuffer && pBuffer->IsValid()); + + return ParsePack(this, pInfo, pBuffer, pSocketObj, m_dwMaxPackSize, m_usHeaderFlag, pData, iLength); +} + +EnHandleResult CTcpPackServer::FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + EnHandleResult result = __super::FireClose(pSocketObj, enOperation, iErrorCode); + + TBufferPackInfo* pInfo = nullptr; + GetConnectionReserved(pSocketObj, (PVOID*)&pInfo); + ASSERT(pInfo); + + m_bfPool.PutFreeBuffer(pInfo->pBuffer); + TBufferPackInfo::Destruct(pInfo); + + return result; +} + +EnHandleResult CTcpPackServer::FireShutdown() +{ + EnHandleResult result = __super::FireShutdown(); + + m_bfPool.Clear(); + + return HR_OK; +} diff --git a/HP-Socket/Src/TcpPackServer.h b/HP-Socket/Src/TcpPackServer.h new file mode 100644 index 000000000..24351621c --- /dev/null +++ b/HP-Socket/Src/TcpPackServer.h @@ -0,0 +1,77 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "TcpServer.h" +#include "MiscHelper.h" +#include "../../Common/Src/bufferpool.h" + +class CTcpPackServer : public IPackSocket, public CTcpServer +{ +public: + virtual BOOL SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount); + +protected: + virtual EnHandleResult FireAccept(TSocketObj* pSocketObj); + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength); + virtual EnHandleResult FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult FireShutdown(); + + virtual BOOL CheckParams(); + virtual void PrepareStart(); + +public: + virtual void SetMaxPackSize (DWORD dwMaxPackSize) {m_dwMaxPackSize = dwMaxPackSize;} + virtual void SetPackHeaderFlag (USHORT usPackHeaderFlag) {m_usHeaderFlag = usPackHeaderFlag;} + virtual DWORD GetMaxPackSize () {return m_dwMaxPackSize;} + virtual USHORT GetPackHeaderFlag() {return m_usHeaderFlag;} + +private: + EnHandleResult FireSuperReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return __super::FireReceive(pSocketObj, pData, iLength);} + + friend EnHandleResult ParsePack<> (CTcpPackServer* pThis, TBufferPackInfo* pInfo, TBuffer* pBuffer, TSocketObj* pSocket, + DWORD dwMaxPackSize, USHORT usPackHeaderFlag, const BYTE* pData, int iLength); + +public: + CTcpPackServer(ITcpServerListener* psoListener) : CTcpServer(psoListener) + , m_dwMaxPackSize (TCP_PACK_DEFAULT_MAX_SIZE) + , m_usHeaderFlag (TCP_PACK_DEFAULT_HEADER_FLAG) + { + + } + + virtual ~CTcpPackServer() + { + if(HasStarted()) + Stop(); + } + +private: + DWORD m_dwMaxPackSize; + USHORT m_usHeaderFlag; + + CBufferPool m_bfPool; +}; diff --git a/HP-Socket/Src/TcpPullAgent.cpp b/HP-Socket/Src/TcpPullAgent.cpp new file mode 100644 index 000000000..f39315049 --- /dev/null +++ b/HP-Socket/Src/TcpPullAgent.cpp @@ -0,0 +1,81 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "TcpPullAgent.h" +#include "MiscHelper.h" + +EnHandleResult CTcpPullAgent::FireConnect(TSocketObj* pSocketObj) +{ + EnHandleResult result = __super::FireConnect(pSocketObj); + + if(result != HR_ERROR) + { + TBuffer* pBuffer = m_bfPool.PutCacheBuffer(pSocketObj->connID); + VERIFY(SetConnectionReserved(pSocketObj, pBuffer)); + } + + return result; +} + +EnHandleResult CTcpPullAgent::FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) +{ + TBuffer* pBuffer = nullptr; + GetConnectionReserved(pSocketObj, (PVOID*)&pBuffer); + ASSERT(pBuffer && pBuffer->IsValid()); + + pBuffer->Cat(pData, iLength); + + return __super::FireReceive(pSocketObj, pBuffer->Length()); +} + +EnHandleResult CTcpPullAgent::FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + EnHandleResult result = __super::FireClose(pSocketObj, enOperation, iErrorCode); + + m_bfPool.PutFreeBuffer(pSocketObj->connID); + + return result; +} + +EnHandleResult CTcpPullAgent::FireShutdown() +{ + EnHandleResult result = __super::FireShutdown(); + + m_bfPool.Clear(); + + return result; +} + +EnFetchResult CTcpPullAgent::Fetch(CONNID dwConnID, BYTE* pData, int iLength) +{ + TBuffer* pBuffer = m_bfPool[dwConnID]; + return ::FetchBuffer(pBuffer, pData, iLength); +} + +EnFetchResult CTcpPullAgent::Peek(CONNID dwConnID, BYTE* pData, int iLength) +{ + TBuffer* pBuffer = m_bfPool[dwConnID]; + return ::PeekBuffer(pBuffer, pData, iLength); +} diff --git a/HP-Socket/Src/TcpPullAgent.h b/HP-Socket/Src/TcpPullAgent.h new file mode 100644 index 000000000..cacee4a3f --- /dev/null +++ b/HP-Socket/Src/TcpPullAgent.h @@ -0,0 +1,70 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "TcpAgent.h" +#include "../../Common/Src/bufferpool.h" + +class CTcpPullAgent : public IPullSocket, public CTcpAgent +{ +public: + virtual EnFetchResult Fetch (CONNID dwConnID, BYTE* pData, int iLength); + virtual EnFetchResult Peek (CONNID dwConnID, BYTE* pData, int iLength); + +protected: + virtual EnHandleResult FireConnect(TSocketObj* pSocketObj); + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength); + virtual EnHandleResult FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult FireShutdown(); + + virtual void PrepareStart() + { + __super::PrepareStart(); + + m_bfPool.SetItemCapacity (GetSocketBufferSize()); + m_bfPool.SetItemPoolSize (GetFreeBufferObjPool()); + m_bfPool.SetItemPoolHold (GetFreeBufferObjHold()); + m_bfPool.SetBufferLockTime (GetFreeSocketObjLockTime()); + m_bfPool.SetBufferPoolSize (GetFreeSocketObjPool()); + m_bfPool.SetBufferPoolHold (GetFreeSocketObjHold()); + + m_bfPool.Prepare(); + } + +public: + CTcpPullAgent(ITcpAgentListener* psoListener) : CTcpAgent(psoListener) + { + + } + + virtual ~CTcpPullAgent() + { + if(HasStarted()) + Stop(); + } + +private: + CBufferPool m_bfPool; +}; diff --git a/HP-Socket/Src/TcpPullClient.cpp b/HP-Socket/Src/TcpPullClient.cpp new file mode 100644 index 000000000..12c0c6664 --- /dev/null +++ b/HP-Socket/Src/TcpPullClient.cpp @@ -0,0 +1,51 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "TcpPullClient.h" +#include "MiscHelper.h" + +EnHandleResult CTcpPullClient::FireReceive(IClient* pClient, const BYTE* pData, int iLength) +{ + m_lsBuffer.Cat(pData, iLength); + + return __super::FireReceive(pClient, m_lsBuffer.Length()); +} + +EnFetchResult CTcpPullClient::Fetch(BYTE* pData, int iLength) +{ + return ::FetchBuffer(&m_lsBuffer, pData, iLength); +} + +EnFetchResult CTcpPullClient::Peek(BYTE* pData, int iLength) +{ + return ::PeekBuffer(&m_lsBuffer, pData, iLength); +} + +void CTcpPullClient::Reset(BOOL bAll) +{ + m_lsBuffer.Clear(); + + return __super::Reset(bAll); +} diff --git a/HP-Socket/Src/TcpPullClient.h b/HP-Socket/Src/TcpPullClient.h new file mode 100644 index 000000000..51d60002a --- /dev/null +++ b/HP-Socket/Src/TcpPullClient.h @@ -0,0 +1,52 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "TcpClient.h" +#include "../../Common/Src/bufferpool.h" + +class CTcpPullClient : public IPullClient, public CTcpClient +{ +public: + virtual EnFetchResult Fetch (BYTE* pData, int iLength); + virtual EnFetchResult Peek (BYTE* pData, int iLength); + +protected: + virtual EnHandleResult FireReceive(IClient* pClient, const BYTE* pData, int iLength); + + virtual void Reset(BOOL bAll = TRUE); + +public: + CTcpPullClient(ITcpClientListener* psoListener) : CTcpClient(psoListener) + , m_lsBuffer(m_itPool) + { + + } + + virtual ~CTcpPullClient() {if(HasStarted()) Stop();} + +private: + TItemListEx m_lsBuffer; +}; diff --git a/HP-Socket/Src/TcpPullServer.cpp b/HP-Socket/Src/TcpPullServer.cpp new file mode 100644 index 000000000..3d16bcdb2 --- /dev/null +++ b/HP-Socket/Src/TcpPullServer.cpp @@ -0,0 +1,81 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "TcpPullServer.h" +#include "MiscHelper.h" + +EnHandleResult CTcpPullServer::FireAccept(TSocketObj* pSocketObj) +{ + EnHandleResult result = __super::FireAccept(pSocketObj); + + if(result != HR_ERROR) + { + TBuffer* pBuffer = m_bfPool.PutCacheBuffer(pSocketObj->connID); + VERIFY(SetConnectionReserved(pSocketObj, pBuffer)); + } + + return result; +} + +EnHandleResult CTcpPullServer::FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) +{ + TBuffer* pBuffer = nullptr; + GetConnectionReserved(pSocketObj, (PVOID*)&pBuffer); + ASSERT(pBuffer && pBuffer->IsValid()); + + pBuffer->Cat(pData, iLength); + + return __super::FireReceive(pSocketObj, pBuffer->Length()); +} + +EnHandleResult CTcpPullServer::FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + EnHandleResult result = __super::FireClose(pSocketObj, enOperation, iErrorCode); + + m_bfPool.PutFreeBuffer(pSocketObj->connID); + + return result; +} + +EnHandleResult CTcpPullServer::FireShutdown() +{ + EnHandleResult result = __super::FireShutdown(); + + m_bfPool.Clear(); + + return result; +} + +EnFetchResult CTcpPullServer::Fetch(CONNID dwConnID, BYTE* pData, int iLength) +{ + TBuffer* pBuffer = m_bfPool[dwConnID]; + return ::FetchBuffer(pBuffer, pData, iLength); +} + +EnFetchResult CTcpPullServer::Peek(CONNID dwConnID, BYTE* pData, int iLength) +{ + TBuffer* pBuffer = m_bfPool[dwConnID]; + return ::PeekBuffer(pBuffer, pData, iLength); +} diff --git a/HP-Socket/Src/TcpPullServer.h b/HP-Socket/Src/TcpPullServer.h new file mode 100644 index 000000000..427a4a73f --- /dev/null +++ b/HP-Socket/Src/TcpPullServer.h @@ -0,0 +1,70 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "TcpServer.h" +#include "../../Common/Src/bufferpool.h" + +class CTcpPullServer : public IPullSocket, public CTcpServer +{ +public: + virtual EnFetchResult Fetch (CONNID dwConnID, BYTE* pData, int iLength); + virtual EnFetchResult Peek (CONNID dwConnID, BYTE* pData, int iLength); + +protected: + virtual EnHandleResult FireAccept(TSocketObj* pSocketObj); + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength); + virtual EnHandleResult FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + virtual EnHandleResult FireShutdown(); + + virtual void PrepareStart() + { + __super::PrepareStart(); + + m_bfPool.SetItemCapacity (GetSocketBufferSize()); + m_bfPool.SetItemPoolSize (GetFreeBufferObjPool()); + m_bfPool.SetItemPoolHold (GetFreeBufferObjHold()); + m_bfPool.SetBufferLockTime (GetFreeSocketObjLockTime()); + m_bfPool.SetBufferPoolSize (GetFreeSocketObjPool()); + m_bfPool.SetBufferPoolHold (GetFreeSocketObjHold()); + + m_bfPool.Prepare(); + } + +public: + CTcpPullServer(ITcpServerListener* psoListener) : CTcpServer(psoListener) + { + + } + + virtual ~CTcpPullServer() + { + if(HasStarted()) + Stop(); + } + +private: + CBufferPool m_bfPool; +}; diff --git a/HP-Socket/Src/TcpServer.cpp b/HP-Socket/Src/TcpServer.cpp new file mode 100644 index 000000000..1bf3c39ba --- /dev/null +++ b/HP-Socket/Src/TcpServer.cpp @@ -0,0 +1,1384 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include +#include "TcpServer.h" +#include "../../Common/Src/WaitFor.h" + +#include +#include + +EnHandleResult CTcpServer::TriggerFireAccept(TSocketObj* pSocketObj) +{ + CReentrantSpinLock locallock(pSocketObj->csRecv); + return FireAccept(pSocketObj); +} + +EnHandleResult CTcpServer::TriggerFireReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + EnHandleResult rs = (EnHandleResult)HR_CLOSED; + + if(TSocketObj::IsValid(pSocketObj)) + { + CReentrantSpinLock locallock(pSocketObj->csRecv); + + if(TSocketObj::IsValid(pSocketObj)) + { + rs = FireReceive(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len); + } + } + + return rs; +} + +EnHandleResult CTcpServer::TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + EnHandleResult rs = FireSend(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len); + + if(rs == HR_ERROR) + { + TRACE(" OnSend() event should not return 'HR_ERROR' !!\n", pSocketObj->connID); + ASSERT(FALSE); + } + + AddFreeBufferObj(pBufferObj); + + return rs; +} + +EnHandleResult CTcpServer::TriggerFireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + CReentrantSpinLock locallock(pSocketObj->csRecv); + return FireClose(pSocketObj, enOperation, iErrorCode); +} + +void CTcpServer::SetLastError(EnSocketError code, LPCSTR func, int ec) +{ + m_enLastError = code; + + TRACE("%s --> Error: %d, EC: %d\n", func, code, ec); +} + +BOOL CTcpServer::Start(LPCTSTR pszBindAddress, USHORT usPort) +{ + if(!CheckParams() || !CheckStarting()) + return FALSE; + + PrepareStart(); + + if(CreateListenSocket(pszBindAddress, usPort)) + if(CreateCompletePort()) + if(CreateWorkerThreads()) + if(StartAccept()) + { + m_enState = SS_STARTED; + return TRUE; + } + + Stop(); + + return FALSE; +} + +BOOL CTcpServer::CheckParams() +{ + if(m_enSendPolicy >= SP_PACK && m_enSendPolicy <= SP_DIRECT) + if((int)m_dwWorkerThreadCount > 0 && m_dwWorkerThreadCount <= MAX_WORKER_THREAD_COUNT) + if((int)m_dwAcceptSocketCount > 0) + if((int)m_dwSocketBufferSize >= MIN_SOCKET_BUFFER_SIZE) + if((int)m_dwSocketListenQueue > 0) + if((int)m_dwFreeSocketObjLockTime >= 0) + if((int)m_dwFreeSocketObjPool >= 0) + if((int)m_dwFreeBufferObjPool >= 0) + if((int)m_dwFreeSocketObjHold >= m_dwFreeSocketObjPool) + if((int)m_dwFreeBufferObjHold >= m_dwFreeBufferObjPool) + if((int)m_dwKeepAliveTime >= 1000 || m_dwKeepAliveTime == 0) + if((int)m_dwKeepAliveInterval >= 1000 || m_dwKeepAliveInterval == 0) + return TRUE; + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CTcpServer::PrepareStart() +{ + m_lsFreeSocket.Reset(m_dwFreeSocketObjHold); + m_lsFreeBuffer.Reset(m_dwFreeBufferObjHold); + + m_itPool.SetItemCapacity((int)m_dwSocketBufferSize); + m_itPool.SetPoolSize((int)m_dwFreeBufferObjPool); + m_itPool.SetPoolHold((int)m_dwFreeBufferObjHold); + + m_itPool.Prepare(); +} + +BOOL CTcpServer::CheckStarting() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STOPPED) + m_enState = SS_STARTING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CTcpServer::CheckStoping() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STARTED || m_enState == SS_STARTING) + m_enState = SS_STOPPING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CTcpServer::CreateListenSocket(LPCTSTR pszBindAddress, USHORT usPort) +{ + BOOL isOK = FALSE; + + m_soListen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if(m_soListen != INVALID_SOCKET) + { + SOCKADDR_IN addr; + ::sockaddr_A_2_IN(AF_INET, pszBindAddress, usPort, addr); + + BOOL bOnOff = (m_dwKeepAliveTime > 0 && m_dwKeepAliveInterval > 0); + ::SSO_KeepAliveVals(m_soListen, bOnOff, m_dwKeepAliveTime, m_dwKeepAliveInterval); + + if(::bind(m_soListen, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)) != SOCKET_ERROR) + { + if(FirePrepareListen(m_soListen) != HR_ERROR) + { + if(::listen(m_soListen, m_dwSocketListenQueue) != SOCKET_ERROR) + { + m_pfnAcceptEx = ::Get_AcceptEx_FuncPtr(m_soListen); + m_pfnGetAcceptExSockaddrs = ::Get_GetAcceptExSockaddrs_FuncPtr(m_soListen); + m_pfnDisconnectEx = ::Get_DisconnectEx_FuncPtr(m_soListen); + + ASSERT(m_pfnAcceptEx); + ASSERT(m_pfnGetAcceptExSockaddrs); + ASSERT(m_pfnDisconnectEx); + + isOK = TRUE; + } + else + SetLastError(SE_SOCKET_LISTEN, __FUNCTION__, ::WSAGetLastError()); + } + else + SetLastError(SE_SOCKET_PREPARE, __FUNCTION__, ERROR_CANCELLED); + } + else + SetLastError(SE_SOCKET_BIND, __FUNCTION__, ::WSAGetLastError()); + } + else + SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError()); + + return isOK; +} + +BOOL CTcpServer::CreateCompletePort() +{ + m_hCompletePort = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 0); + if(m_hCompletePort == nullptr) + SetLastError(SE_CP_CREATE, __FUNCTION__, ::GetLastError()); + + return (m_hCompletePort != nullptr); +} + +BOOL CTcpServer::CreateWorkerThreads() +{ + BOOL isOK = TRUE; + + for(DWORD i = 0; i < m_dwWorkerThreadCount; i++) + { + HANDLE hThread = (HANDLE)_beginthreadex(nullptr, 0, WorkerThreadProc, (LPVOID)this, 0, nullptr); + if(hThread) + m_vtWorkerThreads.push_back(hThread); + else + { + SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ::GetLastError()); + isOK = FALSE; + break; + } + } + + return isOK; +} + +BOOL CTcpServer::StartAccept() +{ + BOOL isOK = TRUE; + + if(::CreateIoCompletionPort((HANDLE)m_soListen, m_hCompletePort, m_soListen, 0)) + { + m_iRemainAcceptSockets = m_dwAcceptSocketCount; + + for(DWORD i = 0; i < m_dwAcceptSocketCount; i++) + VERIFY(::PostIocpAccept(m_hCompletePort)); + } + else + { + SetLastError(SE_SOCKE_ATTACH_TO_CP, __FUNCTION__, ::GetLastError()); + isOK = FALSE; + } + + return isOK; +} + +BOOL CTcpServer::Stop() +{ + if(!CheckStoping()) + return FALSE; + + CloseListenSocket(); + + WaitForAcceptSocketClose(); + + DisconnectClientSocket(); + WaitForClientSocketClose(); + WaitForWorkerThreadEnd(); + + ReleaseClientSocket(); + + FireShutdown(); + + ReleaseFreeSocket(); + ReleaseFreeBuffer(); + + CloseCompletePort(); + + Reset(); + + return TRUE; +} + +void CTcpServer::Reset(BOOL bAll) +{ + if(bAll) + { + m_phSocket.Reset(); + m_phBuffer.Reset(); + m_itPool.Clear(); + } + + m_iRemainAcceptSockets = 0; + m_pfnAcceptEx = nullptr; + m_pfnGetAcceptExSockaddrs = nullptr; + m_pfnDisconnectEx = nullptr; + m_enState = SS_STOPPED; +} + +void CTcpServer::CloseListenSocket() +{ + if(m_soListen != INVALID_SOCKET) + { + ::ManualCloseSocket(m_soListen); + m_soListen = INVALID_SOCKET; + + ::WaitWithMessageLoop(150); + } +} + +void CTcpServer::DisconnectClientSocket() +{ + CReentrantReadLock locallock(m_csClientSocket); + + for(TSocketObjPtrMapI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + Disconnect(it->first); +} + +void CTcpServer::ReleaseClientSocket() +{ + CReentrantWriteLock locallock(m_csClientSocket); + + for(TSocketObjPtrMapI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + TSocketObj* pSocketObj = it->second; + + CloseClientSocketObj(pSocketObj); + DeleteSocketObj(pSocketObj); + } + + m_mpClientSocket.clear(); +} + +TSocketObj* CTcpServer::GetFreeSocketObj(CONNID dwConnID, SOCKET soClient) +{ + DWORD dwIndex; + TSocketObj* pSocketObj = nullptr; + + if(m_lsFreeSocket.TryLock(&pSocketObj, dwIndex)) + { + if(::GetTimeGap32(pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) + m_lsFreeSocket.ReleaseLock(nullptr, dwIndex); + else + { + m_lsFreeSocket.ReleaseLock(pSocketObj, dwIndex); + pSocketObj = nullptr; + } + } + + if(!pSocketObj) pSocketObj = CreateSocketObj(); + pSocketObj->Reset(dwConnID, soClient); + + return pSocketObj; +} + +void CTcpServer::AddFreeSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode) +{ + if(!InvalidSocketObj(pSocketObj)) + return; + + CloseClientSocketObj(pSocketObj, enFlag, enOperation, iErrorCode); + TSocketObj::Release(pSocketObj); + + { + CReentrantWriteLock locallock(m_csClientSocket); + m_mpClientSocket.erase(pSocketObj->connID); + } + + if(!m_lsFreeSocket.TryPut(pSocketObj)) + { + m_lsGCSocket.PushBack(pSocketObj); + + if(m_lsGCSocket.Size() > m_dwFreeSocketObjPool) + ReleaseGCSocketObj(); + } +} + +void CTcpServer::ReleaseGCSocketObj(BOOL bForce) +{ + TSocketObj* pSocketObj = nullptr; + DWORD now = ::TimeGetTime(); + + while(m_lsGCSocket.PopFront(&pSocketObj)) + { + if(bForce || (now - pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) + DeleteSocketObj(pSocketObj); + else + { + m_lsGCSocket.PushBack(pSocketObj); + break; + } + } +} + +BOOL CTcpServer::InvalidSocketObj(TSocketObj* pSocketObj) +{ + BOOL bDone = FALSE; + + if(TSocketObj::IsValid(pSocketObj)) + { + CReentrantSpinLock locallock(pSocketObj->csRecv); + CCriSecLock locallock2(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + { + TSocketObj::Invalid(pSocketObj); + bDone = TRUE; + } + } + + return bDone; +} + +void CTcpServer::AddClientSocketObj(CONNID dwConnID, TSocketObj* pSocketObj) +{ + ASSERT(FindSocketObj(dwConnID) == nullptr); + + pSocketObj->connTime = ::TimeGetTime(); + pSocketObj->activeTime = pSocketObj->connTime; + + CReentrantWriteLock locallock(m_csClientSocket); + m_mpClientSocket[dwConnID] = pSocketObj; +} + +void CTcpServer::ReleaseFreeSocket() +{ + TSocketObj* pSocketObj = nullptr; + + while(m_lsFreeSocket.TryGet(&pSocketObj)) + DeleteSocketObj(pSocketObj); + + VERIFY(m_lsFreeSocket.IsEmpty()); + m_lsFreeSocket.Reset(); + + ReleaseGCSocketObj(TRUE); + VERIFY(m_lsGCSocket.IsEmpty()); +} + +TSocketObj* CTcpServer::CreateSocketObj() +{ + TSocketObj* pSocketObj = (TSocketObj*)m_phSocket.Alloc(sizeof(TSocketObj)); + ASSERT(pSocketObj); + + pSocketObj->TSocketObj::TSocketObj(m_itPool); + + return pSocketObj; +} + +void CTcpServer::DeleteSocketObj(TSocketObj* pSocketObj) +{ + ASSERT(pSocketObj); + + pSocketObj->TSocketObj::~TSocketObj(); + m_phSocket.Free(pSocketObj); +} + +TBufferObj* CTcpServer::GetFreeBufferObj(int iLen) +{ + ASSERT(iLen >= 0 && iLen <= (int)m_dwSocketBufferSize); + + TBufferObj* pBufferObj = nullptr; + + if(!m_lsFreeBuffer.TryGet(&pBufferObj)) + pBufferObj = CreateBufferObj(); + + if(iLen <= 0) iLen = m_dwSocketBufferSize; + pBufferObj->buff.len = iLen; + + return pBufferObj; +} + +void CTcpServer::AddFreeBufferObj(TBufferObj* pBufferObj) +{ + if(!m_lsFreeBuffer.TryPut(pBufferObj)) + DeleteBufferObj(pBufferObj); +} + +void CTcpServer::ReleaseFreeBuffer() +{ + TBufferObj* pBufferObj = nullptr; + + while(m_lsFreeBuffer.TryGet(&pBufferObj)) + DeleteBufferObj(pBufferObj); + + VERIFY(m_lsFreeBuffer.IsEmpty()); + m_lsFreeBuffer.Reset(); +} + +TBufferObj* CTcpServer::CreateBufferObj() +{ + TBufferObj* pBufferObj = (TBufferObj*)m_phBuffer.Alloc(sizeof(TBufferObj) + m_dwSocketBufferSize); + ASSERT(pBufferObj); + + ::ZeroMemory(pBufferObj, sizeof(TBufferObj)); + pBufferObj->buff.buf = ((char*)pBufferObj) + sizeof(TBufferObj); + + return pBufferObj; +} + +void CTcpServer::DeleteBufferObj(TBufferObj* pBufferObj) +{ + ASSERT(pBufferObj); + m_phBuffer.Free(pBufferObj); +} + +TSocketObj* CTcpServer::FindSocketObj(CONNID dwConnID) +{ + TSocketObj* pSocketObj = nullptr; + + { + CReentrantReadLock locallock(m_csClientSocket); + + TSocketObjPtrMapCI it = m_mpClientSocket.find(dwConnID); + if(it != m_mpClientSocket.end()) + pSocketObj = it->second; + } + + return pSocketObj; +} + +void CTcpServer::CloseClientSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode, int iShutdownFlag) +{ + ASSERT(TSocketObj::IsExist(pSocketObj)); + + if(enFlag == SCF_CLOSE) + TriggerFireClose(pSocketObj, SO_CLOSE, SE_OK); + else if(enFlag == SCF_ERROR) + TriggerFireClose(pSocketObj, enOperation, iErrorCode); + + SOCKET socket = pSocketObj->socket; + pSocketObj->socket = INVALID_SOCKET; + + ::ManualCloseSocket(socket, iShutdownFlag); +} + +BOOL CTcpServer::GetListenAddress(TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + return ::GetSocketLocalAddress(m_soListen, lpszAddress, iAddressLen, usPort); +} + +BOOL CTcpServer::GetRemoteAddress(CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsExist(pSocketObj)) + { + ADDRESS_FAMILY usFamily; + return ::sockaddr_IN_2_A(pSocketObj->remoteAddr, usFamily, lpszAddress, iAddressLen, usPort); + } + + return FALSE; +} + +BOOL CTcpServer::SetConnectionExtra(CONNID dwConnID, PVOID pExtra) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return SetConnectionExtra(pSocketObj, pExtra); +} + +BOOL CTcpServer::SetConnectionExtra(TSocketObj* pSocketObj, PVOID pExtra) +{ + if(TSocketObj::IsExist(pSocketObj)) + { + pSocketObj->extra = pExtra; + return TRUE; + } + + return FALSE; +} + +BOOL CTcpServer::GetConnectionExtra(CONNID dwConnID, PVOID* ppExtra) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return GetConnectionExtra(pSocketObj, ppExtra); +} + +BOOL CTcpServer::GetConnectionExtra(TSocketObj* pSocketObj, PVOID* ppExtra) +{ + ASSERT(ppExtra != nullptr); + + if(TSocketObj::IsExist(pSocketObj)) + { + *ppExtra = pSocketObj->extra; + return TRUE; + } + + return FALSE; +} + +BOOL CTcpServer::SetConnectionReserved(CONNID dwConnID, PVOID pReserved) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return SetConnectionReserved(pSocketObj, pReserved); +} + +BOOL CTcpServer::SetConnectionReserved(TSocketObj* pSocketObj, PVOID pReserved) +{ + if(TSocketObj::IsExist(pSocketObj)) + { + pSocketObj->reserved = pReserved; + return TRUE; + } + + return FALSE; +} + +BOOL CTcpServer::GetConnectionReserved(CONNID dwConnID, PVOID* ppReserved) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return GetConnectionReserved(pSocketObj, ppReserved); +} + +BOOL CTcpServer::GetConnectionReserved(TSocketObj* pSocketObj, PVOID* ppReserved) +{ + ASSERT(ppReserved != nullptr); + + if(TSocketObj::IsExist(pSocketObj)) + { + *ppReserved = pSocketObj->reserved; + return TRUE; + } + + return FALSE; +} + +BOOL CTcpServer::GetPendingDataLength(CONNID dwConnID, int& iPending) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + iPending = pSocketObj->Pending(); + return TRUE; + } + + return FALSE; +} + +DWORD CTcpServer::GetConnectionCount() +{ + return (DWORD)m_mpClientSocket.size(); +} + +BOOL CTcpServer::GetAllConnectionIDs(CONNID pIDs[], DWORD& dwCount) +{ + BOOL isOK = FALSE; + DWORD dwSize = 0; + + { + CReentrantReadLock locallock(m_csClientSocket); + + dwSize = (DWORD)m_mpClientSocket.size(); + + if(pIDs != nullptr && dwSize <= dwCount) + { + TSocketObjPtrMapCI it = m_mpClientSocket.begin(); + TSocketObjPtrMapCI end = m_mpClientSocket.end(); + + for(int i = 0; it != end; ++it, ++i) + pIDs[i] = it->first; + + isOK = TRUE; + } + } + + dwCount = dwSize; + return isOK; +} + +BOOL CTcpServer::GetConnectPeriod(CONNID dwConnID, DWORD& dwPeriod) +{ + BOOL isOK = TRUE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + dwPeriod = ::GetTimeGap32(pSocketObj->connTime); + else + isOK = FALSE; + + return isOK; +} + +BOOL CTcpServer::GetSilencePeriod(CONNID dwConnID, DWORD& dwPeriod) +{ + if(!m_bMarkSilence) + return FALSE; + + BOOL isOK = TRUE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + dwPeriod = ::GetTimeGap32(pSocketObj->activeTime); + else + isOK = FALSE; + + return isOK; +} + +BOOL CTcpServer::Disconnect(CONNID dwConnID, BOOL bForce) +{ + BOOL isOK = FALSE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + if(bForce) + isOK = ::PostIocpDisconnect(m_hCompletePort, dwConnID); + else + isOK = m_pfnDisconnectEx(pSocketObj->socket, nullptr, 0, 0); + } + + return isOK; +} + +BOOL CTcpServer::DisconnectLongConnections(DWORD dwPeriod, BOOL bForce) +{ + ulong_ptr_deque ls; + + { + CReentrantReadLock locallock(m_csClientSocket); + + DWORD now = ::TimeGetTime(); + + for(TSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(now - it->second->connTime >= dwPeriod) + ls.push_back(it->first); + } + } + + for(ulong_ptr_deque::const_iterator it = ls.begin(), end = ls.end(); it != end; ++it) + Disconnect(*it, bForce); + + return ls.size() > 0; +} + +BOOL CTcpServer::DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce) +{ + if(!m_bMarkSilence) + return FALSE; + + ulong_ptr_deque ls; + + { + CReentrantReadLock locallock(m_csClientSocket); + + DWORD now = ::TimeGetTime(); + + for(TSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(now - it->second->activeTime >= dwPeriod) + ls.push_back(it->first); + } + } + + for(ulong_ptr_deque::const_iterator it = ls.begin(), end = ls.end(); it != end; ++it) + Disconnect(*it, bForce); + + return ls.size() > 0; +} + +void CTcpServer::WaitForAcceptSocketClose() +{ + DWORD dwWait = 0; + DWORD dwOrig = ::TimeGetTime(); + + while(m_iRemainAcceptSockets > 0) + { + ::WaitWithMessageLoop(100); + dwWait = ::GetTimeGap32(dwOrig); + } +} + +void CTcpServer::WaitForClientSocketClose() +{ + DWORD dwWait = 0; + DWORD dwOrig = ::TimeGetTime(); + + while(m_mpClientSocket.size() > 0) + { + ::WaitWithMessageLoop(100); + dwWait = ::GetTimeGap32(dwOrig); + } +} + +void CTcpServer::WaitForWorkerThreadEnd() +{ + int count = (int)m_vtWorkerThreads.size(); + + for(int i = 0; i < count; i++) + ::PostIocpExit(m_hCompletePort); + + int remain = count; + int index = 0; + + while(remain > 0) + { + int wait = min(remain, MAXIMUM_WAIT_OBJECTS); + HANDLE* pHandles = (HANDLE*)_alloca(sizeof(HANDLE) * wait); + + for(int i = 0; i < wait; i++) + pHandles[i] = m_vtWorkerThreads[i + index]; + + VERIFY(::WaitForMultipleObjects((DWORD)wait, pHandles, TRUE, INFINITE) == WAIT_OBJECT_0); + + for(int i = 0; i < wait; i++) + ::CloseHandle(pHandles[i]); + + remain -= wait; + index += wait; + } + + m_vtWorkerThreads.clear(); +} + +void CTcpServer::CloseCompletePort() +{ + if(m_hCompletePort != nullptr) + { + ::CloseHandle(m_hCompletePort); + m_hCompletePort = nullptr; + } +} + +BOOL CTcpServer::DoAccept() +{ + BOOL isOK = FALSE; + + if(HasStarted()) + { + SOCKET soClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + TBufferObj* pBufferObj = GetFreeBufferObj(); + + ASSERT(soClient != INVALID_SOCKET); + + isOK = (::PostAccept(m_pfnAcceptEx, m_soListen, soClient, pBufferObj) == NO_ERROR); + + if(!isOK) + { + VERIFY(!HasStarted()); + + ::ManualCloseSocket(soClient); + AddFreeBufferObj(pBufferObj); + } + } + + if(!isOK) + { + ::InterlockedDecrement(&m_iRemainAcceptSockets); + ASSERT(m_iRemainAcceptSockets >= 0); + } + + return isOK; +} + +UINT WINAPI CTcpServer::WorkerThreadProc(LPVOID pv) +{ + CTcpServer* pServer = (CTcpServer*)pv; + + while(TRUE) + { + DWORD dwErrorCode = NO_ERROR; + + DWORD dwBytes; + OVERLAPPED* pOverlapped; + TSocketObj* pSocketObj; + + BOOL result = ::GetQueuedCompletionStatus + ( + pServer->m_hCompletePort, + &dwBytes, + (PULONG_PTR)&pSocketObj, + &pOverlapped, + INFINITE + ); + + if(pOverlapped == nullptr) + { + EnIocpAction action = pServer->CheckIocpCommand(pOverlapped, dwBytes, (ULONG_PTR)pSocketObj); + + if(action == IOCP_ACT_CONTINUE) + continue; + else if(action == IOCP_ACT_BREAK) + break; + } + + TBufferObj* pBufferObj = CONTAINING_RECORD(pOverlapped, TBufferObj, ov); + CONNID dwConnID = pBufferObj->operation != SO_ACCEPT ? pSocketObj->connID : 0; + + if (!result) + { + DWORD dwFlag = 0; + DWORD dwSysCode = ::GetLastError(); + + if(pServer->HasStarted()) + { + SOCKET sock = pBufferObj->operation != SO_ACCEPT ? pBufferObj->client : (SOCKET)pSocketObj; + result = ::WSAGetOverlappedResult(sock, &pBufferObj->ov, &dwBytes, FALSE, &dwFlag); + + if (!result) + { + dwErrorCode = ::WSAGetLastError(); + TRACE("GetQueuedCompletionStatus error ( SYS: %d, SOCK: %d, FLAG: %d)\n", dwConnID, dwSysCode, dwErrorCode, dwFlag); + } + } + else + dwErrorCode = dwSysCode; + + ASSERT(dwSysCode != 0 && dwErrorCode != 0); + } + + pServer->HandleIo(dwConnID, pSocketObj, pBufferObj, dwBytes, dwErrorCode); + } + + return 0; +} + +EnIocpAction CTcpServer::CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey) +{ + ASSERT(pOverlapped == nullptr); + + EnIocpAction action = IOCP_ACT_CONTINUE; + + if(dwBytes == IOCP_CMD_SEND) + DoSend((CONNID)ulCompKey); + else if(dwBytes == IOCP_CMD_ACCEPT) + DoAccept(); + else if(dwBytes == IOCP_CMD_DISCONNECT) + ForceDisconnect((CONNID)ulCompKey); + else if(dwBytes == IOCP_CMD_EXIT && ulCompKey == 0) + action = IOCP_ACT_BREAK; + else + VERIFY(FALSE); + + return action; +} + +void CTcpServer::ForceDisconnect(CONNID dwConnID) +{ + AddFreeSocketObj(FindSocketObj(dwConnID), SCF_CLOSE); +} + +void CTcpServer::HandleIo(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode) +{ + ASSERT(pBufferObj != nullptr); + ASSERT(pSocketObj != nullptr); + + if(dwErrorCode != NO_ERROR) + { + HandleError(dwConnID, pSocketObj, pBufferObj, dwErrorCode); + return; + } + + if(dwBytes == 0 && pBufferObj->operation != SO_ACCEPT) + { + AddFreeSocketObj(pSocketObj, SCF_CLOSE); + AddFreeBufferObj(pBufferObj); + return; + } + + pBufferObj->buff.len = dwBytes; + + switch(pBufferObj->operation) + { + case SO_ACCEPT: + HandleAccept((SOCKET)pSocketObj, pBufferObj); + break; + case SO_SEND: + HandleSend(dwConnID, pSocketObj, pBufferObj); + break; + case SO_RECEIVE: + HandleReceive(dwConnID, pSocketObj, pBufferObj); + break; + default: + ASSERT(FALSE); + } +} + +void CTcpServer::HandleError(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwErrorCode) +{ + if(pBufferObj->operation != SO_ACCEPT) + CheckError(pSocketObj, pBufferObj->operation, dwErrorCode); + else + { + ::ManualCloseSocket(pBufferObj->client); + VERIFY(::PostIocpAccept(m_hCompletePort)); + } + + AddFreeBufferObj(pBufferObj); +} + +void CTcpServer::HandleAccept(SOCKET soListen, TBufferObj* pBufferObj) +{ + VERIFY(::PostIocpAccept(m_hCompletePort)); + + int iLocalSockaddrLen; + int iRemoteSockaddrLen; + SOCKADDR* pLocalSockAddr; + SOCKADDR* pRemoteSockAddr; + + m_pfnGetAcceptExSockaddrs + ( + pBufferObj->buff.buf, + 0, + sizeof(SOCKADDR_IN) + 16, + sizeof(SOCKADDR_IN) + 16, + (SOCKADDR **)&pLocalSockAddr, + &iLocalSockaddrLen, + (SOCKADDR **)&pRemoteSockAddr, + &iRemoteSockaddrLen + ); + + SOCKET socket = pBufferObj->client; + CONNID dwConnID = ::GenerateConnectionID(); + TSocketObj* pSocketObj = GetFreeSocketObj(dwConnID, socket); + + memcpy(&pSocketObj->remoteAddr, pRemoteSockAddr, sizeof(SOCKADDR_IN)); + AddClientSocketObj(dwConnID, pSocketObj); + + ::SSO_UpdateAcceptContext(socket, soListen); + ::CreateIoCompletionPort((HANDLE)socket, m_hCompletePort, (ULONG_PTR)pSocketObj, 0); + + if(TriggerFireAccept(pSocketObj) != HR_ERROR) + DoReceive(dwConnID, pSocketObj, pBufferObj); + else + { + AddFreeSocketObj(pSocketObj, SCF_NONE); + AddFreeBufferObj(pBufferObj); + } +} + +void CTcpServer::HandleSend(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + switch(m_enSendPolicy) + { + case SP_PACK: + { + long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount); + + TriggerFireSend(pSocketObj, pBufferObj); + if(sndCount == 0) DoSendPack(pSocketObj); + } + + break; + case SP_SAFE: + { + long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount); + + if(sndCount == 0 && !pSocketObj->smooth) + { + CCriSecLock locallock(pSocketObj->csSend); + + if((sndCount = pSocketObj->sndCount) == 0) + pSocketObj->smooth = TRUE; + } + + TriggerFireSend(pSocketObj, pBufferObj); + if(sndCount == 0) DoSendSafe(pSocketObj); + } + + break; + case SP_DIRECT: + { + TriggerFireSend(pSocketObj, pBufferObj); + } + + break; + default: + ASSERT(FALSE); + } +} + +void CTcpServer::HandleReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime(); + EnHandleResult hr = TriggerFireReceive(pSocketObj, pBufferObj); + + if(hr == HR_OK || hr == HR_IGNORE) + DoReceive(dwConnID, pSocketObj, pBufferObj); + else if(hr == HR_CLOSED) + { + AddFreeBufferObj(pBufferObj); + } + else + { + AddFreeSocketObj(pSocketObj, SCF_ERROR, SO_RECEIVE, ERROR_CANCELLED); + AddFreeBufferObj(pBufferObj); + } +} + +int CTcpServer::DoReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + pBufferObj->buff.len = m_dwSocketBufferSize; + int result =::PostReceive(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + CheckError(pSocketObj, SO_RECEIVE, result); + AddFreeBufferObj(pBufferObj); + } + + return result; +} + +BOOL CTcpServer::Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset) +{ + ASSERT(pBuffer && iLength > 0); + + if(iOffset != 0) pBuffer += iOffset; + + WSABUF buffer; + buffer.len = iLength; + buffer.buf = (char*)pBuffer; + + return SendPackets(dwConnID, &buffer, 1); +} + +BOOL CTcpServer::SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + TSocketObj* pSocketObj = nullptr; + + ASSERT(pBuffers && iCount > 0); + + if(pBuffers && iCount > 0) + { + pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + result = SendInternal(pSocketObj, pBuffers, iCount); + else + result = ERROR_OBJECT_NOT_FOUND; + } + else + result = ERROR_OBJECT_NOT_FOUND; + } + else + result = ERROR_INVALID_PARAMETER; + + if(result != NO_ERROR) + { + if(m_enSendPolicy == SP_DIRECT && TSocketObj::IsValid(pSocketObj)) + CheckError(pSocketObj, SO_SEND, result); + + ::SetLastError(result); + } + + return (result == NO_ERROR); +} + +int CTcpServer::SendInternal(TSocketObj* pSocketObj, const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + + for(int i = 0; i < iCount; i++) + { + int iBufLen = pBuffers[i].len; + + if(iBufLen > 0) + { + BYTE* pBuffer = (BYTE*)pBuffers[i].buf; + ASSERT(pBuffer); + + switch(m_enSendPolicy) + { + case SP_PACK: result = SendPack(pSocketObj, pBuffer, iBufLen); break; + case SP_SAFE: result = SendSafe(pSocketObj, pBuffer, iBufLen); break; + case SP_DIRECT: result = SendDirect(pSocketObj, pBuffer, iBufLen); break; + default: ASSERT(FALSE); result = ERROR_INVALID_INDEX; break; + } + + if(result != NO_ERROR) + break; + } + } + + return result; +} + +int CTcpServer::SendPack(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + BOOL isPostSend = !TSocketObj::IsPending(pSocketObj); + return CatAndPost(pSocketObj, pBuffer, iLength, isPostSend); +} + +int CTcpServer::SendSafe(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + BOOL isPostSend = !TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj); + return CatAndPost(pSocketObj, pBuffer, iLength, isPostSend); +} + +int CTcpServer::SendDirect(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + int result = NO_ERROR; + int iRemain = iLength; + + while(iRemain > 0) + { + int iBufferSize = min(iRemain, (int)m_dwSocketBufferSize); + TBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize); + memcpy(pBufferObj->buff.buf, pBuffer, iBufferSize); + + result = ::PostSend(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + AddFreeBufferObj(pBufferObj); + break; + } + + iRemain -= iBufferSize; + pBuffer += iBufferSize; + } + + return result; +} + +int CTcpServer::CatAndPost(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend) +{ + int result = NO_ERROR; + + pSocketObj->sndBuff.Cat(pBuffer, iLength); + pSocketObj->pending += iLength; + + if(isPostSend && !::PostIocpSend(m_hCompletePort, pSocketObj->connID)) + result = ::GetLastError(); + + return result; +} + +int CTcpServer::DoSend(CONNID dwConnID) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + return DoSend(pSocketObj); + + return ERROR_OBJECT_NOT_FOUND; +} + +int CTcpServer::DoSend(TSocketObj* pSocketObj) +{ + switch(m_enSendPolicy) + { + case SP_PACK: return DoSendPack(pSocketObj); + case SP_SAFE: return DoSendSafe(pSocketObj); + default: ASSERT(FALSE); return ERROR_INVALID_INDEX; + } +} + +int CTcpServer::DoSendPack(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + if(TSocketObj::IsPending(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + result = SendItem(pSocketObj); + } + + if(!IOCP_SUCCESS(result)) + CheckError(pSocketObj, SO_SEND, result); + + return result; +} + +int CTcpServer::DoSendSafe(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + if(TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj)) + { + pSocketObj->smooth = FALSE; + + result = SendItem(pSocketObj); + + if(result == NO_ERROR) + pSocketObj->smooth = TRUE; + } + } + + if(!IOCP_SUCCESS(result)) + CheckError(pSocketObj, SO_SEND, result); + + return result; +} + +int CTcpServer::SendItem(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + while(pSocketObj->sndBuff.Size() > 0) + { + ::InterlockedIncrement(&pSocketObj->sndCount); + + TItemPtr itPtr(m_itPool, pSocketObj->sndBuff.PopFront()); + + int iBufferSize = itPtr->Size(); + ASSERT(iBufferSize > 0 && iBufferSize <= (int)m_dwSocketBufferSize); + + pSocketObj->pending -= iBufferSize; + TBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize); + memcpy(pBufferObj->buff.buf, itPtr->Ptr(), iBufferSize); + + result = ::PostSendNotCheck(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + if(result != WSA_IO_PENDING) + AddFreeBufferObj(pBufferObj); + + break; + } + } + + return result; +} + +BOOL CTcpServer::SendSmallFile(CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead, const LPWSABUF pTail) +{ + ASSERT(lpszFileName != nullptr); + + CAtlFile file; + HRESULT hr = file.Create(lpszFileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); + + if(SUCCEEDED(hr)) + { + ULONGLONG ullLen; + hr = file.GetSize(ullLen); + + if(SUCCEEDED(hr)) + { + if(ullLen > 0 && ullLen <= MAX_SMALL_FILE_SIZE) + { + CAtlFileMapping<> fmap; + hr = fmap.MapFile(file); + + if(SUCCEEDED(hr)) + { + WSABUF bufs[3] = {0}; + + bufs[1].len = (ULONG)ullLen; + bufs[1].buf = fmap; + + if(pHead) memcpy(&bufs[0], pHead, sizeof(WSABUF)); + if(pTail) memcpy(&bufs[2], pTail, sizeof(WSABUF)); + + return SendPackets(dwConnID, bufs, 3); + } + } + else if(ullLen == 0) + hr = HRESULT_FROM_WIN32(ERROR_FILE_INVALID); + else + hr = HRESULT_FROM_WIN32(ERROR_FILE_TOO_LARGE); + } + } + + ::SetLastError(hr & 0x0000FFFF); + + return FALSE; +} + +void CTcpServer::CheckError(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + if(iErrorCode != WSAENOTSOCK && iErrorCode != ERROR_OPERATION_ABORTED) + AddFreeSocketObj(pSocketObj, SCF_ERROR, enOperation, iErrorCode); +} diff --git a/HP-Socket/Src/TcpServer.h b/HP-Socket/Src/TcpServer.h new file mode 100644 index 000000000..bac32e6e5 --- /dev/null +++ b/HP-Socket/Src/TcpServer.h @@ -0,0 +1,268 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "SocketHelper.h" +#include "../../Common/Src/Event.h" +#include "../../Common/Src/RWLock.h" +#include "../../Common/Src/STLHelper.h" +#include "../../Common/Src/RingBuffer.h" +#include "../../Common/Src/PrivateHeap.h" + +class CTcpServer : public ITcpServer +{ +public: + CTcpServer(ITcpServerListener* psoListener) + : m_psoListener (psoListener) + , m_hCompletePort (nullptr) + , m_soListen (INVALID_SOCKET) + , m_iRemainAcceptSockets (0) + , m_pfnAcceptEx (nullptr) + , m_pfnGetAcceptExSockaddrs (nullptr) + , m_pfnDisconnectEx (nullptr) + , m_enLastError (SE_OK) + , m_enState (SS_STOPPED) + , m_enSendPolicy (SP_PACK) + , m_dwWorkerThreadCount (DEFAULT_WORKER_THREAD_COUNT) + , m_dwSocketListenQueue (DEFAULT_TCP_SERVER_SOCKET_LISTEN_QUEUE) + , m_dwAcceptSocketCount (DEFAULT_TCP_SERVER_ACCEPT_SOCKET_COUNT) + , m_dwSocketBufferSize (DEFAULT_TCP_SOCKET_BUFFER_SIZE) + , m_dwFreeSocketObjLockTime (DEFAULT_FREE_SOCKETOBJ_LOCK_TIME) + , m_dwFreeSocketObjPool (DEFAULT_FREE_SOCKETOBJ_POOL) + , m_dwFreeBufferObjPool (DEFAULT_FREE_BUFFEROBJ_POOL) + , m_dwFreeSocketObjHold (DEFAULT_FREE_SOCKETOBJ_HOLD) + , m_dwFreeBufferObjHold (DEFAULT_FREE_BUFFEROBJ_HOLD) + , m_dwKeepAliveTime (DEFALUT_TCP_KEEPALIVE_TIME) + , m_dwKeepAliveInterval (DEFALUT_TCP_KEEPALIVE_INTERVAL) + , m_bMarkSilence (FALSE) + { + ASSERT(m_wsSocket.IsValid()); + ASSERT(m_psoListener); + + Reset(FALSE); + } + + virtual ~CTcpServer() + { + if(HasStarted()) + Stop(); + } + +public: + virtual BOOL Start (LPCTSTR pszBindAddress, USHORT usPort); + virtual BOOL Stop (); + virtual BOOL Send (CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0); + virtual BOOL SendPackets (CONNID dwConnID, const WSABUF pBuffers[], int iCount); + virtual BOOL SendSmallFile (CONNID dwConnID, LPCTSTR lpszFileName, const LPWSABUF pHead = nullptr, const LPWSABUF pTail = nullptr); + virtual BOOL HasStarted () {return m_enState == SS_STARTED || m_enState == SS_STARTING;} + virtual EnServiceState GetState () {return m_enState;} + virtual BOOL Disconnect (CONNID dwConnID, BOOL bForce = TRUE); + virtual BOOL DisconnectLongConnections (DWORD dwPeriod, BOOL bForce = TRUE); + virtual BOOL DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce = TRUE); + virtual BOOL GetListenAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + virtual BOOL GetRemoteAddress (CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + + virtual BOOL GetPendingDataLength (CONNID dwConnID, int& iPending); + virtual DWORD GetConnectionCount (); + virtual BOOL GetAllConnectionIDs (CONNID pIDs[], DWORD& dwCount); + virtual BOOL GetConnectPeriod (CONNID dwConnID, DWORD& dwPeriod); + virtual BOOL GetSilencePeriod (CONNID dwConnID, DWORD& dwPeriod); + virtual EnSocketError GetLastError () {return m_enLastError;} + virtual LPCTSTR GetLastErrorDesc () {return ::GetSocketErrorDesc(m_enLastError);} + +public: + virtual BOOL SetConnectionExtra(CONNID dwConnID, PVOID pExtra); + virtual BOOL GetConnectionExtra(CONNID dwConnID, PVOID* ppExtra); + + virtual void SetSendPolicy (EnSendPolicy enSendPolicy) {m_enSendPolicy = enSendPolicy;} + virtual void SetWorkerThreadCount (DWORD dwWorkerThreadCount) {m_dwWorkerThreadCount = dwWorkerThreadCount;} + virtual void SetSocketListenQueue (DWORD dwSocketListenQueue) {m_dwSocketListenQueue = dwSocketListenQueue;} + virtual void SetAcceptSocketCount (DWORD dwAcceptSocketCount) {m_dwAcceptSocketCount = dwAcceptSocketCount;} + virtual void SetSocketBufferSize (DWORD dwSocketBufferSize) {m_dwSocketBufferSize = dwSocketBufferSize;} + virtual void SetFreeSocketObjLockTime (DWORD dwFreeSocketObjLockTime) {m_dwFreeSocketObjLockTime = dwFreeSocketObjLockTime;} + virtual void SetFreeSocketObjPool (DWORD dwFreeSocketObjPool) {m_dwFreeSocketObjPool = dwFreeSocketObjPool;} + virtual void SetFreeBufferObjPool (DWORD dwFreeBufferObjPool) {m_dwFreeBufferObjPool = dwFreeBufferObjPool;} + virtual void SetFreeSocketObjHold (DWORD dwFreeSocketObjHold) {m_dwFreeSocketObjHold = dwFreeSocketObjHold;} + virtual void SetFreeBufferObjHold (DWORD dwFreeBufferObjHold) {m_dwFreeBufferObjHold = dwFreeBufferObjHold;} + virtual void SetKeepAliveTime (DWORD dwKeepAliveTime) {m_dwKeepAliveTime = dwKeepAliveTime;} + virtual void SetKeepAliveInterval (DWORD dwKeepAliveInterval) {m_dwKeepAliveInterval = dwKeepAliveInterval;} + virtual void SetMarkSilence (BOOL bMarkSilence) {m_bMarkSilence = bMarkSilence;} + + virtual EnSendPolicy GetSendPolicy () {return m_enSendPolicy;} + virtual DWORD GetWorkerThreadCount () {return m_dwWorkerThreadCount;} + virtual DWORD GetSocketListenQueue () {return m_dwSocketListenQueue;} + virtual DWORD GetAcceptSocketCount () {return m_dwAcceptSocketCount;} + virtual DWORD GetSocketBufferSize () {return m_dwSocketBufferSize;} + virtual DWORD GetFreeSocketObjLockTime () {return m_dwFreeSocketObjLockTime;} + virtual DWORD GetFreeSocketObjPool () {return m_dwFreeSocketObjPool;} + virtual DWORD GetFreeBufferObjPool () {return m_dwFreeBufferObjPool;} + virtual DWORD GetFreeSocketObjHold () {return m_dwFreeSocketObjHold;} + virtual DWORD GetFreeBufferObjHold () {return m_dwFreeBufferObjHold;} + virtual DWORD GetKeepAliveTime () {return m_dwKeepAliveTime;} + virtual DWORD GetKeepAliveInterval () {return m_dwKeepAliveInterval;} + virtual BOOL IsMarkSilence () {return m_bMarkSilence;} + +protected: + virtual EnHandleResult FirePrepareListen(SOCKET soListen) + {return m_psoListener->OnPrepareListen(soListen);} + virtual EnHandleResult FireAccept(TSocketObj* pSocketObj) + {return m_psoListener->OnAccept(pSocketObj->connID, pSocketObj->socket);} + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return m_psoListener->OnReceive(pSocketObj->connID, pData, iLength);} + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, int iLength) + {return m_psoListener->OnReceive(pSocketObj->connID, iLength);} + virtual EnHandleResult FireSend(TSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return m_psoListener->OnSend(pSocketObj->connID, pData, iLength);} + virtual EnHandleResult FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) + {return m_psoListener->OnClose(pSocketObj->connID, enOperation, iErrorCode);} + virtual EnHandleResult FireShutdown() + {return m_psoListener->OnShutdown();} + + void SetLastError(EnSocketError code, LPCSTR func, int ec); + virtual BOOL CheckParams(); + virtual void PrepareStart(); + virtual void Reset(BOOL bAll = TRUE); + +private: + EnHandleResult TriggerFireAccept(TSocketObj* pSocketObj); + EnHandleResult TriggerFireReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj); + EnHandleResult TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj); + EnHandleResult TriggerFireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + +protected: + BOOL SetConnectionExtra(TSocketObj* pSocketObj, PVOID pExtra); + BOOL GetConnectionExtra(TSocketObj* pSocketObj, PVOID* ppExtra); + BOOL SetConnectionReserved(CONNID dwConnID, PVOID pReserved); + BOOL GetConnectionReserved(CONNID dwConnID, PVOID* ppReserved); + BOOL SetConnectionReserved(TSocketObj* pSocketObj, PVOID pReserved); + BOOL GetConnectionReserved(TSocketObj* pSocketObj, PVOID* ppReserved); + +private: + BOOL CheckStarting(); + BOOL CheckStoping(); + BOOL CreateListenSocket(LPCTSTR pszBindAddress, USHORT usPort); + BOOL CreateCompletePort(); + BOOL CreateWorkerThreads(); + BOOL StartAccept(); + + void CloseListenSocket(); + void WaitForAcceptSocketClose(); + void DisconnectClientSocket(); + void WaitForClientSocketClose(); + void ReleaseClientSocket(); + void ReleaseFreeSocket(); + void ReleaseFreeBuffer(); + void WaitForWorkerThreadEnd(); + void CloseCompletePort(); + + TBufferObj* GetFreeBufferObj(int iLen = 0); + TSocketObj* GetFreeSocketObj(CONNID dwConnID, SOCKET soClient); + void AddFreeBufferObj(TBufferObj* pBufferObj); + void AddFreeSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0); + TBufferObj* CreateBufferObj(); + TSocketObj* CreateSocketObj(); + void DeleteBufferObj(TBufferObj* pBufferObj); + void DeleteSocketObj(TSocketObj* pSocketObj); + BOOL InvalidSocketObj(TSocketObj* pSocketObj); + void ReleaseGCSocketObj(BOOL bForce = FALSE); + + void AddClientSocketObj(CONNID dwConnID, TSocketObj* pSocketObj); + void CloseClientSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0, int iShutdownFlag = SD_SEND); + TSocketObj* FindSocketObj(CONNID dwConnID); + +private: + static UINT WINAPI WorkerThreadProc(LPVOID pv); + + EnIocpAction CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey); + + void ForceDisconnect(CONNID dwConnID); + void HandleIo (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode); + void HandleError (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwErrorCode); + void HandleAccept (SOCKET soListen, TBufferObj* pBufferObj); + void HandleSend (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + void HandleReceive (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + + int SendInternal(TSocketObj* pSocketObj, const WSABUF pBuffers[], int iCount); + int SendPack (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int SendSafe (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int SendDirect (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int CatAndPost (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend); + + BOOL DoAccept (); + int DoReceive (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + + int DoSend (CONNID dwConnID); + int DoSend (TSocketObj* pSocketObj); + int DoSendPack (TSocketObj* pSocketObj); + int DoSendSafe (TSocketObj* pSocketObj); + int SendItem (TSocketObj* pSocketObj); + + void CheckError (TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + +private: + EnSendPolicy m_enSendPolicy; + DWORD m_dwWorkerThreadCount; + DWORD m_dwSocketListenQueue; + DWORD m_dwAcceptSocketCount; + DWORD m_dwSocketBufferSize; + DWORD m_dwFreeSocketObjLockTime; + DWORD m_dwFreeSocketObjPool; + DWORD m_dwFreeBufferObjPool; + DWORD m_dwFreeSocketObjHold; + DWORD m_dwFreeBufferObjHold; + DWORD m_dwKeepAliveTime; + DWORD m_dwKeepAliveInterval; + BOOL m_bMarkSilence; + +private: + CInitSocket m_wsSocket; + LPFN_ACCEPTEX m_pfnAcceptEx; + LPFN_GETACCEPTEXSOCKADDRS m_pfnGetAcceptExSockaddrs; + LPFN_DISCONNECTEX m_pfnDisconnectEx; + +private: + ITcpServerListener* m_psoListener; + SOCKET m_soListen; + HANDLE m_hCompletePort; + EnServiceState m_enState; + EnSocketError m_enLastError; + + vector m_vtWorkerThreads; + + CPrivateHeap m_phBuffer; + CPrivateHeap m_phSocket; + CItemPool m_itPool; + + CSpinGuard m_csState; + + CRWLock m_csClientSocket; + TSocketObjPtrMap m_mpClientSocket; + + TBufferObjPtrList m_lsFreeBuffer; + TSocketObjPtrList m_lsFreeSocket; + TSocketObjPtrQueue m_lsGCSocket; + + volatile long m_iRemainAcceptSockets; +}; diff --git a/HP-Socket/Src/UdpAgent.cpp b/HP-Socket/Src/UdpAgent.cpp new file mode 100644 index 000000000..af1c8db20 --- /dev/null +++ b/HP-Socket/Src/UdpAgent.cpp @@ -0,0 +1,1359 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include +#include "UdpAgent.h" +#include "../../Common/Src/WaitFor.h" + +#include +#include + +EnHandleResult CUdpAgent::TriggerFireConnect(TSocketObj* pSocketObj) +{ + CReentrantSpinLock locallock(pSocketObj->csRecv); + return FireConnect(pSocketObj); +} + +EnHandleResult CUdpAgent::TriggerFireReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + EnHandleResult rs = (EnHandleResult)HR_CLOSED; + + if(TSocketObj::IsValid(pSocketObj)) + { + CReentrantSpinLock locallock(pSocketObj->csRecv); + + if(TSocketObj::IsValid(pSocketObj)) + { + rs = FireReceive(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len); + } + } + + return rs; +} + +EnHandleResult CUdpAgent::TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + EnHandleResult rs = FireSend(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len); + + if(rs == HR_ERROR) + { + TRACE(" OnSend() event should not return 'HR_ERROR' !!\n", pSocketObj->connID); + ASSERT(FALSE); + } + + AddFreeBufferObj(pBufferObj); + + return rs; +} + +EnHandleResult CUdpAgent::TriggerFireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + CReentrantSpinLock locallock(pSocketObj->csRecv); + return FireClose(pSocketObj, enOperation, iErrorCode); +} + +void CUdpAgent::SetLastError(EnSocketError code, LPCSTR func, int ec) +{ + m_enLastError = code; + + TRACE("%s --> Error: %d, EC: %d\n", func, code, ec); +} + +BOOL CUdpAgent::Start(LPCTSTR pszBindAddress, BOOL bAsyncConnect) +{ + if(!CheckParams() || !CheckStarting()) + return FALSE; + + PrepareStart(); + + if(ParseBindAddress(pszBindAddress, bAsyncConnect)) + if(CreateCompletePort()) + if(CreateWorkerThreads()) + { + m_bAsyncConnect = bAsyncConnect; + m_enState = SS_STARTED; + + return TRUE; + } + + Stop(); + + return FALSE; +} + +BOOL CUdpAgent::CheckParams() +{ + if(m_enSendPolicy >= SP_PACK && m_enSendPolicy <= SP_DIRECT) + if((int)m_dwWorkerThreadCount > 0 && m_dwWorkerThreadCount <= MAX_WORKER_THREAD_COUNT) + if((int)m_dwFreeSocketObjLockTime >= 0) + if((int)m_dwFreeSocketObjPool >= 0) + if((int)m_dwFreeBufferObjPool >= 0) + if((int)m_dwFreeSocketObjHold >= m_dwFreeSocketObjPool) + if((int)m_dwFreeBufferObjHold >= m_dwFreeBufferObjPool) + if((int)m_dwMaxDatagramSize > 0) + if((int)m_dwDetectAttempts >= 0) + if((int)m_dwDetectInterval >= 0) + return TRUE; + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CUdpAgent::PrepareStart() +{ + m_lsFreeSocket.Reset(m_dwFreeSocketObjHold); + m_lsFreeBuffer.Reset(m_dwFreeBufferObjHold); + + m_itPool.SetItemCapacity((int)m_dwMaxDatagramSize); + m_itPool.SetPoolSize((int)m_dwFreeBufferObjPool); + m_itPool.SetPoolHold((int)m_dwFreeBufferObjHold); + + m_itPool.Prepare(); +} + +BOOL CUdpAgent::CheckStarting() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STOPPED) + m_enState = SS_STARTING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CUdpAgent::CheckStoping() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STARTED || m_enState == SS_STARTING) + m_enState = SS_STOPPING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CUdpAgent::ParseBindAddress(LPCTSTR pszBindAddress, BOOL bAsyncConnect) +{ + BOOL isOK = FALSE; + SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if(sock != INVALID_SOCKET) + { + if(!pszBindAddress) + pszBindAddress = DEFAULT_BIND_ADDRESS; + + ::sockaddr_A_2_IN(AF_INET, pszBindAddress, 0, m_soAddrIN); + + if(!bAsyncConnect || ::bind(sock, (SOCKADDR*)&m_soAddrIN, sizeof(SOCKADDR_IN)) != SOCKET_ERROR) + { + m_pfnConnectEx = ::Get_ConnectEx_FuncPtr(sock); + m_pfnDisconnectEx = ::Get_DisconnectEx_FuncPtr(sock); + + ASSERT(m_pfnConnectEx); + ASSERT(m_pfnDisconnectEx); + + isOK = TRUE; + } + else + SetLastError(SE_SOCKET_BIND, __FUNCTION__, ::WSAGetLastError()); + + ::ManualCloseSocket(sock); + } + else + SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError()); + + return isOK; +} + +BOOL CUdpAgent::CreateCompletePort() +{ + m_hCompletePort = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 0); + if(m_hCompletePort == nullptr) + SetLastError(SE_CP_CREATE, __FUNCTION__, ::GetLastError()); + + return (m_hCompletePort != nullptr); +} + +BOOL CUdpAgent::CreateWorkerThreads() +{ + BOOL isOK = TRUE; + + for(DWORD i = 0; i < m_dwWorkerThreadCount; i++) + { + HANDLE hThread = (HANDLE)_beginthreadex(nullptr, 0, WorkerThreadProc, (LPVOID)this, 0, nullptr); + if(hThread) + m_vtWorkerThreads.push_back(hThread); + else + { + SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ::GetLastError()); + isOK = FALSE; + break; + } + } + + return isOK; +} + +BOOL CUdpAgent::Stop() +{ + if(!CheckStoping()) + return FALSE; + + ::WaitWithMessageLoop(150); + + DisconnectClientSocket(); + WaitForClientSocketClose(); + WaitForWorkerThreadEnd(); + + ReleaseClientSocket(); + + FireShutdown(); + + ReleaseFreeSocket(); + ReleaseFreeBuffer(); + + CloseCompletePort(); + + Reset(); + + return TRUE; +} + +void CUdpAgent::Reset(BOOL bAll) +{ + if(bAll) + { + m_phSocket.Reset(); + m_phBuffer.Reset(); + m_itPool.Clear(); + } + + ::ZeroMemory((void*)&m_soAddrIN, sizeof(SOCKADDR_IN)); + + m_pfnConnectEx = nullptr; + m_pfnDisconnectEx = nullptr; + m_enState = SS_STOPPED; +} + +void CUdpAgent::DisconnectClientSocket() +{ + CReentrantReadLock locallock(m_csClientSocket); + + for(TSocketObjPtrMapI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + Disconnect(it->first); +} + +void CUdpAgent::ReleaseClientSocket() +{ + CReentrantWriteLock locallock(m_csClientSocket); + + for(TSocketObjPtrMapI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + TSocketObj* pSocketObj = it->second; + + CloseClientSocketObj(pSocketObj); + DeleteSocketObj(pSocketObj); + } + + m_mpClientSocket.clear(); +} + +TSocketObj* CUdpAgent::GetFreeSocketObj(CONNID dwConnID, SOCKET soClient) +{ + DWORD dwIndex; + TSocketObj* pSocketObj = nullptr; + + if(m_lsFreeSocket.TryLock(&pSocketObj, dwIndex)) + { + if(::GetTimeGap32(pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) + m_lsFreeSocket.ReleaseLock(nullptr, dwIndex); + else + { + m_lsFreeSocket.ReleaseLock(pSocketObj, dwIndex); + pSocketObj = nullptr; + } + } + + if(!pSocketObj) pSocketObj = CreateSocketObj(); + pSocketObj->Reset(dwConnID, soClient); + + return pSocketObj; +} + +void CUdpAgent::AddFreeSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode) +{ + if(!InvalidSocketObj(pSocketObj)) + return; + + CloseClientSocketObj(pSocketObj, enFlag, enOperation, iErrorCode); + TSocketObj::Release(pSocketObj); + + { + CReentrantWriteLock locallock(m_csClientSocket); + m_mpClientSocket.erase(pSocketObj->connID); + } + + if(!m_lsFreeSocket.TryPut(pSocketObj)) + { + m_lsGCSocket.PushBack(pSocketObj); + + if(m_lsGCSocket.Size() > m_dwFreeSocketObjPool) + ReleaseGCSocketObj(); + } +} + +void CUdpAgent::ReleaseGCSocketObj(BOOL bForce) +{ + TSocketObj* pSocketObj = nullptr; + DWORD now = ::TimeGetTime(); + + while(m_lsGCSocket.PopFront(&pSocketObj)) + { + if(bForce || (now - pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) + DeleteSocketObj(pSocketObj); + else + { + m_lsGCSocket.PushBack(pSocketObj); + break; + } + } +} + +BOOL CUdpAgent::InvalidSocketObj(TSocketObj* pSocketObj) +{ + BOOL bDone = FALSE; + + if(TSocketObj::IsValid(pSocketObj)) + { + CReentrantSpinLock locallock(pSocketObj->csRecv); + CCriSecLock locallock2(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + { + TSocketObj::Invalid(pSocketObj); + bDone = TRUE; + } + } + + return bDone; +} + +void CUdpAgent::AddClientSocketObj(CONNID dwConnID, TSocketObj* pSocketObj) +{ + ASSERT(FindSocketObj(dwConnID) == nullptr); + + pSocketObj->connTime = ::TimeGetTime(); + pSocketObj->activeTime = pSocketObj->connTime; + + CReentrantWriteLock locallock(m_csClientSocket); + m_mpClientSocket[dwConnID] = pSocketObj; +} + +void CUdpAgent::ReleaseFreeSocket() +{ + TSocketObj* pSocketObj = nullptr; + + while(m_lsFreeSocket.TryGet(&pSocketObj)) + DeleteSocketObj(pSocketObj); + + VERIFY(m_lsFreeSocket.IsEmpty()); + m_lsFreeSocket.Reset(); + + ReleaseGCSocketObj(TRUE); + VERIFY(m_lsGCSocket.IsEmpty()); +} + +TSocketObj* CUdpAgent::CreateSocketObj() +{ + TSocketObj* pSocketObj = (TSocketObj*)m_phSocket.Alloc(sizeof(TSocketObj)); + ASSERT(pSocketObj); + + pSocketObj->TSocketObj::TSocketObj(m_itPool); + + return pSocketObj; +} + +void CUdpAgent::DeleteSocketObj(TSocketObj* pSocketObj) +{ + ASSERT(pSocketObj); + + pSocketObj->TSocketObj::~TSocketObj(); + m_phSocket.Free(pSocketObj); +} + +TBufferObj* CUdpAgent::GetFreeBufferObj(int iLen) +{ + ASSERT(iLen >= 0 && iLen <= (int)m_dwMaxDatagramSize); + + TBufferObj* pBufferObj = nullptr; + + if(!m_lsFreeBuffer.TryGet(&pBufferObj)) + pBufferObj = CreateBufferObj(); + + if(iLen <= 0) iLen = m_dwMaxDatagramSize; + pBufferObj->buff.len = iLen; + + return pBufferObj; +} + +void CUdpAgent::AddFreeBufferObj(TBufferObj* pBufferObj) +{ + if(!m_lsFreeBuffer.TryPut(pBufferObj)) + DeleteBufferObj(pBufferObj); +} + +void CUdpAgent::ReleaseFreeBuffer() +{ + TBufferObj* pBufferObj = nullptr; + + while(m_lsFreeBuffer.TryGet(&pBufferObj)) + DeleteBufferObj(pBufferObj); + + VERIFY(m_lsFreeBuffer.IsEmpty()); + m_lsFreeBuffer.Reset(); +} + +TBufferObj* CUdpAgent::CreateBufferObj() +{ + TBufferObj* pBufferObj = (TBufferObj*)m_phBuffer.Alloc(sizeof(TBufferObj) + m_dwMaxDatagramSize); + ASSERT(pBufferObj); + + ::ZeroMemory(pBufferObj, sizeof(TBufferObj)); + pBufferObj->buff.buf = ((char*)pBufferObj) + sizeof(TBufferObj); + + return pBufferObj; +} + +void CUdpAgent::DeleteBufferObj(TBufferObj* pBufferObj) +{ + ASSERT(pBufferObj); + m_phBuffer.Free(pBufferObj); +} + +TSocketObj* CUdpAgent::FindSocketObj(CONNID dwConnID) +{ + TSocketObj* pSocketObj = nullptr; + + { + CReentrantReadLock locallock(m_csClientSocket); + + TSocketObjPtrMapCI it = m_mpClientSocket.find(dwConnID); + if(it != m_mpClientSocket.end()) + pSocketObj = it->second; + } + + return pSocketObj; +} + +void CUdpAgent::CloseClientSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode, int iShutdownFlag) +{ + ASSERT(TSocketObj::IsExist(pSocketObj)); + + if(enFlag == SCF_CLOSE) + TriggerFireClose(pSocketObj, SO_CLOSE, SE_OK); + else if(enFlag == SCF_ERROR) + TriggerFireClose(pSocketObj, enOperation, iErrorCode); + + SOCKET socket = pSocketObj->socket; + pSocketObj->socket = INVALID_SOCKET; + + ::ManualCloseSocket(socket, iShutdownFlag); +} + +BOOL CUdpAgent::GetLocalAddress(CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + return ::GetSocketLocalAddress(pSocketObj->socket, lpszAddress, iAddressLen, usPort); + + return FALSE; +} + +BOOL CUdpAgent::GetRemoteAddress(CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsExist(pSocketObj)) + { + ADDRESS_FAMILY usFamily; + return ::sockaddr_IN_2_A(pSocketObj->remoteAddr, usFamily, lpszAddress, iAddressLen, usPort); + } + + return FALSE; +} + +BOOL CUdpAgent::SetConnectionExtra(CONNID dwConnID, PVOID pExtra) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return SetConnectionExtra(pSocketObj, pExtra); +} + +BOOL CUdpAgent::SetConnectionExtra(TSocketObj* pSocketObj, PVOID pExtra) +{ + if(TSocketObj::IsExist(pSocketObj)) + { + pSocketObj->extra = pExtra; + return TRUE; + } + + return FALSE; +} + +BOOL CUdpAgent::GetConnectionExtra(CONNID dwConnID, PVOID* ppExtra) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return GetConnectionExtra(pSocketObj, ppExtra); +} + +BOOL CUdpAgent::GetConnectionExtra(TSocketObj* pSocketObj, PVOID* ppExtra) +{ + ASSERT(ppExtra != nullptr); + + if(TSocketObj::IsExist(pSocketObj)) + { + *ppExtra = pSocketObj->extra; + return TRUE; + } + + return FALSE; +} + +BOOL CUdpAgent::SetConnectionReserved(CONNID dwConnID, PVOID pReserved) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return SetConnectionReserved(pSocketObj, pReserved); +} + +BOOL CUdpAgent::SetConnectionReserved(TSocketObj* pSocketObj, PVOID pReserved) +{ + if(TSocketObj::IsExist(pSocketObj)) + { + pSocketObj->reserved = pReserved; + return TRUE; + } + + return FALSE; +} + +BOOL CUdpAgent::GetConnectionReserved(CONNID dwConnID, PVOID* ppReserved) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + return GetConnectionReserved(pSocketObj, ppReserved); +} + +BOOL CUdpAgent::GetConnectionReserved(TSocketObj* pSocketObj, PVOID* ppReserved) +{ + ASSERT(ppReserved != nullptr); + + if(TSocketObj::IsExist(pSocketObj)) + { + *ppReserved = pSocketObj->reserved; + return TRUE; + } + + return FALSE; +} + +BOOL CUdpAgent::GetPendingDataLength(CONNID dwConnID, int& iPending) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + iPending = pSocketObj->Pending(); + return TRUE; + } + + return FALSE; +} + +DWORD CUdpAgent::GetConnectionCount() +{ + return (DWORD)m_mpClientSocket.size(); +} + +BOOL CUdpAgent::GetAllConnectionIDs(CONNID pIDs[], DWORD& dwCount) +{ + BOOL isOK = FALSE; + DWORD dwSize = 0; + + { + CReentrantReadLock locallock(m_csClientSocket); + + dwSize = (DWORD)m_mpClientSocket.size(); + + if(pIDs != nullptr && dwSize <= dwCount) + { + TSocketObjPtrMapCI it = m_mpClientSocket.begin(); + TSocketObjPtrMapCI end = m_mpClientSocket.end(); + + for(int i = 0; it != end; ++it, ++i) + pIDs[i] = it->first; + + isOK = TRUE; + } + } + + dwCount = dwSize; + return isOK; +} + +BOOL CUdpAgent::GetConnectPeriod(CONNID dwConnID, DWORD& dwPeriod) +{ + BOOL isOK = TRUE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + dwPeriod = ::GetTimeGap32(pSocketObj->connTime); + else + isOK = FALSE; + + return isOK; +} + +BOOL CUdpAgent::GetSilencePeriod(CONNID dwConnID, DWORD& dwPeriod) +{ + if(!m_bMarkSilence) + return FALSE; + + BOOL isOK = TRUE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + dwPeriod = ::GetTimeGap32(pSocketObj->activeTime); + else + isOK = FALSE; + + return isOK; +} + +BOOL CUdpAgent::Disconnect(CONNID dwConnID, BOOL bForce) +{ + BOOL isOK = FALSE; + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + if(bForce) + isOK = ::PostIocpDisconnect(m_hCompletePort, dwConnID); + else + isOK = m_pfnDisconnectEx(pSocketObj->socket, nullptr, 0, 0); + } + + return isOK; +} + +BOOL CUdpAgent::DisconnectLongConnections(DWORD dwPeriod, BOOL bForce) +{ + ulong_ptr_deque ls; + + { + CReentrantReadLock locallock(m_csClientSocket); + + DWORD now = ::TimeGetTime(); + + for(TSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(now - it->second->connTime >= dwPeriod) + ls.push_back(it->first); + } + } + + for(ulong_ptr_deque::const_iterator it = ls.begin(), end = ls.end(); it != end; ++it) + Disconnect(*it, bForce); + + return ls.size() > 0; +} + +BOOL CUdpAgent::DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce) +{ + if(!m_bMarkSilence) + return FALSE; + + ulong_ptr_deque ls; + + { + CReentrantReadLock locallock(m_csClientSocket); + + DWORD now = ::TimeGetTime(); + + for(TSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(now - it->second->activeTime >= dwPeriod) + ls.push_back(it->first); + } + } + + for(ulong_ptr_deque::const_iterator it = ls.begin(), end = ls.end(); it != end; ++it) + Disconnect(*it, bForce); + + return ls.size() > 0; +} + +void CUdpAgent::WaitForClientSocketClose() +{ + DWORD dwWait = 0; + DWORD dwOrig = ::TimeGetTime(); + + while(m_mpClientSocket.size() > 0) + { + ::WaitWithMessageLoop(100); + dwWait = ::GetTimeGap32(dwOrig); + } + + ASSERT(m_mpClientSocket.size() == 0); +} + +void CUdpAgent::WaitForWorkerThreadEnd() +{ + int count = (int)m_vtWorkerThreads.size(); + + for(int i = 0; i < count; i++) + ::PostIocpExit(m_hCompletePort); + + int remain = count; + int index = 0; + + while(remain > 0) + { + int wait = min(remain, MAXIMUM_WAIT_OBJECTS); + HANDLE* pHandles = (HANDLE*)_alloca(sizeof(HANDLE) * wait); + + for(int i = 0; i < wait; i++) + pHandles[i] = m_vtWorkerThreads[i + index]; + + VERIFY(::WaitForMultipleObjects((DWORD)wait, pHandles, TRUE, INFINITE) == WAIT_OBJECT_0); + + for(int i = 0; i < wait; i++) + ::CloseHandle(pHandles[i]); + + remain -= wait; + index += wait; + } + + m_vtWorkerThreads.clear(); +} + +void CUdpAgent::CloseCompletePort() +{ + if(m_hCompletePort != nullptr) + { + ::CloseHandle(m_hCompletePort); + m_hCompletePort = nullptr; + } +} + +UINT WINAPI CUdpAgent::WorkerThreadProc(LPVOID pv) +{ + CUdpAgent* pServer = (CUdpAgent*)pv; + + while(TRUE) + { + DWORD dwErrorCode = NO_ERROR; + + DWORD dwBytes; + OVERLAPPED* pOverlapped; + TSocketObj* pSocketObj; + + BOOL result = ::GetQueuedCompletionStatus + ( + pServer->m_hCompletePort, + &dwBytes, + (PULONG_PTR)&pSocketObj, + &pOverlapped, + INFINITE + ); + + if(pOverlapped == nullptr) + { + EnIocpAction action = pServer->CheckIocpCommand(pOverlapped, dwBytes, (ULONG_PTR)pSocketObj); + + if(action == IOCP_ACT_CONTINUE) + continue; + else if(action == IOCP_ACT_BREAK) + break; + } + + TBufferObj* pBufferObj = CONTAINING_RECORD(pOverlapped, TBufferObj, ov); + CONNID dwConnID = pSocketObj->connID; + + if (!result) + { + DWORD dwFlag = 0; + DWORD dwSysCode = ::GetLastError(); + + if(pServer->HasStarted()) + { + SOCKET sock = pBufferObj->client; + result = ::WSAGetOverlappedResult(sock, &pBufferObj->ov, &dwBytes, FALSE, &dwFlag); + + if (!result) + { + dwErrorCode = ::WSAGetLastError(); + TRACE("GetQueuedCompletionStatus error ( SYS: %d, SOCK: %d, FLAG: %d)\n", dwConnID, dwSysCode, dwErrorCode, dwFlag); + } + } + else + dwErrorCode = dwSysCode; + + ASSERT(dwSysCode != 0 && dwErrorCode != 0); + } + + pServer->HandleIo(dwConnID, pSocketObj, pBufferObj, dwBytes, dwErrorCode); + } + + return 0; +} + +EnIocpAction CUdpAgent::CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey) +{ + ASSERT(pOverlapped == nullptr); + + EnIocpAction action = IOCP_ACT_CONTINUE; + + if(dwBytes == IOCP_CMD_SEND) + DoSend((CONNID)ulCompKey); + else if(dwBytes == IOCP_CMD_DISCONNECT) + ForceDisconnect((CONNID)ulCompKey); + else if(dwBytes == IOCP_CMD_EXIT && ulCompKey == 0) + action = IOCP_ACT_BREAK; + else + VERIFY(FALSE); + + return action; +} + +void CUdpAgent::ForceDisconnect(CONNID dwConnID) +{ + AddFreeSocketObj(FindSocketObj(dwConnID), SCF_CLOSE); +} + +void CUdpAgent::HandleIo(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode) +{ + ASSERT(pBufferObj != nullptr); + ASSERT(pSocketObj != nullptr); + + if(dwErrorCode != NO_ERROR) + { + HandleError(dwConnID, pSocketObj, pBufferObj, dwErrorCode); + return; + } + + if(dwBytes == 0 && pBufferObj->operation != SO_CONNECT) + { + AddFreeSocketObj(pSocketObj, SCF_CLOSE); + AddFreeBufferObj(pBufferObj); + return; + } + + pBufferObj->buff.len = dwBytes; + + switch(pBufferObj->operation) + { + case SO_CONNECT: + HandleConnect(dwConnID, pSocketObj, pBufferObj); + break; + case SO_SEND: + HandleSend(dwConnID, pSocketObj, pBufferObj); + break; + case SO_RECEIVE: + HandleReceive(dwConnID, pSocketObj, pBufferObj); + break; + default: + ASSERT(FALSE); + } +} + +void CUdpAgent::HandleError(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwErrorCode) +{ + CheckError(pSocketObj, pBufferObj->operation, dwErrorCode); + AddFreeBufferObj(pBufferObj); +} + +void CUdpAgent::HandleConnect(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + ::SSO_UpdateConnectContext(pBufferObj->client, 0); + + if(TriggerFireConnect(pSocketObj) != HR_ERROR) + DoReceive(dwConnID, pSocketObj, pBufferObj); + else + { + AddFreeSocketObj(pSocketObj, SCF_NONE); + AddFreeBufferObj(pBufferObj); + } +} + +void CUdpAgent::HandleSend(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + switch(m_enSendPolicy) + { + case SP_PACK: + { + long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount); + + TriggerFireSend(pSocketObj, pBufferObj); + if(sndCount == 0) DoSendPack(pSocketObj); + } + + break; + case SP_SAFE: + { + long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount); + + if(sndCount == 0 && !pSocketObj->smooth) + { + CCriSecLock locallock(pSocketObj->csSend); + + if((sndCount = pSocketObj->sndCount) == 0) + pSocketObj->smooth = TRUE; + } + + TriggerFireSend(pSocketObj, pBufferObj); + if(sndCount == 0) DoSendSafe(pSocketObj); + } + + break; + case SP_DIRECT: + { + TriggerFireSend(pSocketObj, pBufferObj); + } + + break; + default: + ASSERT(FALSE); + } +} + +void CUdpAgent::HandleReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime(); + EnHandleResult hr = TriggerFireReceive(pSocketObj, pBufferObj); + + if(hr == HR_OK || hr == HR_IGNORE) + DoReceive(dwConnID, pSocketObj, pBufferObj); + else if(hr == HR_CLOSED) + { + AddFreeBufferObj(pBufferObj); + } + else + { + TRACE(" OnReceive() event return 'HR_ERROR', connection will be closed !\n", dwConnID); + AddFreeSocketObj(pSocketObj, SCF_ERROR, SO_RECEIVE, ERROR_CANCELLED); + AddFreeBufferObj(pBufferObj); + } +} + +int CUdpAgent::DoReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + pBufferObj->buff.len = m_dwMaxDatagramSize; + int result =::PostReceive(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + CheckError(pSocketObj, SO_RECEIVE, result); + AddFreeBufferObj(pBufferObj); + } + + return result; +} + +BOOL CUdpAgent::Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID) +{ + ASSERT(pszRemoteAddress && usPort != 0); + + if(pdwConnID) *pdwConnID = 0; + + DWORD result = NO_ERROR; + SOCKET soClient = INVALID_SOCKET; + + if(!HasStarted()) + result = ERROR_INVALID_STATE; + else + { + result = CreateClientSocket(soClient); + + if(result == NO_ERROR) + { + CONNID dwConnID = ::GenerateConnectionID(); + if(pdwConnID) *pdwConnID = dwConnID; + + if(FirePrepareConnect(dwConnID, soClient) != HR_ERROR) + result = ConnectToServer(dwConnID, soClient, pszRemoteAddress, usPort); + else + result = ERROR_CANCELLED; + } + } + + if(result != NO_ERROR) + { + if(soClient != INVALID_SOCKET) + ::ManualCloseSocket(soClient); + + ::SetLastError(result); + } + + return (result == NO_ERROR); +} + +DWORD CUdpAgent::CreateClientSocket(SOCKET& soClient) +{ + DWORD result = NO_ERROR; + soClient = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if(soClient != INVALID_SOCKET) + { + VERIFY(::SSO_ReuseAddress(soClient, m_bReuseAddress) != SOCKET_ERROR); + + if(m_bAsyncConnect && ::bind(soClient, (SOCKADDR*)&m_soAddrIN, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) + result = ::WSAGetLastError(); + } + else + result = ::WSAGetLastError(); + + return result; +} + +DWORD CUdpAgent::ConnectToServer(CONNID dwConnID, SOCKET& soClient, LPCTSTR pszRemoteAddress, USHORT usPort) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + + if(!::GetIPAddress(pszRemoteAddress, szAddress, iAddressLen)) + return WSAEADDRNOTAVAIL; + + SOCKADDR_IN addr; + if(!::sockaddr_A_2_IN(AF_INET, szAddress, usPort, addr)) + return WSAEADDRNOTAVAIL; + + TBufferObj* pBufferObj = GetFreeBufferObj(); + TSocketObj* pSocketObj = GetFreeSocketObj(dwConnID, soClient); + + memcpy(&pSocketObj->remoteAddr, &addr, sizeof(SOCKADDR_IN)); + AddClientSocketObj(dwConnID, pSocketObj); + + DWORD result = NO_ERROR; + BOOL bNeedFree = TRUE; + + if(m_bAsyncConnect) + { + if(::CreateIoCompletionPort((HANDLE)soClient, m_hCompletePort, (ULONG_PTR)pSocketObj, 0)) + { + result = DoConnect(dwConnID, pSocketObj, pBufferObj); + bNeedFree = FALSE; + } + else + result = ::GetLastError(); + } + else + { + if(::connect(soClient, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)) != SOCKET_ERROR) + { + if(::CreateIoCompletionPort((HANDLE)soClient, m_hCompletePort, (ULONG_PTR)pSocketObj, 0)) + { + if(TriggerFireConnect(pSocketObj) != HR_ERROR) + { + result = DoReceive(dwConnID, pSocketObj, pBufferObj); + bNeedFree = FALSE; + } + else + result = ERROR_CANCELLED; + } + else + result = ::GetLastError(); + } + else + result = ::WSAGetLastError(); + } + + if(result != NO_ERROR) + { + if(bNeedFree) + { + AddFreeSocketObj(pSocketObj, SCF_NONE); + AddFreeBufferObj(pBufferObj); + } + + soClient = INVALID_SOCKET; + } + + return result; +} + +int CUdpAgent::DoConnect(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj) +{ + int result = ::PostConnect(m_pfnConnectEx, pSocketObj->socket, pSocketObj->remoteAddr, pBufferObj); + + if(result != NO_ERROR) + { + CheckError(pSocketObj, SO_CONNECT, result); + AddFreeBufferObj(pBufferObj); + } + + return result; +} + +BOOL CUdpAgent::Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset) +{ + ASSERT(pBuffer && iLength > 0); + + if(iOffset != 0) pBuffer += iOffset; + + WSABUF buffer; + buffer.len = iLength; + buffer.buf = (char*)pBuffer; + + return SendPackets(dwConnID, &buffer, 1); +} + +BOOL CUdpAgent::SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + TSocketObj* pSocketObj = nullptr; + + ASSERT(pBuffers && iCount > 0); + + if(pBuffers && iCount > 0) + { + pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + result = SendInternal(pSocketObj, pBuffers, iCount); + else + result = ERROR_OBJECT_NOT_FOUND; + } + else + result = ERROR_OBJECT_NOT_FOUND; + } + else + result = ERROR_INVALID_PARAMETER; + + if(result != NO_ERROR) + { + if(m_enSendPolicy == SP_DIRECT && TSocketObj::IsValid(pSocketObj)) + CheckError(pSocketObj, SO_SEND, result); + + ::SetLastError(result); + } + + return (result == NO_ERROR); +} + +int CUdpAgent::SendInternal(TSocketObj* pSocketObj, const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + + for(int i = 0; i < iCount; i++) + { + int iBufLen = pBuffers[i].len; + + if(iBufLen > 0) + { + BYTE* pBuffer = (BYTE*)pBuffers[i].buf; + ASSERT(pBuffer); + + switch(m_enSendPolicy) + { + case SP_PACK: result = SendPack(pSocketObj, pBuffer, iBufLen); break; + case SP_SAFE: result = SendSafe(pSocketObj, pBuffer, iBufLen); break; + case SP_DIRECT: result = SendDirect(pSocketObj, pBuffer, iBufLen); break; + default: ASSERT(FALSE); result = ERROR_INVALID_INDEX; break; + } + + if(result != NO_ERROR) + break; + } + } + + return result; +} + +int CUdpAgent::SendPack(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + BOOL isPostSend = !TSocketObj::IsPending(pSocketObj); + return CatAndPost(pSocketObj, pBuffer, iLength, isPostSend); +} + +int CUdpAgent::SendSafe(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + BOOL isPostSend = !TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj); + return CatAndPost(pSocketObj, pBuffer, iLength, isPostSend); +} + +int CUdpAgent::SendDirect(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + int result = NO_ERROR; + int iRemain = iLength; + + while(iRemain > 0) + { + int iBufferSize = min(iRemain, (int)m_dwMaxDatagramSize); + TBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize); + memcpy(pBufferObj->buff.buf, pBuffer, iBufferSize); + + result = ::PostSend(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + AddFreeBufferObj(pBufferObj); + break; + } + + iRemain -= iBufferSize; + pBuffer += iBufferSize; + } + + return result; +} + +int CUdpAgent::CatAndPost(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend) +{ + int result = NO_ERROR; + + pSocketObj->sndBuff.Cat(pBuffer, iLength); + pSocketObj->pending += iLength; + + if(isPostSend && !::PostIocpSend(m_hCompletePort, pSocketObj->connID)) + result = ::GetLastError(); + + return result; +} + +int CUdpAgent::DoSend(CONNID dwConnID) +{ + TSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TSocketObj::IsValid(pSocketObj)) + return DoSend(pSocketObj); + + return ERROR_OBJECT_NOT_FOUND; +} + +int CUdpAgent::DoSend(TSocketObj* pSocketObj) +{ + switch(m_enSendPolicy) + { + case SP_PACK: return DoSendPack(pSocketObj); + case SP_SAFE: return DoSendSafe(pSocketObj); + default: ASSERT(FALSE); return ERROR_INVALID_INDEX; + } +} + +int CUdpAgent::DoSendPack(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + if(TSocketObj::IsPending(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsValid(pSocketObj)) + result = SendItem(pSocketObj); + } + + if(!IOCP_SUCCESS(result)) + CheckError(pSocketObj, SO_SEND, result); + + return result; +} + +int CUdpAgent::DoSendSafe(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + if(TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj)) + { + pSocketObj->smooth = FALSE; + + result = SendItem(pSocketObj); + + if(result == NO_ERROR) + pSocketObj->smooth = TRUE; + } + } + + if(!IOCP_SUCCESS(result)) + CheckError(pSocketObj, SO_SEND, result); + + return result; +} + +int CUdpAgent::SendItem(TSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + while(pSocketObj->sndBuff.Size() > 0) + { + ::InterlockedIncrement(&pSocketObj->sndCount); + + TItemPtr itPtr(m_itPool, pSocketObj->sndBuff.PopFront()); + + int iBufferSize = itPtr->Size(); + ASSERT(iBufferSize > 0 && iBufferSize <= (int)m_dwMaxDatagramSize); + + pSocketObj->pending -= iBufferSize; + TBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize); + memcpy(pBufferObj->buff.buf, itPtr->Ptr(), iBufferSize); + + result = ::PostSendNotCheck(pSocketObj, pBufferObj); + + if(result != NO_ERROR) + { + if(result != WSA_IO_PENDING) + AddFreeBufferObj(pBufferObj); + + break; + } + } + + return result; +} + +void CUdpAgent::CheckError(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + if(iErrorCode != WSAENOTSOCK && iErrorCode != ERROR_OPERATION_ABORTED) + AddFreeSocketObj(pSocketObj, SCF_ERROR, enOperation, iErrorCode); +} diff --git a/HP-Socket/Src/UdpAgent.h b/HP-Socket/Src/UdpAgent.h new file mode 100644 index 000000000..6a0d78603 --- /dev/null +++ b/HP-Socket/Src/UdpAgent.h @@ -0,0 +1,261 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "SocketHelper.h" +#include "../../Common/Src/Event.h" +#include "../../Common/Src/RWLock.h" +#include "../../Common/Src/STLHelper.h" +#include "../../Common/Src/RingBuffer.h" +#include "../../Common/Src/PrivateHeap.h" + +class CUdpAgent : public IUdpAgent +{ +public: + CUdpAgent(IUdpAgentListener* psoListener) + : m_psoListener (psoListener) + , m_hCompletePort (nullptr) + , m_pfnConnectEx (nullptr) + , m_pfnDisconnectEx (nullptr) + , m_enLastError (SE_OK) + , m_enState (SS_STOPPED) + , m_bAsyncConnect (TRUE) + , m_enSendPolicy (SP_PACK) + , m_dwWorkerThreadCount (DEFAULT_WORKER_THREAD_COUNT) + , m_dwFreeSocketObjLockTime (DEFAULT_FREE_SOCKETOBJ_LOCK_TIME) + , m_dwFreeSocketObjPool (DEFAULT_FREE_SOCKETOBJ_POOL) + , m_dwFreeBufferObjPool (DEFAULT_FREE_BUFFEROBJ_POOL) + , m_dwFreeSocketObjHold (DEFAULT_FREE_SOCKETOBJ_HOLD) + , m_dwFreeBufferObjHold (DEFAULT_FREE_BUFFEROBJ_HOLD) + , m_dwMaxDatagramSize (DEFAULT_UDP_MAX_DATAGRAM_SIZE) + , m_dwDetectAttempts (DEFAULT_UDP_DETECT_ATTEMPTS) + , m_dwDetectInterval (DEFAULT_UDP_DETECT_INTERVAL) + , m_bReuseAddress (FALSE) + , m_bMarkSilence (FALSE) + { + ASSERT(m_wsSocket.IsValid()); + ASSERT(m_psoListener); + + Reset(FALSE); + } + + virtual ~CUdpAgent() + { + if(HasStarted()) + Stop(); + } + +public: + virtual BOOL Start (LPCTSTR pszBindAddress = nullptr, BOOL bAsyncConnect = TRUE); + virtual BOOL Stop (); + virtual BOOL Connect(LPCTSTR pszRemoteAddress, USHORT usPort, CONNID* pdwConnID = nullptr); + virtual BOOL Send (CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0); + virtual BOOL SendPackets (CONNID dwConnID, const WSABUF pBuffers[], int iCount); + virtual BOOL HasStarted () {return m_enState == SS_STARTED || m_enState == SS_STARTING;} + virtual EnServiceState GetState () {return m_enState;} + virtual BOOL Disconnect (CONNID dwConnID, BOOL bForce = TRUE); + virtual BOOL DisconnectLongConnections (DWORD dwPeriod, BOOL bForce = TRUE); + virtual BOOL DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce = TRUE); + virtual BOOL GetLocalAddress (CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + virtual BOOL GetRemoteAddress (CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + + virtual BOOL GetPendingDataLength (CONNID dwConnID, int& iPending); + virtual DWORD GetConnectionCount (); + virtual BOOL GetAllConnectionIDs (CONNID pIDs[], DWORD& dwCount); + virtual BOOL GetConnectPeriod (CONNID dwConnID, DWORD& dwPeriod); + virtual BOOL GetSilencePeriod (CONNID dwConnID, DWORD& dwPeriod); + virtual EnSocketError GetLastError () {return m_enLastError;} + virtual LPCTSTR GetLastErrorDesc () {return ::GetSocketErrorDesc(m_enLastError);} + +public: + virtual BOOL SetConnectionExtra(CONNID dwConnID, PVOID pExtra); + virtual BOOL GetConnectionExtra(CONNID dwConnID, PVOID* ppExtra); + + virtual void SetSendPolicy (EnSendPolicy enSendPolicy) {m_enSendPolicy = enSendPolicy;} + virtual void SetWorkerThreadCount (DWORD dwWorkerThreadCount) {m_dwWorkerThreadCount = dwWorkerThreadCount;} + virtual void SetFreeSocketObjLockTime (DWORD dwFreeSocketObjLockTime) {m_dwFreeSocketObjLockTime = dwFreeSocketObjLockTime;} + virtual void SetFreeSocketObjPool (DWORD dwFreeSocketObjPool) {m_dwFreeSocketObjPool = dwFreeSocketObjPool;} + virtual void SetFreeBufferObjPool (DWORD dwFreeBufferObjPool) {m_dwFreeBufferObjPool = dwFreeBufferObjPool;} + virtual void SetFreeSocketObjHold (DWORD dwFreeSocketObjHold) {m_dwFreeSocketObjHold = dwFreeSocketObjHold;} + virtual void SetFreeBufferObjHold (DWORD dwFreeBufferObjHold) {m_dwFreeBufferObjHold = dwFreeBufferObjHold;} + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) {m_dwMaxDatagramSize = dwMaxDatagramSize;} + virtual void SetDetectAttempts (DWORD dwDetectAttempts) {m_dwDetectAttempts = dwDetectAttempts;} + virtual void SetDetectInterval (DWORD dwDetectInterval) {m_dwDetectInterval = dwDetectInterval;} + virtual void SetReuseAddress (BOOL bReuseAddress) {m_bReuseAddress = bReuseAddress;} + virtual void SetMarkSilence (BOOL bMarkSilence) {m_bMarkSilence = bMarkSilence;} + + virtual EnSendPolicy GetSendPolicy () {return m_enSendPolicy;} + virtual DWORD GetWorkerThreadCount () {return m_dwWorkerThreadCount;} + virtual DWORD GetFreeSocketObjLockTime () {return m_dwFreeSocketObjLockTime;} + virtual DWORD GetFreeSocketObjPool () {return m_dwFreeSocketObjPool;} + virtual DWORD GetFreeBufferObjPool () {return m_dwFreeBufferObjPool;} + virtual DWORD GetFreeSocketObjHold () {return m_dwFreeSocketObjHold;} + virtual DWORD GetFreeBufferObjHold () {return m_dwFreeBufferObjHold;} + virtual DWORD GetMaxDatagramSize () {return m_dwMaxDatagramSize;} + virtual DWORD GetDetectAttempts () {return m_dwDetectAttempts;} + virtual DWORD GetDetectInterval () {return m_dwDetectInterval;} + virtual BOOL IsReuseAddress () {return m_bReuseAddress;} + virtual BOOL IsMarkSilence () {return m_bMarkSilence;} + +protected: + virtual EnHandleResult FirePrepareConnect(CONNID dwConnID, SOCKET socket) + {return m_psoListener->OnPrepareConnect(dwConnID, socket);} + virtual EnHandleResult FireConnect(TSocketObj* pSocketObj) + {return m_psoListener->OnConnect(pSocketObj->connID);} + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return m_psoListener->OnReceive(pSocketObj->connID, pData, iLength);} + virtual EnHandleResult FireReceive(TSocketObj* pSocketObj, int iLength) + {return m_psoListener->OnReceive(pSocketObj->connID, iLength);} + virtual EnHandleResult FireSend(TSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return m_psoListener->OnSend(pSocketObj->connID, pData, iLength);} + virtual EnHandleResult FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) + {return m_psoListener->OnClose(pSocketObj->connID, enOperation, iErrorCode);} + virtual EnHandleResult FireShutdown() + {return m_psoListener->OnShutdown();} + + void SetLastError(EnSocketError code, LPCSTR func, int ec); + virtual BOOL CheckParams(); + virtual void PrepareStart(); + virtual void Reset(BOOL bAll = TRUE); + +private: + EnHandleResult TriggerFireConnect(TSocketObj* pSocketObj); + EnHandleResult TriggerFireReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj); + EnHandleResult TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj); + EnHandleResult TriggerFireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + +protected: + BOOL SetConnectionExtra(TSocketObj* pSocketObj, PVOID pExtra); + BOOL GetConnectionExtra(TSocketObj* pSocketObj, PVOID* ppExtra); + BOOL SetConnectionReserved(CONNID dwConnID, PVOID pReserved); + BOOL GetConnectionReserved(CONNID dwConnID, PVOID* ppReserved); + BOOL SetConnectionReserved(TSocketObj* pSocketObj, PVOID pReserved); + BOOL GetConnectionReserved(TSocketObj* pSocketObj, PVOID* ppReserved); + +private: + BOOL CheckStarting(); + BOOL CheckStoping(); + BOOL ParseBindAddress(LPCTSTR pszBindAddress, BOOL bAsyncConnect); + BOOL CreateCompletePort(); + BOOL CreateWorkerThreads(); + + void DisconnectClientSocket(); + void WaitForClientSocketClose(); + void ReleaseClientSocket(); + void ReleaseFreeSocket(); + void ReleaseFreeBuffer(); + void WaitForWorkerThreadEnd(); + void CloseCompletePort(); + + TBufferObj* GetFreeBufferObj(int iLen = 0); + TSocketObj* GetFreeSocketObj(CONNID dwConnID, SOCKET soClient); + void AddFreeBufferObj(TBufferObj* pBufferObj); + void AddFreeSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0); + TBufferObj* CreateBufferObj(); + TSocketObj* CreateSocketObj(); + void DeleteBufferObj(TBufferObj* pBufferObj); + void DeleteSocketObj(TSocketObj* pSocketObj); + BOOL InvalidSocketObj(TSocketObj* pSocketObj); + void ReleaseGCSocketObj(BOOL bForce = FALSE); + + void AddClientSocketObj(CONNID dwConnID, TSocketObj* pSocketObj); + void CloseClientSocketObj(TSocketObj* pSocketObj, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0, int iShutdownFlag = SD_SEND); + TSocketObj* FindSocketObj(CONNID dwConnID); + +private: + static UINT WINAPI WorkerThreadProc(LPVOID pv); + + EnIocpAction CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey); + + DWORD CreateClientSocket(SOCKET& soClient); + DWORD ConnectToServer (CONNID dwConnID, SOCKET& soClient, LPCTSTR pszRemoteAddress, USHORT usPort); + void ForceDisconnect (CONNID dwConnID); + + void HandleIo (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode); + void HandleError (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwErrorCode); + void HandleConnect (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + void HandleSend (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + void HandleReceive (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + + int SendInternal(TSocketObj* pSocketObj, const WSABUF pBuffers[], int iCount); + int SendPack (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int SendSafe (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int SendDirect (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int CatAndPost (TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend); + + int DoConnect (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + int DoReceive (CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj); + + int DoSend (CONNID dwConnID); + int DoSend (TSocketObj* pSocketObj); + int DoSendPack (TSocketObj* pSocketObj); + int DoSendSafe (TSocketObj* pSocketObj); + int SendItem (TSocketObj* pSocketObj); + + void CheckError (TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + +private: + + + EnSendPolicy m_enSendPolicy; + DWORD m_dwWorkerThreadCount; + DWORD m_dwFreeSocketObjLockTime; + DWORD m_dwFreeSocketObjPool; + DWORD m_dwFreeBufferObjPool; + DWORD m_dwFreeSocketObjHold; + DWORD m_dwFreeBufferObjHold; + DWORD m_dwMaxDatagramSize; + DWORD m_dwDetectAttempts; + DWORD m_dwDetectInterval; + BOOL m_bReuseAddress; + BOOL m_bMarkSilence; + +private: + CInitSocket m_wsSocket; + LPFN_CONNECTEX m_pfnConnectEx; + LPFN_DISCONNECTEX m_pfnDisconnectEx; + +private: + IUdpAgentListener* m_psoListener; + BOOL m_bAsyncConnect; + HANDLE m_hCompletePort; + EnServiceState m_enState; + EnSocketError m_enLastError; + SOCKADDR_IN m_soAddrIN; + vector m_vtWorkerThreads; + + CPrivateHeap m_phBuffer; + CPrivateHeap m_phSocket; + CItemPool m_itPool; + + CSpinGuard m_csState; + + CRWLock m_csClientSocket; + TSocketObjPtrMap m_mpClientSocket; + + TBufferObjPtrList m_lsFreeBuffer; + TSocketObjPtrList m_lsFreeSocket; + TSocketObjPtrQueue m_lsGCSocket; +}; diff --git a/HP-Socket/Src/UdpCast.cpp b/HP-Socket/Src/UdpCast.cpp new file mode 100644 index 000000000..0697278ef --- /dev/null +++ b/HP-Socket/Src/UdpCast.cpp @@ -0,0 +1,650 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "UdpCast.h" +#include "../../Common/Src/WaitFor.h" + +#include + +BOOL CUdpCast::Start(LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect) +{ + if(!CheckParams() || !CheckStarting()) + return FALSE; + + PrepareStart(); + + BOOL isOK = FALSE; + + if(CreateClientSocket()) + { + if(FirePrepareConnect(this, m_soClient) != HR_ERROR) + { + if(ConnectToGroup(pszRemoteAddress, usPort)) + { + if(CreateWorkerThread()) + { + isOK = TRUE; + } + else + SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ERROR_CREATE_FAILED); + } + else + SetLastError(SE_CONNECT_SERVER, __FUNCTION__, ::WSAGetLastError()); + } + else + SetLastError(SE_SOCKET_PREPARE, __FUNCTION__, ERROR_CANCELLED); + } + else + SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError()); + + if(!isOK) Stop(); + + return isOK; +} + +BOOL CUdpCast::CheckParams() +{ + if((int)m_dwMaxDatagramSize > 0) + if((int)m_dwFreeBufferPoolSize >= 0) + if((int)m_dwFreeBufferPoolHold >= 0) + if(m_enCastMode >= CM_MULTICAST && m_enCastMode <= CM_BROADCAST) + if(m_iMCTtl >= 0 && m_iMCTtl <= 255) + if(m_bMCLoop >= 0 && m_bMCLoop <= 1) + if(::IsIPAddress(m_strBindAddress)) + return TRUE; + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CUdpCast::PrepareStart() +{ + m_itPool.SetItemCapacity((int)m_dwMaxDatagramSize); + m_itPool.SetPoolSize((int)m_dwFreeBufferPoolSize); + m_itPool.SetPoolHold((int)m_dwFreeBufferPoolHold); + + m_itPool.Prepare(); +} + +BOOL CUdpCast::CheckStarting() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STOPPED) + m_enState = SS_STARTING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CUdpCast::CheckStoping() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STARTED || m_enState == SS_STARTING) + m_enState = SS_STOPPING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CUdpCast::CreateClientSocket() +{ + m_soClient = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if(m_soClient != INVALID_SOCKET) + { + VERIFY(::SSO_UDP_ConnReset(m_soClient, FALSE) == NO_ERROR); + VERIFY(::SSO_ReuseAddress(m_soClient, m_bReuseAddress) != SOCKET_ERROR); + + m_evSocket = ::WSACreateEvent(); + ASSERT(m_evSocket != WSA_INVALID_EVENT); + + m_dwConnID = ::GenerateConnectionID(); + + return TRUE; + } + + return FALSE; +} + +BOOL CUdpCast::ConnectToGroup(LPCTSTR pszRemoteAddress, USHORT usPort) +{ + if(m_enCastMode == CM_MULTICAST) + { + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + + if(!::GetIPAddress(pszRemoteAddress, szAddress, iAddressLen)) + { + ::WSASetLastError(WSAEADDRNOTAVAIL); + return FALSE; + } + + if(!::sockaddr_A_2_IN(AF_INET, szAddress, usPort, m_castAddr)) + { + ::WSASetLastError(WSAEADDRNOTAVAIL); + return FALSE; + } + + VERIFY(::SSO_SetSocketOption(m_soClient, IPPROTO_IP, IP_MULTICAST_TTL, &m_iMCTtl, sizeof(int)) != SOCKET_ERROR); + VERIFY(::SSO_SetSocketOption(m_soClient, IPPROTO_IP, IP_MULTICAST_LOOP, &m_bMCLoop, sizeof(BOOL)) != SOCKET_ERROR); + } + else + { + m_castAddr.sin_family = AF_INET; + m_castAddr.sin_addr.s_addr = INADDR_BROADCAST; + m_castAddr.sin_port = htons(usPort); + + BOOL bSet = TRUE; + VERIFY(::SSO_SetSocketOption(m_soClient, SOL_SOCKET, SO_BROADCAST, &bSet, sizeof(BOOL)) != SOCKET_ERROR); + } + + SOCKADDR_IN bindAddr; + if(!::sockaddr_A_2_IN(AF_INET, m_strBindAddress, usPort, bindAddr)) + { + ::WSASetLastError(WSAEADDRNOTAVAIL); + return FALSE; + } + + if(::bind(m_soClient, (struct sockaddr*)&bindAddr, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) + return FALSE; + else + { + if(m_enCastMode == CM_MULTICAST) + { + ip_mreq mcast; + ::ZeroMemory(&mcast, sizeof(ip_mreq)); + + mcast.imr_multiaddr = m_castAddr.sin_addr; + mcast.imr_interface = bindAddr.sin_addr; + + if(::SSO_SetSocketOption(m_soClient, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast, sizeof(ip_mreq)) == SOCKET_ERROR) + return FALSE; + } + } + + BOOL isOK = FALSE; + + if(::WSAEventSelect(m_soClient, m_evSocket, FD_READ | FD_WRITE | FD_CLOSE) != SOCKET_ERROR) + { + if(FireConnect(this) != HR_ERROR) + { + m_enState = SS_STARTED; + isOK = TRUE; + } + } + + return isOK; +} + +BOOL CUdpCast::CreateWorkerThread() +{ + m_hWorker = (HANDLE)_beginthreadex(nullptr, 0, WorkerThreadProc, (LPVOID)this, 0, &m_dwWorkerID); + + return m_hWorker != nullptr; +} + +UINT WINAPI CUdpCast::WorkerThreadProc(LPVOID pv) +{ + TRACE("---------------> Client Worker Thread 0x%08X started <---------------\n", ::GetCurrentThreadId()); + + CUdpCast* pClient = (CUdpCast*)pv; + HANDLE hEvents[] = {pClient->m_evSocket, pClient->m_evBuffer, pClient->m_evWorker}; + + pClient->m_rcBuffer.Malloc(pClient->m_dwMaxDatagramSize); + + while(pClient->HasStarted()) + { + DWORD retval = ::WSAWaitForMultipleEvents(3, hEvents, FALSE, WSA_INFINITE, FALSE); + + if(retval == WSA_WAIT_EVENT_0) + { + if(!pClient->ProcessNetworkEvent()) + { + if(pClient->HasStarted()) + pClient->Stop(); + + break; + } + } + else if(retval == WSA_WAIT_EVENT_0 + 1) + { + if(!pClient->SendData()) + { + if(pClient->HasStarted()) + pClient->Stop(); + + break; + } + } + else if(retval == WSA_WAIT_EVENT_0 + 2) + break; + else + ASSERT(FALSE); + } + + TRACE("---------------> Client Worker Thread 0x%08X stoped <---------------\n", ::GetCurrentThreadId()); + + return 0; +} + +BOOL CUdpCast::ProcessNetworkEvent() +{ + BOOL bContinue = TRUE; + WSANETWORKEVENTS events; + + int rc = ::WSAEnumNetworkEvents(m_soClient, m_evSocket, &events); + + if(rc == SOCKET_ERROR) + bContinue = HandleError(events); + + if(bContinue && events.lNetworkEvents & FD_READ) + bContinue = HandleRead(events); + + if(bContinue && events.lNetworkEvents & FD_WRITE) + bContinue = HandleWrite(events); + + if(bContinue && events.lNetworkEvents & FD_CLOSE) + bContinue = HandleClose(events); + + return bContinue; +} + +BOOL CUdpCast::HandleError(WSANETWORKEVENTS& events) +{ + int iCode = ::WSAGetLastError(); + EnSocketOperation enOperation = SO_UNKNOWN; + + if(events.lNetworkEvents & FD_CLOSE) + enOperation = SO_CLOSE; + else if(events.lNetworkEvents & FD_READ) + enOperation = SO_RECEIVE; + else if(events.lNetworkEvents & FD_WRITE) + enOperation = SO_SEND; + + VERIFY(::WSAResetEvent(m_evSocket)); + FireClose(this, enOperation, iCode); + + return FALSE; +} + +BOOL CUdpCast::HandleRead(WSANETWORKEVENTS& events) +{ + BOOL bContinue = TRUE; + int iCode = events.iErrorCode[FD_READ_BIT]; + + if(iCode == 0) + bContinue = ReadData(); + else + { + FireClose(this, SO_RECEIVE, iCode); + bContinue = FALSE; + } + + return bContinue; +} + +BOOL CUdpCast::HandleWrite(WSANETWORKEVENTS& events) +{ + BOOL bContinue = TRUE; + int iCode = events.iErrorCode[FD_WRITE_BIT]; + + if(iCode == 0) + bContinue = SendData(); + else + { + FireClose(this, SO_SEND, iCode); + bContinue = FALSE; + } + + return bContinue; +} + +BOOL CUdpCast::HandleClose(WSANETWORKEVENTS& events) +{ + int iCode = events.iErrorCode[FD_CLOSE_BIT]; + + if(iCode == 0) + FireClose(this, SO_CLOSE, SE_OK); + else + FireClose(this, SO_CLOSE, iCode); + + return FALSE; +} + +BOOL CUdpCast::ReadData() +{ + while(TRUE) + { + int addrLen = sizeof(SOCKADDR_IN); + int rc = recvfrom(m_soClient, (char*)(BYTE*)m_rcBuffer, m_dwMaxDatagramSize, 0, (sockaddr*)&m_remoteAddr, &addrLen); + + if(rc >= 0) + { + if(FireReceive(this, m_rcBuffer, rc) == HR_ERROR) + { + TRACE(" OnReceive() event return 'HR_ERROR', connection will be closed !\n", m_dwConnID); + + FireClose(this, SO_RECEIVE, ERROR_CANCELLED); + return FALSE; + } + } + else if(rc == SOCKET_ERROR) + { + int code = ::WSAGetLastError(); + + if(code == WSAEWOULDBLOCK) + break; + else + { + FireClose(this, SO_RECEIVE, code); + return FALSE; + } + } + else + ASSERT(FALSE); + } + + return TRUE; +} + +BOOL CUdpCast::SendData() +{ + while(TRUE) + { + TItemPtr itPtr(m_itPool, GetSendBuffer()); + + if(itPtr.IsValid()) + { + ASSERT(!itPtr->IsEmpty()); + + int rc = 0; + + { + CCriSecLock locallock(m_csSend); + + rc = sendto(m_soClient, (char*)itPtr->Ptr(), itPtr->Size(), 0, (sockaddr*)&m_castAddr, sizeof(SOCKADDR_IN)); + if(rc > 0) m_iPending -= rc; + } + + if(rc > 0) + { + ASSERT(rc == itPtr->Size()); + + if(FireSend(this, itPtr->Ptr(), rc) == HR_ERROR) + { + TRACE(" OnSend() event should not return 'HR_ERROR' !!\n", m_dwConnID); + ASSERT(FALSE); + } + } + else if(rc == SOCKET_ERROR) + { + int iCode = ::WSAGetLastError(); + + if(iCode == WSAEWOULDBLOCK) + { + CCriSecLock locallock(m_csSend); + m_lsSend.PushFront(itPtr.Detach()); + break; + } + else + { + FireClose(this, SO_SEND, iCode); + return FALSE; + } + } + else + ASSERT(FALSE); + } + else + break; + } + + return TRUE; +} + +TItem* CUdpCast::GetSendBuffer() +{ + TItem* pItem = nullptr; + + if(m_lsSend.Size() > 0) + { + CCriSecLock locallock(m_csSend); + + if(m_lsSend.Size() > 0) + pItem = m_lsSend.PopFront(); + } + + return pItem; +} + +BOOL CUdpCast::Stop() +{ + BOOL bNeedFireClose = FALSE; + EnServiceState enCurState = m_enState; + DWORD dwCurrentThreadID = ::GetCurrentThreadId(); + + if(!CheckStoping()) + return FALSE; + + if( enCurState == SS_STARTED && + dwCurrentThreadID != m_dwWorkerID ) + bNeedFireClose = TRUE; + + WaitForWorkerThreadEnd(dwCurrentThreadID); + + if(bNeedFireClose) + FireClose(this, SO_CLOSE, SE_OK); + + if(m_evSocket != nullptr) + { + ::WSACloseEvent(m_evSocket); + m_evSocket = nullptr; + } + + if(m_soClient != INVALID_SOCKET) + { + shutdown(m_soClient, SD_SEND); + closesocket(m_soClient); + m_soClient = INVALID_SOCKET; + } + + Reset(); + + return TRUE; +} + +void CUdpCast::Reset(BOOL bAll) +{ + if(bAll) + { + m_rcBuffer.Free(); + m_evBuffer.Reset(); + m_evWorker.Reset(); + m_evDetector.Reset(); + m_lsSend.Clear(); + m_itPool.Clear(); + } + + ::ZeroMemory(&m_castAddr, sizeof(SOCKADDR_IN)); + ::ZeroMemory(&m_remoteAddr, sizeof(SOCKADDR_IN)); + + m_iPending = 0; + m_enState = SS_STOPPED; +} + +void CUdpCast::WaitForWorkerThreadEnd(DWORD dwCurrentThreadID) +{ + if(m_hWorker != nullptr) + { + if(dwCurrentThreadID != m_dwWorkerID) + { + m_evWorker.Set(); + VERIFY(::WaitForSingleObject(m_hWorker, INFINITE) == WAIT_OBJECT_0); + } + + ::CloseHandle(m_hWorker); + + m_hWorker = nullptr; + m_dwWorkerID = 0; + } +} + +BOOL CUdpCast::Send(const BYTE* pBuffer, int iLength, int iOffset) +{ + int result = NO_ERROR; + EnSocketError enCode = SE_OK; + + ASSERT(pBuffer && iLength > 0 && iLength <= (int)m_dwMaxDatagramSize); + + if(pBuffer && iLength > 0 && iLength <= (int)m_dwMaxDatagramSize) + { + if(iOffset != 0) pBuffer += iOffset; + result = SendInternal(pBuffer, iLength, enCode); + } + else + { + result = ERROR_INVALID_PARAMETER; + enCode = SE_INVALID_PARAM; + } + + if(result != NO_ERROR) + ::SetLastError(result); + + return (result == NO_ERROR); +} + +BOOL CUdpCast::SendPackets(const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + EnSocketError enCode = SE_OK; + + ASSERT(pBuffers && iCount > 0); + + if(pBuffers && iCount > 0) + { + int iLength = 0; + int iMaxLen = (int)m_dwMaxDatagramSize; + + TItemPtr itPtr(m_itPool, m_itPool.PickFreeItem()); + + for(int i = 0; i < iCount; i++) + { + int iBufLen = pBuffers[i].len; + + if(iBufLen > 0) + { + BYTE* pBuffer = (BYTE*)pBuffers[i].buf; + ASSERT(pBuffer); + + iLength += iBufLen; + + if(iLength <= iMaxLen) + itPtr->Cat(pBuffer, iBufLen); + else + break; + } + } + + if(iLength > 0 && iLength <= iMaxLen) + result = SendInternal(itPtr->Ptr(), iLength, enCode); + else + { + result = ERROR_INCORRECT_SIZE; + enCode = SE_INVALID_PARAM; + } + } + else + { + result = ERROR_INVALID_PARAMETER; + enCode = SE_INVALID_PARAM; + } + + if(result != NO_ERROR) + ::SetLastError(result); + + return (result == NO_ERROR); +} + +int CUdpCast::SendInternal(const BYTE* pBuffer, int iLength, EnSocketError& enCode) +{ + int result = NO_ERROR; + + if(HasStarted()) + { + CCriSecLock locallock(m_csSend); + + if(HasStarted()) + { + ASSERT(m_iPending >= 0); + + BOOL isPending = m_iPending > 0; + + TItem* pItem = m_itPool.PickFreeItem(); + pItem->Cat(pBuffer, iLength); + m_lsSend.PushBack(pItem); + + m_iPending += iLength; + + if(!isPending) m_evBuffer.Set(); + } + else + { + result = ERROR_INVALID_STATE; + enCode = SE_ILLEGAL_STATE; + } + } + else + { + result = ERROR_INVALID_STATE; + enCode = SE_ILLEGAL_STATE; + } + + return result; +} + +void CUdpCast::SetLastError(EnSocketError code, LPCSTR func, int ec) +{ + TRACE("%s --> Error: %d, EC: %d\n", func, code, ec); + + m_enLastError = code; + ::SetLastError(ec); +} + +BOOL CUdpCast::GetLocalAddress(TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + return ::GetSocketLocalAddress(m_soClient, lpszAddress, iAddressLen, usPort); +} diff --git a/HP-Socket/Src/UdpCast.h b/HP-Socket/Src/UdpCast.h new file mode 100644 index 000000000..37e8f95b0 --- /dev/null +++ b/HP-Socket/Src/UdpCast.h @@ -0,0 +1,197 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "SocketHelper.h" +#include "../../Common/Src/Event.h" +#include "../../Common/Src/bufferptr.h" +#include "../../Common/Src/bufferpool.h" +#include "../../Common/Src/CriticalSection.h" + +class CUdpCast : public IUdpCast +{ +public: + virtual BOOL Start (LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect = FALSE); + virtual BOOL Stop (); + virtual BOOL Send (const BYTE* pBuffer, int iLength, int iOffset = 0); + virtual BOOL SendPackets (const WSABUF pBuffers[], int iCount); + virtual BOOL HasStarted () {return m_enState == SS_STARTED || m_enState == SS_STARTING;} + virtual EnServiceState GetState () {return m_enState;} + virtual CONNID GetConnectionID () {return m_dwConnID;}; + virtual BOOL GetLocalAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + virtual BOOL GetPendingDataLength (int& iPending) {iPending = m_iPending; return HasStarted();} + virtual EnSocketError GetLastError () {return m_enLastError;} + virtual LPCTSTR GetLastErrorDesc () {return ::GetSocketErrorDesc(m_enLastError);} + +public: + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) {m_dwMaxDatagramSize = dwMaxDatagramSize;} + virtual void SetFreeBufferPoolSize (DWORD dwFreeBufferPoolSize) {m_dwFreeBufferPoolSize = dwFreeBufferPoolSize;} + virtual void SetFreeBufferPoolHold (DWORD dwFreeBufferPoolHold) {m_dwFreeBufferPoolHold = dwFreeBufferPoolHold;} + virtual void SetReuseAddress (BOOL bReuseAddress) {m_bReuseAddress = bReuseAddress;} + virtual void SetBindAdddress (LPCTSTR pszBindAddress) {m_strBindAddress = pszBindAddress;} + virtual void SetCastMode (EnCastMode enCastMode) {m_enCastMode = enCastMode;} + virtual void SetMultiCastTtl (int iMCTtl) {m_iMCTtl = iMCTtl;} + virtual void SetMultiCastLoop (BOOL bMCLoop) {m_bMCLoop = bMCLoop;} + virtual void SetExtra (PVOID pExtra) {m_pExtra = pExtra;} + + virtual DWORD GetMaxDatagramSize () {return m_dwMaxDatagramSize;} + virtual DWORD GetFreeBufferPoolSize () {return m_dwFreeBufferPoolSize;} + virtual DWORD GetFreeBufferPoolHold () {return m_dwFreeBufferPoolHold;} + virtual BOOL IsReuseAddress () {return m_bReuseAddress;} + virtual LPCTSTR GetBindAdddress () {return (LPCTSTR)m_strBindAddress;} + virtual EnCastMode GetCastMode () {return m_enCastMode;} + virtual int GetMultiCastTtl () {return m_iMCTtl;} + virtual BOOL IsMultiCastLoop () {return m_bMCLoop;} + virtual PVOID GetExtra () {return m_pExtra;} + + virtual BOOL GetRemoteAddress(TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) + { + ADDRESS_FAMILY usFamily; + return ::sockaddr_IN_2_A(m_remoteAddr, usFamily, lpszAddress, iAddressLen, usPort); + } + +protected: + virtual EnHandleResult FirePrepareConnect(IClient* pClient, SOCKET socket) + {return m_psoListener->OnPrepareConnect(pClient, socket);} + virtual EnHandleResult FireConnect(IClient* pClient) + {return m_psoListener->OnConnect(pClient);} + virtual EnHandleResult FireSend(IClient* pClient, const BYTE* pData, int iLength) + {return m_psoListener->OnSend(pClient, pData, iLength);} + virtual EnHandleResult FireReceive(IClient* pClient, const BYTE* pData, int iLength) + {return m_psoListener->OnReceive(pClient, pData, iLength);} + virtual EnHandleResult FireReceive(IClient* pClient, int iLength) + {return m_psoListener->OnReceive(pClient, iLength);} + virtual EnHandleResult FireClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) + {return m_psoListener->OnClose(pClient, enOperation, iErrorCode);} + + void SetLastError(EnSocketError code, LPCSTR func, int ec); + virtual BOOL CheckParams(); + virtual void PrepareStart(); + virtual void Reset(BOOL bAll = TRUE); + +protected: + void SetReserved (PVOID pReserved) {m_pReserved = pReserved;} + PVOID GetReserved () {return m_pReserved;} + +private: + BOOL CheckStarting(); + BOOL CheckStoping(); + BOOL CreateClientSocket(); + BOOL ConnectToGroup(LPCTSTR pszRemoteAddress, USHORT usPort); + BOOL CreateWorkerThread(); + BOOL CreateDetectorThread(); + BOOL ProcessNetworkEvent(); + BOOL ReadData(); + BOOL SendData(); + TItem* GetSendBuffer(); + int SendInternal(const BYTE* pBuffer, int iLength, EnSocketError& enCode); + void WaitForWorkerThreadEnd(DWORD dwCurrentThreadID); + + BOOL HandleError(WSANETWORKEVENTS& events); + BOOL HandleRead(WSANETWORKEVENTS& events); + BOOL HandleWrite(WSANETWORKEVENTS& events); + BOOL HandleConnect(WSANETWORKEVENTS& events); + BOOL HandleClose(WSANETWORKEVENTS& events); + + static UINT WINAPI WorkerThreadProc(LPVOID pv); + +public: + CUdpCast(IUdpCastListener* psoListener) + : m_psoListener (psoListener) + , m_lsSend (m_itPool) + , m_soClient (INVALID_SOCKET) + , m_evSocket (nullptr) + , m_dwConnID (0) + , m_hWorker (nullptr) + , m_dwWorkerID (0) + , m_iPending (0) + , m_enState (SS_STOPPED) + , m_enLastError (SE_OK) + , m_pExtra (nullptr) + , m_pReserved (nullptr) + , m_dwMaxDatagramSize (DEFAULT_UDP_MAX_DATAGRAM_SIZE) + , m_dwFreeBufferPoolSize(DEFAULT_CLIENT_FREE_BUFFER_POOL_SIZE) + , m_dwFreeBufferPoolHold(DEFAULT_CLIENT_FREE_BUFFER_POOL_HOLD) + , m_bReuseAddress (FALSE) + , m_iMCTtl (1) + , m_bMCLoop (FALSE) + , m_enCastMode (CM_MULTICAST) + , m_strBindAddress (DEFAULT_BIND_ADDRESS) + { + ASSERT(m_psoListener); + Reset(FALSE); + } + + virtual ~CUdpCast() {if(HasStarted()) Stop();} + +private: + CInitSocket m_wsSocket; + +private: + IUdpCastListener* m_psoListener; + + SOCKET m_soClient; + HANDLE m_evSocket; + CONNID m_dwConnID; + + BOOL m_bReuseAddress; + DWORD m_dwMaxDatagramSize; + DWORD m_dwFreeBufferPoolSize; + DWORD m_dwFreeBufferPoolHold; + + int m_iMCTtl; + BOOL m_bMCLoop; + EnCastMode m_enCastMode; + CString m_strBindAddress; + + HANDLE m_hWorker; + UINT m_dwWorkerID; + + EnServiceState m_enState; + EnSocketError m_enLastError; + + PVOID m_pExtra; + PVOID m_pReserved; + + SOCKADDR_IN m_castAddr; + SOCKADDR_IN m_remoteAddr; + + CBufferPtr m_rcBuffer; + +protected: + CItemPool m_itPool; + + CSpinGuard m_csState; + +private: + CCriSec m_csSend; + TItemList m_lsSend; + + CEvt m_evBuffer; + CEvt m_evWorker; + CEvt m_evDetector; + + volatile int m_iPending; +}; diff --git a/HP-Socket/Src/UdpClient.cpp b/HP-Socket/Src/UdpClient.cpp new file mode 100644 index 000000000..115a20e4f --- /dev/null +++ b/HP-Socket/Src/UdpClient.cpp @@ -0,0 +1,748 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "UdpClient.h" +#include "../../Common/Src/WaitFor.h" + +#include + +BOOL CUdpClient::Start(LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect) +{ + if(!CheckParams() || !CheckStarting()) + return FALSE; + + PrepareStart(); + + BOOL isOK = FALSE; + m_bAsyncConnect = bAsyncConnect; + + if(CreateClientSocket()) + { + if(FirePrepareConnect(this, m_soClient) != HR_ERROR) + { + if(ConnectToServer(pszRemoteAddress, usPort)) + { + if(CreateWorkerThread()) + { + if(CreateDetectorThread()) + isOK = TRUE; + else + SetLastError(SE_DETECT_THREAD_CREATE, __FUNCTION__, ERROR_CREATE_FAILED); + } + else + SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ERROR_CREATE_FAILED); + } + else + SetLastError(SE_CONNECT_SERVER, __FUNCTION__, ::WSAGetLastError()); + } + else + SetLastError(SE_SOCKET_PREPARE, __FUNCTION__, ERROR_CANCELLED); + } + else + SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError()); + + if(!isOK) Stop(); + + return isOK; +} + +BOOL CUdpClient::CheckParams() +{ + if((int)m_dwMaxDatagramSize > 0) + if((int)m_dwFreeBufferPoolSize >= 0) + if((int)m_dwFreeBufferPoolHold >= 0) + if((int)m_dwDetectAttempts >= 0) + if((int)m_dwDetectInterval >= 0) + return TRUE; + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CUdpClient::PrepareStart() +{ + m_itPool.SetItemCapacity((int)m_dwMaxDatagramSize); + m_itPool.SetPoolSize((int)m_dwFreeBufferPoolSize); + m_itPool.SetPoolHold((int)m_dwFreeBufferPoolHold); + + m_itPool.Prepare(); +} + +BOOL CUdpClient::CheckStarting() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STOPPED) + m_enState = SS_STARTING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CUdpClient::CheckStoping() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STARTED || m_enState == SS_STARTING) + m_enState = SS_STOPPING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CUdpClient::CreateClientSocket() +{ + m_soClient = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if(m_soClient != INVALID_SOCKET) + { + VERIFY(::SSO_UDP_ConnReset(m_soClient, FALSE) == NO_ERROR); + + m_evSocket = ::WSACreateEvent(); + ASSERT(m_evSocket != WSA_INVALID_EVENT); + + m_dwConnID = ::GenerateConnectionID(); + + return TRUE; + } + + return FALSE; +} + +BOOL CUdpClient::ConnectToServer(LPCTSTR pszRemoteAddress, USHORT usPort) +{ + TCHAR szAddress[40]; + int iAddressLen = sizeof(szAddress) / sizeof(TCHAR); + + if(!::GetIPAddress(pszRemoteAddress, szAddress, iAddressLen)) + return FALSE; + + SOCKADDR_IN addr; + if(!::sockaddr_A_2_IN(AF_INET, szAddress, usPort, addr)) + { + ::WSASetLastError(WSAEADDRNOTAVAIL); + return FALSE; + } + + BOOL isOK = FALSE; + + if(m_bAsyncConnect) + { + if(::WSAEventSelect(m_soClient, m_evSocket, FD_CONNECT | FD_CLOSE) != SOCKET_ERROR) + { + int rc = ::connect(m_soClient, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)); + isOK = (rc == NO_ERROR || (rc == SOCKET_ERROR && ::WSAGetLastError() == WSAEWOULDBLOCK)); + } + } + else + { + if(::connect(m_soClient, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)) != SOCKET_ERROR) + { + if(::WSAEventSelect(m_soClient, m_evSocket, FD_READ | FD_WRITE | FD_CLOSE) != SOCKET_ERROR) + { + if(FireConnect(this) != HR_ERROR) + { + VERIFY(NeedDetectorThread() || DetectConnection() == NO_ERROR); + + m_enState = SS_STARTED; + isOK = TRUE; + } + } + } + } + + return isOK; +} + +BOOL CUdpClient::CreateWorkerThread() +{ + m_hWorker = (HANDLE)_beginthreadex(nullptr, 0, WorkerThreadProc, (LPVOID)this, 0, &m_dwWorkerID); + + return m_hWorker != nullptr; +} + +UINT WINAPI CUdpClient::WorkerThreadProc(LPVOID pv) +{ + TRACE("---------------> Client Worker Thread 0x%08X started <---------------\n", ::GetCurrentThreadId()); + + CUdpClient* pClient = (CUdpClient*)pv; + HANDLE hEvents[] = {pClient->m_evSocket, pClient->m_evBuffer, pClient->m_evWorker}; + + pClient->m_rcBuffer.Malloc(pClient->m_dwMaxDatagramSize); + + while(pClient->HasStarted()) + { + DWORD retval = ::WSAWaitForMultipleEvents(3, hEvents, FALSE, WSA_INFINITE, FALSE); + + if(retval == WSA_WAIT_EVENT_0) + { + if(!pClient->ProcessNetworkEvent()) + { + if(pClient->HasStarted()) + pClient->Stop(); + + break; + } + } + else if(retval == WSA_WAIT_EVENT_0 + 1) + { + if(!pClient->SendData()) + { + if(pClient->HasStarted()) + pClient->Stop(); + + break; + } + } + else if(retval == WSA_WAIT_EVENT_0 + 2) + break; + else + ASSERT(FALSE); + } + + TRACE("---------------> Client Worker Thread 0x%08X stoped <---------------\n", ::GetCurrentThreadId()); + + return 0; +} + +BOOL CUdpClient::ProcessNetworkEvent() +{ + BOOL bContinue = TRUE; + WSANETWORKEVENTS events; + + int rc = ::WSAEnumNetworkEvents(m_soClient, m_evSocket, &events); + + if(rc == SOCKET_ERROR) + bContinue = HandleError(events); + + if(m_bAsyncConnect && bContinue && events.lNetworkEvents & FD_CONNECT) + bContinue = HandleConnect(events); + + if(bContinue && events.lNetworkEvents & FD_READ) + bContinue = HandleRead(events); + + if(bContinue && events.lNetworkEvents & FD_WRITE) + bContinue = HandleWrite(events); + + if(bContinue && events.lNetworkEvents & FD_CLOSE) + bContinue = HandleClose(events); + + return bContinue; +} + +BOOL CUdpClient::HandleError(WSANETWORKEVENTS& events) +{ + int iCode = ::WSAGetLastError(); + EnSocketOperation enOperation = SO_UNKNOWN; + + if(events.lNetworkEvents & FD_CONNECT) + enOperation = SO_CONNECT; + else if(events.lNetworkEvents & FD_CLOSE) + enOperation = SO_CLOSE; + else if(events.lNetworkEvents & FD_READ) + enOperation = SO_RECEIVE; + else if(events.lNetworkEvents & FD_WRITE) + enOperation = SO_SEND; + + VERIFY(::WSAResetEvent(m_evSocket)); + FireClose(this, enOperation, iCode); + + return FALSE; +} + +BOOL CUdpClient::HandleRead(WSANETWORKEVENTS& events) +{ + BOOL bContinue = TRUE; + int iCode = events.iErrorCode[FD_READ_BIT]; + + if(iCode == 0) + bContinue = ReadData(); + else + { + FireClose(this, SO_RECEIVE, iCode); + bContinue = FALSE; + } + + return bContinue; +} + +BOOL CUdpClient::HandleWrite(WSANETWORKEVENTS& events) +{ + BOOL bContinue = TRUE; + int iCode = events.iErrorCode[FD_WRITE_BIT]; + + if(iCode == 0) + bContinue = SendData(); + else + { + FireClose(this, SO_SEND, iCode); + bContinue = FALSE; + } + + return bContinue; +} + +BOOL CUdpClient::HandleConnect(WSANETWORKEVENTS& events) +{ + BOOL bContinue = TRUE; + int iCode = events.iErrorCode[FD_CONNECT_BIT]; + + if(iCode == 0) + { + if(::WSAEventSelect(m_soClient, m_evSocket, FD_READ | FD_WRITE | FD_CLOSE) != SOCKET_ERROR) + { + if(FireConnect(this) != HR_ERROR) + { + VERIFY(NeedDetectorThread() || DetectConnection() == NO_ERROR); + + m_enState = SS_STARTED; + } + else + iCode = ERROR_CANCELLED; + } + else + iCode = ::WSAGetLastError(); + } + + if(iCode != 0) + { + if(iCode != ERROR_CANCELLED) + FireClose(this, SO_CONNECT, iCode); + + bContinue = FALSE; + } + + return bContinue; +} + +BOOL CUdpClient::HandleClose(WSANETWORKEVENTS& events) +{ + int iCode = events.iErrorCode[FD_CLOSE_BIT]; + + if(iCode == 0) + FireClose(this, SO_CLOSE, SE_OK); + else + FireClose(this, SO_CLOSE, iCode); + + return FALSE; +} + +BOOL CUdpClient::ReadData() +{ + while(TRUE) + { + int rc = recv(m_soClient, (char*)(BYTE*)m_rcBuffer, m_dwMaxDatagramSize, 0); + + if(rc > 0) + { + if(FireReceive(this, m_rcBuffer, rc) == HR_ERROR) + { + TRACE(" OnReceive() event return 'HR_ERROR', connection will be closed !\n", m_dwConnID); + + FireClose(this, SO_RECEIVE, ERROR_CANCELLED); + return FALSE; + } + } + else if(rc == SOCKET_ERROR) + { + int code = ::WSAGetLastError(); + + if(code == WSAEWOULDBLOCK) + break; + else + { + FireClose(this, SO_RECEIVE, code); + return FALSE; + } + } + else if(rc == 0) + { + m_dwDetectFails = 0; + TRACE(" recv 0 bytes (detect package)\n", m_dwConnID); + } + else + ASSERT(FALSE); + } + + return TRUE; +} + +BOOL CUdpClient::SendData() +{ + while(TRUE) + { + TItemPtr itPtr(m_itPool, GetSendBuffer()); + + if(itPtr.IsValid()) + { + ASSERT(!itPtr->IsEmpty()); + + int rc = 0; + + { + CCriSecLock locallock(m_csSend); + + rc = send(m_soClient, (char*)itPtr->Ptr(), itPtr->Size(), 0); + if(rc > 0) m_iPending -= rc; + } + + if(rc > 0) + { + ASSERT(rc == itPtr->Size()); + + if(FireSend(this, itPtr->Ptr(), rc) == HR_ERROR) + { + TRACE(" OnSend() event should not return 'HR_ERROR' !!\n", m_dwConnID); + ASSERT(FALSE); + } + } + else if(rc == SOCKET_ERROR) + { + int iCode = ::WSAGetLastError(); + + if(iCode == WSAEWOULDBLOCK) + { + CCriSecLock locallock(m_csSend); + m_lsSend.PushFront(itPtr.Detach()); + break; + } + else + { + FireClose(this, SO_SEND, iCode); + return FALSE; + } + } + else + ASSERT(FALSE); + } + else + break; + } + + return TRUE; +} + +TItem* CUdpClient::GetSendBuffer() +{ + TItem* pItem = nullptr; + + if(m_lsSend.Size() > 0) + { + CCriSecLock locallock(m_csSend); + + if(m_lsSend.Size() > 0) + pItem = m_lsSend.PopFront(); + } + + return pItem; +} + +int CUdpClient::DetectConnection() +{ + int result = NO_ERROR; + + if(send(m_soClient, nullptr, 0, 0) == SOCKET_ERROR) + { + result = ::WSAGetLastError(); + if(result == WSAEWOULDBLOCK) + result = NO_ERROR; + } + + TRACE(" send 0 bytes (detect package)\n", m_dwConnID); + + return result; +} + +BOOL CUdpClient::CreateDetectorThread() +{ + BOOL isOK = TRUE; + + if(NeedDetectorThread()) + { + m_hDetector = (HANDLE)_beginthreadex(nullptr, 0, DetecotrThreadProc, (LPVOID)this, 0, &m_dwDetectorID); + isOK = m_hDetector != nullptr; + } + + return isOK; +} + +UINT WINAPI CUdpClient::DetecotrThreadProc(LPVOID pv) +{ + TRACE("---------------> Client Detecotr Thread 0x%08X started <---------------\n", ::GetCurrentThreadId()); + + CUdpClient* pClient = (CUdpClient*)pv; + DWORD retval = WAIT_TIMEOUT; + + ASSERT(pClient->NeedDetectorThread()); + + while(pClient->HasStarted() && retval == WAIT_TIMEOUT) + { + int iCode = NO_ERROR; + + if(pClient->m_dwDetectFails++ < pClient->m_dwDetectAttempts) + iCode = pClient->DetectConnection(); + else + iCode = WSAECONNRESET; + + if(iCode != NO_ERROR) + { + pClient->FireClose(pClient, SO_CONNECT, WSAECONNRESET); + pClient->Stop(); + break; + } + + retval = ::WaitForSingleObject(pClient->m_evDetector, pClient->m_dwDetectInterval * 1000L); + ASSERT(retval == WAIT_TIMEOUT || retval == WAIT_OBJECT_0); + } + + TRACE("---------------> Client Detecotr Thread 0x%08X stoped <---------------\n", ::GetCurrentThreadId()); + + return 0; +} + +BOOL CUdpClient::Stop() +{ + BOOL bNeedFireClose = FALSE; + EnServiceState enCurState = m_enState; + DWORD dwCurrentThreadID = ::GetCurrentThreadId(); + + if(!CheckStoping()) + return FALSE; + + if( enCurState == SS_STARTED && + dwCurrentThreadID != m_dwWorkerID && + dwCurrentThreadID != m_dwDetectorID ) + bNeedFireClose = TRUE; + + WaitForDetectorThreadEnd(dwCurrentThreadID); + WaitForWorkerThreadEnd(dwCurrentThreadID); + + if(bNeedFireClose) + FireClose(this, SO_CLOSE, SE_OK); + + if(m_evSocket != nullptr) + { + ::WSACloseEvent(m_evSocket); + m_evSocket = nullptr; + } + + if(m_soClient != INVALID_SOCKET) + { + shutdown(m_soClient, SD_SEND); + closesocket(m_soClient); + m_soClient = INVALID_SOCKET; + } + + Reset(); + + return TRUE; +} + +void CUdpClient::Reset(BOOL bAll) +{ + if(bAll) + { + m_rcBuffer.Free(); + m_evBuffer.Reset(); + m_evWorker.Reset(); + m_evDetector.Reset(); + m_lsSend.Clear(); + m_itPool.Clear(); + } + + m_iPending = 0; + m_dwDetectFails = 0; + m_enState = SS_STOPPED; +} + +void CUdpClient::WaitForWorkerThreadEnd(DWORD dwCurrentThreadID) +{ + if(m_hWorker != nullptr) + { + if(dwCurrentThreadID != m_dwWorkerID) + { + m_evWorker.Set(); + VERIFY(::WaitForSingleObject(m_hWorker, INFINITE) == WAIT_OBJECT_0); + } + + ::CloseHandle(m_hWorker); + + m_hWorker = nullptr; + m_dwWorkerID = 0; + } +} + +void CUdpClient::WaitForDetectorThreadEnd(DWORD dwCurrentThreadID) +{ + if(m_hDetector != nullptr) + { + if(dwCurrentThreadID != m_dwDetectorID) + { + m_evDetector.Set(); + VERIFY(::WaitForSingleObject(m_hDetector, INFINITE) == WAIT_OBJECT_0); + } + + ::CloseHandle(m_hDetector); + + m_hDetector = nullptr; + m_dwDetectorID = 0; + } +} + +BOOL CUdpClient::Send(const BYTE* pBuffer, int iLength, int iOffset) +{ + int result = NO_ERROR; + EnSocketError enCode = SE_OK; + + ASSERT(pBuffer && iLength > 0 && iLength <= (int)m_dwMaxDatagramSize); + + if(pBuffer && iLength > 0 && iLength <= (int)m_dwMaxDatagramSize) + { + if(iOffset != 0) pBuffer += iOffset; + result = SendInternal(pBuffer, iLength, enCode); + } + else + { + result = ERROR_INVALID_PARAMETER; + enCode = SE_INVALID_PARAM; + } + + if(result != NO_ERROR) + ::SetLastError(result); + + return (result == NO_ERROR); +} + +BOOL CUdpClient::SendPackets(const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + EnSocketError enCode = SE_OK; + + ASSERT(pBuffers && iCount > 0); + + if(pBuffers && iCount > 0) + { + int iLength = 0; + int iMaxLen = (int)m_dwMaxDatagramSize; + + TItemPtr itPtr(m_itPool, m_itPool.PickFreeItem()); + + for(int i = 0; i < iCount; i++) + { + int iBufLen = pBuffers[i].len; + + if(iBufLen > 0) + { + BYTE* pBuffer = (BYTE*)pBuffers[i].buf; + ASSERT(pBuffer); + + iLength += iBufLen; + + if(iLength <= iMaxLen) + itPtr->Cat(pBuffer, iBufLen); + else + break; + } + } + + if(iLength > 0 && iLength <= iMaxLen) + result = SendInternal(itPtr->Ptr(), iLength, enCode); + else + { + result = ERROR_INCORRECT_SIZE; + enCode = SE_INVALID_PARAM; + } + } + else + { + result = ERROR_INVALID_PARAMETER; + enCode = SE_INVALID_PARAM; + } + + if(result != NO_ERROR) + ::SetLastError(result); + + return (result == NO_ERROR); +} + +int CUdpClient::SendInternal(const BYTE* pBuffer, int iLength, EnSocketError& enCode) +{ + int result = NO_ERROR; + + if(HasStarted()) + { + CCriSecLock locallock(m_csSend); + + if(HasStarted()) + { + ASSERT(m_iPending >= 0); + + BOOL isPending = m_iPending > 0; + + TItem* pItem = m_itPool.PickFreeItem(); + pItem->Cat(pBuffer, iLength); + m_lsSend.PushBack(pItem); + + m_iPending += iLength; + + if(!isPending) m_evBuffer.Set(); + } + else + { + result = ERROR_INVALID_STATE; + enCode = SE_ILLEGAL_STATE; + } + } + else + { + result = ERROR_INVALID_STATE; + enCode = SE_ILLEGAL_STATE; + } + + return result; +} + +void CUdpClient::SetLastError(EnSocketError code, LPCSTR func, int ec) +{ + TRACE("%s --> Error: %d, EC: %d\n", func, code, ec); + + m_enLastError = code; + ::SetLastError(ec); +} + +BOOL CUdpClient::GetLocalAddress(TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + return ::GetSocketLocalAddress(m_soClient, lpszAddress, iAddressLen, usPort); +} diff --git a/HP-Socket/Src/UdpClient.h b/HP-Socket/Src/UdpClient.h new file mode 100644 index 000000000..4c6a2cdde --- /dev/null +++ b/HP-Socket/Src/UdpClient.h @@ -0,0 +1,188 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "SocketHelper.h" +#include "../../Common/Src/Event.h" +#include "../../Common/Src/bufferptr.h" +#include "../../Common/Src/bufferpool.h" +#include "../../Common/Src/CriticalSection.h" + +class CUdpClient : public IUdpClient +{ +public: + virtual BOOL Start (LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect = FALSE); + virtual BOOL Stop (); + virtual BOOL Send (const BYTE* pBuffer, int iLength, int iOffset = 0); + virtual BOOL SendPackets (const WSABUF pBuffers[], int iCount); + virtual BOOL HasStarted () {return m_enState == SS_STARTED || m_enState == SS_STARTING;} + virtual EnServiceState GetState () {return m_enState;} + virtual CONNID GetConnectionID () {return m_dwConnID;}; + virtual BOOL GetLocalAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + virtual BOOL GetPendingDataLength (int& iPending) {iPending = m_iPending; return HasStarted();} + virtual EnSocketError GetLastError () {return m_enLastError;} + virtual LPCTSTR GetLastErrorDesc () {return ::GetSocketErrorDesc(m_enLastError);} + +public: + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) {m_dwMaxDatagramSize = dwMaxDatagramSize;} + virtual void SetDetectAttempts (DWORD dwDetectAttempts) {m_dwDetectAttempts = dwDetectAttempts;} + virtual void SetDetectInterval (DWORD dwDetectInterval) {m_dwDetectInterval = dwDetectInterval;} + virtual void SetFreeBufferPoolSize (DWORD dwFreeBufferPoolSize) {m_dwFreeBufferPoolSize = dwFreeBufferPoolSize;} + virtual void SetFreeBufferPoolHold (DWORD dwFreeBufferPoolHold) {m_dwFreeBufferPoolHold = dwFreeBufferPoolHold;} + virtual void SetExtra (PVOID pExtra) {m_pExtra = pExtra;} + + + virtual DWORD GetMaxDatagramSize () {return m_dwMaxDatagramSize;} + virtual DWORD GetDetectAttempts () {return m_dwDetectAttempts;} + virtual DWORD GetDetectInterval () {return m_dwDetectInterval;} + virtual DWORD GetFreeBufferPoolSize () {return m_dwFreeBufferPoolSize;} + virtual DWORD GetFreeBufferPoolHold () {return m_dwFreeBufferPoolHold;} + virtual PVOID GetExtra () {return m_pExtra;} + +protected: + virtual EnHandleResult FirePrepareConnect(IClient* pClient, SOCKET socket) + {return m_psoListener->OnPrepareConnect(pClient, socket);} + virtual EnHandleResult FireConnect(IClient* pClient) + {return m_psoListener->OnConnect(pClient);} + virtual EnHandleResult FireSend(IClient* pClient, const BYTE* pData, int iLength) + {return m_psoListener->OnSend(pClient, pData, iLength);} + virtual EnHandleResult FireReceive(IClient* pClient, const BYTE* pData, int iLength) + {return m_psoListener->OnReceive(pClient, pData, iLength);} + virtual EnHandleResult FireReceive(IClient* pClient, int iLength) + {return m_psoListener->OnReceive(pClient, iLength);} + virtual EnHandleResult FireClose(IClient* pClient, EnSocketOperation enOperation, int iErrorCode) + {return m_psoListener->OnClose(pClient, enOperation, iErrorCode);} + + void SetLastError(EnSocketError code, LPCSTR func, int ec); + virtual BOOL CheckParams(); + virtual void PrepareStart(); + virtual void Reset(BOOL bAll = TRUE); + +protected: + void SetReserved (PVOID pReserved) {m_pReserved = pReserved;} + PVOID GetReserved () {return m_pReserved;} + +private: + BOOL CheckStarting(); + BOOL CheckStoping(); + BOOL CreateClientSocket(); + BOOL ConnectToServer(LPCTSTR pszRemoteAddress, USHORT usPort); + BOOL CreateWorkerThread(); + BOOL CreateDetectorThread(); + BOOL ProcessNetworkEvent(); + BOOL ReadData(); + BOOL SendData(); + TItem* GetSendBuffer(); + int SendInternal(const BYTE* pBuffer, int iLength, EnSocketError& enCode); + void WaitForWorkerThreadEnd(DWORD dwCurrentThreadID); + void WaitForDetectorThreadEnd(DWORD dwCurrentThreadID); + + BOOL HandleError(WSANETWORKEVENTS& events); + BOOL HandleRead(WSANETWORKEVENTS& events); + BOOL HandleWrite(WSANETWORKEVENTS& events); + BOOL HandleConnect(WSANETWORKEVENTS& events); + BOOL HandleClose(WSANETWORKEVENTS& events); + + int DetectConnection (); + BOOL NeedDetectorThread () {return m_dwDetectAttempts > 0 && m_dwDetectInterval > 0;} + + static UINT WINAPI WorkerThreadProc(LPVOID pv); + static UINT WINAPI DetecotrThreadProc(LPVOID pv); + +public: + CUdpClient(IUdpClientListener* psoListener) + : m_psoListener (psoListener) + , m_lsSend (m_itPool) + , m_soClient (INVALID_SOCKET) + , m_evSocket (nullptr) + , m_dwConnID (0) + , m_hWorker (nullptr) + , m_dwWorkerID (0) + , m_hDetector (nullptr) + , m_dwDetectorID (0) + , m_bAsyncConnect (FALSE) + , m_iPending (0) + , m_enState (SS_STOPPED) + , m_enLastError (SE_OK) + , m_dwDetectFails (0) + , m_pExtra (nullptr) + , m_pReserved (nullptr) + , m_dwMaxDatagramSize (DEFAULT_UDP_MAX_DATAGRAM_SIZE) + , m_dwFreeBufferPoolSize(DEFAULT_CLIENT_FREE_BUFFER_POOL_SIZE) + , m_dwFreeBufferPoolHold(DEFAULT_CLIENT_FREE_BUFFER_POOL_HOLD) + , m_dwDetectAttempts (DEFAULT_UDP_DETECT_ATTEMPTS) + , m_dwDetectInterval (DEFAULT_UDP_DETECT_INTERVAL) + { + ASSERT(m_psoListener); + } + + virtual ~CUdpClient() {if(HasStarted()) Stop();} + +private: + CInitSocket m_wsSocket; + +private: + IUdpClientListener* m_psoListener; + + BOOL m_bAsyncConnect; + SOCKET m_soClient; + HANDLE m_evSocket; + CONNID m_dwConnID; + + DWORD m_dwMaxDatagramSize; + DWORD m_dwFreeBufferPoolSize; + DWORD m_dwFreeBufferPoolHold; + DWORD m_dwDetectAttempts; + DWORD m_dwDetectInterval; + + HANDLE m_hWorker; + HANDLE m_hDetector; + UINT m_dwWorkerID; + UINT m_dwDetectorID; + + EnServiceState m_enState; + EnSocketError m_enLastError; + + PVOID m_pExtra; + PVOID m_pReserved; + + CBufferPtr m_rcBuffer; + +protected: + CItemPool m_itPool; + + CSpinGuard m_csState; + +private: + CCriSec m_csSend; + TItemList m_lsSend; + + CEvt m_evBuffer; + CEvt m_evWorker; + CEvt m_evDetector; + + volatile int m_iPending; + volatile DWORD m_dwDetectFails; +}; diff --git a/HP-Socket/Src/UdpServer.cpp b/HP-Socket/Src/UdpServer.cpp new file mode 100644 index 000000000..0c08c7b2a --- /dev/null +++ b/HP-Socket/Src/UdpServer.cpp @@ -0,0 +1,1435 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdafx.h" +#include "UdpServer.h" +#include "../../Common/Src/WaitFor.h" + +#include +#include + +EnHandleResult CUdpServer::TriggerFireAccept(TUdpSocketObj* pSocketObj) +{ + CReentrantSpinLock locallock(pSocketObj->csRecv); + return FireAccept(pSocketObj); +} + +EnHandleResult CUdpServer::TriggerFireReceive(TUdpSocketObj* pSocketObj, TUdpBufferObj* pBufferObj) +{ + EnHandleResult rs = (EnHandleResult)HR_CLOSED; + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + CReentrantSpinLock locallock(pSocketObj->csRecv); + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + rs = FireReceive(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len); + } + } + + return rs; +} + +EnHandleResult CUdpServer::TriggerFireSend(TUdpSocketObj* pSocketObj, TUdpBufferObj* pBufferObj) +{ + EnHandleResult rs = FireSend(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len); + + if(rs == HR_ERROR) + { + TRACE(" OnSend() event should not return 'HR_ERROR' !!\n", pSocketObj->connID); + ASSERT(FALSE); + } + + AddFreeBufferObj(pBufferObj); + + return rs; +} + +EnHandleResult CUdpServer::TriggerFireClose(TUdpSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) +{ + CReentrantSpinLock locallock(pSocketObj->csRecv); + return FireClose(pSocketObj, enOperation, iErrorCode); +} + +void CUdpServer::SetLastError(EnSocketError code, LPCSTR func, int ec) +{ + m_enLastError = code; + + TRACE("%s --> Error: %d, EC: %d\n", func, code, ec); +} + +BOOL CUdpServer::Start(LPCTSTR pszBindAddress, USHORT usPort) +{ + if(!CheckParams() || !CheckStarting()) + return FALSE; + + PrepareStart(); + + if(CreateListenSocket(pszBindAddress, usPort)) + if(CreateCompletePort()) + if(CreateWorkerThreads()) + if(CreateDetectorThread()) + if(StartAccept()) + { + m_enState = SS_STARTED; + return TRUE; + } + + Stop(); + + return FALSE; +} + +BOOL CUdpServer::CheckParams() +{ + if(m_enSendPolicy >= SP_PACK && m_enSendPolicy <= SP_DIRECT) + if((int)m_dwWorkerThreadCount > 0 && m_dwWorkerThreadCount <= MAX_WORKER_THREAD_COUNT) + if((int)m_dwFreeSocketObjLockTime >= 0) + if((int)m_dwFreeSocketObjPool >= 0) + if((int)m_dwFreeBufferObjPool >= 0) + if((int)m_dwFreeSocketObjHold >= m_dwFreeSocketObjPool) + if((int)m_dwFreeBufferObjHold >= m_dwFreeBufferObjPool) + if((int)m_dwMaxDatagramSize > 0) + if((int)m_dwPostReceiveCount > 0) + if((int)m_dwDetectAttempts >= 0) + if((int)m_dwDetectInterval >= 0) + return TRUE; + + SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER); + return FALSE; +} + +void CUdpServer::PrepareStart() +{ + m_lsFreeSocket.Reset(m_dwFreeSocketObjHold); + m_lsFreeBuffer.Reset(m_dwFreeBufferObjHold); + + m_itPool.SetItemCapacity((int)m_dwMaxDatagramSize); + m_itPool.SetPoolSize((int)m_dwFreeBufferObjPool); + m_itPool.SetPoolHold((int)m_dwFreeBufferObjHold); + + m_itPool.Prepare(); +} + +BOOL CUdpServer::CheckStarting() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STOPPED) + m_enState = SS_STARTING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CUdpServer::CheckStoping() +{ + CSpinLock locallock(m_csState); + + if(m_enState == SS_STARTED || m_enState == SS_STARTING) + m_enState = SS_STOPPING; + else + { + SetLastError(SE_ILLEGAL_STATE, __FUNCTION__, ERROR_INVALID_OPERATION); + return FALSE; + } + + return TRUE; +} + +BOOL CUdpServer::CreateListenSocket(LPCTSTR pszBindAddress, USHORT usPort) +{ + BOOL isOK = FALSE; + + m_soListen = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if(m_soListen != INVALID_SOCKET) + { + VERIFY(::SSO_UDP_ConnReset(m_soListen, FALSE) == NO_ERROR); + + SOCKADDR_IN addr; + ::sockaddr_A_2_IN(AF_INET, pszBindAddress, usPort, addr); + + if(::bind(m_soListen, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)) != SOCKET_ERROR) + { + if(FirePrepareListen(m_soListen) != HR_ERROR) + isOK = TRUE; + else + SetLastError(SE_SOCKET_PREPARE, __FUNCTION__, ERROR_CANCELLED); + } + else + SetLastError(SE_SOCKET_BIND, __FUNCTION__, ::WSAGetLastError()); + } + else + SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError()); + + return isOK; +} + +BOOL CUdpServer::CreateCompletePort() +{ + m_hCompletePort = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 0); + if(m_hCompletePort == nullptr) + SetLastError(SE_CP_CREATE, __FUNCTION__, ::GetLastError()); + + return (m_hCompletePort != nullptr); +} + +BOOL CUdpServer::CreateWorkerThreads() +{ + BOOL isOK = TRUE; + + for(DWORD i = 0; i < m_dwWorkerThreadCount; i++) + { + HANDLE hThread = (HANDLE)_beginthreadex(nullptr, 0, WorkerThreadProc, (LPVOID)this, 0, nullptr); + if(hThread) + m_vtWorkerThreads.push_back(hThread); + else + { + SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ::GetLastError()); + isOK = FALSE; + break; + } + } + + return isOK; +} + +BOOL CUdpServer::CreateDetectorThread() +{ + BOOL isOK = TRUE; + + if(NeedDetectorThread()) + { + m_hDetector = (HANDLE)_beginthreadex(nullptr, 0, DetecotrThreadProc, (LPVOID)this, 0, nullptr); + isOK = m_hDetector != nullptr; + } + + return isOK; +} + +BOOL CUdpServer::StartAccept() +{ + BOOL isOK = TRUE; + + if(::CreateIoCompletionPort((HANDLE)m_soListen, m_hCompletePort, m_soListen, 0)) + { + m_iRemainPostReceives = m_dwPostReceiveCount; + + for(DWORD i = 0; i < m_dwPostReceiveCount; i++) + VERIFY(::PostIocpAccept(m_hCompletePort)); + } + else + { + SetLastError(SE_SOCKE_ATTACH_TO_CP, __FUNCTION__, ::GetLastError()); + isOK = FALSE; + } + + return isOK; +} + +BOOL CUdpServer::Stop() +{ + if(!CheckStoping()) + return FALSE; + + CloseListenSocket(); + + WaitForDetectorThreadEnd(); + WaitForPostReceiveRelease(); + + DisconnectClientSocket(); + WaitForClientSocketClose(); + WaitForWorkerThreadEnd(); + + ReleaseClientSocket(); + + FireShutdown(); + + ReleaseFreeSocket(); + ReleaseFreeBuffer(); + + CloseCompletePort(); + + Reset(); + + return TRUE; +} + +void CUdpServer::Reset(BOOL bAll) +{ + if(bAll) + { + m_phSocket.Reset(); + m_phBuffer.Reset(); + m_itPool.Clear(); + } + + m_iRemainPostReceives = 0; + m_enState = SS_STOPPED; +} + +void CUdpServer::CloseListenSocket() +{ + if(m_soListen != INVALID_SOCKET) + { + ::ManualCloseSocket(m_soListen); + m_soListen = INVALID_SOCKET; + + ::WaitWithMessageLoop(150); + } +} + +void CUdpServer::DisconnectClientSocket() +{ + CReentrantReadLock locallock(m_csClientSocket); + + for(TUdpSocketObjPtrMapI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + Disconnect(it->first); +} + +void CUdpServer::ReleaseClientSocket() +{ + CReentrantWriteLock locallock(m_csClientSocket); + + for(TUdpSocketObjPtrMapI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + TUdpSocketObj* pSocketObj = it->second; + DeleteSocketObj(pSocketObj); + } + + m_mpClientAddr.clear(); + m_mpClientSocket.clear(); +} + +TUdpSocketObj* CUdpServer::GetFreeSocketObj(CONNID dwConnID) +{ + DWORD dwIndex; + TUdpSocketObj* pSocketObj = nullptr; + + if(m_lsFreeSocket.TryLock(&pSocketObj, dwIndex)) + { + if(::GetTimeGap32(pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) + m_lsFreeSocket.ReleaseLock(nullptr, dwIndex); + else + { + m_lsFreeSocket.ReleaseLock(pSocketObj, dwIndex); + pSocketObj = nullptr; + } + } + + if(!pSocketObj) pSocketObj = CreateSocketObj(); + pSocketObj->Reset(dwConnID); + + return pSocketObj; +} + +void CUdpServer::AddFreeSocketObj(CONNID dwConnID, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode) +{ + AddFreeSocketObj(FindSocketObj(dwConnID), enFlag, enOperation, iErrorCode); +} + +void CUdpServer::AddFreeSocketObj(TUdpSocketObj* pSocketObj, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode) +{ + if(!InvalidSocketObj(pSocketObj)) + return; + + CloseClientUdpSocketObj(pSocketObj, enFlag, enOperation, iErrorCode); + TUdpSocketObj::Release(pSocketObj); + + { + CReentrantWriteLock locallock(m_csClientSocket); + + m_mpClientAddr.erase(&pSocketObj->remoteAddr); + m_mpClientSocket.erase(pSocketObj->connID); + } + + if(!m_lsFreeSocket.TryPut(pSocketObj)) + { + m_lsGCSocket.PushBack(pSocketObj); + + if(m_lsGCSocket.Size() > m_dwFreeSocketObjPool) + ReleaseGCSocketObj(); + } +} + +void CUdpServer::ReleaseGCSocketObj(BOOL bForce) +{ + TUdpSocketObj* pSocketObj = nullptr; + DWORD now = ::TimeGetTime(); + + while(m_lsGCSocket.PopFront(&pSocketObj)) + { + if(bForce || (now - pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) + DeleteSocketObj(pSocketObj); + else + { + m_lsGCSocket.PushBack(pSocketObj); + break; + } + } +} + +BOOL CUdpServer::InvalidSocketObj(TUdpSocketObj* pSocketObj) +{ + BOOL bDone = FALSE; + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + CReentrantSpinLock locallock(pSocketObj->csRecv); + CCriSecLock locallock2(pSocketObj->csSend); + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + TUdpSocketObj::Invalid(pSocketObj); + bDone = TRUE; + } + } + + return bDone; +} + +void CUdpServer::AddClienTUdpSocketObj(CONNID dwConnID, TUdpSocketObj* pSocketObj) +{ + ASSERT(FindSocketObj(dwConnID) == nullptr); + + pSocketObj->connTime = ::TimeGetTime(); + pSocketObj->activeTime = pSocketObj->connTime; + + CReentrantWriteLock locallock(m_csClientSocket); + + m_mpClientSocket[dwConnID] = pSocketObj; + m_mpClientAddr[&pSocketObj->remoteAddr] = dwConnID; +} + +void CUdpServer::ReleaseFreeSocket() +{ + TUdpSocketObj* pSocketObj = nullptr; + + while(m_lsFreeSocket.TryGet(&pSocketObj)) + DeleteSocketObj(pSocketObj); + + VERIFY(m_lsFreeSocket.IsEmpty()); + m_lsFreeSocket.Reset(); + + ReleaseGCSocketObj(TRUE); + VERIFY(m_lsGCSocket.IsEmpty()); +} + +TUdpSocketObj* CUdpServer::CreateSocketObj() +{ + TUdpSocketObj* pSocketObj = (TUdpSocketObj*)m_phSocket.Alloc(sizeof(TUdpSocketObj)); + ASSERT(pSocketObj); + + pSocketObj->TUdpSocketObj::TUdpSocketObj(m_itPool); + + return pSocketObj; +} + +void CUdpServer::DeleteSocketObj(TUdpSocketObj* pSocketObj) +{ + ASSERT(pSocketObj); + + pSocketObj->TUdpSocketObj::~TUdpSocketObj(); + m_phSocket.Free(pSocketObj); +} + +TUdpBufferObj* CUdpServer::GetFreeBufferObj(int iLen) +{ + ASSERT(iLen >= -1 && iLen <= (int)m_dwMaxDatagramSize); + + TUdpBufferObj* pBufferObj = nullptr; + + if(!m_lsFreeBuffer.TryGet(&pBufferObj)) + pBufferObj = CreateBufferObj(); + + if(iLen < 0) iLen = m_dwMaxDatagramSize; + pBufferObj->addrLen = sizeof(SOCKADDR_IN); + pBufferObj->buff.len = iLen; + + return pBufferObj; +} + +void CUdpServer::AddFreeBufferObj(TUdpBufferObj* pBufferObj) +{ + if(!m_lsFreeBuffer.TryPut(pBufferObj)) + DeleteBufferObj(pBufferObj); +} + +void CUdpServer::ReleaseFreeBuffer() +{ + TUdpBufferObj* pBufferObj = nullptr; + + while(m_lsFreeBuffer.TryGet(&pBufferObj)) + DeleteBufferObj(pBufferObj); + + VERIFY(m_lsFreeBuffer.IsEmpty()); + m_lsFreeBuffer.Reset(); +} + +TUdpBufferObj* CUdpServer::CreateBufferObj() +{ + TUdpBufferObj* pBufferObj = (TUdpBufferObj*)m_phBuffer.Alloc(sizeof(TUdpBufferObj) + m_dwMaxDatagramSize); + ASSERT(pBufferObj); + + ::ZeroMemory(pBufferObj, sizeof(TUdpBufferObj)); + pBufferObj->buff.buf = ((char*)pBufferObj) + sizeof(TUdpBufferObj); + + return pBufferObj; +} + +void CUdpServer::DeleteBufferObj(TUdpBufferObj* pBufferObj) +{ + ASSERT(pBufferObj); + m_phBuffer.Free(pBufferObj); +} + +TUdpSocketObj* CUdpServer::FindSocketObj(CONNID dwConnID) +{ + TUdpSocketObj* pSocketObj = nullptr; + + { + CReentrantReadLock locallock(m_csClientSocket); + + TUdpSocketObjPtrMapCI it = m_mpClientSocket.find(dwConnID); + if(it != m_mpClientSocket.end()) + pSocketObj = it->second; + } + + return pSocketObj; +} + +CONNID CUdpServer::FindConnectionID(SOCKADDR_IN* pAddr) +{ + CONNID dwConnID = 0; + + CReentrantReadLock locallock(m_csClientSocket); + + TSockAddrMapCI it = m_mpClientAddr.find(pAddr); + if(it != m_mpClientAddr.end()) + dwConnID = it->second; + + return dwConnID; +} + +void CUdpServer::CloseClientUdpSocketObj(TUdpSocketObj* pSocketObj, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode) +{ + ASSERT(TUdpSocketObj::IsExist(pSocketObj)); + + if(enFlag == SCF_CLOSE) + TriggerFireClose(pSocketObj, SO_CLOSE, SE_OK); + else if(enFlag == SCF_ERROR) + TriggerFireClose(pSocketObj, enOperation, iErrorCode); +} + +BOOL CUdpServer::GetListenAddress(TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + return ::GetSocketLocalAddress(m_soListen, lpszAddress, iAddressLen, usPort); +} + +BOOL CUdpServer::GetRemoteAddress(CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort) +{ + ASSERT(lpszAddress != nullptr && iAddressLen > 0); + + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsExist(pSocketObj)) + { + ADDRESS_FAMILY usFamily; + return ::sockaddr_IN_2_A(pSocketObj->remoteAddr, usFamily, lpszAddress, iAddressLen, usPort); + } + + return FALSE; +} + +BOOL CUdpServer::SetConnectionExtra(CONNID dwConnID, PVOID pExtra) +{ + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + return SetConnectionExtra(pSocketObj, pExtra); +} + +BOOL CUdpServer::SetConnectionExtra(TUdpSocketObj* pSocketObj, PVOID pExtra) +{ + if(TUdpSocketObj::IsExist(pSocketObj)) + { + pSocketObj->extra = pExtra; + return TRUE; + } + + return FALSE; +} + +BOOL CUdpServer::GetConnectionExtra(CONNID dwConnID, PVOID* ppExtra) +{ + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + return GetConnectionExtra(pSocketObj, ppExtra); +} + +BOOL CUdpServer::GetConnectionExtra(TUdpSocketObj* pSocketObj, PVOID* ppExtra) +{ + ASSERT(ppExtra != nullptr); + + if(TUdpSocketObj::IsExist(pSocketObj)) + { + *ppExtra = pSocketObj->extra; + return TRUE; + } + + return FALSE; +} + +BOOL CUdpServer::SetConnectionReserved(CONNID dwConnID, PVOID pReserved) +{ + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + return SetConnectionReserved(pSocketObj, pReserved); +} + +BOOL CUdpServer::SetConnectionReserved(TUdpSocketObj* pSocketObj, PVOID pReserved) +{ + if(TUdpSocketObj::IsExist(pSocketObj)) + { + pSocketObj->reserved = pReserved; + return TRUE; + } + + return FALSE; +} + +BOOL CUdpServer::GetConnectionReserved(CONNID dwConnID, PVOID* ppReserved) +{ + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + return GetConnectionReserved(pSocketObj, ppReserved); +} + +BOOL CUdpServer::GetConnectionReserved(TUdpSocketObj* pSocketObj, PVOID* ppReserved) +{ + ASSERT(ppReserved != nullptr); + + if(TUdpSocketObj::IsExist(pSocketObj)) + { + *ppReserved = pSocketObj->reserved; + return TRUE; + } + + return FALSE; +} + +BOOL CUdpServer::GetPendingDataLength(CONNID dwConnID, int& iPending) +{ + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + iPending = pSocketObj->Pending(); + return TRUE; + } + + return FALSE; +} + +DWORD CUdpServer::GetConnectionCount() +{ + return (DWORD)m_mpClientSocket.size(); +} + +BOOL CUdpServer::GetAllConnectionIDs(CONNID pIDs[], DWORD& dwCount) +{ + BOOL isOK = FALSE; + DWORD dwSize = 0; + + { + CReentrantReadLock locallock(m_csClientSocket); + + dwSize = (DWORD)m_mpClientSocket.size(); + + if(pIDs != nullptr && dwSize <= dwCount) + { + TUdpSocketObjPtrMapCI it = m_mpClientSocket.begin(); + TUdpSocketObjPtrMapCI end = m_mpClientSocket.end(); + + for(int i = 0; it != end; ++it, ++i) + pIDs[i] = it->first; + + isOK = TRUE; + } + } + + dwCount = dwSize; + return isOK; +} + +BOOL CUdpServer::GetConnectPeriod(CONNID dwConnID, DWORD& dwPeriod) +{ + BOOL isOK = TRUE; + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsValid(pSocketObj)) + dwPeriod = ::GetTimeGap32(pSocketObj->connTime); + else + isOK = FALSE; + + return isOK; +} + +BOOL CUdpServer::GetSilencePeriod(CONNID dwConnID, DWORD& dwPeriod) +{ + if(!m_bMarkSilence) + return FALSE; + + BOOL isOK = TRUE; + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsValid(pSocketObj)) + dwPeriod = ::GetTimeGap32(pSocketObj->activeTime); + else + isOK = FALSE; + + return isOK; +} + +BOOL CUdpServer::Disconnect(CONNID dwConnID, BOOL bForce) +{ + BOOL isOK = FALSE; + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsValid(pSocketObj)) + isOK = ::PostIocpDisconnect(m_hCompletePort, dwConnID); + + return isOK; +} + +BOOL CUdpServer::DisconnectLongConnections(DWORD dwPeriod, BOOL bForce) +{ + ulong_ptr_deque ls; + + { + CReentrantReadLock locallock(m_csClientSocket); + + DWORD now = ::TimeGetTime(); + + for(TUdpSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(now - it->second->connTime >= dwPeriod) + ls.push_back(it->first); + } + } + + for(ulong_ptr_deque::const_iterator it = ls.begin(), end = ls.end(); it != end; ++it) + Disconnect(*it, bForce); + + return ls.size() > 0; +} + +BOOL CUdpServer::DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce) +{ + if(!m_bMarkSilence) + return FALSE; + + ulong_ptr_deque ls; + + { + CReentrantReadLock locallock(m_csClientSocket); + + DWORD now = ::TimeGetTime(); + + for(TUdpSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(now - it->second->activeTime >= dwPeriod) + ls.push_back(it->first); + } + } + + for(ulong_ptr_deque::const_iterator it = ls.begin(), end = ls.end(); it != end; ++it) + Disconnect(*it, bForce); + + return ls.size() > 0; +} + +void CUdpServer::WaitForPostReceiveRelease() +{ + DWORD dwWait = 0; + DWORD dwOrig = ::TimeGetTime(); + + while(m_iRemainPostReceives > 0) + { + ::WaitWithMessageLoop(100); + dwWait = ::GetTimeGap32(dwOrig); + } +} + +void CUdpServer::WaitForClientSocketClose() +{ + DWORD dwWait = 0; + DWORD dwOrig = ::TimeGetTime(); + + while(m_mpClientSocket.size() > 0) + { + ::WaitWithMessageLoop(100); + dwWait = ::GetTimeGap32(dwOrig); + } + + ASSERT(m_mpClientSocket.size() == 0); +} + +void CUdpServer::WaitForWorkerThreadEnd() +{ + int count = (int)m_vtWorkerThreads.size(); + + for(int i = 0; i < count; i++) + ::PostIocpExit(m_hCompletePort); + + int remain = count; + int index = 0; + + while(remain > 0) + { + int wait = min(remain, MAXIMUM_WAIT_OBJECTS); + HANDLE* pHandles = (HANDLE*)_alloca(sizeof(HANDLE) * wait); + + for(int i = 0; i < wait; i++) + pHandles[i] = m_vtWorkerThreads[i + index]; + + VERIFY(::WaitForMultipleObjects((DWORD)wait, pHandles, TRUE, INFINITE) == WAIT_OBJECT_0); + + for(int i = 0; i < wait; i++) + ::CloseHandle(pHandles[i]); + + remain -= wait; + index += wait; + } + + m_vtWorkerThreads.clear(); +} + +void CUdpServer::WaitForDetectorThreadEnd() +{ + if(m_hDetector != nullptr) + { + m_evDetector.Set(); + VERIFY(::WaitForSingleObject(m_hDetector, INFINITE) == WAIT_OBJECT_0); + + ::CloseHandle(m_hDetector); + m_hDetector = nullptr; + } +} + +void CUdpServer::CloseCompletePort() +{ + if(m_hCompletePort != nullptr) + { + ::CloseHandle(m_hCompletePort); + m_hCompletePort = nullptr; + } +} + +BOOL CUdpServer::DoAccept() +{ + TUdpBufferObj* pBufferObj = GetFreeBufferObj(); + return (DoReceive(pBufferObj) == NO_ERROR); +} + +UINT WINAPI CUdpServer::WorkerThreadProc(LPVOID pv) +{ + CUdpServer* pServer = (CUdpServer*)pv; + + while(TRUE) + { + DWORD dwErrorCode = NO_ERROR; + DWORD dwBytes; + ULONG_PTR ulCompKey; + OVERLAPPED* pOverlapped; + + BOOL result = ::GetQueuedCompletionStatus + ( + pServer->m_hCompletePort, + &dwBytes, + &ulCompKey, + &pOverlapped, + INFINITE + ); + + if(pOverlapped == nullptr) + { + EnIocpAction action = pServer->CheckIocpCommand(pOverlapped, dwBytes, ulCompKey); + + if(action == IOCP_ACT_CONTINUE) + continue; + else if(action == IOCP_ACT_BREAK) + break; + } + + TUdpBufferObj* pBufferObj = CONTAINING_RECORD(pOverlapped, TUdpBufferObj, ov); + CONNID dwConnID = pServer->FindConnectionID(&pBufferObj->remoteAddr); + + if (!result) + { + DWORD dwFlag = 0; + DWORD dwSysCode = ::GetLastError(); + + if(pServer->HasStarted()) + { + result = ::WSAGetOverlappedResult((SOCKET)ulCompKey, &pBufferObj->ov, &dwBytes, FALSE, &dwFlag); + + if (!result) + { + dwErrorCode = ::WSAGetLastError(); + TRACE("GetQueuedCompletionStatus error ( SYS: %d, SOCK: %d, FLAG: %d)\n", dwConnID, dwSysCode, dwErrorCode, dwFlag); + } + } + else + dwErrorCode = dwSysCode; + + ASSERT(dwSysCode != 0 && dwErrorCode != 0); + } + + pServer->HandleIo(dwConnID, pBufferObj, dwBytes, dwErrorCode); + } + + return 0; +} + +EnIocpAction CUdpServer::CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey) +{ + ASSERT(pOverlapped == nullptr); + + EnIocpAction action = IOCP_ACT_CONTINUE; + + if(dwBytes == IOCP_CMD_SEND) + DoSend((CONNID)ulCompKey); + else if(dwBytes == IOCP_CMD_ACCEPT) + DoAccept(); + else if(dwBytes == IOCP_CMD_DISCONNECT) + ForceDisconnect((CONNID)ulCompKey); + else if(dwBytes == IOCP_CMD_EXIT && ulCompKey == 0) + action = IOCP_ACT_BREAK; + else + VERIFY(FALSE); + + return action; +} + +void CUdpServer::ForceDisconnect(CONNID dwConnID) +{ + AddFreeSocketObj(dwConnID, SCF_CLOSE); +} + +void CUdpServer::HandleIo(CONNID dwConnID, TUdpBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode) +{ + ASSERT(pBufferObj != nullptr); + + if(dwErrorCode != NO_ERROR) + { + HandleError(dwConnID, pBufferObj, dwErrorCode); + return; + } + + if(dwBytes == 0) + { + HandleZeroBytes(dwConnID, pBufferObj); + return; + } + + pBufferObj->buff.len = dwBytes; + + switch(pBufferObj->operation) + { + case SO_SEND: + HandleSend(dwConnID, pBufferObj); + break; + case SO_RECEIVE: + HandleReceive(dwConnID, pBufferObj); + break; + default: + ASSERT(FALSE); + } +} + +void CUdpServer::HandleError(CONNID dwConnID, TUdpBufferObj* pBufferObj, DWORD dwErrorCode) +{ + if(dwConnID != 0) + AddFreeSocketObj(dwConnID, SCF_ERROR, pBufferObj->operation, dwErrorCode); + + if(pBufferObj->operation == SO_RECEIVE) + DoReceive(pBufferObj); + else + AddFreeBufferObj(pBufferObj); +} + +void CUdpServer::HandleZeroBytes(CONNID dwConnID, TUdpBufferObj* pBufferObj) +{ + if(pBufferObj->operation == SO_RECEIVE) + { + if(dwConnID == 0) + dwConnID = HandleAccept(pBufferObj); + + if(dwConnID != 0) + { + TRACE(" recv 0 bytes (detect package)\n", dwConnID); + + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + pSocketObj->detectFails = 0; + SendDetectPackage(dwConnID, pSocketObj); + } + } + + DoReceive(pBufferObj); + } + else + VERIFY(FALSE); +} + +CONNID CUdpServer::HandleAccept(TUdpBufferObj* pBufferObj) +{ + CONNID dwConnID = 0; + TUdpSocketObj* pSocketObj = nullptr; + + { + CCriSecLock locallock(m_csAccept); + + dwConnID = FindConnectionID(&pBufferObj->remoteAddr); + + if(dwConnID != 0) + return dwConnID; + else + { + dwConnID = ::GenerateConnectionID(); + pSocketObj = GetFreeSocketObj(dwConnID); + + memcpy(&pSocketObj->remoteAddr, &pBufferObj->remoteAddr, sizeof(SOCKADDR_IN)); + AddClienTUdpSocketObj(dwConnID, pSocketObj); + } + } + + if(TriggerFireAccept(pSocketObj) == HR_ERROR) + { + AddFreeSocketObj(pSocketObj); + dwConnID = 0; + } + + return dwConnID; +} + +void CUdpServer::HandleSend(CONNID dwConnID, TUdpBufferObj* pBufferObj) +{ + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + BOOL bOK = TUdpSocketObj::IsValid(pSocketObj); + + switch(m_enSendPolicy) + { + case SP_PACK: + { + if(bOK) + { + long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount); + + TriggerFireSend(pSocketObj, pBufferObj); + if(sndCount == 0) DoSendPack(pSocketObj); + } + } + + break; + case SP_SAFE: + { + if(bOK) + { + long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount); + + if(sndCount == 0 && !pSocketObj->smooth) + { + CCriSecLock locallock(pSocketObj->csSend); + + if((sndCount = pSocketObj->sndCount) == 0) + pSocketObj->smooth = TRUE; + } + + TriggerFireSend(pSocketObj, pBufferObj); + if(sndCount == 0) DoSendSafe(pSocketObj); + } + } + + break; + case SP_DIRECT: + { + if(bOK) TriggerFireSend(pSocketObj, pBufferObj); + } + + break; + default: + ASSERT(FALSE); + } + + if(!bOK) AddFreeBufferObj(pBufferObj); +} + +void CUdpServer::HandleReceive(CONNID dwConnID, TUdpBufferObj* pBufferObj) +{ + if(dwConnID == 0) + dwConnID = HandleAccept(pBufferObj); + + if(dwConnID != 0) + { + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime(); + if(TriggerFireReceive(pSocketObj, pBufferObj) == HR_ERROR) + { + TRACE(" OnReceive() event return 'HR_ERROR', connection will be closed !\n", dwConnID); + AddFreeSocketObj(pSocketObj, SCF_ERROR, SO_RECEIVE, ERROR_CANCELLED); + } + } + } + + DoReceive(pBufferObj); +} + +int CUdpServer::DoReceive(TUdpBufferObj* pBufferObj) +{ + int result = NO_ERROR; + + if(!HasStarted()) + result = ERROR_INVALID_STATE; + else + { + pBufferObj->buff.len = m_dwMaxDatagramSize; + result = ::PostReceiveFrom(m_soListen, pBufferObj); + } + + if(result != NO_ERROR) + { + VERIFY(!HasStarted()); + + ::InterlockedDecrement(&m_iRemainPostReceives); + ASSERT(m_iRemainPostReceives >= 0); + + AddFreeBufferObj(pBufferObj); + } + + return result; +} + +BOOL CUdpServer::Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset) +{ + int result = NO_ERROR; + + ASSERT(pBuffer && iLength > 0 && iLength <= (int)m_dwMaxDatagramSize); + + if(pBuffer && iLength > 0 && iLength <= (int)m_dwMaxDatagramSize) + { + if(iOffset != 0) pBuffer += iOffset; + result = SendInternal(dwConnID, pBuffer, iLength); + } + else + result = ERROR_INVALID_PARAMETER; + + if(result != NO_ERROR) + ::SetLastError(result); + + return (result == NO_ERROR); +} + +BOOL CUdpServer::SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount) +{ + int result = NO_ERROR; + + ASSERT(pBuffers && iCount > 0); + + if(pBuffers && iCount > 0) + { + int iLength = 0; + int iMaxLen = (int)m_dwMaxDatagramSize; + + TItemPtr itPtr(m_itPool, m_itPool.PickFreeItem()); + + for(int i = 0; i < iCount; i++) + { + int iBufLen = pBuffers[i].len; + + if(iBufLen > 0) + { + BYTE* pBuffer = (BYTE*)pBuffers[i].buf; + ASSERT(pBuffer); + + iLength += iBufLen; + + if(iLength <= iMaxLen) + itPtr->Cat(pBuffer, iBufLen); + else + break; + } + } + + if(iLength > 0 && iLength <= iMaxLen) + result = SendInternal(dwConnID, itPtr->Ptr(), iLength); + else + result = ERROR_INCORRECT_SIZE; + } + else + result = ERROR_INVALID_PARAMETER; + + if(result != NO_ERROR) + ::SetLastError(result); + + return (result == NO_ERROR); +} + +int CUdpServer::SendInternal(CONNID dwConnID, const BYTE* pBuffer, int iLength) +{ + int result = NO_ERROR; + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TUdpSocketObj::IsValid(pSocketObj)) + { + switch(m_enSendPolicy) + { + case SP_PACK: result = SendPack(pSocketObj, pBuffer, iLength); break; + case SP_SAFE: result = SendSafe(pSocketObj, pBuffer, iLength); break; + case SP_DIRECT: result = SendDirect(pSocketObj, pBuffer, iLength); break; + default: ASSERT(FALSE); result = ERROR_INVALID_INDEX; break; + } + } + else + result = ERROR_OBJECT_NOT_FOUND; + } + else + result = ERROR_OBJECT_NOT_FOUND; + + return result; +} + +int CUdpServer::SendPack(TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + BOOL isPostSend = !TUdpSocketObj::IsPending(pSocketObj); + return CatAndPost(pSocketObj, pBuffer, iLength, isPostSend); +} + +int CUdpServer::SendSafe(TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + BOOL isPostSend = !TUdpSocketObj::IsPending(pSocketObj) && TUdpSocketObj::IsSmooth(pSocketObj); + return CatAndPost(pSocketObj, pBuffer, iLength, isPostSend); +} + +int CUdpServer::SendDirect(TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength) +{ + TUdpBufferObj* pBufferObj = GetFreeBufferObj(iLength); + + memcpy(&pBufferObj->remoteAddr, &pSocketObj->remoteAddr, sizeof(SOCKADDR_IN)); + memcpy(pBufferObj->buff.buf, pBuffer, iLength); + + int result = ::PostSendTo(m_soListen, pBufferObj); + + if(result != NO_ERROR) + { + VERIFY(!HasStarted()); + AddFreeBufferObj(pBufferObj); + } + + return result; +} + +int CUdpServer::CatAndPost(TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend) +{ + int result = NO_ERROR; + TItem* pItem = m_itPool.PickFreeItem(); + + pItem->Cat(pBuffer, iLength); + pSocketObj->sndBuff.PushBack(pItem); + pSocketObj->pending += iLength; + + if(isPostSend && !::PostIocpSend(m_hCompletePort, pSocketObj->connID)) + result = ::GetLastError(); + + return result; +} + +int CUdpServer::DoSend(CONNID dwConnID) +{ + TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID); + + if(TUdpSocketObj::IsValid(pSocketObj)) + return DoSend(pSocketObj); + + return ERROR_OBJECT_NOT_FOUND; +} + +int CUdpServer::DoSend(TUdpSocketObj* pSocketObj) +{ + switch(m_enSendPolicy) + { + case SP_PACK: return DoSendPack(pSocketObj); + case SP_SAFE: return DoSendSafe(pSocketObj); + default: ASSERT(FALSE); return ERROR_INVALID_INDEX; + } +} + +int CUdpServer::DoSendPack(TUdpSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + if(TUdpSocketObj::IsPending(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TUdpSocketObj::IsValid(pSocketObj)) + result = SendItem(pSocketObj); + } + + + if(!IOCP_SUCCESS(result)) + VERIFY(!HasStarted()); + + return result; +} + +int CUdpServer::DoSendSafe(TUdpSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + if(TUdpSocketObj::IsPending(pSocketObj) && TUdpSocketObj::IsSmooth(pSocketObj)) + { + CCriSecLock locallock(pSocketObj->csSend); + + if(TUdpSocketObj::IsPending(pSocketObj) && TUdpSocketObj::IsSmooth(pSocketObj)) + { + pSocketObj->smooth = FALSE; + + result = SendItem(pSocketObj); + + if(result == NO_ERROR) + pSocketObj->smooth = TRUE; + } + } + + if(!IOCP_SUCCESS(result)) + VERIFY(!HasStarted()); + + return result; +} + +int CUdpServer::SendItem(TUdpSocketObj* pSocketObj) +{ + int result = NO_ERROR; + + while(pSocketObj->sndBuff.Size() > 0) + { + ::InterlockedIncrement(&pSocketObj->sndCount); + + TItemPtr itPtr(m_itPool, pSocketObj->sndBuff.PopFront()); + + int iBufferSize = itPtr->Size(); + ASSERT(iBufferSize > 0 && iBufferSize <= (int)m_dwMaxDatagramSize); + + pSocketObj->pending -= iBufferSize; + TUdpBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize); + + memcpy(&pBufferObj->remoteAddr, &pSocketObj->remoteAddr, sizeof(SOCKADDR_IN)); + memcpy(pBufferObj->buff.buf, itPtr->Ptr(), iBufferSize); + + int result = ::PostSendToNotCheck(m_soListen, pBufferObj); + + if(result != NO_ERROR) + { + if(result != WSA_IO_PENDING) + AddFreeBufferObj(pBufferObj); + + break; + } + } + + return result; +} + +BOOL CUdpServer::SendDetectPackage(CONNID dwConnID, TUdpSocketObj* pSocketObj) +{ + BOOL isOK = TRUE; + + if(!HasStarted()) + isOK = FALSE; + else + { + int rc = sendto(m_soListen, nullptr, 0, 0, (sockaddr*)&pSocketObj->remoteAddr, sizeof(SOCKADDR_IN)); + + if(rc == SOCKET_ERROR && ::WSAGetLastError() != WSAEWOULDBLOCK) + isOK = FALSE; + + if(isOK) + TRACE(" send 0 bytes (detect package)\n", dwConnID); + else + VERIFY(!HasStarted()); + } + + return isOK; +} + +UINT WINAPI CUdpServer::DetecotrThreadProc(LPVOID pv) +{ + TRACE("---------------> Server Detecotr Thread 0x%08X started <---------------\n", ::GetCurrentThreadId()); + + CUdpServer* pServer = (CUdpServer*)pv; + + ASSERT(pServer->NeedDetectorThread()); + + while(pServer->HasStarted()) + { + DWORD retval = ::WaitForSingleObject(pServer->m_evDetector, pServer->m_dwDetectInterval * 1000L); + + if(retval == WAIT_TIMEOUT) + pServer->DetectConnections(); + else if(retval == WAIT_OBJECT_0) + break; + else + ASSERT(FALSE); + } + + TRACE("---------------> Server Detecotr Thread 0x%08X stoped <---------------\n", ::GetCurrentThreadId()); + + return 0; +} + +void CUdpServer::DetectConnections() +{ + CReentrantReadLock locallock(m_csClientSocket); + + for(TUdpSocketObjPtrMapCI it = m_mpClientSocket.begin(), end = m_mpClientSocket.end(); it != end; ++it) + { + if(it->second->detectFails >= m_dwDetectAttempts) + ::PostIocpDisconnect(m_hCompletePort, it->first); + else + ::InterlockedIncrement(&it->second->detectFails); + } +} diff --git a/HP-Socket/Src/UdpServer.h b/HP-Socket/Src/UdpServer.h new file mode 100644 index 000000000..41bbcfdf7 --- /dev/null +++ b/HP-Socket/Src/UdpServer.h @@ -0,0 +1,273 @@ +/* + * Copyright: JessMA Open Source (ldcsaa@gmail.com) + * + * Version : 3.4.3 + * Author : Bruce Liang + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "SocketHelper.h" +#include "../../Common/Src/Event.h" +#include "../../Common/Src/RWLock.h" +#include "../../Common/Src/STLHelper.h" +#include "../../Common/Src/RingBuffer.h" +#include "../../Common/Src/PrivateHeap.h" + +class CUdpServer : public IUdpServer +{ +public: + CUdpServer(IUdpServerListener* psoListener) + : m_psoListener (psoListener) + , m_hCompletePort (nullptr) + , m_soListen (INVALID_SOCKET) + , m_iRemainPostReceives (0) + , m_enLastError (SE_OK) + , m_enState (SS_STOPPED) + , m_hDetector (nullptr) + , m_enSendPolicy (SP_PACK) + , m_dwWorkerThreadCount (DEFAULT_WORKER_THREAD_COUNT) + , m_dwFreeSocketObjLockTime (DEFAULT_FREE_SOCKETOBJ_LOCK_TIME) + , m_dwFreeSocketObjPool (DEFAULT_FREE_SOCKETOBJ_POOL) + , m_dwFreeBufferObjPool (DEFAULT_FREE_BUFFEROBJ_POOL) + , m_dwFreeSocketObjHold (DEFAULT_FREE_SOCKETOBJ_HOLD) + , m_dwFreeBufferObjHold (DEFAULT_FREE_BUFFEROBJ_HOLD) + , m_dwMaxDatagramSize (DEFAULT_UDP_MAX_DATAGRAM_SIZE) + , m_dwPostReceiveCount (DEFAULT_UDP_POST_RECEIVE_COUNT) + , m_dwDetectAttempts (DEFAULT_UDP_DETECT_ATTEMPTS) + , m_dwDetectInterval (DEFAULT_UDP_DETECT_INTERVAL) + , m_bMarkSilence (FALSE) + { + ASSERT(m_wsSocket.IsValid()); + ASSERT(m_psoListener); + + Reset(FALSE); + } + + virtual ~CUdpServer() + { + if(HasStarted()) + Stop(); + } + +public: + virtual BOOL Start (LPCTSTR pszBindAddress, USHORT usPort); + virtual BOOL Stop (); + virtual BOOL Send (CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset = 0); + virtual BOOL SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount); + virtual BOOL HasStarted () {return m_enState == SS_STARTED || m_enState == SS_STARTING;} + virtual EnServiceState GetState () {return m_enState;} + virtual BOOL Disconnect (CONNID dwConnID, BOOL bForce = TRUE); + virtual BOOL DisconnectLongConnections (DWORD dwPeriod, BOOL bForce = TRUE); + virtual BOOL DisconnectSilenceConnections(DWORD dwPeriod, BOOL bForce = TRUE); + virtual BOOL GetListenAddress (TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + virtual BOOL GetRemoteAddress (CONNID dwConnID, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort); + + virtual BOOL GetPendingDataLength (CONNID dwConnID, int& iPending); + virtual DWORD GetConnectionCount (); + virtual BOOL GetAllConnectionIDs (CONNID pIDs[], DWORD& dwCount); + virtual BOOL GetConnectPeriod (CONNID dwConnID, DWORD& dwPeriod); + virtual BOOL GetSilencePeriod (CONNID dwConnID, DWORD& dwPeriod); + virtual EnSocketError GetLastError () {return m_enLastError;} + virtual LPCTSTR GetLastErrorDesc () {return ::GetSocketErrorDesc(m_enLastError);} + +public: + virtual BOOL SetConnectionExtra(CONNID dwConnID, PVOID pExtra); + virtual BOOL GetConnectionExtra(CONNID dwConnID, PVOID* ppExtra); + + virtual void SetSendPolicy (EnSendPolicy enSendPolicy) {m_enSendPolicy = enSendPolicy;} + virtual void SetWorkerThreadCount (DWORD dwWorkerThreadCount) {m_dwWorkerThreadCount = dwWorkerThreadCount;} + virtual void SetFreeSocketObjLockTime (DWORD dwFreeSocketObjLockTime) {m_dwFreeSocketObjLockTime = dwFreeSocketObjLockTime;} + virtual void SetFreeSocketObjPool (DWORD dwFreeSocketObjPool) {m_dwFreeSocketObjPool = dwFreeSocketObjPool;} + virtual void SetFreeBufferObjPool (DWORD dwFreeBufferObjPool) {m_dwFreeBufferObjPool = dwFreeBufferObjPool;} + virtual void SetFreeSocketObjHold (DWORD dwFreeSocketObjHold) {m_dwFreeSocketObjHold = dwFreeSocketObjHold;} + virtual void SetFreeBufferObjHold (DWORD dwFreeBufferObjHold) {m_dwFreeBufferObjHold = dwFreeBufferObjHold;} + virtual void SetMaxDatagramSize (DWORD dwMaxDatagramSize) {m_dwMaxDatagramSize = dwMaxDatagramSize;} + virtual void SetPostReceiveCount (DWORD dwPostReceiveCount) {m_dwPostReceiveCount = dwPostReceiveCount;} + virtual void SetDetectAttempts (DWORD dwDetectAttempts) {m_dwDetectAttempts = dwDetectAttempts;} + virtual void SetDetectInterval (DWORD dwDetectInterval) {m_dwDetectInterval = dwDetectInterval;} + virtual void SetMarkSilence (BOOL bMarkSilence) {m_bMarkSilence = bMarkSilence;} + + virtual EnSendPolicy GetSendPolicy () {return m_enSendPolicy;} + virtual DWORD GetWorkerThreadCount () {return m_dwWorkerThreadCount;} + virtual DWORD GetFreeSocketObjLockTime () {return m_dwFreeSocketObjLockTime;} + virtual DWORD GetFreeSocketObjPool () {return m_dwFreeSocketObjPool;} + virtual DWORD GetFreeBufferObjPool () {return m_dwFreeBufferObjPool;} + virtual DWORD GetFreeSocketObjHold () {return m_dwFreeSocketObjHold;} + virtual DWORD GetFreeBufferObjHold () {return m_dwFreeBufferObjHold;} + virtual DWORD GetMaxDatagramSize () {return m_dwMaxDatagramSize;} + virtual DWORD GetPostReceiveCount () {return m_dwPostReceiveCount;} + virtual DWORD GetDetectAttempts () {return m_dwDetectAttempts;} + virtual DWORD GetDetectInterval () {return m_dwDetectInterval;} + virtual BOOL IsMarkSilence () {return m_bMarkSilence;} + +protected: + virtual EnHandleResult FirePrepareListen(SOCKET soListen) + {return m_psoListener->OnPrepareListen(soListen);} + virtual EnHandleResult FireAccept(TUdpSocketObj* pSocketObj) + {return m_psoListener->OnAccept(pSocketObj->connID, &pSocketObj->remoteAddr);} + virtual EnHandleResult FireReceive(TUdpSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return m_psoListener->OnReceive(pSocketObj->connID, pData, iLength);} + virtual EnHandleResult FireReceive(TUdpSocketObj* pSocketObj, int iLength) + {return m_psoListener->OnReceive(pSocketObj->connID, iLength);} + virtual EnHandleResult FireSend(TUdpSocketObj* pSocketObj, const BYTE* pData, int iLength) + {return m_psoListener->OnSend(pSocketObj->connID, pData, iLength);} + virtual EnHandleResult FireClose(TUdpSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode) + {return m_psoListener->OnClose(pSocketObj->connID, enOperation, iErrorCode);} + virtual EnHandleResult FireShutdown() + {return m_psoListener->OnShutdown();} + + void SetLastError(EnSocketError code, LPCSTR func, int ec); + virtual BOOL CheckParams(); + virtual void PrepareStart(); + virtual void Reset(BOOL bAll = TRUE); + +private: + EnHandleResult TriggerFireAccept(TUdpSocketObj* pSocketObj); + EnHandleResult TriggerFireReceive(TUdpSocketObj* pSocketObj, TUdpBufferObj* pBufferObj); + EnHandleResult TriggerFireSend(TUdpSocketObj* pSocketObj, TUdpBufferObj* pBufferObj); + EnHandleResult TriggerFireClose(TUdpSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode); + +protected: + BOOL SetConnectionExtra(TUdpSocketObj* pSocketObj, PVOID pExtra); + BOOL GetConnectionExtra(TUdpSocketObj* pSocketObj, PVOID* ppExtra); + BOOL SetConnectionReserved(CONNID dwConnID, PVOID pReserved); + BOOL GetConnectionReserved(CONNID dwConnID, PVOID* ppReserved); + BOOL SetConnectionReserved(TUdpSocketObj* pSocketObj, PVOID pReserved); + BOOL GetConnectionReserved(TUdpSocketObj* pSocketObj, PVOID* ppReserved); + +private: + static UINT WINAPI WorkerThreadProc(LPVOID pv); + static UINT WINAPI DetecotrThreadProc(LPVOID pv); + +private: + BOOL CheckStarting(); + BOOL CheckStoping(); + BOOL CreateListenSocket(LPCTSTR pszBindAddress, USHORT usPort); + BOOL CreateCompletePort(); + BOOL CreateWorkerThreads(); + BOOL CreateDetectorThread(); + BOOL StartAccept(); + + void CloseListenSocket(); + void WaitForPostReceiveRelease(); + void DisconnectClientSocket(); + void WaitForClientSocketClose(); + void ReleaseClientSocket(); + void ReleaseFreeSocket(); + void ReleaseFreeBuffer(); + void WaitForWorkerThreadEnd(); + void WaitForDetectorThreadEnd(); + void CloseCompletePort(); + + TUdpBufferObj* GetFreeBufferObj(int iLen = -1); + TUdpSocketObj* GetFreeSocketObj(CONNID dwConnID); + void AddFreeBufferObj(TUdpBufferObj* pBufferObj); + void AddFreeSocketObj(CONNID dwConnID, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0); + void AddFreeSocketObj(TUdpSocketObj* pSocketObj, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0); + TUdpBufferObj* CreateBufferObj(); + TUdpSocketObj* CreateSocketObj(); + void DeleteBufferObj(TUdpBufferObj* pBufferObj); + void DeleteSocketObj(TUdpSocketObj* pSocketObj); + BOOL InvalidSocketObj(TUdpSocketObj* pSocketObj); + void ReleaseGCSocketObj(BOOL bForce = FALSE); + + void AddClienTUdpSocketObj(CONNID dwConnID, TUdpSocketObj* pSocketObj); + void CloseClientUdpSocketObj(TUdpSocketObj* pSocketObj, EnSocketCloseFlag enFlag = SCF_NONE, EnSocketOperation enOperation = SO_UNKNOWN, int iErrorCode = 0); + TUdpSocketObj* FindSocketObj(CONNID dwConnID); + + CONNID FindConnectionID(SOCKADDR_IN* pAddr); + +private: + EnIocpAction CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey); + + void ForceDisconnect(CONNID dwConnID); + void HandleIo (CONNID dwConnID, TUdpBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode); + void HandleError (CONNID dwConnID, TUdpBufferObj* pBufferObj, DWORD dwErrorCode); + void HandleZeroBytes(CONNID dwConnID, TUdpBufferObj* pBufferObj); + CONNID HandleAccept (TUdpBufferObj* pBufferObj); + void HandleSend (CONNID dwConnID, TUdpBufferObj* pBufferObj); + void HandleReceive (CONNID dwConnID, TUdpBufferObj* pBufferObj); + + int SendInternal(CONNID dwConnID, const BYTE* pBuffer, int iLength); + int SendPack (TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int SendSafe (TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int SendDirect (TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength); + int CatAndPost (TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend); + + BOOL DoAccept (); + int DoReceive (TUdpBufferObj* pBufferObj); + + int DoSend (CONNID dwConnID); + int DoSend (TUdpSocketObj* pSocketObj); + int DoSendPack (TUdpSocketObj* pSocketObj); + int DoSendSafe (TUdpSocketObj* pSocketObj); + int SendItem (TUdpSocketObj* pSocketObj); + + void DetectConnections (); + BOOL SendDetectPackage (CONNID dwConnID, TUdpSocketObj* pSocketObj); + BOOL NeedDetectorThread () {return m_dwDetectAttempts > 0 && m_dwDetectInterval > 0;} + +private: + EnSendPolicy m_enSendPolicy; + DWORD m_dwWorkerThreadCount; + DWORD m_dwFreeSocketObjLockTime; + DWORD m_dwFreeSocketObjPool; + DWORD m_dwFreeBufferObjPool; + DWORD m_dwFreeSocketObjHold; + DWORD m_dwFreeBufferObjHold; + DWORD m_dwMaxDatagramSize; + DWORD m_dwPostReceiveCount; + DWORD m_dwDetectAttempts; + DWORD m_dwDetectInterval; + BOOL m_bMarkSilence; + +private: + CInitSocket m_wsSocket; + +private: + IUdpServerListener* m_psoListener; + SOCKET m_soListen; + HANDLE m_hCompletePort; + EnServiceState m_enState; + EnSocketError m_enLastError; + + HANDLE m_hDetector; + vector m_vtWorkerThreads; + + CPrivateHeap m_phBuffer; + CPrivateHeap m_phSocket; + CItemPool m_itPool; + + CSpinGuard m_csState; + + CCriSec m_csAccept; + CEvt m_evDetector; + + CRWLock m_csClientSocket; + TUdpSocketObjPtrMap m_mpClientSocket; + TSockAddrMap m_mpClientAddr; + + TUdpBufferObjPtrList m_lsFreeBuffer; + TUdpSocketObjPtrList m_lsFreeSocket; + TUdpSocketObjPtrQueue m_lsGCSocket; + + volatile long m_iRemainPostReceives; +}; diff --git a/LICENSE b/LICENSE index c4046e5db..e5aa507fe 100644 --- a/LICENSE +++ b/LICENSE @@ -1,12 +1,12 @@ /* - * Copyright JessMA Open Source + * Copyright JessMA Open Source (ldcsaa@gmail.com) * - * Author : Bruce Liang - * Website : http://www.jessma.org - * Project : http://github.com/ldcsaa - * Blog : http://www.cnblogs.com/ldcsaa - * WeiBo : http://weibo.com/u/1402935851 - * QQ Group : 75375912 + * Author : JessMA Open Source + * Website : http://www.jessma.org + * Project : https://github.com/ldcsaa + * Blog : http://www.cnblogs.com/ldcsaa + * Wiki : http://www.oschina.net/p/hp-socket + * QQ Group : 75375912 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,3 +20,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + \ No newline at end of file diff --git a/Readme.txt b/Readme.txt new file mode 100644 index 000000000..2e4cd34eb --- /dev/null +++ b/Readme.txt @@ -0,0 +1,3 @@ +*** HP-Socket Դ *** +---------------------------------------- + HP-Socket v3.4.3 Դ vc-common-src v2.3.11 еĻ롣ˣ HP-Socket v3.4.3 ʱҪͬʱ vc-common-src v2.3.11 \ No newline at end of file