Skip to content

Commit 9044dc0

Browse files
committed
Merge branch 'loop-streamselect-listeners'
* loop-streamselect-listeners: [EventLoop] Fix oversight after code changes. [EventLoop] Associate only one listener per each stream event type.
2 parents 9e1bb34 + 8796192 commit 9044dc0

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

StreamSelectLoop.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ public function addReadStream($stream, $listener)
2626

2727
if (!isset($this->readStreams[$id])) {
2828
$this->readStreams[$id] = $stream;
29-
$this->readListeners[$id] = array();
29+
$this->readListeners[$id] = $listener;
3030
}
31-
32-
$this->readListeners[$id][] = $listener;
3331
}
3432

3533
public function addWriteStream($stream, $listener)
@@ -38,26 +36,28 @@ public function addWriteStream($stream, $listener)
3836

3937
if (!isset($this->writeStreams[$id])) {
4038
$this->writeStreams[$id] = $stream;
41-
$this->writeListeners[$id] = array();
39+
$this->writeListeners[$id] = $listener;
4240
}
43-
44-
$this->writeListeners[$id][] = $listener;
4541
}
4642

4743
public function removeReadStream($stream)
4844
{
4945
$id = (int) $stream;
5046

51-
unset($this->readStreams[$id]);
52-
unset($this->readListeners[$id]);
47+
unset(
48+
$this->readStreams[$id],
49+
$this->readListeners[$id]
50+
);
5351
}
5452

5553
public function removeWriteStream($stream)
5654
{
5755
$id = (int) $stream;
5856

59-
unset($this->writeStreams[$id]);
60-
unset($this->writeListeners[$id]);
57+
unset(
58+
$this->writeStreams[$id],
59+
$this->writeListeners[$id]
60+
);
6161
}
6262

6363
public function removeStream($stream)
@@ -79,11 +79,9 @@ public function tick()
7979
if (stream_select($read, $write, $except, 0, $this->timeout) > 0) {
8080
if ($read) {
8181
foreach ($read as $stream) {
82-
foreach ($this->readListeners[(int) $stream] as $listener) {
83-
if (call_user_func($listener, $stream, $this) === false) {
84-
$this->removeReadStream($stream);
85-
break;
86-
}
82+
$listener = $this->readListeners[(int) $stream];
83+
if (call_user_func($listener, $stream, $this) === false) {
84+
$this->removeReadStream($stream);
8785
}
8886
}
8987
}
@@ -93,11 +91,10 @@ public function tick()
9391
if (!isset($this->writeListeners[(int) $stream])) {
9492
continue;
9593
}
96-
foreach ($this->writeListeners[(int) $stream] as $listener) {
97-
if (call_user_func($listener, $stream, $this) === false) {
98-
$this->removeWriteStream($stream);
99-
break;
100-
}
94+
95+
$listener = $this->writeListeners[(int) $stream];
96+
if (call_user_func($listener, $stream, $this) === false) {
97+
$this->removeWriteStream($stream);
10198
}
10299
}
103100
}

0 commit comments

Comments
 (0)
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