void handle_close(const boost::system::error_code& ec)
{
if(!ec){
LOG4CPLUS_DEBUG(LOG,LOG4CPLUS_TEXT("close connection..."));
socket_.shutdown(boost::asio::socket_base::shutdown_send);
boost::asio::async_read(socket_,boost::asio::null_buffers(),
boost::bind(&Connection::handle_close,
shared_from_this(),
boost::asio::placeholders::error));
}else if(ec == boost::asio::error::eof){
socket_.shutdown(boost::asio::socket_base::shutdown_receive);
socket_.close();
LOG4CPLUS_DEBUG(LOG,LOG4CPLUS_TEXT("connection closed."));
}else{
LOG4CPLUS_ERROR(LOG,LOG4CPLUS_TEXT("error:"<<ec.message()));
}
}
socket_.shutdown(boost::asio::socket_base::shutdown_both);
socket_.close();
只要这个对象是 shared_ptr 管理的,就不需要 close,在 conn 对象析构的时候就会 close
1
jeffersonpig 2016-06-13 09:29:49 +08:00
一看到 boost 这老长老长的嵌套 namespace 就莫名的火大
|