From d64c8a66dc3deb1d11fd350f4d5100cd47fabde1 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Thu, 8 Aug 2002 22:25:16 +0000 Subject: [PATCH] cleanup and some fixes --- direct/src/directd/directd.cxx | 184 ++++++++++----------------------- direct/src/directd/directd.h | 11 +- 2 files changed, 64 insertions(+), 131 deletions(-) diff --git a/direct/src/directd/directd.cxx b/direct/src/directd/directd.cxx index d3aa83a158..84bca4ffeb 100644 --- a/direct/src/directd/directd.cxx +++ b/direct/src/directd/directd.cxx @@ -17,6 +17,7 @@ // //////////////////////////////////////////////////////////////////// +// This define tells the windows headers to include job objects: #define _WIN32_WINNT 0x0500 #include "directd.h" @@ -38,11 +39,10 @@ #include "pset.h" -//#define old_directd -#undef old_directd - -#ifdef old_directd //[ namespace { + // ...This section is part of the old stuff from the original implementation. + // The new stuff that uses job objects doesn't need this stuff: + // The following is from an MSDN example: #define TA_FAILED 0 @@ -132,121 +132,10 @@ namespace { } } -#else //][ -namespace { - // The following is from an MSDN example: - - #define TA_FAILED 0 - #define TA_SUCCESS_CLEAN 1 - #define TA_SUCCESS_KILL 2 - #define TA_SUCCESS_16 3 - - HANDLE sgJobObject; - - BOOL CALLBACK - TerminateAppEnum(HWND hwnd, LPARAM lParam) { - DWORD dwID; - GetWindowThreadProcessId(hwnd, &dwID); - if(dwID == (DWORD)lParam) { - PostMessage(hwnd, WM_CLOSE, 0, 0); - } - return TRUE; - } - - /* - DWORD WINAPI TerminateApp(DWORD dwPID, DWORD dwTimeout) - - Purpose: - Shut down a 32-Bit Process - - Parameters: - dwPID - Process ID of the process to shut down. - - dwTimeout - Wait time in milliseconds before shutting down the process. - - Return Value: - TA_FAILED - If the shutdown failed. - TA_SUCCESS_CLEAN - If the process was shutdown using WM_CLOSE. - TA_SUCCESS_KILL - if the process was shut down with - TerminateProcess(). - */ - DWORD WINAPI - TerminateApp(DWORD dwPID, DWORD dwTimeout) { - HANDLE hProc; - DWORD dwRet; - - // If we can't open the process with PROCESS_TERMINATE rights, - // then we give up immediately. - hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, dwPID); - if(hProc == NULL) { - return TA_FAILED; - } - - // TerminateAppEnum() posts WM_CLOSE to all windows whose PID - // matches your process's. - EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)dwPID); - - // Wait on the handle. If it signals, great. If it times out, - // then you kill it. - if(WaitForSingleObject(hProc, dwTimeout)!=WAIT_OBJECT_0) { - dwRet=(TerminateProcess(hProc,0)?TA_SUCCESS_KILL:TA_FAILED); - } else { - dwRet = TA_SUCCESS_CLEAN; - } - CloseHandle(hProc); - - return dwRet; - } - - /* - Start an application with the command line cmd. - */ - void - StartApp(const string& cmd) { - static inited; - if (!inited) { - inited=1; - sgJobObject=CreateJobObject(0, 0); - if (!sgJobObject) { - nout<<"CreateProcess failed: no sgJobObject"< PidStack; PidStack _pids; + // End of old stuff + typedef pset< PT(Connection) > ConnectionSet; ConnectionSet _connections; - + HANDLE _jobObject; bool _shutdown; void check_for_new_clients();