boost asio通信

2020-09-24 16:08:01 浏览数 (2)

代码语言:javascript复制
void DHNetwork::Network::CreateTCPServer(unsigned short port,CRRMCommon* recv)
{
	boost::thread([port, recv]{
		boost::asio::io_service io_serv;
		std::vector<std::shared_ptr<DHNetwork::Network>>::iterator it;
		tcp::acceptor server_acceptor(io_serv, tcp::endpoint(tcp::v4(), port));
		while (true)
		{
			std::shared_ptr<Network> network = std::make_shared<Network>(port, io_serv);
			try{
				boost::system::error_code ec;
				network->m_notiy = recv;
				server_acceptor.accept(network->m_socket_tclient);
				m_acp_mutex.lock();
				for (it = DHNetwork::Network::m_network_manager.begin(); it != DHNetwork::Network::m_network_manager.end();)
				{
					if (!(*it)->m_socket_tclient.is_open() || ec == boost::asio::error::not_connected)
					{
						(*it)->m_is_exit = false;
						(*it)->m_thd_rec.join();
						it = DHNetwork::Network::m_network_manager.erase(it);
					}
					else
						it  ;
				}
				D

0 人点赞