|
@@ -6,6 +6,7 @@
|
|
|
std::string CPipeClient::m_LastData;
|
|
|
PER_IO_CONTEXT CPipeClient::m_IoRead;
|
|
|
PER_IO_CONTEXT CPipeClient::m_IoWrite;
|
|
|
+ThreadSection CPipeClient::m_cs;
|
|
|
|
|
|
CPipeClient::CPipeClient(LPCTSTR lpPipeName, DWORD dwMode)
|
|
|
{
|
|
@@ -63,6 +64,7 @@ DWORD CPipeClient::ConnectThread(LPVOID lpParam)
|
|
|
}
|
|
|
|
|
|
|
|
|
+ AutoThreadSection acs(&m_cs);
|
|
|
if ( !WaitNamedPipe(pInstance->m_szPipeName, 10000) )
|
|
|
{
|
|
|
Utility::dprintf(_T("<%ld> WaitNamedPipe 失败\n"), Utility::g_WndInfo.dwProcessId);
|
|
@@ -174,6 +176,7 @@ DWORD CPipeClient::ReadMsgThread(LPVOID lpParam)
|
|
|
if ( !WaitFinish(pInstance->m_hPipeInst, &m_IoRead) )
|
|
|
{
|
|
|
|
|
|
+ AutoThreadSection acs(&m_cs);
|
|
|
Utility::dprintf(_T("CloseHandle\n"));
|
|
|
CloseHandle(pInstance->m_hPipeInst);
|
|
|
pInstance->m_hPipeInst = INVALID_HANDLE_VALUE;
|
|
@@ -419,7 +422,27 @@ BOOL CPipeClient::SendData(LPBYTE lpData, DWORD dwDataLen)
|
|
|
|
|
|
DWORD dwNumberOfBytesWritten = 0;
|
|
|
BOOL fWrite = WriteFile(m_hPipeInst, lpData, dwDataLen, &dwNumberOfBytesWritten, NULL);
|
|
|
- Utility::dprintf(_T("SendData:Error=%ld, %d\n"), GetLastError(), fWrite);
|
|
|
+ DWORD dwLastError = GetLastError();
|
|
|
+ if ( dwLastError != 0 )
|
|
|
+ HandleError(dwLastError);
|
|
|
+ Utility::dprintf(_T("SendData:Error=%ld, %d\n"), dwLastError, fWrite);
|
|
|
|
|
|
return fWrite;
|
|
|
+}
|
|
|
+
|
|
|
+void CPipeClient::HandleError(DWORD dwError)
|
|
|
+{
|
|
|
+ switch(dwError)
|
|
|
+ {
|
|
|
+ case ERROR_NO_DATA:
|
|
|
+ {
|
|
|
+ AutoThreadSection acs(&m_cs);
|
|
|
+ CloseHandle(m_hPipeInst);
|
|
|
+ m_hPipeInst = INVALID_HANDLE_VALUE;
|
|
|
+ Utility::dprintf(_T("HandleError:Error=%ld\n"), dwError);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|