diff --git a/src/pipe.toit b/src/pipe.toit index d682d50..ad6fe9b 100644 --- a/src/pipe.toit +++ b/src/pipe.toit @@ -98,7 +98,7 @@ class OpenPipe extends OpenPipe_: class OpenPipe_ implements Stream: resource_ := ? - state_ := ? + state_/monitor.ResourceState_? := ? pid := null child-process-name_ /string? input_ /int := UNKNOWN-DIRECTION_ @@ -152,7 +152,9 @@ class OpenPipe_ implements Stream: read_ -> ByteArray?: while true: + if not state_: return null state_.wait-for-state READ-EVENT_ | CLOSE-EVENT_ + if not state_: return null result := read-from-pipe_ resource_ if result != -1: if result == null: diff --git a/tests/pipe3_exe.toit b/tests/pipe3_exe.toit new file mode 100644 index 0000000..28a721b --- /dev/null +++ b/tests/pipe3_exe.toit @@ -0,0 +1,9 @@ +// Copyright (C) 2025 Toit contributors. +// Use of this source code is governed by a Zero-Clause BSD license that can +// be found in the tests/TESTS_LICENSE file. + +import host.pipe + +main: + // Just wait for a message. + pipe.stdin.in.read diff --git a/tests/pipe3_test.toit b/tests/pipe3_test.toit new file mode 100644 index 0000000..3eb7fff --- /dev/null +++ b/tests/pipe3_test.toit @@ -0,0 +1,32 @@ +// Copyright (C) 2025 Toit contributors. +// Use of this source code is governed by a Zero-Clause BSD license that can +// be found in the tests/TESTS_LICENSE file. + +import expect show * + +import host.pipe +import system + +main args: + toit-exe := args[0] + + my-path := system.program-path + end := my-path.index-of --last "test.toit" + if end == -1: throw "UNEXPECTED" + input := "$my-path[..end]input.toit" + + process := pipe.fork + --create-stdout + --create-stdin + toit-exe + [toit-exe, input] + + to-process := process.stdin + from-process := process.stdout + + from-process.close + + expect-null from-process.in.read + to-process.out.write "done" + + process.wait