22
33namespace React \EventLoop ;
44
5- use React \EventLoop \Signal \Pcntl ;
65use React \EventLoop \Tick \FutureTickQueue ;
76use React \EventLoop \Timer \Timer ;
87use React \EventLoop \Timer \Timers ;
@@ -259,12 +258,12 @@ private function waitForStreamActivity($timeout)
259258 * Emulate a stream_select() implementation that does not break when passed
260259 * empty stream arrays.
261260 *
262- * @param array & $read An array of read streams to select upon.
263- * @param array & $write An array of write streams to select upon.
264- * @param integer |null $timeout Activity timeout in microseconds, or null to wait forever.
261+ * @param array $read An array of read streams to select upon.
262+ * @param array $write An array of write streams to select upon.
263+ * @param int |null $timeout Activity timeout in microseconds, or null to wait forever.
265264 *
266- * @return integer |false The total number of streams that are ready for read/write.
267- * Can return false if stream_select() is interrupted by a signal.
265+ * @return int |false The total number of streams that are ready for read/write.
266+ * Can return false if stream_select() is interrupted by a signal.
268267 */
269268 private function streamSelect (array &$ read , array &$ write , $ timeout )
270269 {
@@ -275,7 +274,13 @@ private function streamSelect(array &$read, array &$write, $timeout)
275274 return @\stream_select ($ read , $ write , $ except , $ timeout === null ? null : 0 , $ timeout );
276275 }
277276
278- $ timeout && \usleep ($ timeout );
277+ if ($ timeout > 0 ) {
278+ \usleep ($ timeout );
279+ } elseif ($ timeout === null ) {
280+ // wait forever (we only reach this if we're only awaiting signals)
281+ // this may be interrupted and return earlier when a signal is received
282+ \sleep (PHP_INT_MAX );
283+ }
279284
280285 return 0 ;
281286 }
0 commit comments