vbox的更動 63301 路徑 trunk/src/VBox/NetworkServices
- 時間撮記:
- 2016-8-10 下午08:45:33 (8 年 以前)
- 位置:
- trunk/src/VBox/NetworkServices
- 檔案:
-
- 修改 2 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp
r63266 r63301 48 48 #include <iprt/time.h> 49 49 #include <iprt/string.h> 50 #ifdef RT_OS_WINDOWS 51 # include <iprt/thread.h> 52 #endif 50 53 51 54 #include <VBox/sup.h> … … 88 91 * DHCP server instance. 89 92 */ 90 class VBoxNetDhcp : public VBoxNetBaseService, public NATNetworkEventAdapter93 class VBoxNetDhcp : public VBoxNetBaseService, public NATNetworkEventAdapter 91 94 { 92 95 public: … … 646 649 } 647 650 651 #ifdef RT_OS_WINDOWS 652 653 /** The class name for the DIFx-killable window. */ 654 static WCHAR g_wszWndClassName[] = L"VBoxNetDHCPClass"; 655 /** Whether to exit the process on quit. */ 656 static bool g_fExitProcessOnQuit = true; 657 658 /** 659 * Window procedure for making us DIFx-killable. 660 */ 661 static LRESULT CALLBACK DIFxKillableWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 662 { 663 if (uMsg == WM_DESTROY) 664 { 665 PostQuitMessage(0); 666 return 0; 667 } 668 return DefWindowProc(hwnd, uMsg, wParam, lParam); 669 } 670 671 /** @callback_method_impl{FNRTTHREAD, 672 * Thread that creates service a window the DIFx can destroy, thereby 673 * triggering process termination. } 674 */ 675 static DECLCALLBACK(int) DIFxKillableProcessThreadProc(RTTHREAD hThreadSelf, void *pvUser) 676 { 677 RT_NOREF(hThreadSelf, pvUser); 678 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); 679 680 /* Register the Window Class. */ 681 WNDCLASSW WndCls; 682 WndCls.style = 0; 683 WndCls.lpfnWndProc = DIFxKillableWindowProc; 684 WndCls.cbClsExtra = 0; 685 WndCls.cbWndExtra = sizeof(void *); 686 WndCls.hInstance = hInstance; 687 WndCls.hIcon = NULL; 688 WndCls.hCursor = NULL; 689 WndCls.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1); 690 WndCls.lpszMenuName = NULL; 691 WndCls.lpszClassName = g_wszWndClassName; 692 693 ATOM atomWindowClass = RegisterClassW(&WndCls); 694 if (atomWindowClass != 0) 695 { 696 /* Create the window. */ 697 HWND hwnd = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST, 698 g_wszWndClassName, g_wszWndClassName, 699 WS_POPUPWINDOW, 700 -200, -200, 100, 100, NULL, NULL, hInstance, NULL); 701 if (hwnd) 702 { 703 SetWindowPos(hwnd, HWND_TOPMOST, -200, -200, 0, 0, 704 SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE); 705 706 MSG msg; 707 while (GetMessage(&msg, NULL, 0, 0)) 708 { 709 TranslateMessage(&msg); 710 DispatchMessage(&msg); 711 } 712 713 DestroyWindow(hwnd); 714 } 715 716 UnregisterClassW(g_wszWndClassName, hInstance); 717 718 if (hwnd && g_fExitProcessOnQuit) 719 exit(0); 720 } 721 return 0; 722 } 723 724 #endif /* RT_OS_WINDOWS */ 725 648 726 /** 649 727 * Entry point. … … 654 732 * Instantiate the DHCP server and hand it the options. 655 733 */ 656 657 734 VBoxNetDhcp *pDhcp = new VBoxNetDhcp(); 658 735 if (!pDhcp) … … 661 738 return 1; 662 739 } 663 int rc = pDhcp->parseArgs(argc - 1, argv + 1); 664 if (rc) 665 return rc; 740 741 RTEXITCODE rcExit = (RTEXITCODE)pDhcp->parseArgs(argc - 1, argv + 1); 742 if (rcExit != RTEXITCODE_SUCCESS) 743 return rcExit; 744 745 #ifdef RT_OS_WINDOWS 746 /* DIFx hack. */ 747 RTTHREAD hMakeUseKillableThread = NIL_RTTHREAD; 748 int rc2 = RTThreadCreate(&hMakeUseKillableThread, DIFxKillableProcessThreadProc, NULL, 0, 749 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "DIFxKill"); 750 if (RT_FAILURE(rc2)) 751 hMakeUseKillableThread = NIL_RTTHREAD; 752 #endif 666 753 667 754 pDhcp->init(); … … 670 757 * Try connect the server to the network. 671 758 */ 672 rc = pDhcp->tryGoOnline(); 673 if (RT_FAILURE(rc)) 674 { 675 delete pDhcp; 676 return 1; 677 } 678 679 /* 680 * Process requests. 681 */ 682 g_pDhcp = pDhcp; 683 rc = pDhcp->run(); 684 pDhcp->done(); 685 686 g_pDhcp = NULL; 759 int rc = pDhcp->tryGoOnline(); 760 if (RT_SUCCESS(rc)) 761 { 762 /* 763 * Process requests. 764 */ 765 g_pDhcp = pDhcp; 766 rc = pDhcp->run(); 767 pDhcp->done(); 768 769 g_pDhcp = NULL; 770 } 687 771 delete pDhcp; 688 772 689 return 0; 773 #ifdef RT_OS_WINDOWS 774 /* Kill DIFx hack. */ 775 if (hMakeUseKillableThread != NIL_RTTHREAD) 776 { 777 g_fExitProcessOnQuit = false; 778 PostThreadMessage((DWORD)RTThreadGetNative(hMakeUseKillableThread), WM_QUIT, 0, 0); 779 RTThreadWait(hMakeUseKillableThread, RT_MS_1SEC * 5U, NULL); 780 } 781 #endif 782 783 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 690 784 } 691 785 … … 704 798 # ifdef RT_OS_WINDOWS 705 799 706 static LRESULT CALLBACK WindowProc(HWND hwnd,707 UINT uMsg,708 WPARAM wParam,709 LPARAM lParam710 )711 {712 if(uMsg == WM_DESTROY)713 {714 PostQuitMessage(0);715 return 0;716 }717 return DefWindowProc (hwnd, uMsg, wParam, lParam);718 }719 720 static LPCWSTR g_WndClassName = L"VBoxNetDHCPClass";721 722 static DWORD WINAPI MsgThreadProc(__in LPVOID lpParameter)723 {724 HWND hwnd = 0;725 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle (NULL);726 bool bExit = false;727 728 /* Register the Window Class. */729 WNDCLASS wc;730 wc.style = 0;731 wc.lpfnWndProc = WindowProc;732 wc.cbClsExtra = 0;733 wc.cbWndExtra = sizeof(void *);734 wc.hInstance = hInstance;735 wc.hIcon = NULL;736 wc.hCursor = NULL;737 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);738 wc.lpszMenuName = NULL;739 wc.lpszClassName = g_WndClassName;740 741 ATOM atomWindowClass = RegisterClass(&wc);742 743 if (atomWindowClass != 0)744 {745 /* Create the window. */746 hwnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,747 g_WndClassName, g_WndClassName,748 WS_POPUPWINDOW,749 -200, -200, 100, 100, NULL, NULL, hInstance, NULL);750 751 if (hwnd)752 {753 SetWindowPos(hwnd, HWND_TOPMOST, -200, -200, 0, 0,754 SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE);755 756 MSG msg;757 while (GetMessage(&msg, NULL, 0, 0))758 {759 TranslateMessage(&msg);760 DispatchMessage(&msg);761 }762 763 DestroyWindow (hwnd);764 765 bExit = true;766 }767 768 UnregisterClass (g_WndClassName, hInstance);769 }770 771 if(bExit)772 {773 /* no need any accuracy here, in anyway the DHCP server usually gets terminated with TerminateProcess */774 exit(0);775 }776 777 return 0;778 }779 800 780 801 … … 783 804 { 784 805 NOREF(hInstance); NOREF(hPrevInstance); NOREF(lpCmdLine); NOREF(nCmdShow); 785 786 HANDLE hThread = CreateThread(787 NULL, /*__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, */788 0, /*__in SIZE_T dwStackSize, */789 MsgThreadProc, /*__in LPTHREAD_START_ROUTINE lpStartAddress,*/790 NULL, /*__in_opt LPVOID lpParameter,*/791 0, /*__in DWORD dwCreationFlags,*/792 NULL /*__out_opt LPDWORD lpThreadId*/793 );794 795 if(hThread != NULL)796 CloseHandle(hThread);797 798 806 return main(__argc, __argv); 799 807 } -
trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp
r63267 r63301 247 247 * @param argc Argument count. 248 248 * @param argv Argument vector. 249 * 250 * @todo r=bird: The --help and --version options shall not return a 251 * non-zero exit code. So, this method need to grow some 252 * complexity. I'm to blame for that blunder :/ 249 253 */ 250 254 int VBoxNetBaseService::parseArgs(int argc, char **argv) … … 295 299 { 296 300 RTStrmPrintf(g_pStdErr, "Invalid trunk type '%s'\n", Val.psz); 297 return 1;301 return RTEXITCODE_SYNTAX; 298 302 } 299 303 break; … … 317 321 case 'V': // --version (missed) 318 322 RTPrintf("%sr%u\n", RTBldCfgVersion(), RTBldCfgRevision()); 319 return 1; 323 return 1; /** @todo this exit code is wrong, of course. :/ */ 320 324 321 325 case 'M': // --need-main … … 338 342 RTPrintf(" -%c, %s\n", m->m_vecOptionDefs[i]->iShort, m->m_vecOptionDefs[i]->pszLong); 339 343 usage(); /* to print Service Specific usage */ 340 return 1; 344 return 1; /** @todo this exit code is wrong, of course. :/ */ 341 345 342 346 default: … … 345 349 if (RT_FAILURE(rc1)) 346 350 { 347 rc= RTGetOptPrintError(rc, &Val);351 RTEXITCODE rcExit = RTGetOptPrintError(rc, &Val); 348 352 RTPrintf("Use --help for more information.\n"); 349 return rc ;353 return rcExit; 350 354 } 351 355 break; … … 355 359 356 360 RTMemFree(paOptionArray); 357 return rc;361 return RTEXITCODE_SUCCESS; 358 362 } 359 363
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器