GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — node/test/sequential/test-child-process-pass-fd.js at main · Ms2ger/node Expand file tree/ Copy pathtest-child-process-pass-fd.jsMore file actions 84 lines (73 loc) · 2.61 KB / Copy pathtest-child-process-pass-fd.jsFile metadata and controls84 lines (73 loc) · 2.61 KB 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 'use strict'; const common = require('../common'); // On some OS X versions, when passing fd's between processes: // When the handle associated to a specific file descriptor is closed by the // sender process before it's received in the destination, the handle is indeed // closed while it should remain opened. In order to fix this behavior, don't // close the handle until the `NODE_HANDLE_ACK` is received by the sender. // This test is basically `test-cluster-net-send` but creating lots of workers // so the issue reproduces on OS X consistently. if (common.isPi()) { common.skip('Too slow for Raspberry Pi devices'); } const assert = require('assert'); const { fork } = require('child_process'); const net = require('net'); const N = 80; let messageCallbackCount = 0; function forkWorker() { const messageCallback = common.mustCall((msg, handle) => { messageCallbackCount++; assert.strictEqual(msg, 'handle'); assert.ok(handle); worker.send('got'); let recvData = ''; handle.on('data', common.mustCall((data) => { recvData += data; })); handle.on('end', common.mustCall(() => { assert.strictEqual(recvData, 'hello'); worker.kill(); })); }); const worker = fork(__filename, ['child']); worker.on('error', (err) => { if (/\bEAGAIN\b/.test(err.message)) { forkWorker(); return; } throw err; }); worker.once('message', messageCallback); } if (process.argv[2] !== 'child') { for (let i = 0; i < N; ++i) { forkWorker(); } process.on('exit', () => { assert.strictEqual(messageCallbackCount, N); }); } else { let socket; let cbcalls = 0; function socketConnected() { if (++cbcalls === 2) process.send('handle', socket); } // As a side-effect, listening for the message event will ref the IPC channel, // so the child process will stay alive as long as it has a parent process/IPC // channel. Once this is done, we can unref our client and server sockets, and // the only thing keeping this worker alive will be IPC. This is important, // because it means a worker with no parent will have no referenced handles, // thus no work to do, and will exit immediately, preventing process leaks. process.on('message', common.mustCall()); const server = net.createServer(common.mustCall((c) => { process.once('message', common.mustCall((msg) => { assert.strictEqual(msg, 'got'); c.end('hello'); })); socketConnected(); })).unref(); server.listen(0, common.localhostIPv4, () => { const { port } = server.address(); socket = net.connect(port, common.localhostIPv4, socketConnected).unref(); }); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |