static Eina_Bool _ecore_con_local_win32_server_read_client_handler(void *data, Ecore_Win32_Handler *wh) { Ecore_Con_Client *cl; void *buf; DWORD n; Eina_Bool broken_pipe = EINA_FALSE; cl = (Ecore_Con_Client *)data; if (!ResetEvent(cl->host_server->event_read)) return ECORE_CALLBACK_RENEW; buf = malloc(cl->host_server->nbr_bytes); if (!buf) return ECORE_CALLBACK_RENEW; if (ReadFile(cl->host_server->pipe, buf, cl->host_server->nbr_bytes, &n, NULL)) { if (!cl->delete_me) ecore_con_event_client_data(cl, buf, cl->host_server->nbr_bytes, EINA_FALSE); cl->host_server->want_write = 1; } else { if (GetLastError() == ERROR_BROKEN_PIPE) broken_pipe = EINA_TRUE; } if (broken_pipe) { #if 0 char *msg; msg = evil_last_error_get(); if (msg) { ecore_con_event_client_error(cl, msg); free(msg); } #endif if (!cl->delete_me) ecore_con_event_client_del(cl); cl->dead = EINA_TRUE; return ECORE_CALLBACK_CANCEL; } if (cl->host_server->want_write) ecore_con_local_win32_client_flush(cl); ecore_main_win32_handler_del(wh); return ECORE_CALLBACK_DONE; }
static Eina_Bool _ecore_con_local_win32_server_read_client_handler(void *data, Ecore_Win32_Handler *wh) { Ecore_Con_Client *obj = data; Ecore_Con_Client_Data *cl = eo_data_scope_get(obj, ECORE_CON_CLIENT_CLASS); void *buf; DWORD n; Eina_Bool broken_pipe = EINA_FALSE; Ecore_Con_Server_Data *host_svr = eo_data_scope_get(cl->host_server, ECORE_CON_SERVER_CLASS); if (!ResetEvent(host_svr->event_read)) return ECORE_CALLBACK_RENEW; buf = malloc(host_svr->nbr_bytes); if (!buf) return ECORE_CALLBACK_RENEW; if (ReadFile(host_svr->pipe, buf, host_svr->nbr_bytes, &n, NULL)) { if (!cl->delete_me) ecore_con_event_client_data(obj, buf, host_svr->nbr_bytes, EINA_FALSE); host_svr->want_write = 1; } else { if (GetLastError() == ERROR_BROKEN_PIPE) broken_pipe = EINA_TRUE; } if (broken_pipe) { #if 0 char *msg; msg = evil_last_error_get(); if (msg) { ecore_con_event_client_error(cl, msg); free(msg); } #endif _ecore_con_client_kill(obj); return ECORE_CALLBACK_CANCEL; } if (host_svr->want_write) ecore_con_local_win32_client_flush(obj); ecore_main_win32_handler_del(wh); return ECORE_CALLBACK_DONE; }
Eina_Bool ecore_con_local_win32_client_flush(Ecore_Con_Client *obj) { Ecore_Con_Client_Data *cl = eo_data_scope_get(obj, ECORE_CON_CLIENT_CLASS); Ecore_Con_Type type; size_t num; BOOL res; DWORD written; Ecore_Con_Server_Data *svr = eo_data_scope_get(cl->host_server, ECORE_CON_SERVER_CLASS); type = svr->type & ECORE_CON_TYPE; /* This check should never be true */ if (type == ECORE_CON_LOCAL_ABSTRACT) return EINA_TRUE; if ((type != ECORE_CON_LOCAL_USER) && (type != ECORE_CON_LOCAL_SYSTEM)) return EINA_FALSE; num = eina_binbuf_length_get(cl->buf) - cl->buf_offset; if (num <= 0) return EINA_TRUE; res = WriteFile(svr->pipe, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num, &written, NULL); if (!res) { char *msg; msg = evil_last_error_get(); if (msg) { ecore_con_event_client_error(obj, msg); free(msg); } _ecore_con_client_kill(obj); } cl->buf_offset += written; if (cl->buf_offset >= eina_binbuf_length_get(cl->buf)) { cl->buf_offset = 0; eina_binbuf_free(cl->buf); cl->buf = NULL; svr->want_write = 0; } else if (written < (DWORD)num) svr->want_write = 1; return EINA_TRUE; }
Eina_Bool ecore_con_local_win32_client_flush(Ecore_Con_Client *cl) { Ecore_Con_Type type; int num; BOOL res; DWORD written; type = cl->host_server->type & ECORE_CON_TYPE; /* This check should never be true */ if (type == ECORE_CON_LOCAL_ABSTRACT) return EINA_TRUE; if ((type != ECORE_CON_LOCAL_USER) && (type != ECORE_CON_LOCAL_SYSTEM)) return EINA_FALSE; num = eina_binbuf_length_get(cl->buf) - cl->buf_offset; if (num <= 0) return EINA_TRUE; res = WriteFile(cl->host_server->pipe, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num, &written, NULL); if (!res) { char *msg; msg = evil_last_error_get(); if (msg) { ecore_con_event_client_error(cl, msg); free(msg); } if (!cl->delete_me) ecore_con_event_client_del(cl); cl->dead = EINA_TRUE; } cl->buf_offset += written; if (cl->buf_offset >= eina_binbuf_length_get(cl->buf)) { cl->buf_offset = 0; eina_binbuf_free(cl->buf); cl->buf = NULL; cl->host_server->want_write = 0; } else if (written < (DWORD)num) cl->host_server->want_write = 1; return EINA_TRUE; }