| 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());
|
|
|