11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst fs = require('fs'); 61cb0ef41Sopenharmony_ciconst { Server } = require('net'); 71cb0ef41Sopenharmony_ciconst { Worker, isMainThread, parentPort } = require('worker_threads'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciif (isMainThread) { 101cb0ef41Sopenharmony_ci const w = new Worker(__filename); 111cb0ef41Sopenharmony_ci let fd = null; 121cb0ef41Sopenharmony_ci w.on('message', common.mustCall((fd_) => { 131cb0ef41Sopenharmony_ci assert.strictEqual(typeof fd_, 'number'); 141cb0ef41Sopenharmony_ci fd = fd_; 151cb0ef41Sopenharmony_ci })); 161cb0ef41Sopenharmony_ci w.on('exit', common.mustCall(() => { 171cb0ef41Sopenharmony_ci if (fd === -1) { 181cb0ef41Sopenharmony_ci // This happens when server sockets don’t have file descriptors, 191cb0ef41Sopenharmony_ci // i.e. on Windows. 201cb0ef41Sopenharmony_ci return; 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci assert.throws(() => fs.fstatSync(fd), { code: 'EBADF' }); 231cb0ef41Sopenharmony_ci })); 241cb0ef41Sopenharmony_ci} else { 251cb0ef41Sopenharmony_ci const server = new Server(); 261cb0ef41Sopenharmony_ci server.listen(0); 271cb0ef41Sopenharmony_ci parentPort.postMessage(server._handle.fd); 281cb0ef41Sopenharmony_ci server.unref(); 291cb0ef41Sopenharmony_ci} 30