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

Side by Side Diff: runtime/bin/vmservice/server.dart

Issue 1338753004: Force disconnect all service clients when VM is shutting down (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/service/client.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of vmservice_io; 5 part of vmservice_io;
6 6
7 class WebSocketClient extends Client { 7 class WebSocketClient extends Client {
8 static const int PARSE_ERROR_CODE = 4000; 8 static const int PARSE_ERROR_CODE = 4000;
9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001;
10 static const int NOT_MAP_ERROR_CODE = 4002; 10 static const int NOT_MAP_ERROR_CODE = 4002;
11 static const int ID_ERROR_CODE = 4003; 11 static const int ID_ERROR_CODE = 4003;
12 final WebSocket socket; 12 final WebSocket socket;
13 13
14 WebSocketClient(this.socket, VMService service) : super(service) { 14 WebSocketClient(this.socket, VMService service) : super(service) {
15 socket.listen((message) => onWebSocketMessage(message)); 15 socket.listen((message) => onWebSocketMessage(message));
16 socket.done.then((_) => close()); 16 socket.done.then((_) => close());
17 } 17 }
18 18
19 disconnect() {
20 if (socket != null) {
21 socket.close();
22 }
23 }
24
19 void onWebSocketMessage(message) { 25 void onWebSocketMessage(message) {
20 if (message is String) { 26 if (message is String) {
21 var map; 27 var map;
22 try { 28 try {
23 map = JSON.decode(message); 29 map = JSON.decode(message);
24 } catch (e) { 30 } catch (e) {
25 socket.close(PARSE_ERROR_CODE, 'Message parse error: $e'); 31 socket.close(PARSE_ERROR_CODE, 'Message parse error: $e');
26 return; 32 return;
27 } 33 }
28 if (map is! Map) { 34 if (map is! Map) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 67
62 68
63 class HttpRequestClient extends Client { 69 class HttpRequestClient extends Client {
64 static ContentType jsonContentType = 70 static ContentType jsonContentType =
65 new ContentType("application", "json", charset: "utf-8"); 71 new ContentType("application", "json", charset: "utf-8");
66 final HttpRequest request; 72 final HttpRequest request;
67 73
68 HttpRequestClient(this.request, VMService service) 74 HttpRequestClient(this.request, VMService service)
69 : super(service, sendEvents:false); 75 : super(service, sendEvents:false);
70 76
77 disconnect() {
78 request.response.close();
79 close();
80 }
81
71 void post(String result) { 82 void post(String result) {
72 if (result == null) { 83 if (result == null) {
73 close(); 84 close();
74 return; 85 return;
75 } 86 }
76 request.response..headers.contentType = jsonContentType 87 request.response..headers.contentType = jsonContentType
77 ..write(result) 88 ..write(result)
78 ..close(); 89 ..close();
79 close(); 90 close();
80 } 91 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); 207 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n');
197 _notifyServerState("", 0); 208 _notifyServerState("", 0);
198 return this; 209 return this;
199 }); 210 });
200 } 211 }
201 212
202 } 213 }
203 214
204 void _notifyServerState(String ip, int port) 215 void _notifyServerState(String ip, int port)
205 native "VMServiceIO_NotifyServerState"; 216 native "VMServiceIO_NotifyServerState";
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/service/client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698