| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #pragma once
- #include <thread>
- #include <mutex>
- #include <map>
- #include <string>
- #include <UDPSocket.h>
- #include <ProtocolHandler.h>
- #include <ZlDataDefine.h>
- #include "SuperTCPClient.h"
- //#include "SuperHandler.h"
- #include "SuperBuffer.h"
- #include "LibEventTCPClient.h"
- #include "SuperHandler.h"
- /*
- 同步策略 更新加定时
- */
- struct per_user_data
- {
- SOCKADDR_IN addr = { 0 };
- char ip[16] = { 0 };
- uint16_t port = 10090;
- CSuperBuffer m_buffer;
- CSuperTCPClient m_socket;
- CLibEventTCPClient m_client; //new
- CSuperHandler handler;
- uint32_t sendcount = 0;
- uint64_t sendlen = 0;
- uint32_t recvcount = 0;
- uint32_t sendfail = 0;
- uint32_t rectfail = 0;
- time_t tmLastSendBeart = 0;
- };
- class CSuperManager
- {
- private:
- CSuperManager();
- ~CSuperManager();
- public:
- BOOL Start(CString,uint16_t port = 10089);
- void Stop();
- inline uint8_t GetSuperNum(){
- return m_super_num;
- }
- inline string SendDesc()
- {
- string desc;
- for (const auto&it : m_super)
- {
- string strLog;
- auto& item = it.second.sendlen;
- if (item > 1024 * 1024 * 1024)
- strLog = fmt::format("{}GB {}MB {} KB", item / (1024 * 1024 * 1024),
- item % (1024 * 1024 * 1024) / (1024 * 1024), item % (1024 * 1024) / 1024);
- else if (item > 1024 * 1024)
- strLog = fmt::format("{}MB {} KB", item / (1024 * 1024), item % (1024 * 1024) / 1024);
- else
- strLog = fmt::format("{} KB ", item / 1024);
- desc += fmt::format("{} 包数:{} 流量:{};", it.first, it.second.sendcount, strLog);
- }
- return desc;
- }
- inline string FailDesc()
- {
- string desc;
- for (auto& it : m_super)
- desc += fmt::format("{} 包数:{}; 待发送:{}", it.first, it.second.sendfail, it.second.handler.tasksize());
- return desc;
- }
- inline string recvDesc()
- {
- string desc;
- for (auto& it : m_super)
- desc += fmt::format("{} 包数:{} 发送缓冲:{};", it.first, it.second.recvcount, it.second.m_client.send_queue_len());
- return desc;
- }
- inline void SendPack(LPBYTE pPack, int nPackLen, uint32_t packno, E_ZL_PROTOCAL protocal, bool r)
- {
- for (auto& it : m_super)
- //it.second.m_socket.Insert(pPack, nPackLen, packno, protocal, r);
- it.second.handler.Insert(pPack, nPackLen, packno, protocal, r);
- }
- inline static auto Instance() { return &obj; };
- private:
- static CSuperManager obj;
- static void ThreadProcForSend(DWORD_PTR);
- std::thread* m_pThread = nullptr;
- bool m_bWork = false;
- std::map<std::string, per_user_data> m_super; //ip,data
- uint8_t m_super_num = 0;
- };
|