Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2083)

Unified Diff: pkg/analysis_server/lib/src/channel.dart

Issue 426243005: Make "server.shutdown" exit the analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/channel.dart
diff --git a/pkg/analysis_server/lib/src/channel.dart b/pkg/analysis_server/lib/src/channel.dart
index 895316a11ee979b48400a66d6e04011e14ae17ca..9e6889071bfcaaf1c478fbb071573ff11ce2e829 100644
--- a/pkg/analysis_server/lib/src/channel.dart
+++ b/pkg/analysis_server/lib/src/channel.dart
@@ -63,6 +63,11 @@ abstract class ServerCommunicationChannel {
* Send the given [response] to the client.
*/
void sendResponse(Response response);
+
+ /**
+ * Close the communication channel.
+ */
+ void close();
}
/**
@@ -167,6 +172,11 @@ class WebSocketServerChannel implements ServerCommunicationChannel {
sendResponse(new Response.invalidRequestFormat());
}
}
+
+ @override
+ void close() {
+ socket.close(WebSocketStatus.NORMAL_CLOSURE);
+ }
}
/**
@@ -242,18 +252,28 @@ class ByteStreamServerChannel implements ServerCommunicationChannel {
input.transform((new Utf8Codec()).decoder).transform(new LineSplitter()
).listen((String data) => _readRequest(data, onRequest), onError: onError,
onDone: () {
- _closed.complete();
+ close();
onDone();
});
}
@override
void sendNotification(Notification notification) {
+ // Don't send any further notifications after the communication channel is
+ // closed.
+ if (_closed.isCompleted) {
+ return;
+ }
output.writeln(JSON.encode(notification.toJson()));
}
@override
void sendResponse(Response response) {
+ // Don't send any further responses after the communication channel is
+ // closed.
+ if (_closed.isCompleted) {
+ return;
+ }
output.writeln(JSON.encode(response.toJson()));
}
@@ -262,6 +282,10 @@ class ByteStreamServerChannel implements ServerCommunicationChannel {
* the request.
*/
void _readRequest(Object data, void onRequest(Request request)) {
+ // Ignore any further requests after the communication channel is closed.
+ if (_closed.isCompleted) {
+ return;
+ }
// Parse the string as a JSON descriptor and process the resulting
// structure as a request.
Request request = new Request.fromString(data);
@@ -271,6 +295,13 @@ class ByteStreamServerChannel implements ServerCommunicationChannel {
}
onRequest(request);
}
+
+ @override
+ void close() {
+ if (!_closed.isCompleted) {
+ _closed.complete();
+ }
+ }
}
/**
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/test/integration/integration_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698