TcpServer中ConnectionMap是否有必要存在

66 views
Skip to first unread message

zhangy...@gmail.com

unread,
Jan 18, 2019, 1:29:45 PM1/18/19
to Muduo network library
陈硕你好,我对TcpServer中ConnectionMap的设计不太明白。
查看全部代码,ConnectionMap仅在TcpServer析构的时候使用。
我尝试ConnectionMap放入到各自连接的ioLoop中。handleClose的时候直接当前loop调用connectDestroyed。
TcpServer析构时,所有连接的释放也下推到EventLoop的析构中处理。

talk is cheap,here is the code. 为实现上述所新建的一个branch
https://github.com/zhangyu0310/muduo/tree/connInLoop

Shuo Chen

unread,
Jan 18, 2019, 4:51:40 PM1/18/19
to Muduo network library
TcpServer::newConnection() 里的这一行
  ioLoop->connections_[connName] = conn;
有 data race,至少应该用 mutex 保护。

另外,把 ConnectionMap 放到 EventLoop 里是错误的, EventLoop 不应该知道 TcpConnection/TcpServer 的任何事情。
Reply all
Reply to author
Forward
0 new messages