Server.listenFD deprecated, what's the recommended alternative?

229 views
Skip to first unread message

Ruben Vermeersch

unread,
Jan 12, 2012, 6:12:20 AM1/12/12
to nodejs
Hi,

In node 0.6.x, Server.listenFD has been deprecated. Unfortunately,
this was crucial for one of the modules we use at my company Flow
Pilots.

Given an fd number, we need to be able to use the socket, without
calling bind / listen first.

What is the recommended replacement for listenFD?

Kind regards,
Ruben

billywhizz

unread,
Jan 12, 2012, 12:30:32 PM1/12/12
to nodejs
i don't think the fd is available any more as it's not portable (is
only used on *nix). if you look at the c++ bindings though, it is
possible to call listen on a previously created handle, so would be
nice if there was a way of asking a net/http server to listen using an
already existing handle. the bindings are there, it's just a matter of
exposing them to allow this.

if you want to do something like this for now, you can use this
somewhat hacky solution:
https://gist.github.com/1601899

Bert Belder

unread,
Jan 12, 2012, 5:39:52 PM1/12/12
to nodejs
Hi Ruben,

I can give you a hack to do this from the c++ layer but I think you're
not really interested in a hack. What the *recommended* solution is
depends on what problem you are trying to solve. Where does this
socket fd come from in the first place?

- Bert

Ruben Vermeersch

unread,
Jan 13, 2012, 6:48:29 AM1/13/12
to nodejs
Hi Bert,

The socket fd comes from systemd, the init daemon on Fedora (and soon
openSuse and others). I have a working module for this on Node 0.4.x
[1], which I'd like to port to 0.6.x (we have a rather large
deployment running on this).

[2] describes how daemons should handle their sockets, basically
systemd does all the bind/listen for you, and you can just assume that
the socket is ready to run. When you look at the existing node-
systemd, you'll see that I barely have to do anything, just set up the
socket for eio and we're good.

I'm working out how to port this to 0.6.x in a somewhat recommended
way, but given that the stack completely changed, I figured it might
be a good idea to ask the node.js devs first.

Ruben


[1] https://github.com/rubenv/node-systemd
[2] http://0pointer.de/blog/projects/socket-activation.html

Ruben Vermeersch

unread,
Jan 13, 2012, 6:49:09 AM1/13/12
to nodejs


On Jan 12, 6:30 pm, billywhizz <apjohn...@gmail.com> wrote:
> i don't think the fd is available any more as it's not portable (is
> only used on *nix). if you look at the c++ bindings though, it is
> possible to call listen on a previously created handle, so would be
> nice if there was a way of asking a net/http server to listen using an
> already existing handle. the bindings are there, it's just a matter of
> exposing them to allow this.
>
> if you want to do something like this for now, you can use this
> somewhat hacky solution:https://gist.github.com/1601899

This could be interesting, I'll have a look at it.

billywhizz

unread,
Jan 13, 2012, 2:24:58 PM1/13/12
to nodejs
Ruben. As far as I know this will only work with libuv handles that
have been created in node.js or from a socket handle that is passed to
a child process over stdin. is it possible for systemd to send the
socket fd over stdin when spawning the node.js process? if so, you
should be able to get at it in the child process as follows:

var Pipe = process.binding("pipe_wrap").Pipe;
var p = new Pipe(true);
p.open(0);
p.onread = function(pool, offset, length, handle) {
if(handle) {
handle.onconnection = function(client) {
};
handle.listen();
p.onread = function() {};
p.close();
}
}
p.readStart();
Reply all
Reply to author
Forward
0 new messages