From: Seonah Moon Date: Wed, 14 Apr 2021 06:54:35 +0000 (+0900) Subject: pubsub: create a disc handle for ip_resolve() X-Git-Tag: submit/tizen/20210414.073506~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c000154b040b0c613e35e4362f815cbb268b71f;p=platform%2Fcore%2Fapi%2Fvine.git pubsub: create a disc handle for ip_resolve() Change-Id: Ie693e2fea547fafc202ec9c5825ceff9ce4b265b --- diff --git a/src/vine-dp.cpp b/src/vine-dp.cpp index 7fcf898..8b5ed35 100644 --- a/src/vine-dp.cpp +++ b/src/vine-dp.cpp @@ -290,25 +290,39 @@ static void _service_discovered_cb(vine_disc_h disc, bool available, if (!user_data || !available) return; + vine_disc_h disc_handle; + int ret = vine_disc_create(VINE_DISCOVERY_METHOD_DNS_SD, &disc_handle); + RET_IF(ret != VINE_ERROR_NONE, "Fail to create a disc"); + vine_service_h service; - int ret = _vine_service_create(&service, false); - RET_IF(ret != VINE_ERROR_NONE, "Fail to create a service"); + ret = _vine_service_create(&service, false); + if (ret != VINE_ERROR_NONE) { + vine_disc_destroy(disc_handle); + return; + } auto it = attr.find(VINE_DP_PUBSUB_RANK_KEY); if (it == attr.end()) { VINE_LOGE("peer doens't have a rank."); _vine_service_destroy(service); + vine_disc_destroy(disc_handle); return; } - ret = _vine_service_set_disc_handle(service, disc); - RET_IF(ret != VINE_ERROR_NONE, "Fail to set disc_handle"); + ret = _vine_service_set_disc_handle(service, disc_handle); + if (ret != VINE_ERROR_NONE) { + VINE_LOGE("Fail to set disc_handle. error(%d)", ret); + _vine_service_destroy(service); + vine_disc_destroy(disc_handle); + return; + } ret = __vine_set_discovered_service(service, service_type, service_name, host_name, port, attr, iface_name); if (ret != VINE_ERROR_NONE) { VINE_LOGE("Fail to set a service. error(%d)", ret); _vine_service_destroy(service); + vine_disc_destroy(disc_handle); return; } @@ -318,10 +332,15 @@ static void _service_discovered_cb(vine_disc_h disc, bool available, dp->increase_init_disc_num(); } - ret = vine_disc_resolve_ip(disc, service, + ret = vine_disc_resolve_ip(disc_handle, service, _ip_resolved_cb, user_data, (vine_event_queue_h)static_cast(user_data)->get_eventfd()); - RET_IF(ret != VINE_ERROR_NONE, "Fail to vine_disc_resolve_ip"); + if (ret != VINE_ERROR_NONE) { + VINE_LOGE("Fail to resolve IP. error(%d)", ret); + _vine_service_destroy(service); + vine_disc_destroy(disc_handle); + return; + } } static void _service_published_cb(vine_disc_h disc, @@ -984,7 +1003,7 @@ int DPPubSub::compare_ip_priority(const char *peer_ip) break; } - VINE_LOGD("peer_ip[%s] found_ip[%s]", peer_ip, found_ip.c_str()); + VINE_LOGD("peer_ip[%s] found_ip[%s] subnet[%s]", peer_ip, found_ip.c_str(), subnet.c_str()); try { last = std::stoi(found_ip.substr(pos + 1)); peer_last = std::stoi(peer_ip_str.substr(pos + 1)); @@ -1046,6 +1065,7 @@ void DPPubSub::_open_timer(void *user_data) static_cast(user_data)->invoke_opened_cb(VINE_ERROR_NONE); return; } + VINE_LOGD("invoke opened_cb with an error. sd_state[%d]", sd_state); static_cast(user_data)->invoke_opened_cb(VINE_ERROR_OPERATION_FAILED); }