void OsDestroy() { DestroyInterfaceChangedObserver(); pthread_key_delete(gThreadArgKey); OsMutexDestroy(gMutex); gMutex = kHandleNull; }
int32_t OsCreate() { FILETIME ft; WSADATA wsaData; WORD ver = (2<<8)|2; // WinSock v2.2. Standard on XP and later char* noErrDlgs = getenv("OHNET_NO_ERROR_DIALOGS"); if (noErrDlgs != NULL && strcmp(noErrDlgs, "1") == 0) { _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); } GetSystemTimeAsFileTime(&ft); gStartTime = ft.dwHighDateTime; gStartTime <<= 32; gStartTime |= ft.dwLowDateTime; gTlsIndex = TlsAlloc(); if (TLS_OUT_OF_INDEXES == gTlsIndex) { return -1; } gMutex = OsMutexCreate(""); if (kHandleNull == gMutex) { TlsFree(gTlsIndex); return -1; } if (0 != WSAStartup(ver, &wsaData)) { OsMutexDestroy(gMutex); TlsFree(gTlsIndex); return -1; } gDebugSymbolHandle = GetCurrentProcess(); (void)SymInitialize(gDebugSymbolHandle, NULL, TRUE); return 0; }
void OsDestroy(OsContext* aContext) { if (aContext != NULL) { DestroyInterfaceChangedObserver(aContext); pthread_key_delete(aContext->iThreadArgKey); OsMutexDestroy(aContext->iMutex); free(aContext); } }
OsContext* OsCreate() { FILETIME ft; WSADATA wsaData; WORD ver = (2<<8)|2; // WinSock v2.2. Standard on XP and later char* noErrDlgs = getenv("OHNET_NO_ERROR_DIALOGS"); OsContext* ctx = malloc(sizeof(*ctx)); if (noErrDlgs != NULL && strcmp(noErrDlgs, "1") == 0) { _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); } if (ctx == NULL) { return NULL; } ctx->iInterfaceChangeObserver = NULL; ctx->iTestInterfaceIndex = -1; GetSystemTimeAsFileTime(&ft); ctx->iStartTime = ft.dwHighDateTime; ctx->iStartTime <<= 32; ctx->iStartTime |= ft.dwLowDateTime; ctx->iPrevTime = 0; ctx->iTimeAdjustment = 0; ctx->iTlsIndex = TlsAlloc(); if (TLS_OUT_OF_INDEXES == ctx->iTlsIndex) { free(ctx); return NULL; } ctx->iMutex = OsMutexCreate(ctx, ""); if (kHandleNull == ctx->iMutex) { TlsFree(ctx->iTlsIndex); free(ctx); return NULL; } if (0 != WSAStartup(ver, &wsaData)) { OsMutexDestroy(ctx->iMutex); TlsFree(ctx->iTlsIndex); free(ctx); return NULL; } { HMODULE hModule = GetModuleHandle(NULL); CHAR path[MAX_PATH]; GetModuleFileName(hModule, path, MAX_PATH); ctx->iDebugSymbolHandle = GetCurrentProcess(); (void)SymInitialize(ctx->iDebugSymbolHandle, /*NULL*/path, TRUE); } return ctx; }
int32_t OsCreate() { int errnum; gettimeofday(&gStartTime, NULL); gPrevTime = gStartTime; gMutex = OsMutexCreate("DNSM"); if (gMutex == kHandleNull) return -1; errnum = pthread_key_create(&gThreadArgKey, NULL); if (errnum != 0) { OsMutexDestroy(gMutex); gMutex = kHandleNull; return -1; } return 0; }
OsContext* OsCreate() { OsContext* ctx = malloc(sizeof(*ctx)); gettimeofday(&ctx->iStartTime, NULL); ctx->iPrevTime = ctx->iStartTime; memset(&ctx->iTimeAdjustment, 0, sizeof(ctx->iTimeAdjustment)); ctx->iMutex = OsMutexCreate(ctx, "DNSM"); if (ctx->iMutex == kHandleNull) { free(ctx); return NULL; } if (pthread_key_create(&ctx->iThreadArgKey, NULL) != 0) { OsMutexDestroy(ctx->iMutex); free(ctx); return NULL; } ctx->iInterfaceChangedObserver = NULL; return ctx; }
void OsDestroy() { (void)SymCleanup(gDebugSymbolHandle); if (NULL != gInterfaceChangeObserver) { gInterfaceChangeObserver->iShutdown = 1; (void)WSASetEvent(gInterfaceChangeObserver->iShutdownEvent); (void)WaitForSingleObject(gInterfaceChangeObserver->iSem, INFINITE); CloseHandle(gInterfaceChangeObserver->iSem); WSACloseEvent(gInterfaceChangeObserver->iEvent); WSACloseEvent(gInterfaceChangeObserver->iShutdownEvent); (void)closesocket(gInterfaceChangeObserver->iSocket); free(gInterfaceChangeObserver); gInterfaceChangeObserver = NULL; } (void)WSACleanup(); OsMutexDestroy(gMutex); gMutex = kHandleNull; TlsFree(gTlsIndex); }
static void OsNetworkHandle_Destroy(OsNetworkHandle* aHandle) { LOGFUNC(); #if INT_ENABLED if ( aHandle->iIntSocket >= 0 ) { lwip_close(aHandle->iIntSocket); } #endif OsMutexDestroy(aHandle->iMutex); aHandle->iSocket = -1; aHandle->iIntSocket = -1; aHandle->iFlagInterrupted = 1; free(aHandle); LOG("Destroyd OsNetworkHandle %08x\n", aHandle); }
void OsDestroy(OsContext* aContext) { if (aContext == NULL) { return; } (void)SymCleanup(aContext->iDebugSymbolHandle); if (NULL != aContext->iInterfaceChangeObserver) { aContext->iInterfaceChangeObserver->iShutdown = 1; (void)WSASetEvent(aContext->iInterfaceChangeObserver->iShutdownEvent); (void)WaitForSingleObject(aContext->iInterfaceChangeObserver->iSem, INFINITE); CloseHandle(aContext->iInterfaceChangeObserver->iSem); WSACloseEvent(aContext->iInterfaceChangeObserver->iEvent); WSACloseEvent(aContext->iInterfaceChangeObserver->iShutdownEvent); (void)closesocket(aContext->iInterfaceChangeObserver->iSocket); free(aContext->iInterfaceChangeObserver); aContext->iInterfaceChangeObserver = NULL; } (void)WSACleanup(); OsMutexDestroy(aContext->iMutex); aContext->iMutex = kHandleNull; TlsFree(aContext->iTlsIndex); free(aContext); }