Skip to content

Commit 3365ea2

Browse files
committed
Fix selectTimeout
1 parent d0e9b75 commit 3365ea2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Events/Select.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ final class Select implements EventInterface
112112
*
113113
* @var int
114114
*/
115-
private int $selectTimeout = 800000;
115+
private int $selectTimeout = self::MAX_SELECT_TIMOUT_US;
116116

117117
/**
118118
* Next run time of the timer.
@@ -126,6 +126,13 @@ final class Select implements EventInterface
126126
*/
127127
private $errorHandler = null;
128128

129+
/**
130+
* Select timeout.
131+
*
132+
* @var int
133+
*/
134+
const MAX_SELECT_TIMOUT_US = 800000;
135+
129136
/**
130137
* Construct.
131138
*/
@@ -359,11 +366,10 @@ protected function setNextTickTime(float $nextTickTime): void
359366
if ($nextTickTime == 0) {
360367
// Swow will affect the signal interruption characteristics of stream_select,
361368
// so a shorter timeout should be used to detect signals.
362-
$this->selectTimeout = 800000;
369+
$this->selectTimeout = self::MAX_SELECT_TIMOUT_US;
363370
return;
364371
}
365-
$timeNow = microtime(true);
366-
$this->selectTimeout = max((int)(($nextTickTime - $timeNow) * 1000000), 0);
372+
$this->selectTimeout = min(max((int)(($nextTickTime - microtime(true)) * 1000000), 0), self::MAX_SELECT_TIMOUT_US);
367373
}
368374

369375
/**

0 commit comments

Comments
 (0)