Skip to content

Commit 7bbda73

Browse files
Merge pull request #31 from gaaf/fix-30
Don't assume stream_select will preserve array keys
2 parents 2390074 + 5de6af4 commit 7bbda73

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Driver/Userland/Connection/StreamSocketConnectionPool.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,28 @@ public function close()
117117
*/
118118
private function selectConnections(&$readSockets, $timeout)
119119
{
120+
// stream_select will not always preserve array keys
121+
// call it with a (deep) copy so the original is preserved
122+
$read = [];
123+
foreach ($readSockets as $id => $socket) {
124+
$read[] = $socket;
125+
}
120126
$writeSockets = $exceptSockets = [];
121127

122-
if (false === @stream_select($readSockets, $writeSockets, $exceptSockets, $timeout)) {
128+
if (false === @stream_select($read, $writeSockets, $exceptSockets, $timeout)) {
123129
$error = error_get_last();
124130

125131
if (false === stripos($error['message'], 'interrupted system call')) {
126132
throw new \RuntimeException('stream_select failed: '.$error['message']);
127133
}
128134

129135
$readSockets = [];
136+
} else {
137+
$res = [];
138+
foreach($read as $socket) {
139+
$res[array_search($socket, $readSockets)] = $socket;
140+
}
141+
$readSockets = $res;
130142
}
131143
}
132144

0 commit comments

Comments
 (0)