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.');