From e83fccca129b7b7282c50f469465c438042fdd63 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Mon, 24 Oct 2016 15:57:48 +0800 Subject: [PATCH] Modify PackateQueue to let auth request go first and other request go last --- lib/PacketQueue.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/PacketQueue.js b/lib/PacketQueue.js index b3afa23..9583d5c 100644 --- a/lib/PacketQueue.js +++ b/lib/PacketQueue.js @@ -13,6 +13,8 @@ var util = require('util'); var events = require('events'); +var jute = require('./jute'); + function PacketQueue() { events.EventEmitter.call(this); @@ -28,7 +30,14 @@ PacketQueue.prototype.push = function (packet) { throw new Error('packet must be a valid object.'); } - this.queue.push(packet); + if (packet.request.header.type === jute.OP_CODES.AUTH && + packet.request.header.xid === jute.XID_AUTHENTICATION) { + // let auth request go first + this.queue.unshift(packet); + } else { + // otherwise go last + this.queue.push(packet); + } this.emit('readable'); };