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

Unified Diff: runtime/bin/socket_patch.dart

Issue 17463003: Detect EOF when reading stdio from terminal on Mac OS (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Final fixes Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_patch.dart
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart
index 3caf14806bc3f7f152d4248485e0a1a3ce8479a9..cd4d099fb2e7e2663052094f7b937c8deaaff26b 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -715,6 +715,9 @@ class _RawSocket extends Stream<RawSocketEvent>
bool _readEventsEnabled = true;
bool _writeEventsEnabled = true;
+ // Flag to handle Ctrl-D closing of stdio on Mac OS.
+ bool _isMacOSTerminalInput = false;
+
static Future<RawSocket> connect(host, int port) {
return _NativeSocket.connect(host, port)
.then((socket) => new _RawSocket(socket));
@@ -754,7 +757,11 @@ class _RawSocket extends Stream<RawSocketEvent>
var native = new _NativeSocket.pipe();
native.isClosedWrite = true;
if (fd != null) _getStdioHandle(native, fd);
- return new _RawSocket(native);
+ var result = new _RawSocket(native);
+ result._isMacOSTerminalInput =
+ Platform.isMacOS &&
+ _StdIOUtils._socketType(result) == _STDIO_HANDLE_TYPE_TERMINAL;
+ return result;
}
StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event),
@@ -770,7 +777,21 @@ class _RawSocket extends Stream<RawSocketEvent>
int available() => _socket.available();
- List<int> read([int len]) => _socket.read(len);
+ List<int> read([int len]) {
+ if (_isMacOSTerminalInput) {
+ var available = available();
+ if (available == 0) return null;
+ var data = _socket.read(len);
+ if (data == null || data.length < available) {
+ // Reading less than available from a Mac OS terminal indicate Ctrl-D.
+ // This is interpreted as read closed.
+ runAsync(() => _controller.add(RawSocketEvent.READ_CLOSED));
+ }
+ return data;
+ } else {
+ return _socket.read(len);
+ }
+ }
int write(List<int> buffer, [int offset, int count]) =>
_socket.write(buffer, offset, count);
« no previous file with comments | « runtime/bin/socket.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698