Browse Source

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.
v0.7.4-release
Peter Griess 15 years ago
committed by Ryan Dahl
parent
commit
a0134ff0f8
  1. 17
      lib/net.js

17
lib/net.js

@ -1167,11 +1167,24 @@ Server.prototype.listen = function () {
} }
}; };
Server.prototype._doListen = function () { Server.prototype.listenFD = function (fd) {
listen(this.fd, 128); 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.set(this.fd, true, false);
this.watcher.start(); this.watcher.start();
this.emit("listening"); this.emit("listening");
};
Server.prototype._doListen = function () {
listen(this.fd, 128);
this._startWatcher();
} }

Loading…
Cancel
Save