Windows: port the process helper and fix a stdin deadlock

- Tests: build VoidProcessHelper on Windows with the fork/poll-based modes
  compiled out, binary stdio, and a Windows fd listing; enable the
  ProcessStream suite there.
- Process (Windows): communicate_blocking could block forever when the
  stdin write completed synchronously: the wait only armed pending
  operations, so the stdin pipe was never closed and the child never saw
  EOF. Complete ready operations before waiting, and report real EOF only
  when a read actually reached end of stream.
This commit is contained in:
faumaray committed 2026-12-06 15:42:31 +03:00
1 parent b3c959b920
commit 9f45841c7d
4 files changed
+115 -60

No files matched your search

+3 -3
View File
@@ -232,9 +232,9 @@ endif()
# ── Test-support executables & libraries ──────────────────────────────────────
# These are NOT test files; they are helper executables/libs referenced by tests.
# The process helper is POSIX-only (poll.h, fork/wait); Windows tests that
# need it are guarded or not built.
if(TARGET VoidTests AND (TARGET Void::System OR TARGET Void::IPC) AND NOT WIN32)
# The process helper builds everywhere; the fork/poll-based helper modes are
# POSIX-only and are compiled out on Windows.
if(TARGET VoidTests AND (TARGET Void::System OR TARGET Void::IPC))
add_executable(VoidProcessHelper
"${CMAKE_CURRENT_SOURCE_DIR}/helpers/ProcessHelper.cpp")
set_target_properties(VoidProcessHelper PROPERTIES
+30
View File
@@ -1,5 +1,7 @@
#include <fcntl.h>
#if !defined(_WIN32)
#include <poll.h>
#endif
#include <unistd.h>
#include <algorithm>
@@ -17,6 +19,17 @@
#include <thread>
#include <vector>
#if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <io.h>
#include <windows.h>
#endif
extern char** environ;
namespace
@@ -194,6 +207,7 @@ int mode_ignore_sigterm(int argc, char** argv)
return 0;
}
#if !defined(_WIN32)
int mode_grandchild_ignore_sigterm(int argc, char** argv)
{
if (argc < 3) {
@@ -358,6 +372,7 @@ int mode_simultaneous_io(int argc, char** argv)
}
return (in_read > 0 || total == 0) ? 0 : 0;
}
#endif // !_WIN32
int mode_flood(int argc, char** argv)
{
@@ -415,9 +430,16 @@ int mode_check_fds()
{
std::vector<int> open_fds;
for (int fd = 3; fd <= 64; ++fd) {
#if defined(_WIN32)
const auto handle = ::_get_osfhandle(fd);
if (handle != -1) {
open_fds.push_back(fd);
}
#else
if (::fcntl(fd, F_GETFD) != -1 || errno != EBADF) {
open_fds.push_back(fd);
}
#endif
}
if (open_fds.empty()) {
std::cout << "clean\n";
@@ -536,6 +558,12 @@ int mode_ipc_pipe_echo()
int main(int argc, char** argv)
{
std::ios::sync_with_stdio(false);
#if defined(_WIN32)
// Helpers speak over binary pipes: no CRLF translation or Ctrl-Z EOF.
(void)_setmode(_fileno(stdin), _O_BINARY);
(void)_setmode(_fileno(stdout), _O_BINARY);
(void)_setmode(_fileno(stderr), _O_BINARY);
#endif
if (argc < 2) {
return usage_error("missing mode");
}
@@ -561,6 +589,7 @@ int main(int argc, char** argv)
if (mode == "ignore-sigterm") {
return mode_ignore_sigterm(argc, argv);
}
#if !defined(_WIN32)
if (mode == "grandchild-ignore-sigterm") {
return mode_grandchild_ignore_sigterm(argc, argv);
}
@@ -570,6 +599,7 @@ int main(int argc, char** argv)
if (mode == "simultaneous-io") {
return mode_simultaneous_io(argc, argv);
}
#endif
if (mode == "flood") {
return mode_flood(argc, argv);
}
@@ -1,4 +1,3 @@
// @requires-posix: streaming tests drive the POSIX process helper.
#include <Void/System/Process.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Suite.hpp>