boost asio 同步 如果正在accept怎么退出线程

发布网友 发布时间:2022-04-22 03:16

我来回答

1个回答

热心网友 时间:2024-01-12 02:09

void CTcpSrv::read_handler(const boost::system::error_code& error, std::size_t bytes_transferred)
{
if (!error)
{
#if DHAVE_CONFIG_H
printf("receive packet length is [%u]...\n", bytes_transferred);
#endif
//parse TCP packet
parse_tcp_packet(bytes_transferred);

//next read
memset(m_strBuffer, '\0', bytes_transferred);
m_socket.async_read_some(boost::asio::buffer(m_strBuffer, MAX_BUFFER_SIZE), \
boost::bind(&CTcpSrv::read_handler, shared_from_this(), \
boost::asio::placeholders::error, \
boost::asio::placeholders::bytes_transferred));
}
else
{
//An error occurred
std::cout<<"the connection was closed by the peer..."<<std::endl;
//g_client_manage_list->remove_client(shared_from_this());
}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com