From db988a09143141d23165266f26fc0cd80d378391 Mon Sep 17 00:00:00 2001 From: Konstantin Grachev Date: Mon, 1 Feb 2021 02:38:19 +0300 Subject: [PATCH] Fix receiving partial message from nsq --- src/NsqSocket.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/NsqSocket.php b/src/NsqSocket.php index 082eeb2..c41353a 100644 --- a/src/NsqSocket.php +++ b/src/NsqSocket.php @@ -44,9 +44,15 @@ final class NsqSocket { $buffer = $this->input; - $buffer->append( - $this->socket->read(Bytes::BYTES_SIZE), - ); + $size = Bytes::BYTES_SIZE; + + do { + $buffer->append( + $this->socket->read($size), + ); + + $size -= $buffer->size(); + } while ($buffer->size() < Bytes::BYTES_SIZE); if ('' === $buffer->bytes()) { throw new ConnectionFail('Probably connection closed.');