From a0134ff0f8a44e08823a0a8e219aff599fd5e011 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Mon, 7 Jun 2010 10:08:57 -0700 Subject: [PATCH] add net.Server.listenFD Now that FD passing is in master, it'd be great to be able to use a received socket (which has already had bind(2) and listen(2) called on it) to fire up a new net.Server instance. This patch adds a net.Server.listenFD() method which will start up the accept watcher on the provided FD. --- lib/net.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/net.js b/lib/net.js index fd825dad7fb..685c64b326d 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(); }