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

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

Issue 10962012: Use native wrapper fields to store socket ids. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
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 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 (_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 _getStdioHandle(s, 0);
24 s._closed = false;
24 return s.inputStream; 25 return s.inputStream;
25 case _STDIO_HANDLE_TYPE_FILE: 26 case _STDIO_HANDLE_TYPE_FILE:
26 return new _FileInputStream.fromStdio(0); 27 return new _FileInputStream.fromStdio(0);
27 default: 28 default:
28 throw new FileIOException("Unsupported stdin type"); 29 throw new FileIOException("Unsupported stdin type");
29 } 30 }
30 } 31 }
31 32
32 33
33 OutputStream _getStdioOutputStream(int fd) { 34 OutputStream _getStdioOutputStream(int fd) {
34 assert(fd == 1 || fd == 2); 35 assert(fd == 1 || fd == 2);
35 switch (_getStdioHandleType(fd)) { 36 switch (_getStdioHandleType(fd)) {
36 case _STDIO_HANDLE_TYPE_TERMINAL: 37 case _STDIO_HANDLE_TYPE_TERMINAL:
37 case _STDIO_HANDLE_TYPE_PIPE: 38 case _STDIO_HANDLE_TYPE_PIPE:
38 case _STDIO_HANDLE_TYPE_SOCKET: 39 case _STDIO_HANDLE_TYPE_SOCKET:
39 Socket s = new _Socket._internalWriteOnly(); 40 Socket s = new _Socket._internalWriteOnly();
40 _getStdioHandle(s, fd); 41 _getStdioHandle(s, fd);
42 s._closed = false;
41 return s.outputStream; 43 return s.outputStream;
42 case _STDIO_HANDLE_TYPE_FILE: 44 case _STDIO_HANDLE_TYPE_FILE:
43 return new _FileOutputStream.fromStdio(fd); 45 return new _FileOutputStream.fromStdio(fd);
44 default: 46 default:
45 throw new FileIOException("Unsupported stdin type"); 47 throw new FileIOException("Unsupported stdin type");
46 } 48 }
47 } 49 }
48 50
49 51
50 InputStream get stdin { 52 InputStream get stdin {
(...skipping 14 matching lines...) Expand all
65 67
66 OutputStream get stderr { 68 OutputStream get stderr {
67 if (_stderr == null) { 69 if (_stderr == null) {
68 _stderr = _getStdioOutputStream(2); 70 _stderr = _getStdioOutputStream(2);
69 } 71 }
70 return _stderr; 72 return _stderr;
71 } 73 }
72 74
73 _getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle"; 75 _getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle";
74 _getStdioHandleType(int num) native "File_GetStdioHandleType"; 76 _getStdioHandleType(int num) native "File_GetStdioHandleType";
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698