shared_ptr智能指针作为参数的问题

john_liqinghan 2020-01-16 02:55:50


class connection{
....
};

class iodriver{
public:
void start_accept();
void handle_accept(connection pConnect, const boost::system::error_code& error);
private:
boost::asio::io_service m_IOServer; //IO句柄
boost::asio::ip::tcp::acceptor m_acceptor; //套接字接收器
}
typedef boost::shared_ptr<connection> connection_ptr;

void iodriver:start_accept()
{
connection_ptr pConnect = connection_ptr(new connection(m_IOServer));
m_acceptor.async_accept(pConnect ->GetSock(), boost::bind(&iodirver::handle_accept, this, pConnect , boost::asio::placeholders::error));
}

void odriver::handle_accept(connection_ptr pConnect, const boost::system::error_code& error)
{
if (!error)
{
boost::system::error_code err;
unsigned int uPort = pConnect->GetSock().remote_endpoint(err).port();
std::string strIp = pConnect->GetSock().remote_endpoint(err).address().to_string();
printf("+accept socket form [%s-%u][0x%x]", strIp.c_str(), uPort, pConnect.get());
m_xNewConnect.AddConnect(pConnect);
start_recv_head(pConnect);
}
else
{
printf("accept error [%d]", error.value());
}
start_accept();
}

void iodriver::start_recv_head(connection_ptr pConnect)
{
xWMessage_ptr pMsg = xWMessage_ptr(new xWMessage);
boost::asio::async_read(pConnect->GetSock(), boost::asio::buffer(pMsg->head_data(), xWMessage::Msg_Head_Len), boost::bind(&xIODirve::handle_recv_head, this, pConnect, pMsg, _1));
}

void iodriver::handle_recv_head(connection_ptr pConnect, xWMessage_ptr pMsg, const boost::system::error_code& error)
{
if (!error)
{
start_recv_head(pConnect);

}
else
{
printf("recv one msg head error[%u] \n", error.value());
//偶尔存在此处会打印995错误
....
}
}

handle_recv_head函数会打印995错误,因为对智能指针不了解,不知道这个问题怎么引起的。请大家帮帮忙。该如何改正这个错误。

...全文
459 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yshuise 2020-02-12
  • 打赏
  • 举报
回复
顶一下帖子
john_liqinghan 2020-02-10
  • 打赏
  • 举报
回复
我知道原因了,不是这个问题引起的
sdghchj 2020-01-19
  • 打赏
  • 举报
回复
哪里能看出是智能指针导致的??

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