diff --git a/src/LibEvLoop.php b/src/LibEvLoop.php index 1f0124ae..929d2eb6 100644 --- a/src/LibEvLoop.php +++ b/src/LibEvLoop.php @@ -35,6 +35,10 @@ public function __construct() */ public function addReadStream($stream, callable $listener) { + if (isset($this->readEvents[(int) $stream])) { + return; + } + $callback = function () use ($stream, $listener) { call_user_func($listener, $stream, $this); }; @@ -50,6 +54,10 @@ public function addReadStream($stream, callable $listener) */ public function addWriteStream($stream, callable $listener) { + if (isset($this->writeEvents[(int) $stream])) { + return; + } + $callback = function () use ($stream, $listener) { call_user_func($listener, $stream, $this); }; diff --git a/tests/AbstractLoopTest.php b/tests/AbstractLoopTest.php index d054648a..3351a8aa 100644 --- a/tests/AbstractLoopTest.php +++ b/tests/AbstractLoopTest.php @@ -47,6 +47,20 @@ public function testAddReadStream() $this->tickLoop($this->loop); } + public function testAddReadStreamIgnoresSecondCallable() + { + list ($input, $output) = $this->createSocketPair(); + + $this->loop->addReadStream($input, $this->expectCallableExactly(2)); + $this->loop->addReadStream($input, $this->expectCallableNever()); + + fwrite($output, "foo\n"); + $this->tickLoop($this->loop); + + fwrite($output, "bar\n"); + $this->tickLoop($this->loop); + } + public function testAddWriteStream() { list ($input) = $this->createSocketPair(); @@ -56,6 +70,16 @@ public function testAddWriteStream() $this->tickLoop($this->loop); } + public function testAddWriteStreamIgnoresSecondCallable() + { + list ($input) = $this->createSocketPair(); + + $this->loop->addWriteStream($input, $this->expectCallableExactly(2)); + $this->loop->addWriteStream($input, $this->expectCallableNever()); + $this->tickLoop($this->loop); + $this->tickLoop($this->loop); + } + public function testRemoveReadStreamInstantly() { list ($input, $output) = $this->createSocketPair(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy