亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? processupdate.cpp

?? <Visual C++ 網絡程序設計實例詳解>配套源碼
?? CPP
字號:
#include "stdafx.h"
#include "RemoteAdmin.h"
#include "ProcessUpdate.h"
#include "Command.h"
#include "RemoteAdminDoc.h"
#include "MachineView.h"
#include "Resource.h"
#include "RemoteAdminView.h"
#include "GlobalMFCHelperFunc.h"


extern BOOL g_bUpdateProcessList;
extern UINT g_iUpdateProcessDelay;
extern CRITICAL_SECTION g_CriticalSection;

// Thread function that updates the all machines process's
UINT __stdcall ProcessUpdate::UpdateProcessListForAllMachines(void* pParam)
{
    SDocView* pDocView = reinterpret_cast<SDocView*>(pParam);

    CRemoteAdminDoc* pDoc              = pDocView->pDoc;
    CRemoteAdminView* pRemoteAdminView = pDocView->pRemoteAdminView;
    CMachineView* pMachineView         = pDocView->pMachineView;

    CString* pstrConnctedMachinesIP = NULL;
    int iNumberOfConnectedMachines = 0;
	OVERLAPPED olOverlapped = {0};
    
    // Debug diagnostics
    #ifdef _DEBUG
        int count = 0;
        CString strDebug;
    #endif
    CProcessInfoList pilProcessInfo;
    while (TRUE)
    {   
        // << Debug diagnostics
        #ifdef _DEBUG
            strDebug.Format("\n\nThreadID %d : counter %d\n", ::GetCurrentThreadId(), ++count);
        #endif
        TRACE0(strDebug.GetBuffer(0));         


        if (g_bUpdateProcessList == FALSE)
        {
            return 0;
        }
        //::EnterCriticalSection(&g_CriticalSection);
        pDoc->GetConnectedMachinesIP(&pstrConnctedMachinesIP, &iNumberOfConnectedMachines);

		// Start to get the processes on the remote computer and diaplay it
		for (int iCounter = 0; iCounter < iNumberOfConnectedMachines; ++iCounter)
        {
            HANDLE hProcessInfoPipe = pDoc->GetRemoteAdminProcessInfoPipe(pstrConnctedMachinesIP[iCounter]);
            
            #ifdef _DEBUG
                strDebug.Format("IP %s\n", pstrConnctedMachinesIP[iCounter].GetBuffer(0));
                TRACE0(strDebug.GetBuffer(0));
            #endif

            if (hProcessInfoPipe != NULL)
            {
				// Tell the server application, that we want an updated process list from 
				// that machine
                TriggerRemoteServiceToPrepareForProcessInfoUpdate(hProcessInfoPipe);              

				// First get the process count on that machine
                UINT iProcessCount = ProcessUpdate::ReceiveProcessCountFromRemoteMachine(hProcessInfoPipe);
                
				// This has to be a n/w problem
				if (iProcessCount <= 0 || iProcessCount >= INT_MAX)  
				{
					if (pstrConnctedMachinesIP[iCounter] != _T(""))
						ProcessUpdate::DisconnectAndReconnectToRemoteService(pstrConnctedMachinesIP[iCounter], pDoc, pMachineView, pRemoteAdminView);					

					continue;
				}

                #ifdef _DEBUG
                    strDebug.Format("Total Processes %d\n",iProcessCount);
                    TRACE0(strDebug.GetBuffer(0));
                #endif

                // Create a new list with all the updated processes
                //CProcessInfoList pilProcessInfo;
                for (UINT i = 0; i < iProcessCount; ++i)
                {
					ProcessUpdate::ReceiveProcessFromRemoteMachine(hProcessInfoPipe, pilProcessInfo, pstrConnctedMachinesIP[iCounter], iProcessCount, i + 1);       
					
					// This may be that case of the user loading a new file for monitoring from the
					// open command or MRU list. So please quit. g_bUpdateProcessList may be made 
					// FALSE in CRemoteAdminDoc::OnOpenDocument()
					if (g_bUpdateProcessList == FALSE)
					{
						return 0;
					}
                }

                // Now update with new processes info forthis machine IP
                pDoc->RefreshProcessList(pstrConnctedMachinesIP[iCounter], pilProcessInfo);

                // Now free the list
				ProcessUpdate::FreeProcessInfoList(pilProcessInfo);
            }
        }
  
        CString strIP = pMachineView->GetSelectedItemTextInTreeView();

        // strIP will be zero for root, else it will give the IP of the selected
        // machine
        if (strIP != _T("0"))
        {
            pRemoteAdminView->RefreshProcesses(strIP);
        }
        
		// Free the memory allocated for machine information
		if (pstrConnctedMachinesIP != NULL)
		{
			delete[] pstrConnctedMachinesIP;
			pstrConnctedMachinesIP = NULL;
		}
        
        
        //::LeaveCriticalSection(&g_CriticalSection);
        ::Sleep(g_iUpdateProcessDelay);
    }

	if (pDocView)
	{
		delete pDocView;
	}
    return 0;
}


