blob: 70d6a4df2a950c1fe2f342f47793281879054dd2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
'use strict';
const common = require('../common');
const http = require('http');
const cluster = require('cluster');
const assert = require('assert');
cluster.schedulingPolicy = cluster.SCHED_NONE;
const server = http.createServer();
if (cluster.isMaster) {
let worker;
server.listen(0, common.mustCall((error) => {
assert.ifError(error);
assert(worker);
worker.send({port: server.address().port});
}));
worker = cluster.fork();
worker.on('exit', common.mustCall(() => {
server.close();
}));
} else {
process.on('message', common.mustCall((msg) => {
assert(msg.port);
server.listen(msg.port);
server.on('error', common.mustCall((e) => {
cluster.worker.disconnect();
}));
}));
}
|