Skip to content

Commit

Permalink
Merge pull request #103 from watson/listen2
Browse files Browse the repository at this point in the history
Handle rename of net.Server.prototype._listen2
  • Loading branch information
watson authored Dec 21, 2017
2 parents 29a5362 + 0b3befe commit a3da517
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ if (v7plus && !net._normalizeArgs) {
};
}

wrap(net.Server.prototype, '_listen2', function (original) {
// In https://github.com/nodejs/node/pull/11796 `_listen2` was renamed
// `_setUpListenHandle`. It's still aliased as `_listen2`, and currently the
// Node internals still call the alias - but who knows for how long. So better
// make sure we use the new name instead if available.
if ('_setUpListenHandle' in net.Server.prototype) {
wrap(net.Server.prototype, '_setUpListenHandle', wrapSetUpListenHandle);
} else {
wrap(net.Server.prototype, '_listen2', wrapSetUpListenHandle);
}

function wrapSetUpListenHandle(original) {
return function () {
this.on('connection', function (socket) {
if (socket._handle) {
Expand All @@ -92,7 +102,7 @@ wrap(net.Server.prototype, '_listen2', function (original) {
}
}
};
});
}

function patchOnRead(ctx) {
if (ctx && ctx._handle) {
Expand Down

0 comments on commit a3da517

Please sign in to comment.