void __stdcall ProcessUpdate::ReceiveProcessFromRemoteMachine(HANDLE hProcessInfoPipe, CProcessInfoList& pilProcessInfo, CString strIP, UINT iProcessCount, UINT iCounter)
{
	::EnterCriticalSection(&g_CriticalSection);

	ASSERT(hProcessInfoPipe != NULL);
	ASSERT(hProcessInfoPipe != INVALID_HANDLE_VALUE);

	//PROCESSENTRY32* pPe = new PROCESSENTRY32;
    SProcessInfo* pPe = new SProcessInfo;
	ASSERT(pPe);

	// Debug diagnostics
    #ifdef _DEBUG
        int count = 0;
        CString strDebug;
    #endif
       
    if (pPe != NULL)
    {
		//::memset(pPe, 0, sizeof(PROCESSENTRY32));
        ::memset(pPe, 0, sizeof(SProcessInfo));

		#ifdef _DEBUG
			strDebug.Format("Before Process %d of %d IP %s\n", iCounter, iProcessCount, strIP.GetBuffer(0));
			TRACE0(strDebug.GetBuffer(0));
        #endif
						
		DWORD dwRead			= 0;
        DWORD dwWritten			= 0;
		OVERLAPPED olOverlapped = {0};
		
		//BOOL bOk = ::ReadFile(hProcessInfoPipe, pPe, sizeof(PROCESSENTRY32), &dwRead, &olOverlapped);
        BOOL bOk = ::ReadFile(hProcessInfoPipe, pPe, sizeof(SProcessInfo), &dwRead, &olOverlapped);
						
		// If not successful, give some more time for the i/o coperation to complete
		if (!bOk)
		{
			ProcessUpdate::WaitFor_IO_OperationToCompleteWithExtraTime(300, 200);
		}
		
        
		pilProcessInfo.AddTail(pPe);
	}
	else
    {
		::AfxMessageBox(IDS_NO_MEMORY_FOR_NEW_PROCESSINFO);
    }

	::LeaveCriticalSection(&g_CriticalSection);
}


void __stdcall ProcessUpdate::TriggerRemoteServiceToPrepareForProcessInfoUpdate(HANDLE hProcessInfoPipe)
{
	::EnterCriticalSection(&g_CriticalSection);

    DWORD dwWritten			= 0;
    SCommand cmd			= {0};
    OVERLAPPED olOverlapped = {0};

    cmd.m_bThreadExit = FALSE;
    
    TRACE0("Before write\n");

    BOOL bOk = ::WriteFile(hProcessInfoPipe, &cmd, sizeof(SCommand), &dwWritten, &olOverlapped);
	if (!bOk)
	{
		ProcessUpdate::WaitFor_IO_OperationToComplete(400);
	}

	::LeaveCriticalSection(&g_CriticalSection);
}


