MCPcopy Index your code
hub / github.com/nodejs/node / setupChannel

Function setupChannel

lib/internal/child_process.js:619–994  ·  view source on GitHub ↗
(target, channel, serializationMode)

Source from the content-addressed store, hash-verified

617
618let serialization;
619function setupChannel(target, channel, serializationMode) {
620 const control = new Control(channel);
621 target.channel = control;
622 target[kChannelHandle] = channel;
623
624 target._handleQueue = null;
625 target._pendingMessage = null;
626
627 if (serialization === undefined)
628 serialization = require('internal/child_process/serialization');
629 const {
630 initMessageChannel,
631 parseChannelMessages,
632 writeChannelMessage,
633 } = serialization[serializationMode];
634
635 let pendingHandle = null;
636 initMessageChannel(channel);
637 channel.pendingHandle = null;
638 channel.onread = function(arrayBuffer) {
639 const recvHandle = channel.pendingHandle;
640 channel.pendingHandle = null;
641 if (arrayBuffer) {
642 const nread = streamBaseState[kReadBytesOrError];
643 const offset = streamBaseState[kArrayBufferOffset];
644 const pool = new Uint8Array(arrayBuffer, offset, nread);
645 if (recvHandle)
646 pendingHandle = recvHandle;
647
648 for (const message of parseChannelMessages(channel, pool)) {
649 // There will be at most one NODE_HANDLE message in every chunk we
650 // read because SCM_RIGHTS messages don't get coalesced. Make sure
651 // that we deliver the handle with the right message however.
652 if (isInternal(message)) {
653 if (message.cmd === 'NODE_HANDLE') {
654 handleMessage(message, pendingHandle, true);
655 pendingHandle = null;
656 } else {
657 handleMessage(message, undefined, true);
658 }
659 } else {
660 handleMessage(message, undefined, false);
661 }
662 }
663 } else {
664 this.buffering = false;
665 target.disconnect();
666 channel.onread = nop;
667 channel.close();
668 target.channel = null;
669 maybeClose(target);
670 }
671 };
672
673 // Object where socket lists will live
674 channel.sockets = { got: {}, send: {} };
675
676 // Handlers will go through this

Callers 2

_forkChildFunction · 0.85
child_process.jsFile · 0.85

Calls 15

unrefCountedMethod · 0.95
refCountedMethod · 0.95
initMessageChannelFunction · 0.85
parseChannelMessagesFunction · 0.85
isInternalFunction · 0.85
closePendingHandleFunction · 0.85
writeChannelMessageFunction · 0.85
_sendMethod · 0.80
listenerCountMethod · 0.80
handleMessageFunction · 0.70
maybeCloseFunction · 0.70
assertFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…