node/lib/internal/cluster/shared_handle.js
Yash Ladha b2768ae185
cluster: removed unused addressType argument from constructor
When intializing the constructor for cluster master we are heavily using
a generic structure, but the effect of passing arguments that are
related to shared_handle is that there is a stale argument passed.

We can avoid such scenarios as all the remaining entities are being
destructured from the message object.

PR-URL: https://github.com/nodejs/node/pull/32963
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
2020-04-27 19:32:49 +02:00

46 lines
1.1 KiB
JavaScript

'use strict';
const { Map } = primordials;
const assert = require('internal/assert');
const dgram = require('internal/dgram');
const net = require('net');
module.exports = SharedHandle;
function SharedHandle(key, address, { port, addressType, fd, flags }) {
this.key = key;
this.workers = new Map();
this.handle = null;
this.errno = 0;
let rval;
if (addressType === 'udp4' || addressType === 'udp6')
rval = dgram._createSocketHandle(address, port, addressType, fd, flags);
else
rval = net._createServerHandle(address, port, addressType, fd, flags);
if (typeof rval === 'number')
this.errno = rval;
else
this.handle = rval;
}
SharedHandle.prototype.add = function(worker, send) {
assert(!this.workers.has(worker.id));
this.workers.set(worker.id, worker);
send(this.errno, null, this.handle);
};
SharedHandle.prototype.remove = function(worker) {
if (!this.workers.has(worker.id))
return false;
this.workers.delete(worker.id);
if (this.workers.size !== 0)
return false;
this.handle.close();
this.handle = null;
return true;
};