UINT __stdcall ProcessUpdate::ReceiveProcessCountFromRemoteMachine(HANDLE hProcessInfoPipe)
{
	TRACE0("Before Process count read\n");

	::EnterCriticalSection(&g_CriticalSection);

	UINT iProcessCount		= 0;
	DWORD dwRead			= 0;
	OVERLAPPED olOverlapped = {0};

    BOOL bOk = ::ReadFile(hProcessInfoPipe, &iProcessCount, sizeof(UINT), &dwRead, &olOverlapped);
				
	// If not successful, give some more time for the i/o coperation to complete
	if (!bOk)
	{
		ProcessUpdate::WaitFor_IO_OperationToCompleteWithExtraTime(1000, 2000);
	}

	::LeaveCriticalSection(&g_CriticalSection);

	return iProcessCount;
}


void __stdcall ProcessUpdate::DisconnectAndReconnectToRemoteService(CString strIP, CRemoteAdminDoc* pDoc, CMachineView* pMachineView, CRemoteAdminView* pRemoteAdminView)
{
	// Retrive the password before we delete machine information, as we require it for reconnection.
	//CString strPwd = pDoc->GetPasswordForMachine(strIP);

	// Had to do all these hackery because MFC CString fails here dues to reference counting.
	// Other wise we would have taken the password in a CString
	TCHAR szPwd[_MAX_PATH];

	::memset(szPwd, 0, _MAX_PATH);
	::strcpy(szPwd, (LPCTSTR)pDoc->GetPasswordForMachine(strIP));
	
	//if (strPwd == _T("Could not retrieve the password"))  // Only disconnect machine
	if (strcmp(szPwd, "Could not retrieve the password") == 0)  // Only disconnect machine
	{
		// Show a balloon the system tray, that this machine is being disconnected.
		(MFC_DocView::GetApp())->ShowBalloonMsgInTray(strIP, "Password retrieval failure! Disconnecting the machine....");

		// Since we could not retrieve the password for the machine, there is some problem, 
		// disconnect the machine. Since there is a password retrieval failure, no point in 
		// reconnecting
		pMachineView->DeleteMachineFromBeingMonitored(strIP, pRemoteAdminView);
	}
	else  // Disconnect and try to reconnect the machine
	{
        // Show a balloon the system tray, that this machine is being disconnected.
		(MFC_DocView::GetApp())->ShowBalloonMsgInTray(strIP, "Network error! Trying to reconnect.......");

		// Get the machine's password length for creating a buffer to hold the password
		//unsigned int iPwdLen = (strPwd.GetLength() + sizeof(TCHAR)); // + sizeof(TCHAR) to accomodate '\0'

		// Get the password in a buffer because of reference counting errors in 
		// MFC's CString.
		//TCHAR* szPwd = new TCHAR[iPwdLen];

		//ASSERT(szPwd != NULL);

	//	if (szPwd != NULL)
	//	{
			// Prepare the password buffer
//            ::memset(szPwd, 0, iPwdLen);

			// Copy the password to the buffer
//			::strcpy(szPwd, (LPCTSTR)strPwd);

			// Since process count is zero or less, there is some problem, disconnect the machine and
			// try to connect again
			pMachineView->DeleteMachineFromBeingMonitored(strIP, pRemoteAdminView);
	
			// Try adding the same machine again, as there was a problem, network or otherwise.
			//	CString strPwd = szPwd;
			pMachineView->AddMachine(strIP, szPwd, pDoc, pRemoteAdminView);

//			if (szPwd != NULL)
//			{
//				delete szPwd;
///			}
//		}
//		else
//		{
		//	pMachineView->DeleteMachineFromBeingMonitored(strIP, pRemoteAdminView);
//		}
	}
}


void __stdcall ProcessUpdate::FreeProcessInfoList(CProcessInfoList& pilProcessInfo)
{
	::EnterCriticalSection(&g_CriticalSection);

	//PROCESSENTRY32* pPe = NULL;
    SProcessInfo* pPe = NULL;
    
	POSITION pos = pilProcessInfo.GetHeadPosition();
    while (pos != (POSITION)0xcdcdcdcd && pos != NULL)
    {
		pPe = pilProcessInfo.GetNext(pos);
        delete pPe;
    }

    pilProcessInfo.RemoveAll();

	::LeaveCriticalSection(&g_CriticalSection);
}

