mirror of
https://github.com/reactos/reactos.git
synced 2024-11-01 12:26:32 +00:00
[SERVICES] ScmControlService: Use TransactNamedPipe() instead of successive Write+Read (#7441)
This function combines those that write a message to and read a message from the specified pipe into a single operation. Its usage helps in simplifying the code further.
This commit is contained in:
parent
0f7b021fe6
commit
84f423f030
|
@ -1430,7 +1430,6 @@ ScmControlServiceEx(
|
||||||
DWORD PacketSize;
|
DWORD PacketSize;
|
||||||
DWORD i;
|
DWORD i;
|
||||||
PWSTR Ptr;
|
PWSTR Ptr;
|
||||||
DWORD dwWriteCount = 0;
|
|
||||||
DWORD dwReadCount = 0;
|
DWORD dwReadCount = 0;
|
||||||
OVERLAPPED Overlapped = {0};
|
OVERLAPPED Overlapped = {0};
|
||||||
|
|
||||||
|
@ -1507,70 +1506,26 @@ ScmControlServiceEx(
|
||||||
/* Acquire the service control critical section, to synchronize requests */
|
/* Acquire the service control critical section, to synchronize requests */
|
||||||
EnterCriticalSection(&ControlServiceCriticalSection);
|
EnterCriticalSection(&ControlServiceCriticalSection);
|
||||||
|
|
||||||
bResult = WriteFile(hControlPipe,
|
bResult = TransactNamedPipe(hControlPipe,
|
||||||
ControlPacket,
|
ControlPacket,
|
||||||
PacketSize,
|
PacketSize,
|
||||||
&dwWriteCount,
|
|
||||||
&Overlapped);
|
|
||||||
if (!bResult)
|
|
||||||
{
|
|
||||||
dwError = GetLastError();
|
|
||||||
if (dwError == ERROR_IO_PENDING)
|
|
||||||
{
|
|
||||||
DPRINT("WriteFile(%S, %d) returned ERROR_IO_PENDING\n", pServiceName, dwControl);
|
|
||||||
|
|
||||||
dwError = WaitForSingleObject(hControlPipe,
|
|
||||||
PipeTimeout);
|
|
||||||
DPRINT("WaitForSingleObject(%S, %d) returned %lu\n", pServiceName, dwControl, dwError);
|
|
||||||
|
|
||||||
if (dwError == WAIT_TIMEOUT)
|
|
||||||
{
|
|
||||||
DPRINT1("WaitForSingleObject(%S, %d) timed out\n", pServiceName, dwControl);
|
|
||||||
bResult = CancelIo(hControlPipe);
|
|
||||||
if (!bResult)
|
|
||||||
DPRINT1("CancelIo(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, GetLastError());
|
|
||||||
|
|
||||||
dwError = ERROR_SERVICE_REQUEST_TIMEOUT;
|
|
||||||
goto Done;
|
|
||||||
}
|
|
||||||
else if (dwError == WAIT_OBJECT_0)
|
|
||||||
{
|
|
||||||
bResult = GetOverlappedResult(hControlPipe,
|
|
||||||
&Overlapped,
|
|
||||||
&dwWriteCount,
|
|
||||||
TRUE);
|
|
||||||
if (!bResult)
|
|
||||||
{
|
|
||||||
dwError = GetLastError();
|
|
||||||
DPRINT1("GetOverlappedResult(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, dwError);
|
|
||||||
goto Done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT1("WriteFile(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, dwError);
|
|
||||||
goto Done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the reply */
|
|
||||||
Overlapped.hEvent = NULL;
|
|
||||||
|
|
||||||
bResult = ReadFile(hControlPipe,
|
|
||||||
&ReplyPacket,
|
&ReplyPacket,
|
||||||
sizeof(ReplyPacket),
|
sizeof(ReplyPacket),
|
||||||
&dwReadCount,
|
&dwReadCount,
|
||||||
&Overlapped);
|
&Overlapped);
|
||||||
if (!bResult)
|
if (!bResult)
|
||||||
{
|
{
|
||||||
|
/* Fail for any error other than pending IO */
|
||||||
dwError = GetLastError();
|
dwError = GetLastError();
|
||||||
if (dwError == ERROR_IO_PENDING)
|
if (dwError != ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
DPRINT("ReadFile(%S, %d) returned ERROR_IO_PENDING\n", pServiceName, dwControl);
|
DPRINT1("TransactNamedPipe(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, dwError);
|
||||||
|
goto Done;
|
||||||
|
}
|
||||||
|
|
||||||
dwError = WaitForSingleObject(hControlPipe,
|
DPRINT("TransactNamedPipe(%S, %d) returned ERROR_IO_PENDING\n", pServiceName, dwControl);
|
||||||
PipeTimeout);
|
|
||||||
|
dwError = WaitForSingleObject(hControlPipe, PipeTimeout);
|
||||||
DPRINT("WaitForSingleObject(%S, %d) returned %lu\n", pServiceName, dwControl, dwError);
|
DPRINT("WaitForSingleObject(%S, %d) returned %lu\n", pServiceName, dwControl, dwError);
|
||||||
|
|
||||||
if (dwError == WAIT_TIMEOUT)
|
if (dwError == WAIT_TIMEOUT)
|
||||||
|
@ -1581,7 +1536,6 @@ ScmControlServiceEx(
|
||||||
DPRINT1("CancelIo(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, GetLastError());
|
DPRINT1("CancelIo(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, GetLastError());
|
||||||
|
|
||||||
dwError = ERROR_SERVICE_REQUEST_TIMEOUT;
|
dwError = ERROR_SERVICE_REQUEST_TIMEOUT;
|
||||||
goto Done;
|
|
||||||
}
|
}
|
||||||
else if (dwError == WAIT_OBJECT_0)
|
else if (dwError == WAIT_OBJECT_0)
|
||||||
{
|
{
|
||||||
|
@ -1593,16 +1547,9 @@ ScmControlServiceEx(
|
||||||
{
|
{
|
||||||
dwError = GetLastError();
|
dwError = GetLastError();
|
||||||
DPRINT1("GetOverlappedResult(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, dwError);
|
DPRINT1("GetOverlappedResult(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, dwError);
|
||||||
goto Done;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT1("ReadFile(%S, %d) failed (Error %lu)\n", pServiceName, dwControl, dwError);
|
|
||||||
goto Done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
/* Release the service control critical section */
|
/* Release the service control critical section */
|
||||||
|
|
Loading…
Reference in a new issue