diff --git a/lib/net.js b/lib/net.js index fd825dad7f..685c64b326 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1167,11 +1167,24 @@ Server.prototype.listen = function () { } }; -Server.prototype._doListen = function () { - listen(this.fd, 128); +Server.prototype.listenFD = function (fd) { + if (this.fd) { + throw new Error('Server already opened'); + } + + this.fd = fd; + this._startWatcher(); +}; + +Server.prototype._startWatcher = function () { this.watcher.set(this.fd, true, false); this.watcher.start(); this.emit("listening"); +}; + +Server.prototype._doListen = function () { + listen(this.fd, 128); + this._startWatcher(); }