@@ -26,10 +26,8 @@ public function addReadStream($stream, $listener)
26
26
27
27
if (!isset ($ this ->readStreams [$ id ])) {
28
28
$ this ->readStreams [$ id ] = $ stream ;
29
- $ this ->readListeners [$ id ] = array () ;
29
+ $ this ->readListeners [$ id ] = $ listener ;
30
30
}
31
-
32
- $ this ->readListeners [$ id ][] = $ listener ;
33
31
}
34
32
35
33
public function addWriteStream ($ stream , $ listener )
@@ -38,26 +36,28 @@ public function addWriteStream($stream, $listener)
38
36
39
37
if (!isset ($ this ->writeStreams [$ id ])) {
40
38
$ this ->writeStreams [$ id ] = $ stream ;
41
- $ this ->writeListeners [$ id ] = array () ;
39
+ $ this ->writeListeners [$ id ] = $ listener ;
42
40
}
43
-
44
- $ this ->writeListeners [$ id ][] = $ listener ;
45
41
}
46
42
47
43
public function removeReadStream ($ stream )
48
44
{
49
45
$ id = (int ) $ stream ;
50
46
51
- unset($ this ->readStreams [$ id ]);
52
- unset($ this ->readListeners [$ id ]);
47
+ unset(
48
+ $ this ->readStreams [$ id ],
49
+ $ this ->readListeners [$ id ]
50
+ );
53
51
}
54
52
55
53
public function removeWriteStream ($ stream )
56
54
{
57
55
$ id = (int ) $ stream ;
58
56
59
- unset($ this ->writeStreams [$ id ]);
60
- unset($ this ->writeListeners [$ id ]);
57
+ unset(
58
+ $ this ->writeStreams [$ id ],
59
+ $ this ->writeListeners [$ id ]
60
+ );
61
61
}
62
62
63
63
public function removeStream ($ stream )
@@ -79,11 +79,9 @@ public function tick()
79
79
if (stream_select ($ read , $ write , $ except , 0 , $ this ->timeout ) > 0 ) {
80
80
if ($ read ) {
81
81
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 );
87
85
}
88
86
}
89
87
}
@@ -93,11 +91,10 @@ public function tick()
93
91
if (!isset ($ this ->writeListeners [(int ) $ stream ])) {
94
92
continue ;
95
93
}
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 );
101
98
}
102
99
}
103
100
}
0 commit comments