Chromium Code Reviews| Index: pkg/analysis_server/lib/src/server/http_server.dart |
| diff --git a/pkg/analysis_server/lib/src/server/http_server.dart b/pkg/analysis_server/lib/src/server/http_server.dart |
| index 85c355700c0aa4c5438f25b221e0564db3c07eb9..4d88eb4d01214847e26cc4d655a8560addd30c06 100644 |
| --- a/pkg/analysis_server/lib/src/server/http_server.dart |
| +++ b/pkg/analysis_server/lib/src/server/http_server.dart |
| @@ -14,8 +14,10 @@ import 'package:analysis_server/src/status/get_handler2.dart'; |
| /** |
| * Instances of the class [HttpServer] implement a simple HTTP server. The |
| - * primary responsibility of this server is to listen for an UPGRADE request and |
| - * to start an analysis server. |
| + * server: |
| + * |
| + * - listens for an UPGRADE request in order to start an analysis server |
| + * - serves diagnostic information as html pages |
| */ |
| class HttpAnalysisServer { |
| /** |
| @@ -49,6 +51,11 @@ class HttpAnalysisServer { |
| */ |
| HttpAnalysisServer(this.socketServer); |
| + /** |
| + * Return the port this server is bound to. |
| + */ |
| + Future<int> get boundPort async => (await _server)?.port; |
| + |
| void close() { |
| _server.then((HttpServer server) { |
| server.close(); |
| @@ -69,9 +76,20 @@ class HttpAnalysisServer { |
| /** |
| * Begin serving HTTP requests over the given port. |
| */ |
| - void serveHttp(int port) { |
| - _server = HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port); |
| - _server.then(_handleServer).catchError((_) {/* Ignore errors. */}); |
| + Future<int> serveHttp([int initialPort]) async { |
| + if (_server != null) { |
| + return boundPort; |
| + } |
| + |
| + try { |
| + _server = |
| + HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, initialPort ?? 0); |
| + HttpServer server = await _server; |
| + _handleServer(server); |
| + return server.port; |
| + } catch (ignore) { |
| + return null; |
| + } |
| } |
| /** |
| @@ -111,6 +129,8 @@ class HttpAnalysisServer { |
| * running an analysis server on a [WebSocket]-based communication channel. |
| */ |
| void _handleWebSocket(WebSocket socket) { |
| + // TODO(devoncarew): This is serving the analysis server over a websocket |
| + // connection (as well as the diagnostics page over http); is this intended? |
|
Brian Wilkerson
2017/02/18 21:41:03
It's there for historic reasons. The original plan
devoncarew
2017/02/19 02:43:05
Makes sense. I updated the comment a bit to mentio
|
| socketServer.createAnalysisServer(new WebSocketServerChannel( |
| socket, socketServer.instrumentationService)); |
| } |