From a0e0ecdd7396458dd3e74585502996a0c104c031 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 28 Jul 2016 11:06:42 -0700 Subject: [PATCH] workers: payload length. --- lib/bcoin/workers.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/bcoin/workers.js b/lib/bcoin/workers.js index ba3b0153..a9aa8c9c 100644 --- a/lib/bcoin/workers.js +++ b/lib/bcoin/workers.js @@ -531,13 +531,11 @@ Worker.prototype.destroy = function destroy() { Worker.prototype.execute = function execute(method, args, timeout, callback) { var self = this; - var job = this.uid++; + var job = this.uid; var event, timer; - if (job > 0xffffffff) { + if (++this.uid === 0x100000000) this.uid = 0; - job = this.uid++; - } event = 'response ' + job; @@ -849,7 +847,7 @@ Framer.prototype.packet = function packet(job, cmd, items) { packet.writeUInt32LE(job, 4, true); packet.writeUInt8(cmd.length, 8, true); packet.write(cmd, 9, 'ascii'); - packet.writeUInt32LE(payload.length + 1, 21, true); + packet.writeUInt32LE(payload.length, 21, true); payload.copy(packet, 25); packet[packet.length - 1] = 0x0a; @@ -1023,9 +1021,9 @@ Parser.prototype.read = function read(size) { }; Parser.prototype.parse = function parse(data) { - var packet; + var packet = this.packet; - if (!this.packet) { + if (!packet) { try { packet = this.parseHeader(data); } catch (e) { @@ -1034,13 +1032,11 @@ Parser.prototype.parse = function parse(data) { } this.packet = packet; - this.waiting = packet.size; + this.waiting = packet.size + 1; return; } - packet = this.packet; - this.waiting = 25; this.packet = null;