diff options
Diffstat (limited to 'lib/net.js')
-rw-r--r-- | lib/net.js | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/lib/net.js b/lib/net.js index 9eb7448c59..1cea5bf6ce 100644 --- a/lib/net.js +++ b/lib/net.js @@ -63,7 +63,8 @@ const { writeGeneric, onStreamRead, kAfterAsyncWrite, - kUpdateTimer + kUpdateTimer, + setStreamTimeout } = require('internal/stream_base_commons'); const { codes: { @@ -89,11 +90,7 @@ const kLastWriteQueueSize = Symbol('lastWriteQueueSize'); let cluster; let dns; -const { - kTimeout, - setUnrefTimeout, - validateTimerDuration -} = require('internal/timers'); +const { kTimeout } = require('internal/timers'); function noop() {} @@ -405,28 +402,7 @@ function writeAfterFIN(chunk, encoding, cb) { } } -Socket.prototype.setTimeout = function(msecs, callback) { - this.timeout = msecs; - // Type checking identical to timers.enroll() - msecs = validateTimerDuration(msecs); - - // Attempt to clear an existing timer in both cases - - // even if it will be rescheduled we don't want to leak an existing timer. - clearTimeout(this[kTimeout]); - - if (msecs === 0) { - if (callback) { - this.removeListener('timeout', callback); - } - } else { - this[kTimeout] = setUnrefTimeout(this._onTimeout.bind(this), msecs); - - if (callback) { - this.once('timeout', callback); - } - } - return this; -}; +Socket.prototype.setTimeout = setStreamTimeout; Socket.prototype._onTimeout = function() { |