/************************************************************* /* Copyright (C), 2014-2020, lyfz. Co., Ltd. /* 文件名: IServerImpl.h /* 作者: Jeff.w /* 创建日期: 2014-08-07 /* 版本号: V1.0 /* 描述: 核心层底,客户端与服务端通信接口 /* 其它: /* 主要类模块: /* 历史修改记录: /* 作者 时间 版本 描述 /* Jeff.w 14/08/07 1.0 创建这个模块 ***************************************************************/ #ifndef __ISERVER_IMPL_HEADER__ #define __ISERVER_IMPL_HEADER__ #pragma once #include #include //#pragma warning(push) //#pragma warning(disable:4995) #include //#pragma warning(pop) #include "CritSection.h" #include "SocketHandle.h" #include "SocketServerImpl.h" #if defined(SOCKHANDLE_USE_OVERLAPPED) #include "AsyncSocketServerImpl.h" #endif #include "Global.h" // 宏定义:计算数据包总长度; #define CALCDATALEN(x) (x+sizeof(STProtocolheader)+sizeof(STProtocoltail)) // 使用通信这一块,完全分离出来; namespace ServerSocketImpl { typedef std::list CSocketList; class IServerImpl :public ISocketServerHandler { #if defined(SOCKHANDLE_USE_OVERLAPPED) typedef ASocketServerImpl CSocketServer; #else typedef SocketServerImpl CSocketServer; #endif friend CSocketServer; public: IServerImpl(); ~IServerImpl(); virtual void OnThreadBegin(CSocketHandle* pSH); virtual void OnThreadExit(CSocketHandle* pSH); virtual void OnAddConnection(CSocketHandle* pSH, SOCKET newSocket); virtual void OnDataReceived(CSocketHandle* pSH, const BYTE* pbData, DWORD dwCount, const SockAddrIn& addr); virtual void OnConnectionFailure(CSocketHandle* pSH, SOCKET newSocket); virtual void OnConnectionDropped(CSocketHandle* pSH); virtual void OnConnectionError(CSocketHandle* pSH, DWORD dwError); #if defined(SOCKHANDLE_USE_OVERLAPPED) virtual void OnRemoveConnection(CSocketHandle* pSH , SOCKET dropSocket); //virtual void OnThreadLoopEnter(CSocketHandle* pSH); //virtual void OnThreadLoopLeave(CSocketHandle* pSH); #endif protected: CString m_strPort; int m_nPort; int m_nMode; int m_nSockType; CSocketServer m_SocketServer; void _cdecl AppendText(LPCTSTR lpszFormat, ...); void GetAddress(const SockAddrIn& addrIn, CString& rString) const; bool GetDestination(SockAddrIn& addrIn) const; bool SetupMCAST(); // Jeff.最新研究出来的处理方案; // 对异常包需要计数处理,当1分钟内出现多少异常包时,需要重启服务函数; //unsigned int VerityIntegrityPacket(IN void *pIntegrityPacket,unsigned int nPacketSize); //void ToprocessRecivebuf(IN CSocketHandle &sockHandle, IN const BYTE* pReceivebuf, IN DWORD dwReceiveSize); void ToprocessRecivebuf(IN SocketIOBuffer &sockIOBuffer, IN const BYTE* pReceivebuf, IN DWORD dwReceiveSize); //int OnIntegrityPacket(IN CSocketHandle &sockHandle, IN void *pIntegrityPacket); int OnIntegrityPacket(IN SocketIOBuffer &sockHandle, IN void *pIntegrityPacket); public: BOOL m_bStopbeat; int m_nSocketIndex; CRITICAL_SECTION m_csProcessData; DWORD GetClientConnectCount(); BOOL Initialize(); void Start(IN LPCTSTR strPort,IN const int &nMode); void Stop(); void Send(); void SendAll(CSocketHandle &sockHandle, unsigned char *pMsg, int nLength); HANDLE m_hClearInvalidateSocketThread; HANDLE m_hRunObject; void StartClearInvalidateSocketThread(); static DWORD WINAPI ClearInvalidateSocketThread(void *pInstance); private: CSocketHandle m_SocketFile; }; extern IServerImpl* g_pServerSocket[20]; }; #endif