Skip to content

Commit

Permalink
Fix selectTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Feb 3, 2025
1 parent d0e9b75 commit 3365ea2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Events/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ final class Select implements EventInterface
*
* @var int
*/
private int $selectTimeout = 800000;
private int $selectTimeout = self::MAX_SELECT_TIMOUT_US;

/**
* Next run time of the timer.
Expand All @@ -126,6 +126,13 @@ final class Select implements EventInterface
*/
private $errorHandler = null;

/**
* Select timeout.
*
* @var int
*/
const MAX_SELECT_TIMOUT_US = 800000;

/**
* Construct.
*/
Expand Down Expand Up @@ -359,11 +366,10 @@ protected function setNextTickTime(float $nextTickTime): void
if ($nextTickTime == 0) {
// Swow will affect the signal interruption characteristics of stream_select,
// so a shorter timeout should be used to detect signals.
$this->selectTimeout = 800000;
$this->selectTimeout = self::MAX_SELECT_TIMOUT_US;
return;
}
$timeNow = microtime(true);
$this->selectTimeout = max((int)(($nextTickTime - $timeNow) * 1000000), 0);
$this->selectTimeout = min(max((int)(($nextTickTime - microtime(true)) * 1000000), 0), self::MAX_SELECT_TIMOUT_US);
}

/**
Expand Down

0 comments on commit 3365ea2

Please sign in to comment.