Skip to content

Commit

Permalink
handle high version nodejs
Browse files Browse the repository at this point in the history
Merge of wzrdtales#31
  • Loading branch information
pibi authored Feb 16, 2023
1 parent 7ddc2d4 commit a28ba01
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions lib/sticky-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ function node012Republish(fd, data) {
fd._handle.onread(1, new Buffer(data));
}

/**
* Access 'private' object _handle of file decriptor to republish the read
* packet.
*
* Supports Node version from 5.10 and up.
*/
function node510Republish(fd, data) {
fd._handle.onread(1, Buffer.from(data));
}

/**
* Access 'private' object _handle of file decriptor to republish the read
* packet.
*
* Supports Node version from 11.1 and up.
*/
function node111Republish(fd, data) {
fd._handle.onread(Buffer.from(data));
}

/**
* Hash balanced layer 3 connection listener.
*/
Expand Down Expand Up @@ -160,10 +180,43 @@ function StickyAgent(options, callback) {
this.sync = options.sync;
}

if (Number(version.substr(0, index)) >= 1 ||
Number(version.substr(index + 1)) >= 12) {
this.serverOptions.pauseOnConnect = true;
this.republishPacket = node012Republish;
var major = Number(version.substr(0, index));
var minor = Number(version.substr(index + 1));
switch(major) {
case 0:
if (minor < 12) {
break;
}
case 1:
case 2:
case 3:
case 4:
this.serverOptions.pauseOnConnect = true;
this.republishPacket = node012Republish;
break;
case 5:
if (minor < 10) {
this.serverOptions.pauseOnConnect = true;
this.republishPacket = node012Republish;
break;
}
case 6:
case 7:
case 8:
case 9:
case 10:
this.serverOptions.pauseOnConnect = true;
this.republishPacket = node510Republish;
break;
case 11:
if (minor < 1) {
this.serverOptions.pauseOnConnect = true;
this.republishPacket = node510Republish;
break;
}
default:
this.serverOptions.pauseOnConnect = true;
this.republishPacket = node111Republish;
}
}
}
Expand Down

0 comments on commit a28ba01

Please sign in to comment.