Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid warning when catching signal with pcntl_signal() #297

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/EventLoop/StreamSelectLoop.php
Expand Up @@ -218,7 +218,17 @@ private function waitForStreamActivity($timeout)
$read = $this->readStreams;
$write = $this->writeStreams;

$this->streamSelect($read, $write, $timeout);
$n = $this->streamSelect($read, $write, $timeout);
if (false === $n) {
// if a system call has been interrupted, forget about it, let's try again and avoid warning messages.
if ($this->hasSystemCallBeenInterrupted()) {
return;
}

$this->stop();

return;
}

foreach ($read as $stream) {
$key = (int) $stream;
Expand Down Expand Up @@ -252,11 +262,22 @@ protected function streamSelect(array &$read, array &$write, $timeout)
if ($read || $write) {
$except = null;

return stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
return @stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
}

usleep($timeout);

return 0;
}

/**
* @return bool
*/
private function hasSystemCallBeenInterrupted()
{
$lastError = error_get_last();

// stream_select returns false when the `select` system call is interrupted by an incoming signal
return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests would be much appreciated 👍

Also IIRC, the error messages take the user's LOCALE into account and might be translated to another language. If so, how should we match those?

}
}