Files
sdk/runtime/bin/stdio.dart
T
sgjesse@google.com b4d571dcdd Handle stdio redirection in standalone VM
The recent change to epoll on Linux and kqueue on Mac OS for getting
notifications from file descriptors caused the redirection of stdin,
stdout and stderr for the stand alone VM to stop working.

On Linux epoll failed when file descriptor 0, 1 or 2 redirected from
or to a file war registered. On Mac OS there was just no events
generated from kqueue.

The streams created for stdio, stdout and stderr is now of the correct
type and for file redirections no longer a socket object holding a
file descriptor for a regular file.

Added testing of stdio redirection using both pipes and files. These
tests are currently skipped on Windows.

Fixed handlin of short socket read when reading the process exit code.

Always close the socket port when not waiting for any events.

R=iposva@google.com

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9360040

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4226 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-14 15:20:27 +00:00

72 lines
1.8 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
final int _STDIO_HANDLE_TYPE_TERMINAL = 0;
final int _STDIO_HANDLE_TYPE_PIPE = 1;
final int _STDIO_HANDLE_TYPE_FILE = 2;
final int _STDIO_HANDLE_TYPE_OTHER = 3;
InputStream _stdin;
OutputStream _stdout;
OutputStream _stderr;
InputStream _getStdioInputStream() {
switch (_getStdioHandleType(0)) {
case _STDIO_HANDLE_TYPE_TERMINAL:
case _STDIO_HANDLE_TYPE_PIPE:
Socket s = new _Socket._internalReadOnly();
_getStdioHandle(s, 0);
return s.inputStream;
case _STDIO_HANDLE_TYPE_FILE:
return new _FileInputStream.fromStdio(0);
default:
throw new FileIOException("Unsupported stdin type");
}
}
OutputStream _getStdioOutputStream(int fd) {
assert(fd == 1 || fd == 2);
switch (_getStdioHandleType(fd)) {
case _STDIO_HANDLE_TYPE_TERMINAL:
case _STDIO_HANDLE_TYPE_PIPE:
Socket s = new _Socket._internalWriteOnly();
_getStdioHandle(s, fd);
return s.outputStream;
case _STDIO_HANDLE_TYPE_FILE:
return new _FileOutputStream.fromStdio(fd);
default:
throw new FileIOException("Unsupported stdin type");
}
}
InputStream get stdin() {
if (_stdin == null) {
_stdin = _getStdioInputStream();
}
return _stdin;
}
OutputStream get stdout() {
if (_stdout == null) {
_stdout = _getStdioOutputStream(1);
}
return _stdout;
}
OutputStream get stderr() {
if (_stderr == null) {
_stderr = _getStdioOutputStream(2);
}
return _stderr;
}
_getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle";
_getStdioHandleType(int num) native "File_GetStdioHandleType";