summaryrefslogtreecommitdiff
path: root/src/lib/ecore_con
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-11-30 15:24:23 -0800
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2018-12-06 09:29:28 +0100
commit4485cf64a037f2cb39b5b752a9fdfd4000551586 (patch)
tree8b5a75fffa68c87ba3fe27d7125b61ac3c9ac9dc /src/lib/ecore_con
parenta8244ee642b2b61f6e49c8e21eb1947741d59f27 (diff)
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
Diffstat (limited to 'src/lib/ecore_con')
-rw-r--r--src/lib/ecore_con/efl_net_dialer_tcp.c32
1 files 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 6b29831..a35d565 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
42 double timeout_dial; 42 double timeout_dial;
43} Efl_Net_Dialer_Tcp_Data; 43} Efl_Net_Dialer_Tcp_Data;
44 44
45static void
46_efl_net_dialer_tcp_async_stop(Efl_Net_Dialer_Tcp_Data *pd)
47{
48 if (pd->connect.thread)
49 {
50 ecore_thread_cancel(pd->connect.thread);
51 ecore_thread_wait(pd->connect.thread, 1);
52 pd->connect.thread = NULL;
53 }
54}
55
45EOLIAN static Eo* 56EOLIAN static Eo*
46_efl_net_dialer_tcp_efl_object_constructor(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_UNUSED) 57_efl_net_dialer_tcp_efl_object_constructor(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_UNUSED)
47{ 58{
@@ -63,11 +74,8 @@ _efl_net_dialer_tcp_efl_object_invalidate(Eo *o, Efl_Net_Dialer_Tcp_Data *pd)
63 efl_event_thaw(o); 74 efl_event_thaw(o);
64 } 75 }
65 76
66 if (pd->connect.thread) 77 _efl_net_dialer_tcp_async_stop(pd);
67 { 78
68 ecore_thread_cancel(pd->connect.thread);
69 pd->connect.thread = NULL;
70 }
71 79
72 efl_invalidate(efl_super(o, MY_CLASS)); 80 efl_invalidate(efl_super(o, MY_CLASS));
73} 81}
@@ -87,11 +95,7 @@ _efl_net_dialer_tcp_connect_timeout(Eo *o, const Eina_Value v)
87 Efl_Net_Dialer_Tcp_Data *pd = efl_data_scope_get(o, MY_CLASS); 95 Efl_Net_Dialer_Tcp_Data *pd = efl_data_scope_get(o, MY_CLASS);
88 Eina_Error err = ETIMEDOUT; 96 Eina_Error err = ETIMEDOUT;
89 97
90 if (pd->connect.thread) 98 _efl_net_dialer_tcp_async_stop(pd);
91 {
92 ecore_thread_cancel(pd->connect.thread);
93 pd->connect.thread = NULL;
94 }
95 99
96 efl_ref(o); 100 efl_ref(o);
97 efl_io_reader_eos_set(o, EINA_TRUE); 101 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
155} 159}
156 160
157EOLIAN static Eina_Error 161EOLIAN static Eina_Error
158_efl_net_dialer_tcp_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_UNUSED, const char *address) 162_efl_net_dialer_tcp_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Tcp_Data *pd, const char *address)
159{ 163{
160 const char *proxy_env = NULL, *no_proxy_env = NULL; 164 const char *proxy_env = NULL, *no_proxy_env = NULL;
161 165
@@ -164,11 +168,7 @@ _efl_net_dialer_tcp_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_
164 EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_io_closer_closed_get(o), EBADF); 168 EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_io_closer_closed_get(o), EBADF);
165 EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_loop_fd_get(o) >= 0, EALREADY); 169 EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_loop_fd_get(o) >= 0, EALREADY);
166 170
167 if (pd->connect.thread) 171 _efl_net_dialer_tcp_async_stop(pd);
168 {
169 ecore_thread_cancel(pd->connect.thread);
170 pd->connect.thread = NULL;
171 }
172 172
173 if (!pd->proxy) 173 if (!pd->proxy)
174 { 174 {