(target, channel, serializationMode)
| 617 | |
| 618 | let serialization; |
| 619 | function 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 |
no test coverage detected
searching dependent graphs…