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 |
| 11 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
11 import 'package:analysis_server/src/analysis_server.dart'; | 12 import 'package:analysis_server/src/analysis_server.dart'; |
12 import 'package:analysis_server/src/channel/channel.dart'; | 13 import 'package:analysis_server/src/channel/channel.dart'; |
13 import 'package:analysis_server/src/protocol.dart'; | |
14 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
15 | 15 |
16 /** | 16 /** |
17 * Instances of the class [ByteStreamClientChannel] implement a | 17 * Instances of the class [ByteStreamClientChannel] implement a |
18 * [ClientCommunicationChannel] that uses a stream and a sink (typically, | 18 * [ClientCommunicationChannel] that uses a stream and a sink (typically, |
19 * standard input and standard output) to communicate with servers. | 19 * standard input and standard output) to communicate with servers. |
20 */ | 20 */ |
21 class ByteStreamClientChannel implements ClientCommunicationChannel { | 21 class ByteStreamClientChannel implements ClientCommunicationChannel { |
22 final Stream input; | 22 final Stream input; |
23 final IOSink output; | 23 final IOSink output; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if (!_closeRequested) { | 98 if (!_closeRequested) { |
99 _closeRequested = true; | 99 _closeRequested = true; |
100 assert(!_closed.isCompleted); | 100 assert(!_closed.isCompleted); |
101 _closed.complete(); | 101 _closed.complete(); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 @override | 105 @override |
106 void listen(void onRequest(Request request), | 106 void listen(void onRequest(Request request), |
107 {Function onError, void onDone()}) { | 107 {Function onError, void onDone()}) { |
108 _input | 108 _input.transform(const Utf8Decoder()).transform(new LineSplitter()).listen( |
109 .transform(const Utf8Decoder()) | 109 (String data) => _readRequest(data, onRequest), |
110 .transform(new LineSplitter()) | 110 onError: onError, onDone: () { |
111 .listen((String data) => _readRequest(data, onRequest), | |
112 onError: onError, onDone: () { | |
113 close(); | 111 close(); |
114 onDone(); | 112 onDone(); |
115 }); | 113 }); |
116 } | 114 } |
117 | 115 |
118 @override | 116 @override |
119 void sendNotification(Notification notification) { | 117 void sendNotification(Notification notification) { |
120 // Don't send any further notifications after the communication channel is | 118 // Don't send any further notifications after the communication channel is |
121 // closed. | 119 // closed. |
122 if (_closeRequested) { | 120 if (_closeRequested) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // structure as a request. | 163 // structure as a request. |
166 Request request = new Request.fromString(data); | 164 Request request = new Request.fromString(data); |
167 if (request == null) { | 165 if (request == null) { |
168 sendResponse(new Response.invalidRequestFormat()); | 166 sendResponse(new Response.invalidRequestFormat()); |
169 return; | 167 return; |
170 } | 168 } |
171 onRequest(request); | 169 onRequest(request); |
172 }); | 170 }); |
173 } | 171 } |
174 } | 172 } |
OLD | NEW |