(address, port, addressType, fd, flags)
| 2055 | |
| 2056 | // Returns handle if it can be created, or error code if it can't |
| 2057 | function 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 |
no test coverage detected
searching dependent graphs…