src/vs/base/node/ports.ts

211 LOC · 189 covered · 22 uncovered · 19 ranges · 38 concepts · 4 introducers · 32 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/tunnel/node/tunnelProxy.ts · 599 LOCnode/tunnelProxy.tsextHostTunnelService.ts ×3 · 22 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×2 · 21 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×4 · 38 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×2 · 23 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×1 · 9 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×1 · 17 introduced LOCextHostTunnelService.ts …remoteAgentConnection.ts ×53 · 823 introduced LOCremoteAgentConnection.ts…tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport CONNECT tunnels bidirectional data through a managed socket|occurrence=1 · 0 introduced LOCtunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport forwards an authenticated HTTP GET through a managed socket|occurrence=1 · 0 introduced LOCtunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport dispose disposes the managed remote socket via the adapter|occurrence=1 · 0 introduced LOCtunnelProxy.test|title=T…tunnelProxy.ts ×1 · 6 introduced LOCtunnelProxy.ts ×1tunnelProxy.ts ×2 · 6 introduced LOCtunnelProxy.ts ×2tunnelProxy.test|title=TunnelProxy dispose terminates active CONNECT tunnels|occurrence=1, tunnelProxy.test|title=TunnelProxy CONNECT establishes a tunnel to the target|occurrence=1, +1 · 0 introduced LOCtunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy forwards authenticated HTTP GET to target|occurrence=1, tunnelProxy.test|title=TunnelProxy forwards authenticated HTTP POST to target|occurrence=1, +4 · 0 introduced LOCtunnelProxy.test|title=T…tunnelProxy.ts ×2 · 11 introduced LOCtunnelProxy.ts ×2tunnelProxy.ts ×5 · 21 introduced LOCtunnelProxy.ts ×5tunnelProxy.ts ×4 · 20 introduced LOCtunnelProxy.ts ×4tunnelProxy.ts ×3 · 9 introduced LOCtunnelProxy.ts ×3tunnelProxy.ts ×10 · 66 introduced LOCtunnelProxy.ts ×10tunnelProxy.ts ×1 · 14 introduced LOCtunnelProxy.ts ×1tunnelProxy.ts ×1 · 1 introduced LOCtunnelProxy.ts ×1tunnelProxy.ts ×2 · 9 introduced LOCtunnelProxy.ts ×2tunnelProxy.ts ×2 · 6 introduced LOCtunnelProxy.ts ×2tunnelProxy.ts ×7 · 27 introduced LOCtunnelProxy.ts ×7tunnelProxy.ts ×1 · 2 introduced LOCtunnelProxy.ts ×1tunnelProxy.ts ×3 · 17 introduced LOCtunnelProxy.ts ×3tunnelProxy.ts ×1 · 4 introduced LOCtunnelProxy.ts ×1tunnelProxy.ts ×1 · 8 introduced LOCtunnelProxy.ts ×1tunnelProxy.ts ×5 · 11 introduced LOCtunnelProxy.ts ×5tunnelProxy.ts ×4 · 13 introduced LOCtunnelProxy.ts ×4tunnelProxy.ts ×1 · 2 introduced LOCtunnelProxy.ts ×1tunnelProxy.ts ×20 · 329 introduced LOCtunnelProxy.ts ×20debugAdapter.ts ×2 · 4 introduced LOCdebugAdapter.ts ×2debugAdapter.ts ×2 · 4 introduced LOCdebugAdapter.ts ×2debugAdapter.ts ×9 · 88 introduced LOCdebugAdapter.ts ×9ports.ts ×1 · 3 introduced LOCports.ts ×1ports.ts ×9 · 48 introduced LOCports.ts ×9ports.ts ×5 · 109 introduced LOCports.ts ×5port.test|title=Ports Finds a free port (no timeout)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/node/port.test|title=Ports Finds a free port (no timeout)|occurrence=1port.test|title=Ports Fi…tunnelProxy.test|title=TunnelProxy CONNECT establishes a tunnel to the target|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy CONNECT establishes a tunnel to the target|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy CONNECT rejects invalid port 0|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy CONNECT rejects invalid port 0|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy CONNECT rejects port > 65535|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy CONNECT rejects port > 65535|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy a reset on a pooled tunnel socket does not escalate to an uncaught exception|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy a reset on a pooled tunnel socket does not escalate to an uncaught exception|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy dispose shuts down the server|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy dispose shuts down the server|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy dispose synchronously destroys the remote tunnel socket|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy dispose synchronously destroys the remote tunnel socket|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy dispose terminates CONNECT sockets stuck waiting for the upstream tunnel|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy dispose terminates CONNECT sockets stuck waiting for the upstream tunnel|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy dispose terminates active CONNECT tunnels|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy dispose terminates active CONNECT tunnels|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy dispose terminates idle HTTPS keep-alive connections|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy dispose terminates idle HTTPS keep-alive connections|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy drainConnectionPool destroys pooled tunnel sockets|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy drainConnectionPool destroys pooled tunnel sockets|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy fails the request when the tunnel connection fails|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy fails the request when the tunnel connection fails|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy forwards authenticated HTTP GET to target|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy forwards authenticated HTTP GET to target|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy forwards authenticated HTTP POST to target|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy forwards authenticated HTTP POST to target|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport CONNECT tunnels bidirectional data through a managed socket|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport CONNECT tunnels bidirectional data through a managed socket|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport dispose disposes the managed remote socket via the adapter|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport dispose disposes the managed remote socket via the adapter|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport forwards an authenticated HTTP GET through a managed socket|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy managed (non-NodeSocket) transport forwards an authenticated HTTP GET through a managed socket|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy rejects CONNECT without credentials (407)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy rejects CONNECT without credentials (407)|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy rejects plain HTTP request without credentials (407)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy rejects plain HTTP request without credentials (407)|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy returns 400 for malformed URL|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy returns 400 for malformed URL|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy reuses tunnel socket for multiple requests to the same host|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy reuses tunnel socket for multiple requests to the same host|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy server uses TLS|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy server uses TLS|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy start returns a valid ITunnelProxyInfo|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy start returns a valid ITunnelProxyInfo|occurrence=1tunnelProxy.test|title=T…tunnelProxy.test|title=TunnelProxy strips hop-by-hop headers from forwarded request|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/tunnel/test/node/tunnelProxy.test|title=TunnelProxy strips hop-by-hop headers from forwarded request|occurrence=1tunnelProxy.test|title=T…extHostTunnelService.test|title=ExtHostTunnelService findPorts|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService findPorts|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService getSockets|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService getSockets|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService loadConnectionTable|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService loadConnectionTable|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService loadListeningPorts|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService loadListeningPorts|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService parseIpAddress|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService parseIpAddress|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService tryFindRootPorts|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService tryFindRootPorts|occurrence=1extHostTunnelService.tes…streamDebugAdapter.test|title=Debug - StreamDebugAdapter StreamDebugAdapter (NamedPipeDebugAdapter) can initialize a connection|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/debug/test/node/streamDebugAdapter.test|title=Debug - StreamDebugAdapter StreamDebugAdapter (NamedPipeDebugAdapter) can initialize a connection|occurrence=1streamDebugAdapter.test|…streamDebugAdapter.test|title=Debug - StreamDebugAdapter StreamDebugAdapter (SocketDebugAdapter) can initialize a connection|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/debug/test/node/streamDebugAdapter.test|title=Debug - StreamDebugAdapter StreamDebugAdapter (SocketDebugAdapter) can initialize a connection|occurrence=1streamDebugAdapter.test|…Focused file · src/vs/base/node/ports.ts · 211 LOCnode/ports.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- ports.ts ×5
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import * as net from 'net';
7 >
8 > /**
9 > * Given a start point and a max number of retries, will find a port that
10 > * is openable. Will return 0 in case no free port can be found.
11 > */
12 > export function findFreePort(startPort: number, giveUpAfter: number, timeout: number, stride = 1): Promise<number> {
13 > let done = false; ports.ts ×9
14 >
15 > return new Promise(resolve => {
16 > const timeoutHandle = setTimeout(() => {
17 if (!done) {
18 done = true;
19 return resolve(0);
20 }
21 > }, timeout); ports.ts ×9
22 >
23 > doFindFreePort(startPort, giveUpAfter, stride, (port) => {
24 > if (!done) {
25 > done = true;
26 > clearTimeout(timeoutHandle);
27 > return resolve(port);
28 > }
29 > });
30 > });
31 > }
33 > function doFindFreePort(startPort: number, giveUpAfter: number, stride: number, clb: (port: number) => void): void { ports.ts ×9
34 > if (giveUpAfter === 0) {
35 return clb(0);
36 }
38 > const client = new net.Socket();
39 >
40 > // If we can connect to the port it means the port is already taken so we continue searching
41 > client.once('connect', () => {
42 > dispose(client); ports.ts ×1
43 >
44 > return doFindFreePort(startPort + stride, giveUpAfter - 1, stride, clb);
45 > }); ports.ts ×9
46 >
47 > client.once('data', () => {
48 // this listener is required since node.js 8.x
49 > }); ports.ts ×9
50 >
51 > client.once('error', (err: Error & { code?: string }) => {
52 > dispose(client);
53 >
54 > // If we receive any non ECONNREFUSED error, it means the port is used but we cannot connect
55 > if (err.code !== 'ECONNREFUSED') {
56 return doFindFreePort(startPort + stride, giveUpAfter - 1, stride, clb);
57 }
59 > // Otherwise it means the port is free to use!
60 > return clb(startPort);
61 > });
62 >
63 > client.connect(startPort, '127.0.0.1');
64 > }
66 > // Reference: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/net/base/port_util.cc#56
67 > export const BROWSER_RESTRICTED_PORTS: Record<number, boolean> = {
68 > 1: true, // tcpmux
69 > 7: true, // echo
70 > 9: true, // discard
71 > 11: true, // systat
72 > 13: true, // daytime
73 > 15: true, // netstat
74 > 17: true, // qotd
75 > 19: true, // chargen
76 > 20: true, // ftp data
77 > 21: true, // ftp access
78 > 22: true, // ssh
79 > 23: true, // telnet
80 > 25: true, // smtp
81 > 37: true, // time
82 > 42: true, // name
83 > 43: true, // nicname
84 > 53: true, // domain
85 > 69: true, // tftp
86 > 77: true, // priv-rjs
87 > 79: true, // finger
88 > 87: true, // ttylink
89 > 95: true, // supdup
90 > 101: true, // hostriame
91 > 102: true, // iso-tsap
92 > 103: true, // gppitnp
93 > 104: true, // acr-nema
94 > 109: true, // pop2
95 > 110: true, // pop3
96 > 111: true, // sunrpc
97 > 113: true, // auth
98 > 115: true, // sftp
99 > 117: true, // uucp-path
100 > 119: true, // nntp
101 > 123: true, // NTP
102 > 135: true, // loc-srv /epmap
103 > 137: true, // netbios
104 > 139: true, // netbios
105 > 143: true, // imap2
106 > 161: true, // snmp
107 > 179: true, // BGP
108 > 389: true, // ldap
109 > 427: true, // SLP (Also used by Apple Filing Protocol)
110 > 465: true, // smtp+ssl
111 > 512: true, // print / exec
112 > 513: true, // login
113 > 514: true, // shell
114 > 515: true, // printer
115 > 526: true, // tempo
116 > 530: true, // courier
117 > 531: true, // chat
118 > 532: true, // netnews
119 > 540: true, // uucp
120 > 548: true, // AFP (Apple Filing Protocol)
121 > 554: true, // rtsp
122 > 556: true, // remotefs
123 > 563: true, // nntp+ssl
124 > 587: true, // smtp (rfc6409)
125 > 601: true, // syslog-conn (rfc3195)
126 > 636: true, // ldap+ssl
127 > 989: true, // ftps-data
128 > 990: true, // ftps
129 > 993: true, // ldap+ssl
130 > 995: true, // pop3+ssl
131 > 1719: true, // h323gatestat
132 > 1720: true, // h323hostcall
133 > 1723: true, // pptp
134 > 2049: true, // nfs
135 > 3659: true, // apple-sasl / PasswordServer
136 > 4045: true, // lockd
137 > 5060: true, // sip
138 > 5061: true, // sips
139 > 6000: true, // X11
140 > 6566: true, // sane-port
141 > 6665: true, // Alternate IRC [Apple addition]
142 > 6666: true, // Alternate IRC [Apple addition]
143 > 6667: true, // Standard IRC [Apple addition]
144 > 6668: true, // Alternate IRC [Apple addition]
145 > 6669: true, // Alternate IRC [Apple addition]
146 > 6697: true, // IRC + TLS
147 > 10080: true // Amanda
148 > };
149 >
150 > export function isPortFree(port: number, timeout: number): Promise<boolean> {
151 return findFreePortFaster(port, 0, timeout).then(port => port !== 0);
152 }
153 > ports.ts ×5
154 > interface ServerError {
155 > code?: string;
156 > }
157 >
158 > /**
159 > * Uses listen instead of connect. Is faster, but if there is another listener on 0.0.0.0 then this will take 127.0.0.1 from that listener.
160 > */
161 > export function findFreePortFaster(startPort: number, giveUpAfter: number, timeout: number, hostname: string = '127.0.0.1'): Promise<number> {
162 > let resolved: boolean = false; tunnelProxy.ts ×20
163 > let timeoutHandle: Timeout | undefined = undefined;
164 > let countTried: number = 1;
165 > const server = net.createServer({ pauseOnConnect: true });
166 > function doResolve(port: number, resolve: (port: number) => void) {
167 > if (!resolved) {
168 > resolved = true;
169 > server.removeAllListeners();
170 > server.close();
171 > if (timeoutHandle) {
172 > clearTimeout(timeoutHandle);
173 > }
174 > resolve(port);
175 > }
176 > }
177 > return new Promise<number>(resolve => {
178 > timeoutHandle = setTimeout(() => {
179 doResolve(0, resolve);
180 > }, timeout); tunnelProxy.ts ×20
181 >
182 > server.on('listening', () => {
183 > doResolve(startPort, resolve);
184 > });
185 > server.on('error', (err: ServerError) => {
186 if (err && (err.code === 'EADDRINUSE' || err.code === 'EACCES') && (countTried < giveUpAfter)) {
187 startPort++;
188 countTried++;
189 server.listen(startPort, hostname);
190 } else {
191 doResolve(0, resolve);
192 }
194 > server.on('close', () => {
195 doResolve(0, resolve);
197 > server.listen(startPort, hostname);
198 > });
199 > }
200 > ports.ts ×5
201 > function dispose(socket: net.Socket): void { ports.ts ×9
202 > try {
203 > socket.removeAllListeners('connect');
204 > socket.removeAllListeners('error');
205 > socket.end();
206 > socket.destroy();
207 > socket.unref();
208 > } catch (error) {
209 console.error(error); // otherwise this error would get lost in the callback chain
210 }
211 > } ports.ts ×9