void __stdcall ProcessUpdate::WaitFor_IO_OperationToComplete(UINT iTimeToComplete)
{
	DWORD dwError = ::GetLastError();

	switch (dwError)
	{
	case ERROR_IO_PENDING:
       	::Sleep(iTimeToComplete);
		break;

	default:
		ASSERT(0);   // Generally shouldn't reach here
		break;
	}
}
             

void __stdcall ProcessUpdate::WaitFor_IO_OperationToCompleteWithExtraTime(UINT iTimeToComplete, UINT iExtraTimeToComplete)
{
	DWORD dwError = ::GetLastError();

	switch (dwError)
	{
	case ERROR_IO_PENDING:
       	::Sleep(iTimeToComplete);
        WaitFor_IO_OperationToComplete(iExtraTimeToComplete);
	break;

	default:
		ASSERT(0);	// Generally shouldn't reach here
		break;
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区三区白人| 911精品产国品一二三产区| 国产欧美一区二区三区鸳鸯浴| 毛片av一区二区三区| 欧美成人福利视频| 韩国精品一区二区| 欧美国产精品一区| 色婷婷综合久久久久中文一区二区 | 国产白丝精品91爽爽久久| 久久久激情视频| 99久久久国产精品| 亚洲福利一区二区三区| 337p亚洲精品色噜噜噜| 国产一区二区三区在线看麻豆| 国产亚洲一本大道中文在线| 成人动漫一区二区三区| 亚洲小说春色综合另类电影| 日韩欧美国产一区二区三区| 成人午夜av电影| 亚洲444eee在线观看| 欧美大肚乱孕交hd孕妇| 99热在这里有精品免费| 亚洲高清不卡在线| 国产亚洲精久久久久久| 欧美午夜精品一区二区蜜桃| 美国三级日本三级久久99| 国产精品第一页第二页第三页| 欧美性猛片xxxx免费看久爱| 黑人精品欧美一区二区蜜桃| 综合久久给合久久狠狠狠97色| 欧美日韩精品一区二区天天拍小说 | 欧美一区二区在线观看| 国产v综合v亚洲欧| 天天影视涩香欲综合网| 中文字幕乱码久久午夜不卡| 欧美三级电影精品| 国产成人丝袜美腿| 肉肉av福利一精品导航| 日韩一区在线看| 欧美精品一区二区三区在线| 色欧美片视频在线观看| 国产呦萝稀缺另类资源| 亚洲大片免费看| 国产精品色在线| 欧美成人vr18sexvr| 欧美日韩一区二区三区高清| 成人精品在线视频观看| 久久99国产精品免费| 亚洲成人av在线电影| 亚洲欧洲精品成人久久奇米网| 精品精品欲导航| 欧美日韩精品欧美日韩精品一综合| 国产91在线观看丝袜| 青青草成人在线观看| 亚洲一级二级三级| 亚洲欧美日韩成人高清在线一区| 久久精品人人做人人爽人人| 日韩欧美成人一区二区| 欧美日本国产视频| 精品视频在线免费观看| 91啪亚洲精品| hitomi一区二区三区精品| 国产一区 二区| 国产美女在线精品| 精品一二三四区| 久久精品国产澳门| 免费看欧美美女黄的网站| 五月天激情综合| 偷偷要91色婷婷| 五月天中文字幕一区二区| 亚洲一卡二卡三卡四卡无卡久久| 亚洲精品国产a| 一区二区三区四区在线免费观看| 亚洲丝袜美腿综合| 亚洲精品videosex极品| 一区二区三区在线视频免费观看| 日韩美女啊v在线免费观看| 国产精品国产三级国产a| 国产精品久线观看视频| 国产精品久久久久精k8| 亚洲视频中文字幕| 一区二区在线观看av| 一区二区三区欧美久久| 亚洲五码中文字幕| 午夜a成v人精品| 看国产成人h片视频| 极品少妇xxxx精品少妇偷拍| 极品销魂美女一区二区三区| 国产盗摄一区二区三区| 99视频超级精品| 欧洲在线/亚洲| 欧美日韩一区二区三区免费看| 欧美精品自拍偷拍动漫精品| 日韩一区二区三区免费观看| 精品久久久久av影院| 日本一区二区三级电影在线观看| 国产精品不卡视频| 亚洲成人激情社区| 美女脱光内衣内裤视频久久网站 | 欧美性感一类影片在线播放| 欧美日韩国产高清一区二区三区| 欧美一区二区久久久| 国产午夜三级一区二区三| 国产精品久久久久久福利一牛影视| 一区二区在线看| 麻豆91小视频| 成人av网在线| 欧美精品成人一区二区三区四区| 欧美不卡激情三级在线观看| 欧美国产精品一区| 亚洲成人av电影在线| 国产精品资源在线| 在线免费观看一区| 精品国产91洋老外米糕| 亚洲少妇最新在线视频| 美脚の诱脚舐め脚责91| 91麻豆国产精品久久| 欧美精品高清视频| 中文字幕亚洲区| 日本欧美一区二区在线观看| 成人网在线免费视频| 555夜色666亚洲国产免| 国产精品电影院| 黄色小说综合网站| 欧美自拍丝袜亚洲| 中文字幕免费不卡| 美国毛片一区二区| 欧美视频精品在线观看| 国产精品毛片久久久久久| 天天影视色香欲综合网老头| 99视频一区二区| 久久久不卡影院| 奇米在线7777在线精品| 91福利视频网站| 国产精品嫩草99a| 激情欧美一区二区三区在线观看| 在线亚洲一区二区| 欧美国产日韩在线观看| 精品在线你懂的| 欧美久久久一区| 一区二区三区在线观看欧美 | 日韩精品电影在线| 91老师片黄在线观看| 国产欧美日韩在线| 麻豆91在线看| 欧美一级二级在线观看| 午夜视频一区在线观看| 91福利国产成人精品照片| 亚洲国产精华液网站w| 狠狠色综合日日| 日韩一区二区电影网| 亚洲va欧美va天堂v国产综合| 色综合视频一区二区三区高清| 日本一区免费视频| 国产99精品国产| 欧美经典一区二区| 国产精品一区二区三区99| 欧美不卡一区二区三区| 看电视剧不卡顿的网站| 日韩欧美第一区| 久久精品国产精品亚洲精品| 日韩欧美激情一区| 久久精品国产精品青草| 精品国产乱码久久久久久浪潮 | 欧美在线免费播放| 亚洲综合图片区| 色婷婷综合激情| 一区二区三区精品视频| 在线观看日韩电影| 亚洲影院免费观看| 欧美日产国产精品| 青青青伊人色综合久久| 日韩一区二区免费视频| 看片的网站亚洲| 久久精品视频在线免费观看| 青娱乐精品视频| ww久久中文字幕| 国产91丝袜在线播放0| 国产精品女上位| 欧美性猛交xxxxxx富婆| 日韩福利电影在线观看| 26uuu精品一区二区三区四区在线| 国产精品伊人色| 亚洲国产精品高清| 色综合一个色综合亚洲| 亚洲国产va精品久久久不卡综合| 欧美日韩国产综合一区二区| 蜜臀av性久久久久蜜臀aⅴ四虎| 日韩女优毛片在线| 国产v日产∨综合v精品视频| 中文字幕在线不卡一区二区三区 | 性久久久久久久久久久久| 欧美一二三区在线观看| 国产999精品久久| 亚洲综合999| 精品国产91洋老外米糕| 99热精品一区二区| 欧美aaa在线| 国产精品天天看| 欧美另类videos死尸|