| | |
| | | |
| | | 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; |
| | |
| | | } |
| | | 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}; |
| | | { |
| | |
| | | } |
| | | |
| | | } |
| | | }); |
| | | }, pub); |
| | | return sock; |
| | | } |
| | | |
| | |
| | | } |
| | | // 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); |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | // printf("======>> subscribe nn_recv failed %s\n", nn_strerror(nn_errno())); |
| | | } |
| | | } |
| | | }); |
| | | }, sub); |
| | | return 0; |
| | | } |
| | | |
| | |
| | | |
| | | sv->url_ = url; |
| | | sv->fixed_msg_ = move(fixed_msg); |
| | | sv->t_ = thread([sv]{ |
| | | sv->t_ = get_thread([](const auto sv){ |
| | | |
| | | TAG; |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | }, sv); |
| | | |
| | | return 0; |
| | | } |