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

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

Issue 11773041: Add function for finding what a InputStream or OutputStream is attached to (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « runtime/bin/stdio_patch.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) 2012, 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;
11 const int _STDIO_HANDLE_TYPE_OTHER = -1; 11 const int _STDIO_HANDLE_TYPE_OTHER = -1;
12 12
13 13
14 class StdioType {
15 static const StdioType TERMINAL = const StdioType._("terminal");
16 static const StdioType PIPE = const StdioType._("pipe");
17 static const StdioType FILE = const StdioType._("file");
18 static const StdioType OTHER = const StdioType._("other");
19 const StdioType._(String this.name);
20 final String name;
21 }
22
23
14 InputStream _stdin; 24 InputStream _stdin;
15 OutputStream _stdout; 25 OutputStream _stdout;
16 OutputStream _stderr; 26 OutputStream _stderr;
17 27
18 28
19 InputStream get stdin { 29 InputStream get stdin {
20 if (_stdin == null) { 30 if (_stdin == null) {
21 _stdin = _StdIOUtils._getStdioInputStream(); 31 _stdin = _StdIOUtils._getStdioInputStream();
22 } 32 }
23 return _stdin; 33 return _stdin;
24 } 34 }
25 35
26 36
27 OutputStream get stdout { 37 OutputStream get stdout {
28 if (_stdout == null) { 38 if (_stdout == null) {
29 _stdout = _StdIOUtils._getStdioOutputStream(1); 39 _stdout = _StdIOUtils._getStdioOutputStream(1);
30 } 40 }
31 return _stdout; 41 return _stdout;
32 } 42 }
33 43
34 44
35 OutputStream get stderr { 45 OutputStream get stderr {
36 if (_stderr == null) { 46 if (_stderr == null) {
37 _stderr = _StdIOUtils._getStdioOutputStream(2); 47 _stderr = _StdIOUtils._getStdioOutputStream(2);
38 } 48 }
39 return _stderr; 49 return _stderr;
40 } 50 }
41 51
42 52
53 StdioType stdioType(object) {
54 if (object is _FileOutputStream || object is _FileInputStream) {
55 return StdioType.FILE;
56 }
57 if (object is !_SocketOutputStream && object is !_SocketInputStream) {
58 return StdioType.OTHER;
59 }
60 switch (_StdIOUtils._socketType(object._socket)) {
61 case _STDIO_HANDLE_TYPE_TERMINAL: return StdioType.TERMINAL;
62 case _STDIO_HANDLE_TYPE_PIPE: return StdioType.PIPE;
63 case _STDIO_HANDLE_TYPE_FILE: return StdioType.FILE;
64 default: return StdioType.OTHER;
65 }
66 }
67
68
43 class _StdIOUtils { 69 class _StdIOUtils {
44 external static OutputStream _getStdioOutputStream(int fd); 70 external static OutputStream _getStdioOutputStream(int fd);
45 external static InputStream _getStdioInputStream(); 71 external static InputStream _getStdioInputStream();
72 external static int _socketType(Socket socket);
46 } 73 }
OLDNEW
« no previous file with comments | « runtime/bin/stdio_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698