@@ -351,30 +351,27 @@ piped_processt::send_responset piped_processt::send(const std::string &message)
351351 }
352352#ifdef _WIN32
353353 const auto message_size = narrow<DWORD>(message.size ());
354+ PRECONDITION (message_size > 0 );
354355 DWORD bytes_written = 0 ;
355- const auto write_file = [&]() {
356- return WriteFile (
357- child_std_IN_Wr, message.c_str (), message_size, &bytes_written, NULL );
358- };
359- if (!write_file ())
360- {
361- // Error handling with GetLastError ?
362- return send_responset::FAILED;
363- }
364- // `WriteFile` can return a success status but write 0 bytes if we write
365- // messages quickly enough. This problem has been observed when using a
366- // release build, but resolved when using a debug build or `--verbosity 10`.
367- // Presumably this happens if cbmc gets too far ahead of the sub process.
368- // Flushing the buffer and retrying should then succeed to write the message
369- // in this case.
370- if (bytes_written == 0 )
356+ const int retry_limit = 10 ;
357+ for (int send_attempts = 0 ; send_attempts < retry_limit; ++send_attempts)
371358 {
372- FlushFileBuffers (child_std_IN_Wr);
373- if (!write_file ())
359+ // `WriteFile` can return a success status but write 0 bytes if we write
360+ // messages quickly enough. This problem has been observed when using a
361+ // release build, but resolved when using a debug build or `--verbosity 10`.
362+ // Presumably this happens if cbmc gets too far ahead of the sub process.
363+ // Flushing the buffer and retrying should then succeed to write the message
364+ // in this case.
365+ if (!WriteFile (
366+ child_std_IN_Wr, message.c_str (), message_size, &bytes_written, NULL ))
374367 {
375368 // Error handling with GetLastError ?
376369 return send_responset::FAILED;
377370 }
371+ if (bytes_written != 0 )
372+ break ;
373+ // Give the sub-process chance to read the waiting message(s).
374+ FlushFileBuffers (child_std_IN_Wr);
378375 }
379376 INVARIANT (
380377 message_size == bytes_written,
0 commit comments