#pragma once #include #include "LNContext.h" #include #include #include extern string g_strLocalIp; class CLNAcceptor : public CAcceptor { public: CLNAcceptor(CProtocolHandler *); virtual ~CLNAcceptor(void); friend class CLNHandle; virtual CLNContext* make_handler() override; BOOL Start(); void Stop(); void Lock() { cs.Lock(); } void Unlock() { cs.Unlock(); } virtual void OnClearContext(); //定时清除链接 void ClearAllContexts(); //清除所有链接 int GetContextNum(); //查找链接 CLNContext* FindContext(DWORD_PTR pContext); void SendDataAllContexts(uint8_t* data, size_t len); private: static void ThreadProc(DWORD_PTR); std::thread* m_pThread = nullptr; bool m_bWork = false; time_t m_tmLastKeep = 0; time_t m_tmLastZero = 0; protected: virtual int validate_connection(const ACE_Asynch_Accept::Result& result, const ACE_INET_Addr& remote, const ACE_INET_Addr& local) override { auto ip_addr = local.get_ip_address(); auto strIp =local.get_host_addr();; if (ip_addr != 0x7F000001) g_strLocalIp = strIp; SPDLOG_ERROR("new connection: {}:{} local:{}:{}", remote.get_host_addr(), remote.get_port_number(), strIp, local.get_port_number()); return 0; } CCriticalSection cs; std::list m_lstClientContext; CProtocolHandler *m_pHandler = nullptr; };