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

Function createServerHandle

lib/net.js:2057–2113  ·  view source on GitHub ↗
(address, port, addressType, fd, flags)

Source from the content-addressed store, hash-verified

2055
2056// Returns handle if it can be created, or error code if it can't
2057function createServerHandle(address, port, addressType, fd, flags) {
2058 let err = 0;
2059 // Assign handle in listen, and clean up if bind or listen fails
2060 let handle;
2061
2062 let isTCP = false;
2063 if (typeof fd === 'number' && fd >= 0) {
2064 try {
2065 handle = createHandle(fd, true);
2066 } catch (e) {
2067 // Not a fd we can listen on. This will trigger an error.
2068 debug('listen invalid fd=%d:', fd, e.message);
2069 return UV_EINVAL;
2070 }
2071
2072 err = handle.open(fd);
2073 if (err)
2074 return err;
2075
2076 assert(!address && !port);
2077 } else if (port === -1 && addressType === -1) {
2078 handle = new Pipe(PipeConstants.SERVER);
2079 if (isWindows) {
2080 const instances = NumberParseInt(process.env.NODE_PENDING_PIPE_INSTANCES);
2081 if (!NumberIsNaN(instances)) {
2082 handle.setPendingInstances(instances);
2083 }
2084 }
2085 } else {
2086 handle = new TCP(TCPConstants.SERVER);
2087 isTCP = true;
2088 }
2089
2090 if (address || port || isTCP) {
2091 debug('bind to', address || 'any');
2092 if (!address) {
2093 // Try binding to ipv6 first
2094 err = handle.bind6(DEFAULT_IPV6_ADDR, port, flags);
2095 if (err) {
2096 handle.close();
2097 // Fallback to ipv4
2098 return createServerHandle(DEFAULT_IPV4_ADDR, port, undefined, undefined, flags);
2099 }
2100 } else if (addressType === 6) {
2101 err = handle.bind6(address, port, flags);
2102 } else {
2103 err = handle.bind(address, port, flags);
2104 }
2105 }
2106
2107 if (err) {
2108 handle.close();
2109 return err;
2110 }
2111
2112 return handle;
2113}
2114

Callers 1

setupListenHandleFunction · 0.85

Calls 6

createHandleFunction · 0.70
assertFunction · 0.70
openMethod · 0.65
closeMethod · 0.65
debugFunction · 0.50
bindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…