You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
void TcpConnection::handleClose()
{
loop_->assertInLoopThread();
LOG_TRACE << "fd = " << channel_->fd() << " state = " << stateToString();
assert(state_ == kConnected || state_ == kDisconnecting);
// we don't close fd, leave it to dtor, so we can find leaks easily.
setState(kDisconnected);
channel_->disableAll();
channel->remove();
TcpConnectionPtr guardThis(shared_from_this());
//connectionCallback_(guardThis);
// must be the last line
closeCallback_(guardThis);
}
为了支持上面的写法我对TcpServer做了如下改造
class TcpServer : std::enable_shared_from_this<TcpServer>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
为了支持上面的写法我对TcpServer做了如下改造
其次是在TcpServer::newConnection注册TcpConnection的closeCallback_时
然后在TcpServer析构时,比相比重前的muduo在 TcpServer::~TcpServer直接强制关闭连接
然后为了保证 一个tcpconnection 只属于一个evenloop, 还是保留了这个函数, 确保其在对应的eventloop 里 析构(虽然感觉没什么必要。。。)
Beta Was this translation helpful? Give feedback.
All reactions