zhangmeng
2021-12-30 3d2a193339f6e6cc78007d02e2ffe89229fba7af
add topic \0
1个文件已修改
13 ■■■■ 已修改文件
src/nng_wrap.cpp 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/nng_wrap.cpp
@@ -138,7 +138,7 @@
                msg = &pub->msg_.front();
                if (msg->topic_.empty()) {pub->msg_.pop_front(); continue;}
            }
            string sndmsg(msg->topic_ + msg->data_);
            string sndmsg = (string{msg->topic_}+='\0')+=msg->data_;
            int rc = nn_send(pub->socket_, sndmsg.data(), sndmsg.size(), 0);
            if (rc == (int)sndmsg.size()){
                char* tmp{};
@@ -209,19 +209,18 @@
            if (m_len > 0){
                string tmp_msg{m, (size_t)m_len};
                nn_freemsg(m);
                string topic{}, msg{};
                auto topic{tmp_msg.c_str()};
                string msg{};
                {
                    lock_guard<mutex> l{(*sub)()};
                    for(auto && i : sub->topics_){
                        if (tmp_msg.size() < i.size()) continue;
                        topic = move(tmp_msg.substr(0, i.size()));
                        if (topic == i){
                            msg = move(tmp_msg.substr(i.size()));
                        if (i.compare(topic) == 0){
                            msg = move(tmp_msg.substr(i.size()+1));
                            break;
                        }
                    }
                }
                printf("======>> subscribe recv topic %s msg length %lu\n", topic.c_str(), msg.length());
                printf("======>> subscribe recv topic %s msg length %lu\n", topic, msg.length());
                if (!msg.empty()){
                    lock_guard<mutex> l(sub->mtx_msg_);
                    sub->msg_.emplace_back(topic, move(msg));