var net = require('net');

var Server = net.Server.prototype;
var Pipe = process.binding('pipe_wrap').Pipe;

var oldListen = Server.listen;
Server.listen = function () {
    var self = this;

    if (arguments.length === 1 && arguments[0] === 'systemd') {
        if (!process.env.LISTEN_FDS || parseInt(process.env.LISTEN_FDS, 10) !== 1) {
            throw(new Error('No or too many file descriptors received.'));
        }

        self._handle = new Pipe(process.binding('pipe_wrap').constants.SOCKET);
        self._handle.open(3);
        self._listen2(null, -1, -1);
    } else {
        oldListen.apply(self, arguments);
    }
    return self;
};

var net = require('net');

var Server = net.Server.prototype;
var Pipe = process.binding('pipe_wrap').Pipe;

var oldListen = Server.listen;
Server.listen = function () {
    var self = this;

    if (arguments.length === 1 && arguments[0] === 'systemd') {
        if (!process.env.LISTEN_FDS || parseInt(process.env.LISTEN_FDS, 10) !== 1) {
            throw(new Error('No or too many file descriptors received.'));
        }

        if (!process.binding('pipe_wrap').Pipe.constants) {
            self._handle = new Pipe();
        }
        else {
            self._handle = new Pipe(process.binding('pipe_wrap').Pipe.constants.SOCKET);
        }
        self._handle.open(3);
        self._listen2(null, -1, -1);
    } else {
        oldListen.apply(self, arguments);
    }
    return self;
};

Make the fix backwards compatible
Make the fix backwards compatible
