Groups
Groups
Sign in
Groups
Groups
Muduo network library
Conversations
About
Send feedback
Help
关于Channel对象的生命期管理问题
42 views
Skip to first unread message
yinshen...@gmail.com
unread,
Dec 26, 2018, 2:34:56 PM
12/26/18
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Muduo network library
想问下陈老师,将channel对象作为其owner对象的直接成员是否可行,而不使用smart pointer对其进行包装。以TcpConnection对象为例,只需要保证在Channel::handleEvent执行结束前,以及在TcpConnection::connectDestroyed执行结束前TcpConnection对象还存在即可,这样就可以保证在Poller::removeChannel的过程中其channel指针的有效性,为什么要使用unique_ptr对channel对象进行管理呢?
Shuo Chen
unread,
Dec 26, 2018, 2:38:59 PM
12/26/18
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Muduo network library
muduo TcpConnection 这么做的初衷是避免将 Channel 的具体实现暴露给一般用户。
https://github.com/chenshuo/muduo/blob/30756c73ac330fde82300c1e0d08aec92575d2e3/muduo/net/TcpConnection.h#L138
// we don't expose those classes to client.
std::unique_ptr<Socket> socket_;
std::unique_ptr<Channel> channel_;
Reply all
Reply to author
Forward
0 new messages