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

Function connect

deps/undici/undici.js:9767–9848  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

9765 }
9766 __name(onError, "onError");
9767 function connect(client) {
9768 assert(!client[kConnecting]);
9769 assert(!client[kHTTPContext]);
9770 let { host, hostname, protocol, port } = client[kUrl];
9771 if (hostname[0] === "[") {
9772 const idx = hostname.indexOf("]");
9773 assert(idx !== -1);
9774 const ip = hostname.substring(1, idx);
9775 assert(net.isIPv6(ip));
9776 hostname = ip;
9777 }
9778 client[kConnecting] = true;
9779 if (channels.beforeConnect.hasSubscribers) {
9780 channels.beforeConnect.publish({
9781 connectParams: {
9782 host,
9783 hostname,
9784 protocol,
9785 port,
9786 version: client[kHTTPContext]?.version,
9787 servername: client[kServerName],
9788 localAddress: client[kLocalAddress]
9789 },
9790 connector: client[kConnector]
9791 });
9792 }
9793 try {
9794 client[kConnector]({
9795 host,
9796 hostname,
9797 protocol,
9798 port,
9799 servername: client[kServerName],
9800 localAddress: client[kLocalAddress]
9801 }, (err, socket) => {
9802 if (err) {
9803 handleConnectError(client, err, { host, hostname, protocol, port });
9804 client[kResume]();
9805 return;
9806 }
9807 if (client.destroyed) {
9808 util.destroy(socket.on("error", noop), new ClientDestroyedError());
9809 client[kResume]();
9810 return;
9811 }
9812 assert(socket);
9813 try {
9814 client[kHTTPContext] = socket.alpnProtocol === "h2" ? connectH2(client, socket) : connectH1(client, socket);
9815 } catch (err2) {
9816 socket.destroy().on("error", noop);
9817 handleConnectError(client, err2, { host, hostname, protocol, port });
9818 client[kResume]();
9819 return;
9820 }
9821 client[kConnecting] = false;
9822 socket[kCounter] = 0;
9823 socket[kMaxRequests] = client[kMaxRequests];
9824 socket[kClient] = client;

Callers 2

[kConnect]Method · 0.70
_resumeFunction · 0.70

Calls 15

queueMicrotaskFunction · 0.85
handleConnectErrorFunction · 0.70
connectH2Function · 0.70
connectH1Function · 0.70
dispatchMethod · 0.65
assertFunction · 0.50
rejectFunction · 0.50
resolveFunction · 0.50
callbackFunction · 0.50
indexOfMethod · 0.45
publishMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected