Eina_Bool ecore_con_local_connect(Ecore_Con_Server *obj, Eina_Bool (*cb_done)(void *data, Ecore_Fd_Handler *fd_handler)) { #warning "I am pretty sure cb_done should be used." Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS); char *buf = NULL; Ecore_Win32_Handler *handler_read; Ecore_Win32_Handler *handler_peek; if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT) { WRN("Your system does not support abstract sockets!"); return EINA_FALSE; } if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_USER) buf = ecore_con_local_path_new(EINA_FALSE, svr->name, svr->port); else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM) buf = ecore_con_local_path_new(EINA_TRUE, svr->name, svr->port); EINA_SAFETY_ON_NULL_RETURN_VAL(buf, EINA_FALSE); while (1) { svr->pipe = CreateFile(buf, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (svr->pipe != INVALID_HANDLE_VALUE) break; /* if pipe not busy, we exit */ if (GetLastError() != ERROR_PIPE_BUSY) { DBG("Connection to a server failed"); free(buf); return EINA_FALSE; } /* pipe busy, so we wait for it */ if (!WaitNamedPipe(buf, NMPWAIT_WAIT_FOREVER)) { DBG("Can not wait for a server"); goto close_pipe; } } svr->path = buf; buf = NULL; svr->event_read = CreateEvent(NULL, TRUE, FALSE, NULL); if (!svr->event_read) { ERR("Can not create event read"); goto free_path; } handler_read = ecore_main_win32_handler_add(svr->event_read, _ecore_con_local_win32_client_read_server_handler, obj); if (!handler_read) { ERR("Can not create handler read"); goto close_event_read; } svr->event_peek = CreateEvent(NULL, TRUE, FALSE, NULL); if (!svr->event_peek) { ERR("Can not create event peek"); goto del_handler_read; } handler_peek = ecore_main_win32_handler_add(svr->event_peek, _ecore_con_local_win32_client_peek_server_handler, obj); if (!handler_peek) { ERR("Can not create handler peek"); goto close_event_peek; } svr->thread_read = (HANDLE)_beginthreadex(NULL, 0, _ecore_con_local_win32_client_read_server_thread, obj, CREATE_SUSPENDED, NULL); if (!svr->thread_read) { ERR("Can not launch thread"); goto del_handler_peek; } if (!svr->delete_me) ecore_con_event_server_add(obj); ResumeThread(svr->thread_read); free(buf); return EINA_TRUE; del_handler_peek: ecore_main_win32_handler_del(handler_peek); close_event_peek: CloseHandle(svr->event_peek); del_handler_read: ecore_main_win32_handler_del(handler_read); close_event_read: CloseHandle(svr->event_read); free_path: free(svr->path); svr->path = NULL; close_pipe: CloseHandle(svr->pipe); free(buf); return EINA_FALSE; }
Eina_Bool ecore_con_local_connect(Ecore_Con_Server *svr, Eina_Bool (*cb_done)(void *data, Ecore_Fd_Handler *fd_handler)) { char buf[256]; Ecore_Win32_Handler *handler_read; Ecore_Win32_Handler *handler_peek; if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT) { ERR("Your system does not support abstract sockets!"); return EINA_FALSE; } if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_USER) snprintf(buf, sizeof(buf), "\\\\.\\pipe\\%s", svr->name); else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM) { const char *computername; computername = getenv("COMPUTERNAME"); snprintf(buf, sizeof(buf), "\\\\%s\\pipe\\%s", computername, svr->name); } while (1) { svr->pipe = CreateFile(buf, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (svr->pipe != INVALID_HANDLE_VALUE) break; /* if pipe not busy, we exit */ if (GetLastError() != ERROR_PIPE_BUSY) { ERR("Connection to a server failed"); return EINA_FALSE; } /* pipe busy, so we wait for it */ if (!WaitNamedPipe(buf, NMPWAIT_WAIT_FOREVER)) { ERR("Can not wait for a server"); goto close_pipe; } } svr->path = strdup(buf); if (!svr->path) { ERR("Allocation failed"); goto close_pipe; } svr->event_read = CreateEvent(NULL, TRUE, FALSE, NULL); if (!svr->event_read) { ERR("Can not create event read"); goto free_path; } handler_read = ecore_main_win32_handler_add(svr->event_read, _ecore_con_local_win32_client_read_server_handler, svr); if (!handler_read) { ERR("Can not create handler read"); goto close_event_read; } svr->event_peek = CreateEvent(NULL, TRUE, FALSE, NULL); if (!svr->event_peek) { ERR("Can not create event peek"); goto del_handler_read; } handler_peek = ecore_main_win32_handler_add(svr->event_peek, _ecore_con_local_win32_client_peek_server_handler, svr); if (!handler_peek) { ERR("Can not create handler peek"); goto close_event_peek; } svr->thread_read = (HANDLE)_beginthreadex(NULL, 0, _ecore_con_local_win32_client_read_server_thread, svr, CREATE_SUSPENDED, NULL); if (!svr->thread_read) { ERR("Can not launch thread"); goto del_handler_peek; } if (!svr->delete_me) ecore_con_event_server_add(svr); ResumeThread(svr->thread_read); return EINA_TRUE; del_handler_peek: ecore_main_win32_handler_del(handler_peek); close_event_peek: CloseHandle(svr->event_peek); del_handler_read: ecore_main_win32_handler_del(handler_read); close_event_read: CloseHandle(svr->event_read); free_path: free(svr->path); svr->path = NULL; close_pipe: CloseHandle(svr->pipe); return EINA_FALSE; }