summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-06-20 11:24:57 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-06-20 11:26:55 +0100
commitdf286b238c5aa2d7b615ca94a5b8aecd200a97b9 (patch)
treeeeecd72190cf29fb5a0f1b9b60ac3d5427bc3a22 /src/lib/ecore
parent1064bd09c7aa8f0a55a5634ef52822b0b38677b9 (diff)
ecore - efl thread - handle write call mishaps and complain
fixes warnings too.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/efl_thread.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/lib/ecore/efl_thread.c b/src/lib/ecore/efl_thread.c
index cff9314d1a..1545c74597 100644
--- a/src/lib/ecore/efl_thread.c
+++ b/src/lib/ecore/efl_thread.c
@@ -224,6 +224,43 @@ _cb_appthread_event_callback_del(void *data, const Efl_Event *event)
224 } 224 }
225} 225}
226 226
227static void
228_efl_thread_pipe_write(int fd, const void *buf, size_t count)
229{
230 const char *my_buf = buf;
231 ssize_t ret;
232
233 for (;;)
234 {
235 ret = write(fd, my_buf, count);
236 if (ret < 0)
237 {
238 // try again tyope errors
239 if (errno == EINTR) continue;
240 else if (errno == EAGAIN) continue;
241 // bad errors - fatal for this kind of write
242 else if (errno == EBADF)
243 ERR("Error writing to control pipe fd: Bad fd");
244 else if (errno == EFAULT)
245 ERR("Error writing to control pipe fd: Bad buf outside address space");
246 else if (errno == EINVAL)
247 ERR("Error writing to control pipe fd: Invalid value");
248 else if (errno == EPIPE)
249 ERR("Error writing to control pipe fd: Broken Pipe");
250 else
251 ERR("Error writing to control pipe fd: Something else unexpected");
252 return;
253 }
254 // do it in multiple writes then if only part was written
255 else if (ret >= 0)
256 {
257 my_buf += ret;
258 count -= ret;
259 if (count == 0) return;
260 }
261 }
262}
263
227EFL_CALLBACKS_ARRAY_DEFINE(_appthread_event_callback_watch, 264EFL_CALLBACKS_ARRAY_DEFINE(_appthread_event_callback_watch,
228 { EFL_EVENT_CALLBACK_ADD, _cb_appthread_event_callback_add }, 265 { EFL_EVENT_CALLBACK_ADD, _cb_appthread_event_callback_add },
229 { EFL_EVENT_CALLBACK_DEL, _cb_appthread_event_callback_del }); 266 { EFL_EVENT_CALLBACK_DEL, _cb_appthread_event_callback_del });
@@ -300,7 +337,7 @@ _efl_thread_main(void *data, Eina_Thread t)
300 memset(&cmd, 0, sizeof(cmd)); 337 memset(&cmd, 0, sizeof(cmd));
301 cmd.d.command = CMD_EXITED; 338 cmd.d.command = CMD_EXITED;
302 cmd.d.data = real; 339 cmd.d.data = real;
303 write(thdat->ctrl.in, &cmd, sizeof(Control_Data)); 340 _efl_thread_pipe_write(thdat->ctrl.in, &cmd, sizeof(Control_Data));
304 341
305 efl_unref(obj); 342 efl_unref(obj);
306 343
@@ -805,7 +842,7 @@ _efl_thread_efl_task_end(Eo *obj EINA_UNUSED, Efl_Thread_Data *pd)
805 pd->end_sent = EINA_TRUE; 842 pd->end_sent = EINA_TRUE;
806 memset(&cmd, 0, sizeof(cmd)); 843 memset(&cmd, 0, sizeof(cmd));
807 cmd.d.command = CMD_EXIT; 844 cmd.d.command = CMD_EXIT;
808 write(pd->ctrl.in, &cmd, sizeof(Control_Data)); 845 _efl_thread_pipe_write(pd->ctrl.in, &cmd, sizeof(Control_Data));
809 } 846 }
810} 847}
811 848
@@ -1010,7 +1047,7 @@ _appthread_threadio_call(Eo *obj EINA_UNUSED, Efl_Appthread_Data *pd,
1010 cmd.d.ptr[0] = func; 1047 cmd.d.ptr[0] = func;
1011 cmd.d.ptr[1] = func_data; 1048 cmd.d.ptr[1] = func_data;
1012 cmd.d.ptr[2] = func_free_cb; 1049 cmd.d.ptr[2] = func_free_cb;
1013 write(thdat->ctrl.in, &cmd, sizeof(Control_Data)); 1050 _efl_thread_pipe_write(thdat->ctrl.in, &cmd, sizeof(Control_Data));
1014} 1051}
1015 1052
1016EOLIAN static void 1053EOLIAN static void
@@ -1024,7 +1061,7 @@ _efl_thread_efl_threadio_call(Eo *obj EINA_UNUSED, Efl_Thread_Data *pd,
1024 cmd.d.ptr[0] = func; 1061 cmd.d.ptr[0] = func;
1025 cmd.d.ptr[1] = func_data; 1062 cmd.d.ptr[1] = func_data;
1026 cmd.d.ptr[2] = func_free_cb; 1063 cmd.d.ptr[2] = func_free_cb;
1027 write(pd->ctrl.in, &cmd, sizeof(Control_Data)); 1064 _efl_thread_pipe_write(pd->ctrl.in, &cmd, sizeof(Control_Data));
1028} 1065}
1029 1066
1030void * 1067void *
@@ -1046,7 +1083,7 @@ _appthread_threadio_call_sync(Eo *obj EINA_UNUSED, Efl_Appthread_Data *pd,
1046 cmd.d.ptr[3] = rep; 1083 cmd.d.ptr[3] = rep;
1047 rep->data = NULL; 1084 rep->data = NULL;
1048 eina_semaphore_new(&(rep->sem), 0); 1085 eina_semaphore_new(&(rep->sem), 0);
1049 write(thdat->ctrl.in, &cmd, sizeof(Control_Data)); 1086 _efl_thread_pipe_write(thdat->ctrl.in, &cmd, sizeof(Control_Data));
1050 eina_semaphore_lock(&(rep->sem)); 1087 eina_semaphore_lock(&(rep->sem));
1051 data = rep->data; 1088 data = rep->data;
1052 free(rep); 1089 free(rep);
@@ -1071,7 +1108,7 @@ _efl_thread_efl_threadio_call_sync(Eo *obj EINA_UNUSED, Efl_Thread_Data *pd,
1071 cmd.d.ptr[3] = rep; 1108 cmd.d.ptr[3] = rep;
1072 rep->data = NULL; 1109 rep->data = NULL;
1073 eina_semaphore_new(&(rep->sem), 0); 1110 eina_semaphore_new(&(rep->sem), 0);
1074 write(pd->ctrl.in, &cmd, sizeof(Control_Data)); 1111 _efl_thread_pipe_write(pd->ctrl.in, &cmd, sizeof(Control_Data));
1075 eina_semaphore_lock(&(rep->sem)); 1112 eina_semaphore_lock(&(rep->sem));
1076 data = rep->data; 1113 data = rep->data;
1077 free(rep); 1114 free(rep);