Skip to content

Commit c55b214

Browse files
committed
Refactor usage of PeekNamedPipe to get count rather than read
This makes it more obvious from reading the code that no characters will be removed from the pipe as part of the implementation of `can_receive`. This commit includes renaming of local variables to exactly match the names and types in the API definition, with nullptr used to distinguish pointers from integers.
1 parent 699494b commit c55b214

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/util/piped_process.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,22 @@ bool piped_processt::can_receive(optionalt<std::size_t> wait_time)
418418
const int timeout = wait_time ? narrow<int>(*wait_time) : -1;
419419
#ifdef _WIN32
420420
int waited_time = 0;
421-
// The next four need to be initialised for compiler warnings
422-
DWORD buffer = 0;
423-
LPDWORD nbytes = 0;
424-
LPDWORD rbytes = 0;
425-
LPDWORD rmbytes = 0;
421+
DWORD total_bytes_available = 0;
426422
while(timeout < 0 || waited_time >= timeout)
427423
{
428-
PeekNamedPipe(child_std_OUT_Rd, &buffer, 1, nbytes, rbytes, rmbytes);
429-
if(buffer != 0)
424+
const LPVOID lpBuffer = nullptr;
425+
const DWORD nBufferSize = 0;
426+
const LPDWORD lpBytesRead = nullptr;
427+
const LPDWORD lpTotalBytesAvail = &total_bytes_available;
428+
const LPDWORD lpBytesLeftThisMessage = nullptr;
429+
PeekNamedPipe(
430+
child_std_OUT_Rd,
431+
lpBuffer,
432+
nBufferSize,
433+
lpBytesRead,
434+
lpTotalBytesAvail,
435+
lpBytesLeftThisMessage);
436+
if(total_bytes_available > 0)
430437
{
431438
return true;
432439
}

0 commit comments

Comments
 (0)