Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ function initSocketHandle(self) {
const kBytesRead = Symbol('kBytesRead');
const kBytesWritten = Symbol('kBytesWritten');
const kSetNoDelay = Symbol('kSetNoDelay');
const kSetKeepAlive = Symbol('kSetKeepAlive');

function Socket(options) {
if (!(this instanceof Socket)) return new Socket(options);
Expand All @@ -273,6 +274,7 @@ function Socket(options) {
this._host = null;
this[kSetNoDelay] = false;
this[kLastWriteQueueSize] = 0;
this[kSetKeepAlive] = null;
this[kTimeout] = null;
this[kBuffer] = null;
this[kBufferCb] = null;
Expand Down Expand Up @@ -500,13 +502,26 @@ Socket.prototype.setNoDelay = function(enable) {


Socket.prototype.setKeepAlive = function(setting, msecs) {
if (setting != null && typeof setting !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('enable', 'boolean', setting);

if (msecs != null && typeof msecs !== 'number')
throw new ERR_INVALID_ARG_TYPE('msecs', 'number', msecs);

if (msecs === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is correct?

return;
}

if (!this._handle) {
this.once('connect', () => this.setKeepAlive(setting, msecs));
return this;
}

if (this._handle.setKeepAlive)
if (this._handle.setKeepAlive &&
this[kSetKeepAlive] !== setting) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to include the msec setting as well?

this._handle.setKeepAlive(setting, ~~(msecs / 1000));
this[kSetKeepAlive] = setting;
}

return this;
};
Expand Down