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

Unified Diff: runtime/bin/socket_stream.dart

Issue 8533005: Better handling of stdin/stdout/stderr (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fix Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/socket_stream.dart
diff --git a/runtime/bin/socket_stream.dart b/runtime/bin/socket_stream.dart
index e3d0d725a3fae66337efbfd6e6965932ad4a6034..57e6e998d235f57bb7486ed60dbef8d271d50100 100644
--- a/runtime/bin/socket_stream.dart
+++ b/runtime/bin/socket_stream.dart
@@ -3,9 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
class SocketInputStream implements InputStream {
- SocketInputStream(Socket socket) {
- _socket = socket;
- }
+ SocketInputStream(Socket socket) : _socket = socket;
List<int> read([int len]) {
int bytesToRead = available();
@@ -56,10 +54,7 @@ class SocketInputStream implements InputStream {
class SocketOutputStream implements OutputStream {
SocketOutputStream(Socket socket)
- : _socket = socket, _pendingWrites = new _BufferList() {
- _socket.writeHandler = _writeHandler;
- _socket.errorHandler = _errorHandler;
- }
+ : _socket = socket, _pendingWrites = new _BufferList();
bool write(List<int> buffer, [bool copyBuffer = true]) {
return _write(buffer, 0, buffer.length, copyBuffer);
@@ -91,7 +86,9 @@ class SocketOutputStream implements OutputStream {
void set noPendingWriteHandler(void callback()) {
_noPendingWriteHandler = callback;
- _socket.writeHandler = _writeHandler;
+ if (_noPendingWriteHandler != null) {
+ _socket.writeHandler = _writeHandler;
+ }
}
void set closeHandler(void callback()) {
@@ -100,6 +97,11 @@ class SocketOutputStream implements OutputStream {
void set errorHandler(void callback()) {
_streamErrorHandler = callback;
+ if (_streamErrorHandler != null) {
+ _socket.errorHandler = _errorHandler;
+ } else {
+ _socket.errorHandler = null;
+ }
}
bool _write(List<int> buffer, int offset, int len, bool copyBuffer) {
@@ -122,6 +124,7 @@ class SocketOutputStream implements OutputStream {
assert(offset + len == buffer.length);
_pendingWrites.add(buffer, notWrittenOffset);
}
+ _socket.writeHandler = _writeHandler;
}
void _writeHandler() {
@@ -145,6 +148,7 @@ class SocketOutputStream implements OutputStream {
} else {
if (_noPendingWriteHandler != null) _noPendingWriteHandler();
}
+ if (_noPendingWriteHandler == null) _socket.writeHandler = null;
}
void _errorHandler() {

Powered by Google App Engine
This is Rietveld 408576698