Skip to content

Commit

Permalink
net: remove useless timers
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda committed Jan 5, 2022
1 parent 92d745c commit 220fa69
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,31 +517,34 @@ Socket.prototype._onTimeout = function() {


Socket.prototype.setNoDelay = function(enable) {
// Backwards compatibility: assume true when `enable` is omitted
enable = Boolean(enable === undefined ? true : enable);

if (!this._handle) {
this.once('connect',
enable ? this.setNoDelay : () => this.setNoDelay(enable));
this[kSetNoDelay] = enable;
return this;
}

// Backwards compatibility: assume true when `enable` is omitted
const newValue = enable === undefined ? true : !!enable;
if (this._handle.setNoDelay && newValue !== this[kSetNoDelay]) {
this[kSetNoDelay] = newValue;
this._handle.setNoDelay(newValue);
if (this._handle.setNoDelay && enable !== this[kSetNoDelay]) {
this[kSetNoDelay] = enable;
this._handle.setNoDelay(enable);
}

return this;
};


Socket.prototype.setKeepAlive = function(enable, initialDelayMsecs) {
enable = Boolean(enable);
const initialDelay = ~~(initialDelayMsecs / 1000);

if (!this._handle) {
this.once('connect', () => this.setKeepAlive(enable, initialDelayMsecs));
this[kSetKeepAlive] = enable;
this[kSetKeepAliveInitialDelay] = initialDelay;
return this;
}

if (this._handle.setKeepAlive && enable !== this[kSetKeepAlive]) {
const initialDelay = ~~(initialDelayMsecs / 1000);
this[kSetKeepAlive] = enable;
this[kSetKeepAliveInitialDelay] = initialDelay;
this._handle.setKeepAlive(enable, initialDelay);
Expand Down

0 comments on commit 220fa69

Please sign in to comment.