Skip to content

Commit

Permalink
StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
divinity76 authored Mar 18, 2024
1 parent 2d732eb commit f91f6a3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,26 @@ protected function configure(array $options): void
/**
* Waits for data to become available on the socket.
*
* @param float $maxSeconds The maximum amount of time to wait for data, in seconds.
* @return bool Returns true if data is available, false if the wait timed out.
* @param float $maxSeconds the maximum amount of time to wait for data, in seconds
*
* @return bool returns true if data is available, false if the wait timed out
*/
public function waitForData(float $maxSeconds): bool
{
$read = [$this->socket->getResource()];
$write = null;
$except = null;
$seconds = (int)floor($maxSeconds);
$microseconds = (int)(($maxSeconds - $seconds) * 1e6);
$result = socket_select($read, $write, $except, $seconds, $microseconds);
if ($result === false) {
$seconds = (int) \floor($maxSeconds);
$microseconds = (int) (($maxSeconds - $seconds) * 1e6);
$result = \socket_select($read, $write, $except, $seconds, $microseconds);
if (false === $result) {
// An error occurred
throw new RuntimeException('Error occurred during socket_select.');
} elseif ($result === 0) {
throw new \RuntimeException('Error occurred during socket_select.');
} elseif (0 === $result) {
// Timeout occurred, no data available
return false;
}

// Data is available
return true;
}
Expand Down

0 comments on commit f91f6a3

Please sign in to comment.