Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; | 5 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; |
| 6 const int _STDIO_HANDLE_TYPE_PIPE = 1; | 6 const int _STDIO_HANDLE_TYPE_PIPE = 1; |
| 7 const int _STDIO_HANDLE_TYPE_FILE = 2; | 7 const int _STDIO_HANDLE_TYPE_FILE = 2; |
| 8 const int _STDIO_HANDLE_TYPE_SOCKET = 3; | 8 const int _STDIO_HANDLE_TYPE_SOCKET = 3; |
| 9 const int _STDIO_HANDLE_TYPE_OTHER = -1; | 9 const int _STDIO_HANDLE_TYPE_OTHER = -1; |
| 10 | 10 |
| 11 | 11 |
| 12 InputStream _stdin; | 12 InputStream _stdin; |
| 13 OutputStream _stdout; | 13 OutputStream _stdout; |
| 14 OutputStream _stderr; | 14 OutputStream _stderr; |
| 15 | 15 |
| 16 | 16 |
| 17 InputStream _getStdioInputStream() { | 17 InputStream _getStdioInputStream() { |
| 18 switch (_getStdioHandleType(0)) { | 18 switch (_StdIOUtils._getStdioHandleType(0)) { |
| 19 case _STDIO_HANDLE_TYPE_TERMINAL: | 19 case _STDIO_HANDLE_TYPE_TERMINAL: |
| 20 case _STDIO_HANDLE_TYPE_PIPE: | 20 case _STDIO_HANDLE_TYPE_PIPE: |
| 21 case _STDIO_HANDLE_TYPE_SOCKET: | 21 case _STDIO_HANDLE_TYPE_SOCKET: |
| 22 Socket s = new _Socket._internalReadOnly(); | 22 Socket s = new _Socket._internalReadOnly(); |
| 23 _getStdioHandle(s, 0); | 23 _StdIOUtils._getStdioHandle(s, 0); |
| 24 s._closed = false; | 24 s._closed = false; |
| 25 return s.inputStream; | 25 return s.inputStream; |
| 26 case _STDIO_HANDLE_TYPE_FILE: | 26 case _STDIO_HANDLE_TYPE_FILE: |
| 27 return new _FileInputStream.fromStdio(0); | 27 return new _FileInputStream.fromStdio(0); |
| 28 default: | 28 default: |
| 29 throw new FileIOException("Unsupported stdin type"); | 29 throw new FileIOException("Unsupported stdin type"); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 OutputStream _getStdioOutputStream(int fd) { | 34 OutputStream _getStdioOutputStream(int fd) { |
| 35 assert(fd == 1 || fd == 2); | 35 assert(fd == 1 || fd == 2); |
| 36 switch (_getStdioHandleType(fd)) { | 36 switch (_StdIOUtils._getStdioHandleType(fd)) { |
| 37 case _STDIO_HANDLE_TYPE_TERMINAL: | 37 case _STDIO_HANDLE_TYPE_TERMINAL: |
| 38 case _STDIO_HANDLE_TYPE_PIPE: | 38 case _STDIO_HANDLE_TYPE_PIPE: |
| 39 case _STDIO_HANDLE_TYPE_SOCKET: | 39 case _STDIO_HANDLE_TYPE_SOCKET: |
| 40 Socket s = new _Socket._internalWriteOnly(); | 40 Socket s = new _Socket._internalWriteOnly(); |
| 41 _getStdioHandle(s, fd); | 41 _StdIOUtils._getStdioHandle(s, fd); |
| 42 s._closed = false; | 42 s._closed = false; |
| 43 return s.outputStream; | 43 return s.outputStream; |
| 44 case _STDIO_HANDLE_TYPE_FILE: | 44 case _STDIO_HANDLE_TYPE_FILE: |
| 45 return new _FileOutputStream.fromStdio(fd); | 45 return new _FileOutputStream.fromStdio(fd); |
| 46 default: | 46 default: |
| 47 throw new FileIOException("Unsupported stdin type"); | 47 throw new FileIOException("Unsupported stdin type"); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 65 } | 65 } |
| 66 | 66 |
| 67 | 67 |
| 68 OutputStream get stderr { | 68 OutputStream get stderr { |
| 69 if (_stderr == null) { | 69 if (_stderr == null) { |
| 70 _stderr = _getStdioOutputStream(2); | 70 _stderr = _getStdioOutputStream(2); |
| 71 } | 71 } |
| 72 return _stderr; | 72 return _stderr; |
| 73 } | 73 } |
| 74 | 74 |
| 75 _getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle"; | 75 |
| 76 _getStdioHandleType(int num) native "File_GetStdioHandleType"; | 76 class _StdIOUtils { |
|
Søren Gjesse
2012/10/30 09:28:32
TODO?
| |
| 77 external static _getStdioHandle(Socket socket, int num); | |
| 78 external static _getStdioHandleType(int num); | |
| 79 } | |
| OLD | NEW |