| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/io_buffer.h" | 5 #include "bin/io_buffer.h" |
| 6 #include "bin/socket.h" | 6 #include "bin/socket.h" |
| 7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
| 8 #include "bin/thread.h" | 8 #include "bin/thread.h" |
| 9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
| 10 | 10 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if (length == -1 || available < length) { | 142 if (length == -1 || available < length) { |
| 143 length = available; | 143 length = available; |
| 144 } | 144 } |
| 145 uint8_t* buffer = NULL; | 145 uint8_t* buffer = NULL; |
| 146 Dart_Handle result = IOBuffer::Allocate(length, &buffer); | 146 Dart_Handle result = IOBuffer::Allocate(length, &buffer); |
| 147 if (Dart_IsError(result)) Dart_PropagateError(result); | 147 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 148 ASSERT(buffer != NULL); | 148 ASSERT(buffer != NULL); |
| 149 intptr_t bytes_read = Socket::Read(socket, buffer, length); | 149 intptr_t bytes_read = Socket::Read(socket, buffer, length); |
| 150 if (bytes_read == length) { | 150 if (bytes_read == length) { |
| 151 Dart_SetReturnValue(args, result); | 151 Dart_SetReturnValue(args, result); |
| 152 } else if (bytes_read == 0) { | 152 } else if (bytes_read < length) { |
| 153 // On MacOS when reading from a tty Ctrl-D will result in one | 153 // On MacOS when reading from a tty Ctrl-D will result in reading one |
| 154 // byte reported as available. Attempting to read it out will | 154 // less byte then reported as available. |
| 155 // result in zero bytes read. When that happens there is no | 155 if (bytes_read == 0) { |
| 156 // data which is indicated by a null return value. | 156 Dart_SetReturnValue(args, Dart_Null()); |
| 157 Dart_SetReturnValue(args, Dart_Null()); | 157 } else { |
| 158 uint8_t* new_buffer = NULL; |
| 159 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); |
| 160 if (Dart_IsError(new_result)) Dart_PropagateError(new_result); |
| 161 ASSERT(new_buffer != NULL); |
| 162 memmove(new_buffer, buffer, bytes_read); |
| 163 Dart_SetReturnValue(args, new_result); |
| 164 } |
| 158 } else { | 165 } else { |
| 159 ASSERT(bytes_read == -1); | 166 ASSERT(bytes_read == -1); |
| 160 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 167 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 161 } | 168 } |
| 162 } else { | 169 } else { |
| 163 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 170 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 164 Dart_Handle err = DartUtils::NewDartOSError(&os_error); | 171 Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
| 165 if (Dart_IsError(err)) Dart_PropagateError(err); | 172 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 166 Dart_SetReturnValue(args, err); | 173 Dart_SetReturnValue(args, err); |
| 167 } | 174 } |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 638 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 632 } | 639 } |
| 633 | 640 |
| 634 | 641 |
| 635 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 642 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 636 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 643 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 637 } | 644 } |
| 638 | 645 |
| 639 } // namespace bin | 646 } // namespace bin |
| 640 } // namespace dart | 647 } // namespace dart |
| OLD | NEW |