Close unnecessary socket after use 14/110214/6
authorJiung Yu <jiung.yu@samsung.com>
Fri, 13 Jan 2017 17:55:07 +0000 (23:25 +0530)
committerSaurav Babu <saurav.babu@samsung.com>
Fri, 13 Jan 2017 18:10:08 +0000 (23:40 +0530)
Change-Id: I36430e4d9fe324881d17fc1e50828c4b4f4ff139
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
packaging/capi-network-nsd.spec
src/dns-sd/dns-sd.c

index daad68b1e80239725c7488b7a1c550917a6abac2..d36eb01170b9dff3e96c737347af31ebdeb27898 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-network-nsd
 Summary:    A Network Service Discovery libraries in Native API
-Version:    0.0.12
+Version:    0.0.13
 Release:    1
 Group:      System/Network
 License:    Apache-2.0
index e057de59bea16ca42739187e31fe830732bc9aec..f35ee0e0534179c1bca75c5a42bbabf415855e8e 100644 (file)
@@ -61,7 +61,7 @@ static const char *dnssd_error_to_string(dnssd_error_e error)
                return "DNSSD_ERROR_SERVICE_NOT_RUNNING";//LCOV_EXCL_LINE
        case DNSSD_ERROR_OPERATION_FAILED:
                return "DNSSD_ERROR_OPERATION_FAILED";  //LCOV_EXCL_LINE
-       default :
+       default:
                return "UNSUPPORTED_ERROR";
        }
 }
@@ -897,6 +897,20 @@ int dnssd_deregister_local_service(dnssd_service_h local_service)
        return DNSSD_ERROR_NONE;
 }
 
+//LCOV_EXCL_START
+static gboolean __remove_service_getaddrinfo_socket(gpointer user_data)
+{
+       DNSSD_LOGD("Remove DNSServiceGetAddrInfo socket");
+       dnssd_handle_s *local_handle = user_data;
+       if (local_handle->watch_id > 0)
+               g_source_remove(local_handle->watch_id);
+       DNSServiceRefDeallocate(local_handle->sd_ref);
+       local_handle->watch_id = 0;
+       local_handle->sd_ref = NULL;
+       return FALSE;
+}
+//LCOV_EXCL_STOP
+
 //LCOV_EXCL_START
 static void __dnssd_getaddrinfo_reply_cb(DNSServiceRef sd_ref,
                unsigned int flags, unsigned int if_index,
@@ -972,7 +986,8 @@ static void __dnssd_getaddrinfo_reply_cb(DNSServiceRef sd_ref,
                DNSSD_LOGD("Finished executing Browse %s callback",
                                (flags & kDNSServiceFlagsAdd) ? "Available" : "Unavailable");
        }
-
+       g_idle_add_full(G_PRIORITY_HIGH, __remove_service_getaddrinfo_socket,
+                                       local_handle, NULL);
 }
 //LCOV_EXCL_STOP
 
@@ -1059,6 +1074,20 @@ static int __dnssd_getaddrinfo(dnssd_handle_s *dnssd_handle, unsigned int flags,
 }
 //LCOV_EXCL_STOP
 
+//LCOV_EXCL_START
+static gboolean __remove_service_resolve_socket(gpointer user_data)
+{
+       DNSSD_LOGD("Remove DNSServiceResolve socket");
+       resolve_reply_data *resolve_data = user_data;
+       if (resolve_data->watch_id > 0)
+               g_source_remove(resolve_data->watch_id);
+       DNSServiceRefDeallocate(resolve_data->sd_ref);
+       resolve_data->watch_id = 0;
+       resolve_data->sd_ref = NULL;
+       return FALSE;
+}
+//LCOV_EXCL_STOP
+
 //LCOV_EXCL_START
 static void __dnssd_resolve_reply_cb(DNSServiceRef sd_ref, unsigned int flags,
                unsigned int if_index, DNSServiceErrorType error_code,
@@ -1078,6 +1107,8 @@ static void __dnssd_resolve_reply_cb(DNSServiceRef sd_ref, unsigned int flags,
        __dnssd_getaddrinfo(resolve_data->dnssd_handle, flags, if_index,
                        host_name, fullname, (const char *) txt_record,
                        txt_len, port);
+       g_idle_add_full(G_PRIORITY_HIGH, __remove_service_resolve_socket,
+                                       resolve_data, NULL);
 }
 //LCOV_EXCL_STOP
 
@@ -1408,11 +1439,6 @@ static void __dnssd_remove_found_service(gpointer data, gpointer user_data)
        dnssd_handle_list = g_slist_remove(dnssd_handle_list,
                        found_handle);
 
-       if (found_handle->watch_id > 0)
-               g_source_remove(found_handle->watch_id);
-
-       DNSServiceRefDeallocate(found_handle->sd_ref);
-
        g_free(found_handle->service_type);
        g_free(found_data->service_name);
        g_free(found_data->host);
@@ -1472,11 +1498,6 @@ int dnssd_stop_browsing_service(dnssd_browser_h dnssd_service)
                if (resolve_data->dnssd_handle == local_handle) {
                        resolve_handle_list = g_slist_remove(resolve_handle_list,
                                        resolve_data);
-
-                       if (resolve_data->watch_id > 0)
-                               g_source_remove(resolve_data->watch_id);
-
-                       DNSServiceRefDeallocate(resolve_data->sd_ref);
                        g_free(resolve_data);
                }
                //LCOV_EXCL_STOP