From f04fa59311cab0fe2e406878b4a167227ac50993 Mon Sep 17 00:00:00 2001 From: Arthur Kushman Date: Tue, 26 Jul 2022 04:43:58 +0300 Subject: [PATCH] #69: Remove large payload on false ret (#70) --- src/WebSocketServer.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/WebSocketServer.php b/src/WebSocketServer.php index b31903b..442bde5 100755 --- a/src/WebSocketServer.php +++ b/src/WebSocketServer.php @@ -231,15 +231,14 @@ private function acceptNewClient($server, array &$readSocks): void */ private function messagesWorker(array $readSocks): void { - $largePayloadData = ''; foreach ($readSocks as $kSock => $sock) { $data = $this->decode(fread($sock, self::MAX_BYTES_READ)); if ($data !== null) { - $dataType = $data['type']; - $dataPayload = $data['payload']; - - if ($data === false) { // payload is too large - waiting for remained data - $largePayloadData += $dataPayload; + $dataType = null; + $dataPayload = null; + if ($data !== false) { // payload is too large - waiting for remained data + $dataType = $data['type']; + $dataPayload = $data['payload']; } // to manipulate connection through send/close methods via handler, specified in IConnection @@ -261,11 +260,6 @@ private function messagesWorker(array $readSocks): void && method_exists($this->handler, self::MAP_EVENT_TYPE_TO_METHODS[$dataType]); if ($isSupportedMethod) { try { - if (empty($largePayloadData) === false) { - $dataPayload = $largePayloadData + $dataPayload; - $largePayloadData = ''; // clear saved large payload for the next one - } - // dynamic call: onMessage, onPing, onPong $this->handler->{self::MAP_EVENT_TYPE_TO_METHODS[$dataType]}($cureentConn, $dataPayload); } catch (WebSocketException $e) { @@ -289,7 +283,7 @@ private function handshake($client, string $headers): string $match = []; preg_match(self::SEC_WEBSOCKET_KEY_PTRN, $headers, $match); if (empty($match[1])) { - return false; + return ''; } $key = $match[1];