Fix a bug about timed out error 91/272491/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 18 Mar 2022 00:46:17 +0000 (09:46 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 18 Mar 2022 00:46:17 +0000 (09:46 +0900)
When the timed out error occurs, the callback function has to be invoked.

Change-Id: I9a72edf39d49cf840464ee26e1200024a6accdcd
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/fdbroker-internal.cc

index 0e7b9fb..39099e1 100644 (file)
@@ -835,6 +835,20 @@ void FdBroker::OnResultReceived(GObject* source_object,
                                 GAsyncResult* res,
                                 gpointer user_data) {
   _W("OnResultReceived()");
+  auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
+  auto broker = ptr->lock();
+  if (broker == nullptr) {
+    _E("broker is nullptr");
+    return;
+  }
+
+  std::lock_guard<std::recursive_mutex> lock(broker->GetMutex());
+  if (broker->cancellable_ == nullptr) {
+    _E("Invalid context. Fdbroker(%p)", broker.get());
+    return;
+  }
+
+  IEventWatcher* watcher = broker->watcher_;
   GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(source_object);
   GError* err = nullptr;
   GDBusMessage* reply = g_dbus_connection_send_message_with_reply_finish(conn,
@@ -843,29 +857,18 @@ void FdBroker::OnResultReceived(GObject* source_object,
     if (err) {
       if (err->code == G_IO_ERROR_CANCELLED)
         _E("IO error cancelled");
+      else
+        _E("Error(%s) occurs", err->message);
       g_error_free(err);
     } else {
       _E("g_dbus_connection_send_message_with_reply_finish() is failed");
     }
+    watcher->OnPortDisconnected();
     return;
   }
 
   auto reply_ptr = std::unique_ptr<GDBusMessage, decltype(g_object_unref)*>(
       reply, g_object_unref);
-  auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
-  auto broker = ptr->lock();
-  if (broker == nullptr) {
-    _E("broker is nullptr");
-    return;
-  }
-
-  std::lock_guard<std::recursive_mutex> lock(broker->GetMutex());
-  if (broker->cancellable_ == nullptr) {
-    _E("Invalid context. Fdbroker(%p)", broker.get());
-    return;
-  }
-
-  IEventWatcher* watcher = broker->watcher_;
   if (g_dbus_message_to_gerror(reply, &err)) {
     _E("Failed to send message. error(%s)", err->message);
     g_error_free(err);