| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library channel.byte_stream; | 5 library channel.byte_stream; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 }); | 96 }); |
| 97 } | 97 } |
| 98 | 98 |
| 99 @override | 99 @override |
| 100 void sendNotification(Notification notification) { | 100 void sendNotification(Notification notification) { |
| 101 // Don't send any further notifications after the communication channel is | 101 // Don't send any further notifications after the communication channel is |
| 102 // closed. | 102 // closed. |
| 103 if (_closed.isCompleted) { | 103 if (_closed.isCompleted) { |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 output.writeln(JSON.encode(notification.toJson())); | 106 ServerCommunicationChannel.ToJson.start(); |
| 107 String jsonEncoding = JSON.encode(notification.toJson()); |
| 108 ServerCommunicationChannel.ToJson.stop(); |
| 109 output.writeln(jsonEncoding); |
| 107 } | 110 } |
| 108 | 111 |
| 109 @override | 112 @override |
| 110 void sendResponse(Response response) { | 113 void sendResponse(Response response) { |
| 111 // Don't send any further responses after the communication channel is | 114 // Don't send any further responses after the communication channel is |
| 112 // closed. | 115 // closed. |
| 113 if (_closed.isCompleted) { | 116 if (_closed.isCompleted) { |
| 114 return; | 117 return; |
| 115 } | 118 } |
| 116 output.writeln(JSON.encode(response.toJson())); | 119 ServerCommunicationChannel.ToJson.start(); |
| 120 String jsonEncoding = JSON.encode(response.toJson()); |
| 121 ServerCommunicationChannel.ToJson.stop(); |
| 122 output.writeln(jsonEncoding); |
| 117 } | 123 } |
| 118 | 124 |
| 119 /** | 125 /** |
| 120 * Read a request from the given [data] and use the given function to handle | 126 * Read a request from the given [data] and use the given function to handle |
| 121 * the request. | 127 * the request. |
| 122 */ | 128 */ |
| 123 void _readRequest(Object data, void onRequest(Request request)) { | 129 void _readRequest(Object data, void onRequest(Request request)) { |
| 124 // Ignore any further requests after the communication channel is closed. | 130 // Ignore any further requests after the communication channel is closed. |
| 125 if (_closed.isCompleted) { | 131 if (_closed.isCompleted) { |
| 126 return; | 132 return; |
| 127 } | 133 } |
| 128 // Parse the string as a JSON descriptor and process the resulting | 134 // Parse the string as a JSON descriptor and process the resulting |
| 129 // structure as a request. | 135 // structure as a request. |
| 136 ServerCommunicationChannel.FromJson.start(); |
| 130 Request request = new Request.fromString(data); | 137 Request request = new Request.fromString(data); |
| 138 ServerCommunicationChannel.FromJson.stop(); |
| 131 if (request == null) { | 139 if (request == null) { |
| 132 sendResponse(new Response.invalidRequestFormat()); | 140 sendResponse(new Response.invalidRequestFormat()); |
| 133 return; | 141 return; |
| 134 } | 142 } |
| 135 onRequest(request); | 143 onRequest(request); |
| 136 } | 144 } |
| 137 } | 145 } |
| OLD | NEW |