unsigned int __stdcall ulogout(PVOID pM) #endif // _WIN32 { while((!state.salt_got)&&(state.challegecount<MAX_CHA_TRY)) { i=usend(sock,T_CHAPKT); bftime=time(NULL); if(state.verbose) printf("%d bytes sent\n",i); while((bftime>time(NULL)-WAIT_TIME)&&(!state.salt_got)); if(state.salt_got) break; } if(state.challegecount>=MAX_CHA_TRY) { fprintf(stderr,"cha fail\n"); exit(-1); } if(state.salt_got) { i=usend(sock,T_LGOPKT); if(state.verbose) printf("logout sent\n"); } #if defined(__linux__) || defined(__MACH__) pthread_exit(NULL); return NULL; #endif #ifdef _WIN32 return 0; #endif // _WIN32 }
void *ukplv(void * ptr) { while(state.loggedin) { i=usend(sock,T_KALPKT); if(state.verbose) printf("%d bytes sent\n",i); bftime=time(NULL); while((bftime>time(NULL)-WAIT_TIME)&&(!state.kalsuc)); if(state.kalsuc) { state.kalsuc=false; int protect=0; while((state.mcstate<4)&&(protect++<5)) { state.miscsuc=false; i=usend(sock,T_MSCPKT); if(state.verbose) printf("%d bytes sent\n",i); bftime=time(NULL); while((bftime>time(NULL)-WAIT_TIME)&&(!state.miscsuc)); } state.kalsuc=false; if(state.mcstate<4) { state.loggedin=false; #if defined(__linux__) || defined(__MACH__) pthread_exit(NULL); #endif // defined return NULL; } printf("misc exchange sucess\n"); } else { state.loggedin=false; #if defined(__linux__) || defined(__MACH__) pthread_exit(NULL); #endif // defined return NULL; } sleep(20); } #if defined(__linux__) || defined(__MACH__) pthread_exit(NULL); #endif return NULL; }
void pping_server::shutdown() { if (!initialized) return; close_lstn_thread = true; USOCKET s = usocket(AF_INET, SOCK_STREAM, 0, NULL); if (s == U_INVALID_SOCKET) throw USER_ENV_EXCEPTION("Failed to create socket", false); if (uconnect_tcp(s, port, "localhost", NULL) == U_SOCKET_ERROR) throw USER_ENV_EXCEPTION("Failed to create TCP connection", false); char c = PPING_KEEP_ALIVE_MSG; usend(s, &c, sizeof(c), NULL); if (uThreadJoin(server_lstn_thread_handle, NULL) != 0) throw USER_ENV_EXCEPTION("Error waiting for pping server_lstn thread to shutdown", false); if (uclose_socket(s, NULL) != 0) throw USER_ENV_EXCEPTION("Failed to close socket", false); if (uclose_socket(sock, NULL) != 0) throw USER_ENV_EXCEPTION("Failed to close socket", false); if (uCloseThreadHandle(server_lstn_thread_handle, NULL) != 0) throw USER_EXCEPTION2(SE4063, "pping server_lstn_thread"); }
void pping_client::shutdown() { if (!initialized) return; stop_keep_alive = true; if (UUnnamedSemaphoreUp(&sem, NULL) != 0) throw USER_ENV_EXCEPTION("Failed to up semaphore", false); if (uThreadJoin(client_thread_handle, NULL) != 0) throw USER_ENV_EXCEPTION("Error waiting for pping client thread to shutdown", false); if (uCloseThreadHandle(client_thread_handle, NULL) != 0) throw USER_EXCEPTION2(SE4063, "pping client_thread"); char c = PPING_DISCONNECT_MSG; if (usend(sock, &c, sizeof(char), NULL) != sizeof(char)) throw SYSTEM_EXCEPTION("pping server is down"); if (uclose_socket(sock, NULL) == U_SOCKET_ERROR) throw USER_ENV_EXCEPTION("Failed to close socket", false); if (UUnnamedSemaphoreRelease(&sem, NULL) != 0) throw USER_ENV_EXCEPTION("Failed to release semaphore", false); initialized = false; }
void *udial(void * ptr) { while((!state.salt_got)&&(state.challegecount<MAX_CHA_TRY)) { i=usend(sock,T_CHAPKT); bftime=time(NULL); if(state.verbose) printf("%d bytes sent\n",i); while((bftime>time(NULL)-WAIT_TIME)&&(!state.salt_got)); if(state.salt_got) break; } if(state.challegecount>=MAX_CHA_TRY) { fprintf(stderr,"cha fail\n"); exit(-1); } if(state.salt_got) { i=usend(sock,T_LGIPKT); if(state.verbose) printf("%d bytes sent\n",i); while((bftime>time(NULL)-WAIT_TIME)&&(!state.loggedin)); if(state.loggedin) state.salt_got=false; else { fprintf(stderr,"login fail!\n"); exit(-1); } } #if defined(__linux__) || defined(__MACH__) pthread_exit(NULL); #endif return NULL; }
inline int client_exception_handler(USOCKET sock, const pping_server *pps) { #if (defined(EL_DEBUG) && (EL_DEBUG == 1)) #ifdef _WIN32 char cc = PPING_PROC_EXCEPTION_MSG; HANDLE proc_h; DWORD proc_id; DWORD except_thread_id; PEXCEPTION_POINTERS client_exceptPtrs; MINIDUMP_EXCEPTION_INFORMATION ExpParam; int component; UFile fh; #define GETVAR(v) if (urecv(sock, (char*)&v, sizeof(v), NULL) != sizeof(v)) \ SYS_FAILURE_SERVER("Failure in pping server (cannot receive exception parameter from the client)."); GETVAR(proc_id) GETVAR(component); GETVAR(except_thread_id); GETVAR(client_exceptPtrs); #undef GETVAR proc_h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id); if (proc_h == NULL) d_printf2("Failed to open process handle, GetLastError=%u\n", GetLastError()); ExpParam.ThreadId = except_thread_id; ExpParam.ExceptionPointers = client_exceptPtrs; ExpParam.ClientPointers = TRUE; fh = sedna_soft_fault_log_fh(component, "-dump"); if (!MiniDumpWriteDump(proc_h, proc_id, fh, MiniDumpWithDataSegs, &ExpParam, NULL, NULL)) d_printf2("Failed to save minidump, GetLastError=%u\n", GetLastError()); uCloseFile(fh, NULL); if (usend(sock, &cc, sizeof(cc), NULL) != sizeof(cc)) SYS_FAILURE_SERVER("Failure in pping server (cannot send exception ack to the client)."); #endif /* _WIN32 */ #endif /* EL_DEBUG */ return 1; }
U_THREAD_PROC(pping_client_thread_proc, arg) { if (uThreadBlockAllSignals(NULL) != 0) d_printf1("Failed to block signals for pping_client_thread_proc"); pping_client *ppc = (pping_client*)arg; char c = PPING_KEEP_ALIVE_MSG; while (true) { if (ppc->stop_keep_alive) return 0; int res = usend(ppc->sock, &c, sizeof(c), NULL); if (res != sizeof(c) && !ppc->stop_keep_alive) { sedna_soft_fault("SEDNA GOVERNOR is down", ppc->component); } /* se_stop -hard has been called? */ if(ppc->signaled_flag != NULL && GOV_HEADER_GLOBAL_PTR != NULL && GOV_HEADER_GLOBAL_PTR -> is_server_stop == SE_STOP_HARD) { *(ppc->signaled_flag) = true; } UUnnamedSemaphoreDownTimeout(&(ppc->sem), 1000, NULL); if(ppc->timeout) { if (!ppc->counter && !ppc->reset_flag) { *(ppc->signaled_flag) = true; ppc->counter = ppc->timeout; } if(ppc->reset_flag) { ppc->counter = ppc->timeout; if(ppc->signaled_flag) *(ppc->signaled_flag) = false; ppc->reset_flag = false; } (ppc->counter)--; } #if (defined(EL_DEBUG) && (EL_DEBUG == 1)) #define SENDVAR(v) if (usend(ppc->sock, (char*)&v, sizeof(v), NULL) != sizeof(v)) continue; #ifdef _WIN32 if (ppc->exceptPtrs) { //TODO: do something if usend/urecv fails or get wrong msg char cc = PPING_PROC_EXCEPTION_MSG; DWORD proc_id = GetCurrentProcessId(); if (usend(ppc->sock, &cc, sizeof(cc), NULL) != sizeof(cc)) { ppc->exceptPtrs = NULL; continue; } SENDVAR(proc_id) SENDVAR(ppc->component); SENDVAR(ppc->except_thread_id); SENDVAR(ppc->exceptPtrs); if (urecv(ppc->sock, &cc, sizeof(cc), NULL) != sizeof(cc)) { ppc->exceptPtrs = NULL; continue; } if (cc != PPING_PROC_EXCEPTION_MSG) { ppc->exceptPtrs = NULL; continue; } if (ppc->stacktrace_fh != U_INVALID_FD) { if (StackTraceInit() != 0) { StackTraceWriteFd(ppc->exceptPtrs->ContextRecord, (intptr_t)ppc->stacktrace_fh, 9999, 0); StackTraceDeinit(); } uCloseFile(ppc->stacktrace_fh, NULL); } ppc->exceptPtrs = NULL; } #endif #undef SENDVAR #endif } return 0; }