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 ;
@@ -258,12 +257,12 @@ private function waitForStreamActivity($timeout)
258
257
* Emulate a stream_select() implementation that does not break when passed
259
258
* empty stream arrays.
260
259
*
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 integer |null $timeout Activity timeout in microseconds, or null to wait forever.
260
+ * @param array $read An array of read streams to select upon.
261
+ * @param array $write An array of write streams to select upon.
262
+ * @param int |null $timeout Activity timeout in microseconds, or null to wait forever.
264
263
*
265
- * @return integer |false The total number of streams that are ready for read/write.
266
- * Can return false if stream_select() is interrupted by a signal.
264
+ * @return int |false The total number of streams that are ready for read/write.
265
+ * Can return false if stream_select() is interrupted by a signal.
267
266
*/
268
267
private function streamSelect (array &$ read , array &$ write , $ timeout )
269
268
{
@@ -274,7 +273,13 @@ private function streamSelect(array &$read, array &$write, $timeout)
274
273
return @\stream_select ($ read , $ write , $ except , $ timeout === null ? null : 0 , $ timeout );
275
274
}
276
275
277
- $ timeout && \usleep ($ timeout );
276
+ if ($ timeout > 0 ) {
277
+ \usleep ($ timeout );
278
+ } elseif ($ timeout === null ) {
279
+ // wait forever (we only reach this if we're only awaiting signals)
280
+ // this may be interrupted and return earlier when a signal is received
281
+ \sleep (PHP_INT_MAX );
282
+ }
278
283
279
284
return 0 ;
280
285
}
0 commit comments