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

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: Removed tabs 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 | « no previous file | 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 d9886117023cf22f8eee06128db1f09f727474c6..97e8195a8ef094cf182d518f33dc129365d43b9a 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -1024,8 +1024,23 @@ class _Socket extends Stream<List<int>> implements Socket {
void _onData(event) {
switch (event) {
case RawSocketEvent.READ:
- var buffer = _raw.read();
- if (buffer != null) _controller.add(buffer);
+ // On Mac OS the end of file on stdin, when connected to a terminal,
+ // is detected by readling less bytes than available on the socket. A
+ // Ctrl-D does not generate a read close event.
+ if (Platform.operatingSystem == "macos") {
Anders Johnsen 2013/06/20 12:10:48 Platform.isMacos :)
Søren Gjesse 2013/06/25 10:17:41 Done (that was actually why I added isMacOS to Pla
+ var available = _raw.available();
+ if (available == 0) return;
+ var buffer = _raw.read();
+ if (buffer != null) _controller.add(buffer);
+ // If less bytes than available was read this is end of file.
+ if (buffer == null || buffer.length < available) {
+ _controllerClosed = true;
+ _controller.close();
+ }
+ } else {
+ var buffer = _raw.read();
+ if (buffer != null) _controller.add(buffer);
+ }
break;
case RawSocketEvent.WRITE:
_consumer.write();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698