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

Side by Side Diff: sdk/lib/io/stdio.dart

Issue 195893012: Use a sync-writing StreamConsumer for stdout/stderr. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | 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 dart.io; 5 part of dart.io;
6 6
7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; 7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0;
8 const int _STDIO_HANDLE_TYPE_PIPE = 1; 8 const int _STDIO_HANDLE_TYPE_PIPE = 1;
9 const int _STDIO_HANDLE_TYPE_FILE = 2; 9 const int _STDIO_HANDLE_TYPE_FILE = 2;
10 const int _STDIO_HANDLE_TYPE_SOCKET = 3; 10 const int _STDIO_HANDLE_TYPE_SOCKET = 3;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 final OSError osError; 195 final OSError osError;
196 196
197 const StdoutException(this.message, [this.osError]); 197 const StdoutException(this.message, [this.osError]);
198 198
199 String toString() { 199 String toString() {
200 return "StdoutException: $message${osError == null ? "" : ", $osError"}"; 200 return "StdoutException: $message${osError == null ? "" : ", $osError"}";
201 } 201 }
202 } 202 }
203 203
204 204
205 class _StdConsumer implements StreamConsumer<List<int>> {
206 final _file;
207
208 _StdConsumer(int fd) : _file = _File._openStdioSync(fd);
209
210 Future addStream(Stream<List<int>> stream) {
211 var completer = new Completer();
212 var sub;
213 sub = stream.listen(
214 (data) {
215 try {
216 _file.writeFromSync(data);
217 } catch (e, s) {
218 sub.cancel();
219 completer.completeError(e, s);
220 }
221 },
222 onError: completer.completeError,
223 onDone: completer.complete,
224 cancelOnError: true);
225 return completer.future;
226 }
227
228 Future close() {
229 _file.closeSync();
230 return new Future.value();
231 }
232 }
233
234
205 class _StdSink implements IOSink { 235 class _StdSink implements IOSink {
206 final IOSink _sink; 236 final IOSink _sink;
207 237
208 _StdSink(this._sink); 238 _StdSink(this._sink);
209 239
210 Encoding get encoding => _sink.encoding; 240 Encoding get encoding => _sink.encoding;
211 void set encoding(Encoding encoding) { 241 void set encoding(Encoding encoding) {
212 _sink.encoding = encoding; 242 _sink.encoding = encoding;
213 } 243 }
214 void write(object) => _sink.write(object); 244 void write(object) => _sink.write(object);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return StdioType.OTHER; 332 return StdioType.OTHER;
303 } 333 }
304 334
305 335
306 class _StdIOUtils { 336 class _StdIOUtils {
307 external static _getStdioOutputStream(int fd); 337 external static _getStdioOutputStream(int fd);
308 external static Stdin _getStdioInputStream(); 338 external static Stdin _getStdioInputStream();
309 external static int _socketType(nativeSocket); 339 external static int _socketType(nativeSocket);
310 external static _getStdioHandleType(int fd); 340 external static _getStdioHandleType(int fd);
311 } 341 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698