| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 Dart_PropagateError(result); | 173 Dart_PropagateError(result); |
| 174 } | 174 } |
| 175 ASSERT((offset + length) <= buffer_len); | 175 ASSERT((offset + length) <= buffer_len); |
| 176 | 176 |
| 177 if (short_socket_writes) { | 177 if (short_socket_writes) { |
| 178 length = (length + 1) / 2; | 178 length = (length + 1) / 2; |
| 179 } | 179 } |
| 180 | 180 |
| 181 intptr_t total_bytes_written = 0; | 181 intptr_t total_bytes_written = 0; |
| 182 intptr_t bytes_written = 0; | 182 intptr_t bytes_written = 0; |
| 183 if (Dart_IsByteArrayExternal(buffer_obj)) { | 183 if (Dart_IsExternalTypedData(buffer_obj) != kInvalid) { |
| 184 Dart_TypedData_Type type; |
| 184 void* buffer = NULL; | 185 void* buffer = NULL; |
| 185 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); | 186 intptr_t len; |
| 187 result = Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &len); |
| 186 if (Dart_IsError(result)) { | 188 if (Dart_IsError(result)) { |
| 187 Dart_PropagateError(result); | 189 Dart_PropagateError(result); |
| 188 } | 190 } |
| 189 buffer = static_cast<void*>((static_cast<uint8_t*>(buffer) + offset)); | 191 buffer = static_cast<void*>((static_cast<uint8_t*>(buffer) + offset)); |
| 190 bytes_written = Socket::Write(socket, buffer, length); | 192 bytes_written = Socket::Write(socket, buffer, length); |
| 191 if (bytes_written > 0) total_bytes_written = bytes_written; | 193 if (bytes_written > 0) total_bytes_written = bytes_written; |
| 194 Dart_TypedDataReleaseData(buffer_obj); |
| 192 } else { | 195 } else { |
| 193 // Send data in chunks of maximum 16KB. | 196 // Send data in chunks of maximum 16KB. |
| 194 const intptr_t max_chunk_length = | 197 const intptr_t max_chunk_length = |
| 195 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); | 198 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); |
| 196 uint8_t* buffer = new uint8_t[max_chunk_length]; | 199 uint8_t* buffer = new uint8_t[max_chunk_length]; |
| 197 do { | 200 do { |
| 198 intptr_t chunk_length = | 201 intptr_t chunk_length = |
| 199 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); | 202 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); |
| 200 result = Dart_ListGetAsBytes(buffer_obj, | 203 result = Dart_ListGetAsBytes(buffer_obj, |
| 201 offset + total_bytes_written, | 204 offset + total_bytes_written, |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 435 |
| 433 | 436 |
| 434 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { | 437 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { |
| 435 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 438 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 436 } | 439 } |
| 437 | 440 |
| 438 | 441 |
| 439 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 442 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 440 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 443 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 441 } | 444 } |
| OLD | NEW |