mirror of
https://github.com/danog/process.git
synced 2024-12-11 16:49:40 +01:00
Fix exit code watcher on Windows
This commit is contained in:
parent
586d662b58
commit
4916378931
@ -16,6 +16,9 @@ final class Handle extends ProcessHandle {
|
||||
/** @var string */
|
||||
public $exitCodeWatcher;
|
||||
|
||||
/** @var bool */
|
||||
public $exitCodeRequested = false;
|
||||
|
||||
/** @var resource */
|
||||
public $proc;
|
||||
|
||||
|
@ -110,6 +110,8 @@ final class Runner implements ProcessRunner {
|
||||
/** @inheritdoc */
|
||||
public function join(ProcessHandle $handle): Promise {
|
||||
/** @var Handle $handle */
|
||||
$handle->exitCodeRequested = true;
|
||||
|
||||
if ($handle->exitCodeWatcher !== null) {
|
||||
Loop::reference($handle->exitCodeWatcher);
|
||||
}
|
||||
|
@ -236,8 +236,9 @@ final class SocketConnector {
|
||||
$handle->stdioDeferreds[1]->resolve(new ResourceInputStream($handle->sockets[1]));
|
||||
$handle->stdioDeferreds[2]->resolve(new ResourceInputStream($handle->sockets[2]));
|
||||
|
||||
if ($handle->exitCodeWatcher !== null) {
|
||||
Loop::enable($handle->exitCodeWatcher);
|
||||
$handle->exitCodeWatcher = Loop::onReadable($handle->sockets[0], [$this, 'onReadableExitCode'], $handle);
|
||||
if (!$handle->exitCodeRequested) {
|
||||
Loop::unreference($handle->exitCodeWatcher);
|
||||
}
|
||||
|
||||
unset($this->pendingProcesses[$handle->wrapperPid]);
|
||||
@ -258,7 +259,7 @@ final class SocketConnector {
|
||||
if (\strlen($data) !== 5) {
|
||||
$handle->status = ProcessStatus::ENDED;
|
||||
$handle->joinDeferred->fail(new ProcessException(
|
||||
\sprintf('Failed to read exit code from wrapper: Recieved %d of 5 expected bytes', \strlen($data))
|
||||
\sprintf('Failed to read exit code from wrapper: Received %d of 5 expected bytes', \strlen($data))
|
||||
));
|
||||
return;
|
||||
}
|
||||
@ -324,9 +325,5 @@ final class SocketConnector {
|
||||
$handle->connectTimeoutWatcher = Loop::delay(self::CONNECT_TIMEOUT, [$this, 'onProcessConnectTimeout'], $handle);
|
||||
|
||||
$this->pendingProcesses[$handle->wrapperPid] = $handle;
|
||||
|
||||
$handle->exitCodeWatcher = Loop::onReadable($handle->sockets[0], [$this, 'onReadableExitCode'], $handle);
|
||||
Loop::unreference($handle->exitCodeWatcher);
|
||||
Loop::disable($handle->exitCodeWatcher);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user