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/isolate_data.h" | 6 #include "bin/isolate_data.h" |
7 #include "bin/socket.h" | 7 #include "bin/socket.h" |
8 #include "bin/dartutils.h" | 8 #include "bin/dartutils.h" |
9 #include "bin/thread.h" | 9 #include "bin/thread.h" |
10 #include "bin/utils.h" | 10 #include "bin/utils.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (short_socket_reads) { | 104 if (short_socket_reads) { |
105 length = (length + 1) / 2; | 105 length = (length + 1) / 2; |
106 } | 106 } |
107 uint8_t* buffer = NULL; | 107 uint8_t* buffer = NULL; |
108 Dart_Handle result = IOBuffer::Allocate(length, &buffer); | 108 Dart_Handle result = IOBuffer::Allocate(length, &buffer); |
109 if (Dart_IsError(result)) Dart_PropagateError(result); | 109 if (Dart_IsError(result)) Dart_PropagateError(result); |
110 ASSERT(buffer != NULL); | 110 ASSERT(buffer != NULL); |
111 intptr_t bytes_read = Socket::Read(socket, buffer, length); | 111 intptr_t bytes_read = Socket::Read(socket, buffer, length); |
112 if (bytes_read == length) { | 112 if (bytes_read == length) { |
113 Dart_SetReturnValue(args, result); | 113 Dart_SetReturnValue(args, result); |
114 } else if (bytes_read < length) { | 114 } else if (bytes_read > 0) { |
| 115 uint8_t* new_buffer = NULL; |
| 116 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); |
| 117 if (Dart_IsError(new_result)) Dart_PropagateError(new_result); |
| 118 ASSERT(new_buffer != NULL); |
| 119 memmove(new_buffer, buffer, bytes_read); |
| 120 Dart_SetReturnValue(args, new_result); |
| 121 } else if (bytes_read == 0) { |
115 // On MacOS when reading from a tty Ctrl-D will result in reading one | 122 // On MacOS when reading from a tty Ctrl-D will result in reading one |
116 // less byte then reported as available. | 123 // less byte then reported as available. |
117 if (bytes_read == 0) { | 124 Dart_SetReturnValue(args, Dart_Null()); |
118 Dart_SetReturnValue(args, Dart_Null()); | |
119 } else { | |
120 uint8_t* new_buffer = NULL; | |
121 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); | |
122 if (Dart_IsError(new_result)) Dart_PropagateError(new_result); | |
123 ASSERT(new_buffer != NULL); | |
124 memmove(new_buffer, buffer, bytes_read); | |
125 Dart_SetReturnValue(args, new_result); | |
126 } | |
127 } else { | 125 } else { |
128 ASSERT(bytes_read == -1); | 126 ASSERT(bytes_read == -1); |
129 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 127 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
130 } | 128 } |
131 } else { | 129 } else { |
132 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 130 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
133 Dart_Handle err = DartUtils::NewDartOSError(&os_error); | 131 Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
134 if (Dart_IsError(err)) Dart_PropagateError(err); | 132 if (Dart_IsError(err)) Dart_PropagateError(err); |
135 Dart_SetReturnValue(args, err); | 133 Dart_SetReturnValue(args, err); |
136 } | 134 } |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { | 686 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { |
689 intptr_t socket = 0; | 687 intptr_t socket = 0; |
690 Dart_Handle err = | 688 Dart_Handle err = |
691 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); | 689 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); |
692 if (Dart_IsError(err)) Dart_PropagateError(err); | 690 if (Dart_IsError(err)) Dart_PropagateError(err); |
693 return socket; | 691 return socket; |
694 } | 692 } |
695 | 693 |
696 } // namespace bin | 694 } // namespace bin |
697 } // namespace dart | 695 } // namespace dart |
OLD | NEW |