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

Unified Diff: runtime/bin/socket.cc

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 | « no previous file | runtime/bin/socket_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket.cc
diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc
index a5e64dd2095f712c06bc49b5ae86eb603353494e..0d07897ea18d62d852d5c62757dd76c2f11c1296 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -149,12 +149,19 @@ void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) {
intptr_t bytes_read = Socket::Read(socket, buffer, length);
if (bytes_read == length) {
Dart_SetReturnValue(args, result);
- } else if (bytes_read == 0) {
- // On MacOS when reading from a tty Ctrl-D will result in one
- // byte reported as available. Attempting to read it out will
- // result in zero bytes read. When that happens there is no
- // data which is indicated by a null return value.
- Dart_SetReturnValue(args, Dart_Null());
+ } else if (bytes_read < length) {
+ // On MacOS when reading from a tty Ctrl-D will result in reading one
+ // less byte then reported as available.
+ if (bytes_read == 0) {
+ Dart_SetReturnValue(args, Dart_Null());
+ } else {
+ uint8_t* new_buffer = NULL;
+ Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer);
+ if (Dart_IsError(new_result)) Dart_PropagateError(new_result);
+ ASSERT(new_buffer != NULL);
+ memmove(new_buffer, buffer, bytes_read);
+ Dart_SetReturnValue(args, new_result);
+ }
} else {
ASSERT(bytes_read == -1);
Dart_SetReturnValue(args, DartUtils::NewDartOSError());
« no previous file with comments | « no previous file | runtime/bin/socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698