| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 169 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 170 if (Dart_IsError(result)) { | 170 if (Dart_IsError(result)) { |
| 171 Dart_PropagateError(result); | 171 Dart_PropagateError(result); |
| 172 } | 172 } |
| 173 ASSERT((offset + length) <= buffer_len); | 173 ASSERT((offset + length) <= buffer_len); |
| 174 | 174 |
| 175 if (Dart_IsVMFlagSet("short_socket_write")) { | 175 if (Dart_IsVMFlagSet("short_socket_write")) { |
| 176 length = (length + 1) / 2; | 176 length = (length + 1) / 2; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Send data in chunks of maximum 16KB. | |
| 180 const intptr_t max_chunk_length = | |
| 181 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); | |
| 182 uint8_t* buffer = new uint8_t[max_chunk_length]; | |
| 183 intptr_t total_bytes_written = 0; | 179 intptr_t total_bytes_written = 0; |
| 184 intptr_t bytes_written = 0; | 180 intptr_t bytes_written = 0; |
| 185 do { | 181 if (Dart_IsByteArrayExternal(buffer_obj)) { |
| 186 intptr_t chunk_length = | 182 void* buffer = NULL; |
| 187 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); | 183 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); |
| 188 result = Dart_ListGetAsBytes(buffer_obj, | |
| 189 offset + total_bytes_written, | |
| 190 buffer, | |
| 191 chunk_length); | |
| 192 if (Dart_IsError(result)) { | 184 if (Dart_IsError(result)) { |
| 193 delete[] buffer; | |
| 194 Dart_PropagateError(result); | 185 Dart_PropagateError(result); |
| 195 } | 186 } |
| 196 bytes_written = | 187 bytes_written = Socket::Write(socket, buffer, length); |
| 197 Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length); | 188 total_bytes_written = bytes_written; |
| 198 total_bytes_written += bytes_written; | 189 } else { |
| 199 } while (bytes_written > 0 && total_bytes_written < length); | 190 // Send data in chunks of maximum 16KB. |
| 200 delete[] buffer; | 191 const intptr_t max_chunk_length = |
| 192 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); |
| 193 uint8_t* buffer = new uint8_t[max_chunk_length]; |
| 194 do { |
| 195 intptr_t chunk_length = |
| 196 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); |
| 197 result = Dart_ListGetAsBytes(buffer_obj, |
| 198 offset + total_bytes_written, |
| 199 buffer, |
| 200 chunk_length); |
| 201 if (Dart_IsError(result)) { |
| 202 delete[] buffer; |
| 203 Dart_PropagateError(result); |
| 204 } |
| 205 bytes_written = |
| 206 Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length); |
| 207 total_bytes_written += bytes_written; |
| 208 } while (bytes_written > 0 && total_bytes_written < length); |
| 209 delete[] buffer; |
| 210 } |
| 201 if (bytes_written >= 0) { | 211 if (bytes_written >= 0) { |
| 202 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); | 212 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); |
| 203 } else { | 213 } else { |
| 204 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 214 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 205 } | 215 } |
| 206 Dart_ExitScope(); | 216 Dart_ExitScope(); |
| 207 } | 217 } |
| 208 | 218 |
| 209 | 219 |
| 210 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { | 220 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 413 |
| 404 | 414 |
| 405 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { | 415 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { |
| 406 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 416 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 407 } | 417 } |
| 408 | 418 |
| 409 | 419 |
| 410 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 420 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 411 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 421 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 412 } | 422 } |
| OLD | NEW |