Loop should be recursive, otherwise messages disappear

This commit is contained in:
roblabla 2015-02-19 20:36:37 +00:00
parent 8a81039e88
commit 43b29cf904

View file

@ -83,11 +83,11 @@ Client.prototype.setSocket = function(socket) {
var self = this;
function afterParse(err, parsed) {
if (err || (parsed && parsed.error)) {
this.emit('error', err || parser.error);
this.emit('error', err || parsed.error);
this.end("ProtocolError");
return;
}
if (! parsed) { cont = false; return; }
if (! parsed) { return; }
packet = parsed.results;
incomingBuffer = incomingBuffer.slice(parsed.size);
@ -96,8 +96,16 @@ Client.prototype.setSocket = function(socket) {
self.emit('packet', packet);
self.emit('raw.' + packetName, parsed.buffer);
self.emit('raw', parsed.buffer);
prepareParse();
}
var cont = true;
function prepareParse() {
if(self.compressionThreshold == -2)
afterParse(null, parsePacket(incomingBuffer, self.state, self.isServer, self.packetsToParse));
else
parseNewStylePacket(incomingBuffer, self.state, self.isServer, self.packetsToParse, afterParse);
}
self.socket = socket;
if (self.socket.setNoDelay)
self.socket.setNoDelay(true);
@ -105,12 +113,7 @@ Client.prototype.setSocket = function(socket) {
self.socket.on('data', function(data) {
if (self.encryptionEnabled) data = new Buffer(self.decipher.update(data), 'binary');
incomingBuffer = Buffer.concat([incomingBuffer, data]);
while (cont) {
if(self.compressionThreshold == -2)
afterParse(null, parsePacket(incomingBuffer, self.state, self.isServer, self.packetsToParse));
else
parseNewStylePacket(incomingBuffer, self.state, self.isServer, self.packetsToParse, afterParse);
}
prepareParse()
});
self.socket.on('connect', function() {