2
2
3
3
namespace React \EventLoop ;
4
4
5
- use React \EventLoop \Signal \Pcntl ;
6
5
use React \EventLoop \Tick \FutureTickQueue ;
7
6
use React \EventLoop \Timer \Timer ;
8
7
use React \EventLoop \Timer \Timers ;
@@ -259,12 +258,12 @@ private function waitForStreamActivity($timeout)
259
258
* Emulate a stream_select() implementation that does not break when passed
260
259
* empty stream arrays.
261
260
*
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.
265
264
*
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.
268
267
*/
269
268
private function streamSelect (array &$ read , array &$ write , $ timeout )
270
269
{
@@ -275,7 +274,13 @@ private function streamSelect(array &$read, array &$write, $timeout)
275
274
return @\stream_select ($ read , $ write , $ except , $ timeout === null ? null : 0 , $ timeout );
276
275
}
277
276
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
+ }
279
284
280
285
return 0 ;
281
286
}
0 commit comments