Destroy old rpc handle for clean reconnection 63/293763/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Fri, 2 Jun 2023 11:27:19 +0000 (20:27 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 2 Jun 2023 11:27:19 +0000 (20:27 +0900)
- Issue:
When the client is disconnected, sometimes, the rpc handle can be
expired.

- Solution:
When the client is disconnected, the client should try to reconnect.
However, sometimes, the client can try to reconnect with expired rpc
handle. In this case, the client library can not create new rpc handle,
because current logic only makes new rpc handle if the function returns
I/O error. To resolve this issue, this patch destroyes the old handle
if the client is disconnected. Through this change, the client will be
sure to reconnect with new rpc handle.

Change-Id: Ic801abf2f69a291ca6b5c8748a67f987be81aa93
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_tidl.c

index 7a1f0123b45c6a685ee34c14e3dff341bd9087dd..aef57d6b6d7c71ecb37c2c583db4db44b9ae50a9 100644 (file)
@@ -134,6 +134,45 @@ static void __notify_cb(void *user_data, int pid, int uid, bundle *msg)
        }
 }
 
+static void destroy_scheduled_handle(gpointer data)
+{
+       rpc_port_proxy_tts_h rpc_h = (rpc_port_proxy_tts_h)data;
+       int ret = rpc_port_proxy_tts_destroy(rpc_h);
+       if (RPC_PORT_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy handle. ret(%d/%s)", ret, get_error_message(ret));
+       }
+}
+
+static Eina_Bool destroy_scheduled_handles_by_ecore_idler(void *user_data)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Destroy RPC handles those are scheduled to be destroyed.");
+       g_slist_free_full(g_destruction_scheduled_handles, destroy_scheduled_handle);
+       g_destruction_scheduled_handles = NULL;
+       g_destroy_handles_idler = NULL;
+
+       return EINA_FALSE;
+}
+
+static inline void destroy_rpc_port(tts_tidl_info_s* info)
+{
+       RETM_IF(NULL == info->rpc_h, "[TIDL] Handle is already destroyed");
+
+       g_destruction_scheduled_handles = g_slist_append(g_destruction_scheduled_handles, info->rpc_h);
+       if (NULL == g_destroy_handles_idler) {
+               g_destroy_handles_idler = ecore_idler_add(destroy_scheduled_handles_by_ecore_idler, NULL);
+       }
+
+       info->rpc_h = NULL;
+       info->notify_cb_h = NULL;
+
+       free(info->engine_app_id);
+       info->engine_app_id = NULL;
+
+       info->register_callback_invoked = false;
+       info->connection_requesting = false;
+       info->connected = false;
+}
+
 static void __on_connected(rpc_port_proxy_tts_h h, void *user_data)
 {
        unsigned int uid = (uintptr_t)user_data;
@@ -167,6 +206,7 @@ static void __on_disconnected(rpc_port_proxy_tts_h h, void *user_data)
        SLOG(LOG_DEBUG, TAG_TTSC, "Disconnected from server");
        if (tts_client_is_listening_started(uid)) {
                SLOG(LOG_DEBUG, TAG_TTSC, "Try to reconnect to server");
+               destroy_rpc_port(info);
                tts_core_handle_service_reset();
        }
 }
@@ -223,45 +263,6 @@ int tts_tidl_open_connection(unsigned int uid)
        return TTS_ERROR_NONE;
 }
 
-static void destroy_scheduled_handle(gpointer data)
-{
-       rpc_port_proxy_tts_h rpc_h = (rpc_port_proxy_tts_h)data;
-       int ret = rpc_port_proxy_tts_destroy(rpc_h);
-       if (RPC_PORT_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy handle. ret(%d/%s)", ret, get_error_message(ret));
-       }
-}
-
-static Eina_Bool destroy_scheduled_handles_by_ecore_idler(void *user_data)
-{
-       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Destroy RPC handles those are scheduled to be destroyed.");
-       g_slist_free_full(g_destruction_scheduled_handles, destroy_scheduled_handle);
-       g_destruction_scheduled_handles = NULL;
-       g_destroy_handles_idler = NULL;
-
-       return EINA_FALSE;
-}
-
-static inline void destroy_rpc_port(tts_tidl_info_s* info)
-{
-       RETM_IF(NULL == info->rpc_h, "[TIDL] Handle is already destroyed");
-
-       g_destruction_scheduled_handles = g_slist_append(g_destruction_scheduled_handles, info->rpc_h);
-       if (NULL == g_destroy_handles_idler) {
-               g_destroy_handles_idler = ecore_idler_add(destroy_scheduled_handles_by_ecore_idler, NULL);
-       }
-
-       info->rpc_h = NULL;
-       info->notify_cb_h = NULL;
-
-       free(info->engine_app_id);
-       info->engine_app_id = NULL;
-
-       info->register_callback_invoked = false;
-       info->connection_requesting = false;
-       info->connected = false;
-}
-
 int tts_tidl_close_connection(unsigned int uid)
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_close_connection");