qtcpmsgserver.h

来自「BCB下的高效开发包。包含大并发的网络库」· C头文件 代码 · 共 72 行

H
72
字号
#ifndef QTcpMsgServerH
#define QTcpMsgServerH
#include "Interface_QTcpMsgServer.h"
#include "../QTemplateBase/QTemplateBase.h"
#include "../QAsynTcpServer/Interface_QAsynTcpServer.h"
#include "../QAsynTcpServer/Interface_QTcpListenDevice.h"
#include <assert.h>
#include <vector>
#include <stlport/hash_map>
namespace N_QTcpMsgServer {
//---------------------------------------------------------------------------
struct ITEM
{
        int Sock;
        std::string Buf;
};
struct MSGITEM
{
        int SessionID;
        std::string Msg;
};
//---------------------------------------------------------------------------
class QTcpMsgServer : public IQTcpMsgServer
{
        public:
                             __stdcall QTcpMsgServer();
                virtual      __stdcall ~QTcpMsgServer();
                virtual void __stdcall Release() { assert(this); delete this; }

                virtual bool __stdcall Start(unsigned int Port, unsigned int MaxSession
                    , const std::string& EndSign, unsigned int MaxPackage);
                virtual void __stdcall Stop(void);
                virtual bool __stdcall IsPowerOn(void)const;
                virtual bool __stdcall Send(int SessionID, const std::string& Msg);
                virtual bool __stdcall GetQueuedMsg(int* pSessionID, std::string* pMsg);//当返回pMsg为空表示该Session断开,在GC机制下可以不理会
                virtual std::string __stdcall GetAddress(int SessionID)const;
                virtual void __stdcall ShutDown(int SessionID);
                virtual void __stdcall Process(void);
                virtual void __stdcall ProcessGC(void);
                virtual void __stdcall SetTimeOut(unsigned int TimeOut);
                virtual bool __stdcall IsExist(int SessionID)const;
                virtual unsigned int __stdcall GetCount(void)const;
                virtual void __stdcall SetReadLastData(bool IsReadLast);
                virtual int  __stdcall PushSocket(int Sock);
                
        private:
                bool __stdcall Append(int Sock);
                void __stdcall Remove(int SessionID);
                void __stdcall ProcessAccept(void);
                void __stdcall ProcessDelete(void);
                void __stdcall ProcessRecv(void);
                
                typedef std::hash_map<unsigned int, ITEM> ID_MAP;



                IQAsynTcpServer*        m_Server;
                IQTcpListenDevice*      m_Listener;
                QBasicMsg<MSGITEM>      m_Msg;
                ID_MAP                  m_Map;
                unsigned int            m_NewIter;
                
                unsigned int            m_MaxSession;
                std::string             m_EndSign;
                unsigned int            m_MaxPackage;

                bool                    m_IsReadLastData;
};
//---------------------------------------------------------------------------
}//namespace
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?