Skip to content

Commit

Permalink
Interrupted system call is not handled well - #
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-blok committed Oct 1, 2024
1 parent b6f180a commit 8fdd83a
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ public function write(string $payload): self

$except = null;

try {
$selectResult = socket_select($read, $write, $except, $this->timeoutSeconds, $this->timeoutMicroseconds);
} catch (ErrorException $e) {
if ($this->isInterruptionErrorException()) {
continue;
}

throw $e;
$selectResult = @socket_select($read, $write, $except, $this->timeoutSeconds, $this->timeoutMicroseconds);

if ($selectResult === false && socket_last_error() === SOCKET_EINTR) {
continue;
}

if ($selectResult === false) {
Expand Down Expand Up @@ -99,14 +95,10 @@ public function read(): Generator

$except = null;

try {
$selectResult = socket_select($read, $write, $except, $this->timeoutSeconds, $this->timeoutMicroseconds);
} catch (ErrorException $e) {
if ($this->isInterruptionErrorException()) {
continue;
}
$selectResult = @socket_select($read, $write, $except, $this->timeoutSeconds, $this->timeoutMicroseconds);

throw $e;
if ($selectResult === false && socket_last_error() === SOCKET_EINTR) {
continue;
}

if ($selectResult === false) {
Expand All @@ -126,9 +118,4 @@ public function read(): Generator
yield $outputFromSocket;
}
}

private function isInterruptionErrorException(): bool
{
return 4 === socket_last_error();
}
}

0 comments on commit 8fdd83a

Please sign in to comment.