Skip to content

Commit

Permalink
add net.Server.listenFD
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pgriess authored and ry committed Jun 7, 2010
1 parent 9be6c50 commit a0134ff
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down

0 comments on commit a0134ff

Please sign in to comment.