⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtcpmsgserver.h

📁 BCB下的高效开发包。包含大并发的网络库
💻 H
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -