Skip to content

Commit 6279dd0

Browse files
boyfoolimingxinleo
andauthored
Fixed bug that close event won't be executed when close the connection by websocket server.. (#2214)
* fix:协程模式服务端关闭连接未触发onClose事件 * Optimized code. * Update CHANGELOG-2.0.md Co-authored-by: 李铭昕 <[email protected]>
1 parent ece35ff commit 6279dd0

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/Server.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,10 @@ public function onHandShake(SwooleRequest $request, SwooleResponse $response): v
180180

181181
[$onCloseCallbackClass, $onCloseCallbackMethod] = $callbacks[SwooleEvent::ON_CLOSE];
182182
$onCloseCallbackInstance = $this->container->get($onCloseCallbackClass);
183+
183184
while (true) {
184185
$frame = $response->recv();
185-
if ($frame === false) {
186-
// When close the connection by server-side, the $frame is false.
187-
break;
188-
}
189-
if ($frame instanceof CloseFrame || $frame === '') {
190-
// The connection is closed.
186+
if ($frame === false || $frame instanceof CloseFrame || $frame === '') {
191187
$onCloseCallbackInstance->{$onCloseCallbackMethod}($response, $fd, 0);
192188
break;
193189
}

0 commit comments

Comments
 (0)