Skip to content

Commit

Permalink
修正断言引起的崩溃错误,
Browse files Browse the repository at this point in the history
  • Loading branch information
balloonwj authored Aug 24, 2018
1 parent 0919a66 commit eeb381e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions flamingoserver/net/TcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void TcpServer::newConnection(int sockfd, const InetAddress& peerAddr)
conn->setMessageCallback(messageCallback_);
conn->setWriteCompleteCallback(writeCompleteCallback_);
conn->setCloseCallback(std::bind(&TcpServer::removeConnection, this, std::placeholders::_1)); // FIXME: unsafe
//该线程分离完io事件后,立即调用TcpConnection::connectEstablished
//该线程分离完io事件后,立即调用TcpConnection::connectEstablished
ioLoop->runInLoop(std::bind(&TcpConnection::connectEstablished, conn));
}

Expand All @@ -104,8 +104,15 @@ void TcpServer::removeConnectionInLoop(const TcpConnectionPtr& conn)
LOG_INFO << "TcpServer::removeConnectionInLoop [" << name_
<< "] - connection " << conn->name();
size_t n = connections_.erase(conn->name());
(void)n;
assert(n == 1);
//(void)n;
//assert(n == 1);
if (n != 1)
{
//出现这种情况,是TcpConneaction对象在创建过程中,对方就断开连接了。
LOG_INFO << "TcpServer::removeConnectionInLoop [" << name_ << "] - connection " << conn->name() << ", connection does not exist.";
return;
}

EventLoop* ioLoop = conn->getLoop();
ioLoop->queueInLoop(
std::bind(&TcpConnection::connectDestroyed, conn));
Expand Down

0 comments on commit eeb381e

Please sign in to comment.