chenshuo / muduo

Event-driven network library for multi-threaded Linux server in C++11
https://github.com/chenshuo/muduo
Other
14.88k stars 5.18k forks source link

请教作者一个对于连接的上下文的疑问 #630

Closed xs-411 closed 2 years ago

xs-411 commented 2 years ago
我将conn添加了两个属性,但是我发现它是const, 所以无法修改它的值, 我希望可以给这个连接,绑定一些信息,要怎么做会更优雅呢?
onMessage(const TcpConnectionPtr &conn, Buffer *buffer, Timestamp time) { 
     conn->link_name = ""
     conn->type = "";
}
xs-411 commented 2 years ago

我理解有误。

chenshuo commented 2 years ago

Use TcpConnection::setContext().