| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Future that will be completed when the input stream is closed. | 75 * Future that will be completed when the input stream is closed. |
| 76 */ | 76 */ |
| 77 Future get closed { | 77 Future get closed { |
| 78 return _closed.future; | 78 return _closed.future; |
| 79 } | 79 } |
| 80 | 80 |
| 81 @override | 81 @override |
| 82 void close() { | 82 void close() { |
| 83 if (!_closed.isCompleted) { | 83 output.flush().then((_) { |
| 84 _closed.complete(); | 84 if (!_closed.isCompleted) { |
| 85 } | 85 _closed.complete(); |
| 86 } |
| 87 }); |
| 86 } | 88 } |
| 87 | 89 |
| 88 @override | 90 @override |
| 89 void listen(void onRequest(Request request), {Function onError, void | 91 void listen(void onRequest(Request request), {Function onError, void |
| 90 onDone()}) { | 92 onDone()}) { |
| 91 input.transform((new Utf8Codec()).decoder).transform(new LineSplitter() | 93 input.transform((new Utf8Codec()).decoder).transform(new LineSplitter() |
| 92 ).listen((String data) => _readRequest(data, onRequest), onError: onErro
r, | 94 ).listen((String data) => _readRequest(data, onRequest), onError: onErro
r, |
| 93 onDone: () { | 95 onDone: () { |
| 94 close(); | 96 close(); |
| 95 onDone(); | 97 onDone(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 ServerCommunicationChannel.FromJson.start(); | 138 ServerCommunicationChannel.FromJson.start(); |
| 137 Request request = new Request.fromString(data); | 139 Request request = new Request.fromString(data); |
| 138 ServerCommunicationChannel.FromJson.stop(); | 140 ServerCommunicationChannel.FromJson.stop(); |
| 139 if (request == null) { | 141 if (request == null) { |
| 140 sendResponse(new Response.invalidRequestFormat()); | 142 sendResponse(new Response.invalidRequestFormat()); |
| 141 return; | 143 return; |
| 142 } | 144 } |
| 143 onRequest(request); | 145 onRequest(request); |
| 144 } | 146 } |
| 145 } | 147 } |
| OLD | NEW |