Skip to content

Commit 7eb82ea

Browse files
committed
Add INVARIANT on the expected number of bytes being correctly written
This could end up mismatching for sufficently large messages exceding the length of the pipe's buffer. For the moment it is better to halt if this potential issue is encountered rather than risk introducing communication problems. If this problem is encountered later then it may be possible to work around by splitting the message into multiple writes to the pipe.
1 parent 5b75acd commit 7eb82ea

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/util/piped_process.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,16 @@ piped_processt::send_responset piped_processt::send(const std::string &message)
347347
}
348348
#ifdef _WIN32
349349
const auto message_size = narrow<DWORD>(message.size());
350-
if(!WriteFile(child_std_IN_Wr, message.c_str(), message_size, NULL, NULL))
350+
DWORD bytes_written = 0;
351+
if(!WriteFile(
352+
child_std_IN_Wr, message.c_str(), message_size, &bytes_written, NULL))
351353
{
352354
// Error handling with GetLastError ?
353355
return send_responset::FAILED;
354356
}
357+
INVARIANT(
358+
message_size == bytes_written,
359+
"Number of bytes written to sub process must match message size.");
355360
#else
356361
// send message to solver process
357362
int send_status = fputs(message.c_str(), command_stream);

0 commit comments

Comments
 (0)