2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'dart:async' ;
6
- import 'dart:io' ;
7
-
8
5
import 'package:dwds/src/services/chrome_debug_exception.dart' ;
9
- import 'package:http_multi_server/http_multi_server.dart' ;
10
- import 'package:shelf/shelf.dart' ;
11
- import 'package:shelf/shelf_io.dart' ;
12
- import 'package:stack_trace/stack_trace.dart' ;
13
6
import 'package:vm_service/vm_service.dart' ;
14
7
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
15
8
as wip;
@@ -22,70 +15,6 @@ String createId() {
22
15
return '$_nextId ' ;
23
16
}
24
17
25
- /// Returns `true` if [hostname] is bound to an IPv6 address.
26
- Future <bool > useIPv6ForHost (String hostname) async {
27
- final addresses = await InternetAddress .lookup (hostname);
28
- if (addresses.isEmpty) return false ;
29
- final address = addresses.firstWhere (
30
- (a) => a.type == InternetAddressType .IPv6 ,
31
- orElse: () => addresses.first,
32
- );
33
- return address.type == InternetAddressType .IPv6 ;
34
- }
35
-
36
- /// Returns a port that is probably, but not definitely, not in use.
37
- ///
38
- /// This has a built-in race condition: another process may bind this port at
39
- /// any time after this call has returned.
40
- Future <int > findUnusedPort () async {
41
- int port;
42
- ServerSocket socket;
43
- try {
44
- socket =
45
- await ServerSocket .bind (InternetAddress .loopbackIPv6, 0 , v6Only: true );
46
- } on SocketException {
47
- socket = await ServerSocket .bind (InternetAddress .loopbackIPv4, 0 );
48
- }
49
- port = socket.port;
50
- await socket.close ();
51
- return port;
52
- }
53
-
54
- /// Finds unused port and binds a new http server to it.
55
- ///
56
- /// Retries a few times to recover from errors due to
57
- /// another thread or process opening the same port.
58
- /// Starts by trying to bind to [port] if specified.
59
- Future <HttpServer > startHttpServer (String hostname, {int ? port}) async {
60
- HttpServer ? httpServer;
61
- final retries = 5 ;
62
- var i = 0 ;
63
- var foundPort = port ?? await findUnusedPort ();
64
- while (i < retries) {
65
- i++ ;
66
- try {
67
- httpServer = await HttpMultiServer .bind (hostname, foundPort);
68
- } on SocketException {
69
- if (i == retries) rethrow ;
70
- }
71
- if (httpServer != null || i == retries) return httpServer! ;
72
- foundPort = await findUnusedPort ();
73
- await Future <void >.delayed (const Duration (milliseconds: 100 ));
74
- }
75
- return httpServer! ;
76
- }
77
-
78
- /// Handles [requests] using [handler] .
79
- ///
80
- /// Captures all sync and async stack error traces and passes
81
- /// them to the [onError] handler.
82
- void serveHttpRequests (Stream <HttpRequest > requests, Handler handler,
83
- void Function (Object , StackTrace ) onError) {
84
- return Chain .capture (() {
85
- serveRequests (requests, handler);
86
- }, onError: onError);
87
- }
88
-
89
18
/// Throws an [wip.ExceptionDetails] object if `exceptionDetails` is present on the
90
19
/// result.
91
20
void handleErrorIfPresent (wip.WipResponse ? response, {String ? evalContents}) {
0 commit comments