From 0a64b37b6f4c97fb7ad9e446fcc2db9428406823 Mon Sep 17 00:00:00 2001 From: Nicolas Dextraze Date: Wed, 11 Jul 2018 16:10:53 -0700 Subject: [PATCH] Fix issue with fake-server --- tools/fake-server.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/fake-server.js b/tools/fake-server.js index 5d5502d..e2192a6 100644 --- a/tools/fake-server.js +++ b/tools/fake-server.js @@ -11,12 +11,14 @@ const server = net.createServer(function(socket) { var recvBuf = new Buffer(0); socket.on('data', function(buf) { recvBuf = Buffer.concat([recvBuf, buf]); - const pkgData = tryReadPackage(recvBuf); - if (pkgData) { - handlePackage(pkgData, socket); - var oldBuf = recvBuf; - recvBuf = new Buffer(recvBuf.length - pkgData.size - 4); - oldBuf.copy(recvBuf, 0, 4 + pkgData.size); + let pkgData; + while(pkgData = tryReadPackage(recvBuf)) { + if (pkgData) { + handlePackage(pkgData, socket); + var oldBuf = recvBuf; + recvBuf = new Buffer(recvBuf.length - pkgData.size - 4); + oldBuf.copy(recvBuf, 0, 4 + pkgData.size); + } } }); socket.on('end', function() {