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

Function lookupAndConnect

lib/net.js:1515–1656  ·  view source on GitHub ↗
(self, options)

Source from the content-addressed store, hash-verified

1513}
1514
1515function lookupAndConnect(self, options) {
1516 const { localAddress, localPort } = options;
1517 const host = options.host || 'localhost';
1518 let { port, autoSelectFamilyAttemptTimeout, autoSelectFamily } = options;
1519
1520 validateStringWithoutNullBytes(host, 'options.host');
1521
1522 // An adopted BoundSocket already owns the local endpoint and address family.
1523 if (self[kBoundSource]) {
1524 if (localAddress !== undefined || localPort !== undefined) {
1525 throw new ERR_INVALID_ARG_VALUE(
1526 'options',
1527 options,
1528 'localAddress and localPort cannot be used with an adopted bound socket');
1529 }
1530 autoSelectFamily = false;
1531 }
1532
1533 if (localAddress && !isIP(localAddress)) {
1534 throw new ERR_INVALID_IP_ADDRESS(localAddress);
1535 }
1536
1537 if (localPort) {
1538 validateNumber(localPort, 'options.localPort');
1539 }
1540
1541 if (port !== undefined) {
1542 if (typeof port !== 'number' && typeof port !== 'string') {
1543 throw new ERR_INVALID_ARG_TYPE('options.port',
1544 ['number', 'string'], port);
1545 }
1546 validatePort(port);
1547 }
1548 port |= 0;
1549
1550
1551 if (autoSelectFamily != null) {
1552 validateBoolean(autoSelectFamily, 'options.autoSelectFamily');
1553 } else {
1554 autoSelectFamily = autoSelectFamilyDefault;
1555 }
1556
1557 if (autoSelectFamilyAttemptTimeout != null) {
1558 validateInt32(autoSelectFamilyAttemptTimeout, 'options.autoSelectFamilyAttemptTimeout', 1);
1559
1560 if (autoSelectFamilyAttemptTimeout < 10) {
1561 autoSelectFamilyAttemptTimeout = 10;
1562 }
1563 } else {
1564 autoSelectFamilyAttemptTimeout = autoSelectFamilyAttemptTimeoutDefault;
1565 }
1566
1567 // If host is an IP, skip performing a lookup
1568 const addressType = isIP(host);
1569 if (addressType) {
1570 defaultTriggerAsyncIdScope(self[async_id_symbol], process.nextTick, () => {
1571 if (self.connecting)
1572 defaultTriggerAsyncIdScope(

Callers 1

net.jsFile · 0.85

Calls 8

isIPFunction · 0.85
socketToDnsFamilyFunction · 0.85
lookupAndConnectMultipleFunction · 0.85
lookupFunction · 0.70
requireFunction · 0.50
debugFunction · 0.50
emitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…