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

Function internalConnectMultiple

lib/net.js:1323–1425  ·  view source on GitHub ↗
(context, canceled)

Source from the content-addressed store, hash-verified

1321
1322
1323function internalConnectMultiple(context, canceled) {
1324 clearTimeout(context[kTimeout]);
1325 const self = context.socket;
1326
1327 // We were requested to abort. Stop all operations
1328 if (self._aborted) {
1329 return;
1330 }
1331
1332 // All connections have been tried without success, destroy with error
1333 if (canceled || context.current === context.addresses.length) {
1334 if (context.errors.length === 0) {
1335 self.destroy(new ERR_SOCKET_CONNECTION_TIMEOUT());
1336 return;
1337 }
1338
1339 self.destroy(new NodeAggregateError(context.errors));
1340 return;
1341 }
1342
1343 assert(self.connecting);
1344
1345 const current = context.current++;
1346
1347 if (current > 0) {
1348 self[kReinitializeHandle](new TCP(TCPConstants.SOCKET));
1349 }
1350
1351 const { localPort, port, flags } = context;
1352 const { address, family: addressType } = context.addresses[current];
1353 let localAddress;
1354 let err;
1355
1356 if (localPort) {
1357 if (addressType === 4) {
1358 localAddress = DEFAULT_IPV4_ADDR;
1359 err = self._handle.bind(localAddress, localPort);
1360 } else { // addressType === 6
1361 localAddress = DEFAULT_IPV6_ADDR;
1362 err = self._handle.bind6(localAddress, localPort, flags);
1363 }
1364
1365 debug('connect/multiple: binding to localAddress: %s and localPort: %d (addressType: %d)',
1366 localAddress, localPort, addressType);
1367
1368 err = checkBindError(err, localPort, self._handle);
1369 if (err) {
1370 ArrayPrototypePush(context.errors, new ExceptionWithHostPort(err, 'bind', localAddress, localPort));
1371 internalConnectMultiple(context);
1372 return;
1373 }
1374 }
1375
1376 if (self.blockList?.check(address, `ipv${addressType}`)) {
1377 const ex = new ERR_IP_BLOCKED(address);
1378 ArrayPrototypePush(context.errors, ex);
1379 self.emit('connectionAttemptFailed', address, port, addressType, ex);
1380 internalConnectMultiple(context);

Callers 2

afterConnectMultipleFunction · 0.85

Calls 10

checkBindErrorFunction · 0.85
clearTimeoutFunction · 0.70
assertFunction · 0.70
setTimeoutFunction · 0.70
connectMethod · 0.65
debugFunction · 0.50
destroyMethod · 0.45
bindMethod · 0.45
checkMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…