@@ -6,7 +6,6 @@ Messenger::Messenger() {
66 context_.close ();
77 context_ = zmq::context_t (1 );
88 publisher_ = zmq::socket_t (context_, ZMQ_PUB);
9- // 关闭时不等待未发送消息
109 publisher_.set (zmq::sockopt::linger, 0 );
1110 publisher_.set (zmq::sockopt::rcvtimeo, 1000 );
1211 try {
@@ -48,14 +47,11 @@ void Messenger::PubStruct(const std::string &topic, const void *data, const size
4847}
4948std::string Messenger::GetPubEndpoint () const { return endpoint_; }
5049
51- // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5250
53- // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5451std::unordered_set<std::string> TopicMonitor::GetTopics () const {
5552 std::lock_guard lock (topics_mutex_);
56- return topics_; // 返回副本保证线程安全
53+ return topics_;
5754}
58- // 启动监控线程
5955void TopicMonitor::Start () {
6056 if (monitor_thread_.joinable ()) {
6157 return ;
@@ -64,7 +60,6 @@ void TopicMonitor::Start() {
6460 monitor_thread_ = std::thread (&TopicMonitor::MonitorLoop, this );
6561}
6662
67- // 停止监控
6863void TopicMonitor::Stop () {
6964 if (!should_run_.load ()) {
7065 return ;
@@ -92,7 +87,6 @@ TopicMonitor::~TopicMonitor() {
9287 LOG (ERROR) << " [TopicMonitor] Cleanup error: " << e.what ();
9388 }
9489}
95- // 监控线程主循环
9690void TopicMonitor::MonitorLoop () {
9791 zmq::message_t msg;
9892
@@ -104,7 +98,6 @@ void TopicMonitor::MonitorLoop() {
10498 std::lock_guard lock (topics_mutex_);
10599 topic_frequencies_[topic]++;
106100 }
107- // 如果是多部分消息,跳过数据部分
108101 if (subscriber_.get (zmq::sockopt::rcvmore)) {
109102 zmq::message_t dummy;
110103 subscriber_.recv (dummy);
0 commit comments