mirror of
https://github.com/reactos/reactos.git
synced 2025-01-05 13:59:25 +00:00
fix some issues when reading from a named pipe
fix a typo terminate qemu at exit (when using named pipes) svn path=/trunk/; revision=24653
This commit is contained in:
parent
6497d295c3
commit
a94c4a796e
2 changed files with 67 additions and 31 deletions
|
@ -97,6 +97,8 @@ namespace System_
|
|||
string::size_type size = Buffer.capacity();
|
||||
DWORD cbRead;
|
||||
BOOL fSuccess;
|
||||
TCHAR * localbuf;
|
||||
DWORD localsize = 100;
|
||||
|
||||
//#ifdef NDEBUG
|
||||
memset(buf, 0x0, sizeof(TCHAR) * size);
|
||||
|
@ -105,25 +107,42 @@ namespace System_
|
|||
#ifdef __LINUX__
|
||||
|
||||
#else
|
||||
do
|
||||
{
|
||||
fSuccess = ReadFile(
|
||||
h_Pipe,
|
||||
buf,
|
||||
size,
|
||||
&cbRead,
|
||||
NULL);
|
||||
|
||||
if (! fSuccess && GetLastError() != ERROR_MORE_DATA)
|
||||
break;
|
||||
|
||||
_tprintf( TEXT("%s\n"), buf );
|
||||
} while (!fSuccess); // repeat loop if ERROR_MORE_DATA
|
||||
localbuf = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(TCHAR));
|
||||
if (localbuf != NULL)
|
||||
{
|
||||
|
||||
if (!fSuccess)
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
ZeroMemory(localbuf, sizeof(localsize) * sizeof(TCHAR));
|
||||
|
||||
fSuccess = ReadFile(
|
||||
h_Pipe,
|
||||
localbuf,
|
||||
localsize * sizeof(TCHAR),
|
||||
&cbRead,
|
||||
NULL);
|
||||
|
||||
if (! fSuccess && GetLastError() != ERROR_MORE_DATA)
|
||||
break;
|
||||
|
||||
_tcscat(buf, localbuf);
|
||||
|
||||
} while (!fSuccess); // repeat loop if ERROR_MORE_DATA
|
||||
} while (localbuf[_tcslen(localbuf)-1] != '\n');
|
||||
|
||||
if (!fSuccess)
|
||||
return 0;
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, localbuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
buf[_tcslen(buf)-_tcslen(_T("\n"))-1] = '\0';
|
||||
return _tcslen(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -320,10 +320,11 @@ namespace Sysreg_
|
|||
string pipecmd = _T("");
|
||||
|
||||
#ifdef __LINUX__
|
||||
|
||||
pid_t pid;
|
||||
#else
|
||||
STARTUPINFO siStartInfo;
|
||||
PROCESS_INFORMATION piProcInfo;
|
||||
DWORD pid;
|
||||
|
||||
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
|
||||
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
|
||||
|
@ -339,6 +340,10 @@ namespace Sysreg_
|
|||
cerr << "Error: CreateProcess failed " << boot_cmd <<endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pid = piProcInfo.dwProcessId;
|
||||
}
|
||||
#endif
|
||||
|
||||
string::size_type pipe_pos = boot_cmd.find (_T("serial pipe:"));
|
||||
|
@ -356,7 +361,7 @@ namespace Sysreg_
|
|||
if (m_Delayread)
|
||||
{
|
||||
///
|
||||
/// delay reading untill emulator is ready
|
||||
/// delay reading until emulator is ready
|
||||
///
|
||||
|
||||
_sleep( (clock_t)m_Delayread * CLOCKS_PER_SEC );
|
||||
|
@ -380,23 +385,35 @@ namespace Sysreg_
|
|||
break;
|
||||
}
|
||||
|
||||
namedpipe_reader.readPipe (Buffer);
|
||||
cout << Buffer.c_str() << endl;
|
||||
vect.push_back (Buffer);
|
||||
|
||||
DebugState state = checkDebugData(vect);
|
||||
|
||||
if (state == DebugStateBSODDetected || state == DebugStateUMEDetected)
|
||||
if (namedpipe_reader.readPipe (Buffer) != 0)
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
else if (state == DebugStateCPReached)
|
||||
{
|
||||
break;
|
||||
vect.push_back (Buffer.c_str());
|
||||
|
||||
DebugState state = checkDebugData(vect);
|
||||
if (state == DebugStateBSODDetected || state == DebugStateUMEDetected)
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
else if (state == DebugStateCPReached)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
namedpipe_reader.closePipe ();
|
||||
|
||||
#ifdef __LINUX__
|
||||
kill(pid, SIGTERM);
|
||||
#else
|
||||
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||
if (hProcess)
|
||||
{
|
||||
TerminateProcess(hProcess, 0);
|
||||
}
|
||||
CloseHandle(hProcess);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue