From 0115c72ac5eb2dc0863155509b49332581a1b0e1 Mon Sep 17 00:00:00 2001 From: liuchao412 Date: Sat, 22 Jul 2023 15:14:18 +0800 Subject: [PATCH] Support operating network service interfaces for logic. --- Common/ISessionService.h | 2 + Common/define.h | 1 + PSS_ASIO/Common/NetSvrManager.cpp | 198 ++++++++++++++++++++++++++++ PSS_ASIO/Common/NetSvrManager.h | 51 +++++++ PSS_ASIO/Common/ServerService.cpp | 112 ++-------------- PSS_ASIO/Common/ServerService.h | 22 +--- PSS_ASIO/Message/SessionService.cpp | 9 ++ PSS_ASIO/Message/SessionService.h | 4 + PSS_ASIO/UdpSession/KcpServer.cpp | 3 + PSS_ASIO/UdpSession/UdpServer.cpp | 115 +++++++++------- PSS_ASIO/UdpSession/UdpServer.h | 4 + 11 files changed, 351 insertions(+), 170 deletions(-) create mode 100644 PSS_ASIO/Common/NetSvrManager.cpp create mode 100644 PSS_ASIO/Common/NetSvrManager.h diff --git a/Common/ISessionService.h b/Common/ISessionService.h index 414c669..129c91d 100644 --- a/Common/ISessionService.h +++ b/Common/ISessionService.h @@ -42,4 +42,6 @@ class ISessionService virtual uint32 get_connect_id(uint32 server_id) = 0; virtual void regedit_bridge_session_id(uint32 connect_id = 0) = 0; + virtual void start_single_service(const CConfigNetIO& netio) = 0; + virtual void close_single_service(const CConfigNetIO& netio) = 0; }; diff --git a/Common/define.h b/Common/define.h index 6228daa..3ab4ab5 100644 --- a/Common/define.h +++ b/Common/define.h @@ -90,6 +90,7 @@ class CConfigNetIO public: std::string ip_; io_port_type port_ = 0; + std::string protocol_type_ = "TCP"; unsigned int packet_parse_id_ = 0; unsigned int recv_buff_size_ = 1024; unsigned int send_buff_size_ = 1024; diff --git a/PSS_ASIO/Common/NetSvrManager.cpp b/PSS_ASIO/Common/NetSvrManager.cpp new file mode 100644 index 0000000..b43d898 --- /dev/null +++ b/PSS_ASIO/Common/NetSvrManager.cpp @@ -0,0 +1,198 @@ +#include "NetSvrManager.h" +#include +#include + +CNetSvrManager::CNetSvrManager() +{ +} + +CNetSvrManager::~CNetSvrManager() +{ + this->close_all_service(); +} + +void CNetSvrManager::start_default_service() +{ + string stripport; + + //加载Tcp监听 + for(auto tcp_server : App_ServerConfig::instance()->get_config_tcp_list()) + { + if (tcp_server.ssl_server_password_ != "" + && tcp_server.ssl_server_pem_file_ != "" + && tcp_server.ssl_dh_pem_file_ != "") + { +#ifdef SSL_SUPPORT + auto tcp_ssl_service = make_shared(CreateIoContextFunctor, + tcp_server.ip_, + tcp_server.port_, + tcp_server.packet_parse_id_, + tcp_server.recv_buff_size_, + tcp_server.ssl_server_password_, + tcp_server.ssl_server_pem_file_, + tcp_server.ssl_dh_pem_file_); + stripport = tcp_server.ip_ + "_" + std::to_string(tcp_server.port_); + tcp_ssl_service_map_[stripport] = tcp_ssl_service; +#else + PSS_LOGGER_DEBUG("[CNetSvrManager::start_default_service]you must set SSL_SUPPORT macro on compilation options."); +#endif + } + else + { + //正常的tcp链接 + auto tcp_service = make_shared(CreateIoContextFunctor, + tcp_server.ip_, + tcp_server.port_, + tcp_server.packet_parse_id_, + tcp_server.recv_buff_size_); + stripport = tcp_server.ip_ + "_" + std::to_string(tcp_server.port_); + tcp_service_map_[stripport] = tcp_service; + } + } + + //加载UDP监听 + for (auto udp_server : App_ServerConfig::instance()->get_config_udp_list()) + { + auto udp_service = make_shared(CreateIoContextFunctor(), + udp_server.ip_, + udp_server.port_, + udp_server.packet_parse_id_, + udp_server.recv_buff_size_, + udp_server.send_buff_size_, + udp_server.em_net_type_); + udp_service->start(); + stripport = udp_server.ip_ + "_" + std::to_string(udp_server.port_); + udp_service_map_[stripport] = udp_service; + } + + //加载KCP监听 + for (auto kcp_server : App_ServerConfig::instance()->get_config_kcp_list()) + { + auto kcp_service = make_shared(CreateIoContextFunctor(), + kcp_server.ip_, + kcp_server.port_, + kcp_server.packet_parse_id_, + kcp_server.recv_buff_size_, + kcp_server.send_buff_size_); + kcp_service->start(); + stripport = kcp_server.ip_ + "_" + std::to_string(kcp_server.port_); + kcp_service_map_[stripport] = kcp_service; + } + + //加载tty监听 + for (auto tty_server : App_ServerConfig::instance()->get_config_tty_list()) + { + auto tty_service = make_shared( + tty_server.packet_parse_id_, + tty_server.recv_buff_size_, + tty_server.send_buff_size_); + tty_service->start(CreateIoContextFunctor(), + tty_server.tty_name_, + (uint16)tty_server.tty_port_, + (uint8)tty_server.char_size_, + 0); + tty_service_map_[tty_server.tty_name_] = tty_service; + } + + return; +} + +void CNetSvrManager::close_all_service() +{ + PSS_LOGGER_DEBUG("[CNetSvrManager::close_all_service]begin."); + + //停止所有的TCP监听(TCP) + for (const auto& tcp_service : tcp_service_map_) + { + tcp_service.second->close(); + } + +#ifdef SSL_SUPPORT + //停止所有的SSL监听 + for (const auto& tcp_ssl_service : tcp_ssl_service_map_) + { + tcp_ssl_service.second->close(); + } +#endif + + //清理所有kcp资源 + for (const auto& kcp_service : kcp_service_map_) + { + kcp_service.second->close_all(); + } + + //清理所有udp资源 + for (const auto& udp_service : udp_service_map_) + { + udp_service.second->close_all(); + } + + tcp_service_map_.clear(); + + kcp_service_map_.clear(); + + udp_service_map_.clear(); + +#ifdef SSL_SUPPORT + tcp_ssl_service_map_.clear(); +#endif + PSS_LOGGER_DEBUG("[CNetSvrManager::close_all_service]end."); +} + +void CNetSvrManager::start_single_service(const CConfigNetIO& netio) +{ + std::lock_guard lock(mutex_); + string stripport; + if("TCP" == netio.protocol_type_) + { + PSS_LOGGER_INFO("[CNetSvrManager::start_single_service]create tcp service[{}:{}]",netio.ip_,netio.port_); + auto tcp_service = make_shared(CreateIoContextFunctor, + netio.ip_, + netio.port_, + netio.packet_parse_id_, + netio.recv_buff_size_); + stripport = netio.ip_ + "_" + std::to_string(netio.port_); + tcp_service_map_[stripport] = tcp_service; + } + else + { + PSS_LOGGER_INFO("[CNetSvrManager::start_single_service]create udp service[{}:{}]",netio.ip_,netio.port_); + auto udp_service = make_shared(CreateIoContextFunctor(), + netio.ip_, + netio.port_, + netio.packet_parse_id_, + netio.recv_buff_size_, + netio.send_buff_size_, + netio.em_net_type_); + udp_service->start(); + stripport = netio.ip_ + "_" + std::to_string(netio.port_); + udp_service_map_[stripport] = udp_service; + } +} + +void CNetSvrManager::close_single_service(const CConfigNetIO& netio) +{ + std::lock_guard lock(mutex_); + string stripport = netio.ip_ + "_" + std::to_string(netio.port_); + if("TCP" == netio.protocol_type_) + { + PSS_LOGGER_INFO("[CNetSvrManager::close_single_service]close tcp service[{}:{}]",netio.ip_,netio.port_); + auto tcp = tcp_service_map_.find(stripport); + if (tcp != tcp_service_map_.end()) + { + tcp->second->close(); + tcp_service_map_.erase(stripport); + } + } + else + { + PSS_LOGGER_INFO("[CNetSvrManager::close_single_service]close udp service[{}:{}]",netio.ip_,netio.port_); + auto udp = udp_service_map_.find(stripport); + if (udp != udp_service_map_.end()) + { + udp->second->close_all(); + udp_service_map_.erase(stripport); + } + } +} + diff --git a/PSS_ASIO/Common/NetSvrManager.h b/PSS_ASIO/Common/NetSvrManager.h new file mode 100644 index 0000000..35a87d8 --- /dev/null +++ b/PSS_ASIO/Common/NetSvrManager.h @@ -0,0 +1,51 @@ +#pragma once + +#include "TcpSSLServer.h" +#include "TcpServer.h" +#include "UdpServer.h" +#include "KcpServer.h" +#include "TtyServer.h" +#include "QueueService.h" +#include "serverconfig.h" +#include "CommunicationService.h" +#include "SessionService.h" +#include "IoContextPool.h" + +#if PSS_PLATFORM == PLATFORM_WIN +#include +#endif + +class CNetSvrManager : private asio::noncopyable +{ +public: + CNetSvrManager(); + ~CNetSvrManager(); + void start_default_service(); + void close_all_service(); + + void start_single_service(const CConfigNetIO& netio); + void close_single_service(const CConfigNetIO& netio); + +private: + using hashipport2tcpserver = unordered_map>; + hashipport2tcpserver tcp_service_map_; + + using hashipport2udpserver = unordered_map>; + hashipport2udpserver udp_service_map_; + + using hashipport2kcpserver = unordered_map>; + hashipport2kcpserver kcp_service_map_; + + using hashttyname2tcpserver = unordered_map>; + hashttyname2tcpserver tty_service_map_; + +#ifdef SSL_SUPPORT + using hashipport2tcpsslserver = unordered_map>; + hashipport2tcpsslserver tcp_ssl_service_map_; +#endif + +private: + std::mutex mutex_; +}; + +using App_NetSvrManager = PSS_singleton; diff --git a/PSS_ASIO/Common/ServerService.cpp b/PSS_ASIO/Common/ServerService.cpp index 28be928..90cce1d 100644 --- a/PSS_ASIO/Common/ServerService.cpp +++ b/PSS_ASIO/Common/ServerService.cpp @@ -49,7 +49,7 @@ inline void daemonize() } #endif -bool CServerService::init_servce(const std::string& pss_config_file_name) +bool CServerService::init_service(const std::string& pss_config_file_name) { //指定当前目录,防止访问文件失败 #if PSS_PLATFORM == PLATFORM_WIN @@ -69,7 +69,7 @@ bool CServerService::init_servce(const std::string& pss_config_file_name) return false; } - PSS_LOGGER_DEBUG("[CServerService::init_servce]configure file {0} read ok.", pss_config_file_name); + PSS_LOGGER_DEBUG("[CServerService::init_service]configure file {0} read ok.", pss_config_file_name); #if PSS_PLATFORM == PLATFORM_UNIX if (App_ServerConfig::instance()->get_config_workthread().linux_daemonize_ != 0) @@ -78,7 +78,6 @@ bool CServerService::init_servce(const std::string& pss_config_file_name) daemonize(); } #endif - const auto& config_output = App_ServerConfig::instance()->get_config_console(); //初始化输出 @@ -95,7 +94,7 @@ bool CServerService::init_servce(const std::string& pss_config_file_name) packet_parse.packet_parse_path_, packet_parse.packet_parse_file_name_)) { - PSS_LOGGER_DEBUG("[CServerService::init_servce] load error."); + PSS_LOGGER_DEBUG("[CServerService::init_service] load error."); } } @@ -109,7 +108,7 @@ bool CServerService::init_servce(const std::string& pss_config_file_name) signals.async_wait( [this](std::error_code ec, int) { - PSS_LOGGER_DEBUG("[CServerService::init_servce] server is error({0}).", ec.message()); + PSS_LOGGER_DEBUG("[CServerService::init_service] server is error({0}).", ec.message()); App_IoContextPool::instance()->stop(); }); @@ -136,87 +135,15 @@ bool CServerService::init_servce(const std::string& pss_config_file_name) App_ServerConfig::instance()->get_config_logic_list(), App_SessionService::instance()); - //加载Tcp监听 - for(auto tcp_server : App_ServerConfig::instance()->get_config_tcp_list()) - { - if (tcp_server.ssl_server_password_ != "" - && tcp_server.ssl_server_pem_file_ != "" - && tcp_server.ssl_dh_pem_file_ != "") - { -#ifdef SSL_SUPPORT - auto tcp_ssl_service = make_shared(CreateIoContextFunctor, - tcp_server.ip_, - tcp_server.port_, - tcp_server.packet_parse_id_, - tcp_server.recv_buff_size_, - tcp_server.ssl_server_password_, - tcp_server.ssl_server_pem_file_, - tcp_server.ssl_dh_pem_file_); - tcp_ssl_service_list_.emplace_back(tcp_ssl_service); -#else - PSS_LOGGER_DEBUG("[CServerService::init_servce]you must set SSL_SUPPORT macro on compilation options."); -#endif - } - else - { - //正常的tcp链接 - auto tcp_service = make_shared(CreateIoContextFunctor, - tcp_server.ip_, - tcp_server.port_, - tcp_server.packet_parse_id_, - tcp_server.recv_buff_size_); - tcp_service_list_.emplace_back(tcp_service); - } - } - - //加载UDP监听 - for (auto udp_server : App_ServerConfig::instance()->get_config_udp_list()) - { - auto udp_service = make_shared(CreateIoContextFunctor(), - udp_server.ip_, - udp_server.port_, - udp_server.packet_parse_id_, - udp_server.recv_buff_size_, - udp_server.send_buff_size_, - udp_server.em_net_type_); - udp_service->start(); - udp_service_list_.emplace_back(udp_service); - } - - //加载KCP监听 - for (auto kcp_server : App_ServerConfig::instance()->get_config_kcp_list()) - { - auto kcp_service = make_shared(CreateIoContextFunctor(), - kcp_server.ip_, - kcp_server.port_, - kcp_server.packet_parse_id_, - kcp_server.recv_buff_size_, - kcp_server.send_buff_size_); - kcp_service->start(); - kcp_service_list_.emplace_back(kcp_service); - } - - //加载tty监听 - for (auto tty_server : App_ServerConfig::instance()->get_config_tty_list()) - { - auto tty_service = make_shared( - tty_server.packet_parse_id_, - tty_server.recv_buff_size_, - tty_server.send_buff_size_); - tty_service->start(CreateIoContextFunctor(), - tty_server.tty_name_, - (uint16)tty_server.tty_port_, - (uint8)tty_server.char_size_, - 0); - tty_service_list_.emplace_back(tty_service); - } - + //启动初始化配置好的网络服务 + App_NetSvrManager::instance()->start_default_service(); + //打开服务器间链接 App_CommunicationService::instance()->run_server_to_server(); App_IoContextPool::instance()->run(); - PSS_LOGGER_DEBUG("[CServerService::init_servce] server is over."); + PSS_LOGGER_DEBUG("[CServerService::init_service] server is over."); close_service(); return true; @@ -232,27 +159,8 @@ void CServerService::close_service() //停止服务间消息队列数据接收 App_QueueSessionManager::instance()->close(); - //停止所有的TCP监听(TCP) - for (const auto& tcp_service : tcp_service_list_) - { - tcp_service->close(); - } - -#ifdef SSL_SUPPORT - //停止所有的SSL监听 - for (const auto& tcp_ssl_service : tcp_ssl_service_list_) - { - tcp_ssl_service->close(); - } -#endif - - //清理所有kcp资源 - for (const auto& kcp_service : kcp_service_list_) - { - kcp_service->close_all(); - } - - tcp_service_list_.clear(); + //停止所有网络服务 + App_NetSvrManager::instance()->close_all_service(); App_SessionService::instance()->close(); diff --git a/PSS_ASIO/Common/ServerService.h b/PSS_ASIO/Common/ServerService.h index 965bd1b..3e01cd4 100644 --- a/PSS_ASIO/Common/ServerService.h +++ b/PSS_ASIO/Common/ServerService.h @@ -2,17 +2,11 @@ //服务主入口 //add by freeeyes - -#include "TcpSSLServer.h" -#include "TcpServer.h" -#include "UdpServer.h" -#include "KcpServer.h" -#include "TtyServer.h" #include "QueueService.h" #include "serverconfig.h" #include "CommunicationService.h" #include "SessionService.h" -#include "IoContextPool.h" +#include "NetSvrManager.h" #if PSS_PLATFORM == PLATFORM_WIN #include @@ -21,21 +15,9 @@ class CServerService { public: - bool init_servce(const std::string& pss_config_file_name = config_file_name); - + bool init_service(const std::string& pss_config_file_name = config_file_name); void close_service(); - void stop_service(); - -private: - vector> tcp_service_list_; - vector> udp_service_list_; - vector> kcp_service_list_; - vector> tty_service_list_; - -#ifdef SSL_SUPPORT - vector> tcp_ssl_service_list_; -#endif }; using App_ServerService = PSS_singleton; diff --git a/PSS_ASIO/Message/SessionService.cpp b/PSS_ASIO/Message/SessionService.cpp index 6786304..c7d140b 100644 --- a/PSS_ASIO/Message/SessionService.cpp +++ b/PSS_ASIO/Message/SessionService.cpp @@ -209,3 +209,12 @@ void CSessionService::regedit_bridge_session_id(uint32 connect_id) } } +void CSessionService::start_single_service(const CConfigNetIO& netio) +{ + return App_NetSvrManager::instance()->start_single_service(netio); +} + +void CSessionService::close_single_service(const CConfigNetIO& netio) +{ + return App_NetSvrManager::instance()->close_single_service(netio); +} diff --git a/PSS_ASIO/Message/SessionService.h b/PSS_ASIO/Message/SessionService.h index f7dee32..491fc79 100644 --- a/PSS_ASIO/Message/SessionService.h +++ b/PSS_ASIO/Message/SessionService.h @@ -8,6 +8,7 @@ #include "serverconfig.h" #include "QueueService.h" #include "Iobridge.h" +#include "NetSvrManager.h" class CSessionService : public ISessionService { @@ -42,6 +43,9 @@ class CSessionService : public ISessionService void regedit_bridge_session_id(uint32 connect_id) final; + void start_single_service(const CConfigNetIO& netio) final; + void close_single_service(const CConfigNetIO& netio) final; + void close(); private: diff --git a/PSS_ASIO/UdpSession/KcpServer.cpp b/PSS_ASIO/UdpSession/KcpServer.cpp index cb4776e..76377ef 100644 --- a/PSS_ASIO/UdpSession/KcpServer.cpp +++ b/PSS_ASIO/UdpSession/KcpServer.cpp @@ -184,9 +184,12 @@ void CKcpServer::close_all() for (const auto& session_info : udp_id_2_endpoint_list_) { session_info.second->close_kcp(); + this->close(session_info.first); } udp_id_2_endpoint_list_.clear(); + udp_endpoint_2_id_list_.clear(); + socket_.close(); } void CKcpServer::set_write_buffer(uint32 connect_id, const char* data, size_t length) diff --git a/PSS_ASIO/UdpSession/UdpServer.cpp b/PSS_ASIO/UdpSession/UdpServer.cpp index 47de4a0..359e527 100644 --- a/PSS_ASIO/UdpSession/UdpServer.cpp +++ b/PSS_ASIO/UdpSession/UdpServer.cpp @@ -1,7 +1,7 @@ #include "UdpServer.h" CUdpServer::CUdpServer(asio::io_context* io_context, const std::string& server_ip, io_port_type port, uint32 packet_parse_id, uint32 max_recv_size, uint32 max_send_size, EM_NET_TYPE em_net_type) - : socket_(*io_context), max_recv_size_(max_recv_size), max_send_size_(max_send_size), io_context_(io_context) + : socket_(*io_context), max_recv_size_(max_recv_size), max_send_size_(max_send_size), io_context_(io_context),server_ip_(server_ip),server_port_(port) { //处理链接建立消息 PSS_LOGGER_DEBUG("[CUdpServer::do_accept]{0}:{1} Begin Accept.", server_ip, port); @@ -73,65 +73,72 @@ void CUdpServer::do_receive() void CUdpServer::do_receive_from(std::error_code ec, std::size_t length) { - //查询当前的connect_id - auto connect_id = add_udp_endpoint(recv_endpoint_, length, max_send_size_); - - if (!ec && length > 0) + try { - //处理数据包 - auto self(shared_from_this()); + //查询当前的connect_id + auto connect_id = add_udp_endpoint(recv_endpoint_, length, max_send_size_); - //如果缓冲已满,断开连接,不再接受数据。 - if (session_recv_buffer_.get_buffer_size() == 0) + if (!ec && length > 0) { - //链接断开(缓冲撑满了) - session_recv_buffer_.move(length); - App_WorkThreadLogic::instance()->close_session_event(connect_id); - do_receive(); - return; - } - - session_recv_buffer_.set_write_data(length); + //处理数据包 + auto self(shared_from_this()); - auto session_info = find_udp_endpoint_by_id(connect_id); - - if (nullptr != session_info && EM_SESSION_STATE::SESSION_IO_BRIDGE == session_info->io_state_) - { - recv_data_time_ = std::chrono::steady_clock::now(); - cid_recv_data_time_[connect_id] = std::chrono::steady_clock::now(); - //将数据转发给桥接接口 - auto ret = App_WorkThreadLogic::instance()->do_io_bridge_data(session_info->connect_id_, session_info->io_bridge_connect_id_, session_recv_buffer_, length, shared_from_this()); - if (1 == ret) - { - //远程IO链接已断开 - session_info->io_bridge_connect_id_ = 0; - } - } - else - { - //处理数据拆包 - vector> message_list; - bool ret = packet_parse_interface_->packet_from_recv_buffer_ptr_(connect_client_id_, &session_recv_buffer_, message_list, io_type_); - if (!ret) + //如果缓冲已满,断开连接,不再接受数据。 + if (session_recv_buffer_.get_buffer_size() == 0) { - //链接断开(解析包不正确) + //链接断开(缓冲撑满了) session_recv_buffer_.move(length); App_WorkThreadLogic::instance()->close_session_event(connect_id); + do_receive(); + return; } - else + + session_recv_buffer_.set_write_data(length); + + auto session_info = find_udp_endpoint_by_id(connect_id); + + if (nullptr != session_info && EM_SESSION_STATE::SESSION_IO_BRIDGE == session_info->io_state_) { recv_data_time_ = std::chrono::steady_clock::now(); cid_recv_data_time_[connect_id] = std::chrono::steady_clock::now(); - //添加到数据队列处理 - App_WorkThreadLogic::instance()->assignation_thread_module_logic(connect_id, message_list, self); + //将数据转发给桥接接口 + auto ret = App_WorkThreadLogic::instance()->do_io_bridge_data(session_info->connect_id_, session_info->io_bridge_connect_id_, session_recv_buffer_, length, shared_from_this()); + if (1 == ret) + { + //远程IO链接已断开 + session_info->io_bridge_connect_id_ = 0; + } + } + else + { + //处理数据拆包 + vector> message_list; + bool ret = packet_parse_interface_->packet_from_recv_buffer_ptr_(connect_client_id_, &session_recv_buffer_, message_list, io_type_); + if (!ret) + { + //链接断开(解析包不正确) + session_recv_buffer_.move(length); + App_WorkThreadLogic::instance()->close_session_event(connect_id); + } + else + { + recv_data_time_ = std::chrono::steady_clock::now(); + cid_recv_data_time_[connect_id] = std::chrono::steady_clock::now(); + //添加到数据队列处理 + App_WorkThreadLogic::instance()->assignation_thread_module_logic(connect_id, message_list, self); + } } - } - session_recv_buffer_.move(length); - } + session_recv_buffer_.move(length); - //持续接收数据 - do_receive(); + //持续接收数据 + do_receive(); + } + } + catch (std::system_error const& ex) + { + PSS_LOGGER_WARN("[CUdpServer::do_receive_from]close udp server[{}:{}]",server_ip_,server_port_); + } } void CUdpServer::close(uint32 connect_id) @@ -141,7 +148,19 @@ void CUdpServer::close(uint32 connect_id) { self->close_udp_endpoint_by_id(connect_id); }); +} +void CUdpServer::close_all() +{ + //释放所有kcp资源 + for (const auto& session_info : udp_id_2_endpoint_list_) + { + this->close(session_info.first); + } + + udp_id_2_endpoint_list_.clear(); + udp_endpoint_2_id_list_.clear(); + socket_.close(); } void CUdpServer::set_write_buffer(uint32 connect_id, const char* data, size_t length) @@ -336,8 +355,8 @@ void CUdpServer::close_udp_endpoint_by_id(uint32 connect_id) udp_id_2_endpoint_list_.erase(f); udp_endpoint_2_id_list_.erase(session_endpoint); } - - App_WorkThreadLogic::instance()->delete_thread_session(connect_id, self); + + App_WorkThreadLogic::instance()->delete_thread_session(connect_id, self); auto iter=cid_recv_data_time_.find(connect_id); if(iter != cid_recv_data_time_.end()) diff --git a/PSS_ASIO/UdpSession/UdpServer.h b/PSS_ASIO/UdpSession/UdpServer.h index 2cd9b13..ddc03cc 100644 --- a/PSS_ASIO/UdpSession/UdpServer.h +++ b/PSS_ASIO/UdpSession/UdpServer.h @@ -45,6 +45,8 @@ class CUdpServer : public std::enable_shared_from_this, public ISess void close(uint32 connect_id) final; + void close_all(); + void set_write_buffer(uint32 connect_id, const char* data, size_t length) final; void do_write(uint32 connect_id) final; @@ -104,5 +106,7 @@ class CUdpServer : public std::enable_shared_from_this, public ISess using hashmapcid_recv_data_time = unordered_map; hashmapcid_recv_data_time cid_recv_data_time_; + string server_ip_; + io_port_type server_port_; };