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

Side by Side Diff: runtime/bin/stdio.dart

Issue 9617012: Allow std{in,out,err} to be a socket (Closed)
Patch Set: Respond to review comments Created 8 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
« no previous file with comments | « runtime/bin/file_macos.cc ('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) 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 final int _STDIO_HANDLE_TYPE_TERMINAL = 0; 5 final int _STDIO_HANDLE_TYPE_TERMINAL = 0;
6 final int _STDIO_HANDLE_TYPE_PIPE = 1; 6 final int _STDIO_HANDLE_TYPE_PIPE = 1;
7 final int _STDIO_HANDLE_TYPE_FILE = 2; 7 final int _STDIO_HANDLE_TYPE_FILE = 2;
8 final int _STDIO_HANDLE_TYPE_OTHER = 3; 8 final int _STDIO_HANDLE_TYPE_SOCKET = 3;
9 final int _STDIO_HANDLE_TYPE_OTHER = -1;
9 10
10 11
11 InputStream _stdin; 12 InputStream _stdin;
12 OutputStream _stdout; 13 OutputStream _stdout;
13 OutputStream _stderr; 14 OutputStream _stderr;
14 15
15 16
16 InputStream _getStdioInputStream() { 17 InputStream _getStdioInputStream() {
17 switch (_getStdioHandleType(0)) { 18 switch (_getStdioHandleType(0)) {
18 case _STDIO_HANDLE_TYPE_TERMINAL: 19 case _STDIO_HANDLE_TYPE_TERMINAL:
19 case _STDIO_HANDLE_TYPE_PIPE: 20 case _STDIO_HANDLE_TYPE_PIPE:
21 case _STDIO_HANDLE_TYPE_SOCKET:
20 Socket s = new _Socket._internalReadOnly(); 22 Socket s = new _Socket._internalReadOnly();
21 _getStdioHandle(s, 0); 23 _getStdioHandle(s, 0);
22 return s.inputStream; 24 return s.inputStream;
23 case _STDIO_HANDLE_TYPE_FILE: 25 case _STDIO_HANDLE_TYPE_FILE:
24 return new _FileInputStream.fromStdio(0); 26 return new _FileInputStream.fromStdio(0);
25 default: 27 default:
26 throw new FileIOException("Unsupported stdin type"); 28 throw new FileIOException("Unsupported stdin type");
27 } 29 }
28 } 30 }
29 31
30 32
31 OutputStream _getStdioOutputStream(int fd) { 33 OutputStream _getStdioOutputStream(int fd) {
32 assert(fd == 1 || fd == 2); 34 assert(fd == 1 || fd == 2);
33 switch (_getStdioHandleType(fd)) { 35 switch (_getStdioHandleType(fd)) {
34 case _STDIO_HANDLE_TYPE_TERMINAL: 36 case _STDIO_HANDLE_TYPE_TERMINAL:
35 case _STDIO_HANDLE_TYPE_PIPE: 37 case _STDIO_HANDLE_TYPE_PIPE:
38 case _STDIO_HANDLE_TYPE_SOCKET:
36 Socket s = new _Socket._internalWriteOnly(); 39 Socket s = new _Socket._internalWriteOnly();
37 _getStdioHandle(s, fd); 40 _getStdioHandle(s, fd);
38 return s.outputStream; 41 return s.outputStream;
39 case _STDIO_HANDLE_TYPE_FILE: 42 case _STDIO_HANDLE_TYPE_FILE:
40 return new _FileOutputStream.fromStdio(fd); 43 return new _FileOutputStream.fromStdio(fd);
41 default: 44 default:
42 throw new FileIOException("Unsupported stdin type"); 45 throw new FileIOException("Unsupported stdin type");
43 } 46 }
44 } 47 }
45 48
(...skipping 16 matching lines...) Expand all
62 65
63 OutputStream get stderr() { 66 OutputStream get stderr() {
64 if (_stderr == null) { 67 if (_stderr == null) {
65 _stderr = _getStdioOutputStream(2); 68 _stderr = _getStdioOutputStream(2);
66 } 69 }
67 return _stderr; 70 return _stderr;
68 } 71 }
69 72
70 _getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle"; 73 _getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle";
71 _getStdioHandleType(int num) native "File_GetStdioHandleType"; 74 _getStdioHandleType(int num) native "File_GetStdioHandleType";
OLDNEW
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698