Răsfoiți Sursa

ReadMsgThread中使用BOOL类型来判断管道是否可用,不使用句柄值来判断,因为句柄在CreateFile之后还有设置需要处理,在未处理完成前ReadFile都不对。

JeffWang 3 ani în urmă
părinte
comite
f287e0aea2

+ 5 - 1
Source/OGCAssist/OGCAssist/PipeClient.cpp

@@ -7,6 +7,7 @@ std::string CPipeClient::m_LastData;
 PER_IO_CONTEXT CPipeClient::m_IoRead;
 PER_IO_CONTEXT CPipeClient::m_IoWrite;
 ThreadSection CPipeClient::m_cs;
+BOOL CPipeClient::m_bPipeConnectStatus=FALSE;
 
 CPipeClient::CPipeClient(LPCTSTR lpPipeName, DWORD dwMode)
 {
@@ -100,6 +101,7 @@ DWORD CPipeClient::ConnectThread(LPVOID lpParam)
 				continue;
             }
 
+			m_bPipeConnectStatus = TRUE;
 			Sleep(1500);
 #pragma region 向服务端发送消息:劫持状态+按钮状态;			
 			{
@@ -157,7 +159,7 @@ DWORD CPipeClient::ReadMsgThread(LPVOID lpParam)
 	BOOL bSuccess = FALSE;	
     while(!pInstance->m_bClientStop)
     {
-        if ( pInstance->m_hPipeInst == INVALID_HANDLE_VALUE ) {
+        if ( pInstance->m_hPipeInst == INVALID_HANDLE_VALUE || !m_bPipeConnectStatus ) {
             Sleep(5000);
             continue;
         }
@@ -179,6 +181,7 @@ DWORD CPipeClient::ReadMsgThread(LPVOID lpParam)
 				AutoThreadSection acs(&m_cs);
                 Utility::dprintf(_T("CloseHandle\n"));
                 CloseHandle(pInstance->m_hPipeInst);
+				m_bPipeConnectStatus = FALSE;
                 pInstance->m_hPipeInst = INVALID_HANDLE_VALUE;
             }
             else
@@ -438,6 +441,7 @@ void CPipeClient::HandleError(DWORD dwError)
 		{
 			AutoThreadSection acs(&m_cs);
 			CloseHandle(m_hPipeInst);
+			m_bPipeConnectStatus = FALSE;
 			m_hPipeInst = INVALID_HANDLE_VALUE;
 			Utility::dprintf(_T("HandleError:Error=%ld\n"), dwError);
 		}

+ 1 - 0
Source/OGCAssist/OGCAssist/PipeClient.h

@@ -52,6 +52,7 @@ private:
 	static ThreadSection m_cs;
 	// WriteʹÓÃͬ²½·½Ê½;
 	static PER_IO_CONTEXT m_IoWrite;
+	static BOOL m_bPipeConnectStatus;
 public:
     BOOL StartWork();
     void StopWork() { m_bClientStop = TRUE;Sleep(100000);}