zhangmeng
2021-12-17 aac0fe50f0ae9d13ff8ff7db2288a877b2fb2c53
src/nng_wrap.cpp
@@ -12,18 +12,6 @@
namespace nng_wrap {
// static int server_socket(const string& url, const int protocol, int family=AF_SP){
//     int sock = nn_socket(family, protocol);
//     if (sock < 0) return sock;
//     remove_exist(url);
//     int rc = nn_bind(sock, url.c_str());
//     if (rc < 0) {
//         nn_close(sock);
//         return rc;
//     }
//     return sock;
// }
static int client_socket(const string& url, const int protocol, int family=AF_SP){
    int sock = nn_socket(family, protocol);
    if (sock < 0) return sock;
@@ -135,7 +123,7 @@
    }
    set_socket_timeout(sock, timeout_req_rep);
    pub->socket_ = sock;
    pub->t_ = thread([pub]{
    pub->t_ = get_thread([](const auto pub){
        while (!pub->t_quit_.load()) {
            _ps::psmsg *msg{NULL};
            {
@@ -166,7 +154,7 @@
            }
        }
    });
    }, pub);
    return sock;
}
@@ -211,7 +199,7 @@
    }
    // set_socket_timeout(sock, timeout_req_rep);
    sub->socket_ = sock;
    sub->t_ = thread([sub]{
    sub->t_ = get_thread([](const auto sub){
        while (!sub->t_quit_.load()) {
            char* m;
            int m_len = nn_recv(sub->socket_, &m, NN_MSG, NN_DONTWAIT);
@@ -223,9 +211,9 @@
                    lock_guard<mutex> l{sub->mtx_topics_};
                    for(auto && i : sub->topics_){
                        if (tmp_msg.size() < i.size()) continue;
                        topic = tmp_msg.substr(0, i.size());
                        topic = move(tmp_msg.substr(0, i.size()));
                        if (topic == i){
                            msg = tmp_msg.substr(i.size());
                            msg = move(tmp_msg.substr(i.size()));
                            break;
                        }
                    }
@@ -254,7 +242,7 @@
                // printf("======>> subscribe nn_recv failed %s\n", nn_strerror(nn_errno()));
            }
        }
    });
    }, sub);
    return 0;
}
@@ -331,7 +319,7 @@
    sv->url_ = url;
    sv->fixed_msg_ = move(fixed_msg);
    sv->t_ = thread([sv]{
    sv->t_ = get_thread([](const auto sv){
        TAG;
@@ -355,7 +343,7 @@
                }
            }
        }
    });
    }, sv);
    return 0;
}