我有以下类定义:
// SocketTypeT may be e.g. 'boost::asio::ip::tcp::socket'
template<class SocketTypeT>
class Socket : public SocketTypeT, public boost::enable_shared_from_this< Socket<SocketTypeT> > {
[...]
在这个课程中,我有以下方法'writeAsync':
void writeAsync(const std::string& strData) {
boost::asio::async_write(*this, boost::asio::buffer(strData),
boost::bind(&Socket::handle_write_async,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
最后在'writeAsync'中使用的处理程序(也是类成员函数):
void handle_write_async(const boost::system::error_code& ec, std::size_t cntBytesSent) {
cout << "handle_write_async" << endl;
if (m_pSocketAsyncObserver) {
m_pSocketAsyncObserver->handleAsyncWrite(connectionClosed, cntBytesSent, ec);
}
}
问题:
数据已成功传输到服务器,但永远不会调用“handle_write_async”。可能是什么原因?