| 15 | module.exports = RoundRobinHandle; |
| 16 | |
| 17 | function RoundRobinHandle(key, address, { port, fd, flags, backlog, readableAll, writableAll }) { |
| 18 | this.key = key; |
| 19 | this.all = new SafeMap(); |
| 20 | this.free = new SafeMap(); |
| 21 | this.handles = init({ __proto__: null }); |
| 22 | this.handle = null; |
| 23 | this.server = net.createServer(assert.fail); |
| 24 | |
| 25 | if (fd >= 0) |
| 26 | this.server.listen({ fd, backlog }); |
| 27 | else if (port >= 0) { |
| 28 | this.server.listen({ |
| 29 | port, |
| 30 | host: address, |
| 31 | // Currently, net module only supports `ipv6Only` option in `flags`. |
| 32 | ipv6Only: Boolean(flags & constants.UV_TCP_IPV6ONLY), |
| 33 | backlog, |
| 34 | }); |
| 35 | } else |
| 36 | this.server.listen({ |
| 37 | path: address, |
| 38 | backlog, |
| 39 | readableAll, |
| 40 | writableAll, |
| 41 | }); // UNIX socket path. |
| 42 | this.server.once('listening', () => { |
| 43 | this.handle = this.server._handle; |
| 44 | this.handle.onconnection = (err, handle) => this.distribute(err, handle); |
| 45 | this.server._handle = null; |
| 46 | this.server = null; |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | RoundRobinHandle.prototype.add = function(worker, send) { |
| 51 | assert(this.all.has(worker.id) === false); |