Skip to content

Commit

Permalink
Modify PackateQueue to let auth request go first and other request go…
Browse files Browse the repository at this point in the history
… last
  • Loading branch information
XadillaX committed Oct 24, 2016
1 parent 9eeb2e7 commit e83fccc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/PacketQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
var util = require('util');
var events = require('events');

var jute = require('./jute');

function PacketQueue() {
events.EventEmitter.call(this);

Expand All @@ -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');
};
Expand Down

0 comments on commit e83fccc

Please sign in to comment.