#include <array>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/system/system_error.hpp>
#include <boost/array.hpp>
//using namespace boost::asio;
const int max_length = 1024;
using Socket = boost::asio::ip::tcp::socket;
using SocketPtr = boost::shared_ptr<Socket>;
void rw_handler(SocketPtr sock)
{
try
{
for (;;)
{
boost::array<char, max_length> data_buffer;
boost::system::error_code error;
size_t bytes_transferred = sock->read_some(boost::asio::buffer(data_buffer), error);
if (error == boost::asio::error::eof)
{
break;
}
else if (error)
{
throw boost::system::system_error(error);
}
boost::asio::write(*sock, boost::asio::buffer(data_buffer, bytes_transferred));
}
}
catch (std::exception &e)
{
std::cerr << e
boost asio 同步阻塞
最新推荐文章于 2023-02-17 00:13:12 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)