2017-09-01 17:03:41 +02:00
|
|
|
|
'use strict';
|
|
|
|
|
const common = require('../common');
|
2019-01-08 14:42:26 -08:00
|
|
|
|
|
2017-09-01 17:03:41 +02:00
|
|
|
|
const assert = require('assert');
|
|
|
|
|
const fs = require('fs');
|
2019-01-08 14:42:26 -08:00
|
|
|
|
const { Server } = require('net');
|
|
|
|
|
const { Worker, isMainThread, parentPort } = require('worker_threads');
|
2017-09-01 17:03:41 +02:00
|
|
|
|
|
|
|
|
|
if (isMainThread) {
|
|
|
|
|
const w = new Worker(__filename);
|
|
|
|
|
let fd = null;
|
|
|
|
|
w.on('message', common.mustCall((fd_) => {
|
|
|
|
|
assert.strictEqual(typeof fd_, 'number');
|
|
|
|
|
fd = fd_;
|
|
|
|
|
}));
|
2019-01-08 14:42:26 -08:00
|
|
|
|
w.on('exit', common.mustCall(() => {
|
2017-09-01 17:03:41 +02:00
|
|
|
|
if (fd === -1) {
|
|
|
|
|
// This happens when server sockets don’t have file descriptors,
|
|
|
|
|
// i.e. on Windows.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-08 14:42:26 -08:00
|
|
|
|
assert.throws(() => fs.fstatSync(fd), { code: 'EBADF' });
|
2017-09-01 17:03:41 +02:00
|
|
|
|
}));
|
|
|
|
|
} else {
|
|
|
|
|
const server = new Server();
|
|
|
|
|
server.listen(0);
|
|
|
|
|
parentPort.postMessage(server._handle.fd);
|
|
|
|
|
server.unref();
|
|
|
|
|
}
|