From 4485cf64a037f2cb39b5b752a9fdfd4000551586 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 30 Nov 2018 15:24:23 -0800 Subject: [PATCH] ecore_con: refactor TCP Dialer to always wait for thread to finish. This is a better way to avoid race execution by the async end callback that could happen at some later random point in time. The thread are cancelled right away, so event if their is a "wait" time set, it should never actually matter and be always instantaneous. Differential Revision: https://phab.enlightenment.org/D7396 --- src/lib/ecore_con/efl_net_dialer_tcp.c | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lib/ecore_con/efl_net_dialer_tcp.c b/src/lib/ecore_con/efl_net_dialer_tcp.c index 6b29831aa2..a35d56501d 100644 --- a/src/lib/ecore_con/efl_net_dialer_tcp.c +++ b/src/lib/ecore_con/efl_net_dialer_tcp.c @@ -42,6 +42,17 @@ typedef struct _Efl_Net_Dialer_Tcp_Data double timeout_dial; } Efl_Net_Dialer_Tcp_Data; +static void +_efl_net_dialer_tcp_async_stop(Efl_Net_Dialer_Tcp_Data *pd) +{ + if (pd->connect.thread) + { + ecore_thread_cancel(pd->connect.thread); + ecore_thread_wait(pd->connect.thread, 1); + pd->connect.thread = NULL; + } +} + EOLIAN static Eo* _efl_net_dialer_tcp_efl_object_constructor(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_UNUSED) { @@ -63,11 +74,8 @@ _efl_net_dialer_tcp_efl_object_invalidate(Eo *o, Efl_Net_Dialer_Tcp_Data *pd) efl_event_thaw(o); } - if (pd->connect.thread) - { - ecore_thread_cancel(pd->connect.thread); - pd->connect.thread = NULL; - } + _efl_net_dialer_tcp_async_stop(pd); + efl_invalidate(efl_super(o, MY_CLASS)); } @@ -87,11 +95,7 @@ _efl_net_dialer_tcp_connect_timeout(Eo *o, const Eina_Value v) Efl_Net_Dialer_Tcp_Data *pd = efl_data_scope_get(o, MY_CLASS); Eina_Error err = ETIMEDOUT; - if (pd->connect.thread) - { - ecore_thread_cancel(pd->connect.thread); - pd->connect.thread = NULL; - } + _efl_net_dialer_tcp_async_stop(pd); efl_ref(o); efl_io_reader_eos_set(o, EINA_TRUE); @@ -155,7 +159,7 @@ _efl_net_dialer_tcp_connected(void *data, const struct sockaddr *addr, socklen_t } EOLIAN static Eina_Error -_efl_net_dialer_tcp_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_UNUSED, const char *address) +_efl_net_dialer_tcp_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Tcp_Data *pd, const char *address) { const char *proxy_env = NULL, *no_proxy_env = NULL; @@ -164,11 +168,7 @@ _efl_net_dialer_tcp_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_ EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_io_closer_closed_get(o), EBADF); EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_loop_fd_get(o) >= 0, EALREADY); - if (pd->connect.thread) - { - ecore_thread_cancel(pd->connect.thread); - pd->connect.thread = NULL; - } + _efl_net_dialer_tcp_async_stop(pd); if (!pd->proxy) {