| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_IsByteArrayExternal(buffer_obj)) { |
| 184 void* buffer = NULL; | 184 void* buffer = NULL; |
| 185 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); | 185 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); |
| 186 if (Dart_IsError(result)) { | 186 if (Dart_IsError(result)) { |
| 187 Dart_PropagateError(result); | 187 Dart_PropagateError(result); |
| 188 } | 188 } |
| 189 bytes_written = Socket::Write(socket, buffer, length); | 189 bytes_written = Socket::Write(socket, buffer, length); |
| 190 total_bytes_written = bytes_written; | 190 if (bytes_written > 0) total_bytes_written = bytes_written; |
| 191 } else { | 191 } else { |
| 192 // Send data in chunks of maximum 16KB. | 192 // Send data in chunks of maximum 16KB. |
| 193 const intptr_t max_chunk_length = | 193 const intptr_t max_chunk_length = |
| 194 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); | 194 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); |
| 195 uint8_t* buffer = new uint8_t[max_chunk_length]; | 195 uint8_t* buffer = new uint8_t[max_chunk_length]; |
| 196 do { | 196 do { |
| 197 intptr_t chunk_length = | 197 intptr_t chunk_length = |
| 198 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); | 198 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); |
| 199 result = Dart_ListGetAsBytes(buffer_obj, | 199 result = Dart_ListGetAsBytes(buffer_obj, |
| 200 offset + total_bytes_written, | 200 offset + total_bytes_written, |
| 201 buffer, | 201 buffer, |
| 202 chunk_length); | 202 chunk_length); |
| 203 if (Dart_IsError(result)) { | 203 if (Dart_IsError(result)) { |
| 204 delete[] buffer; | 204 delete[] buffer; |
| 205 Dart_PropagateError(result); | 205 Dart_PropagateError(result); |
| 206 } | 206 } |
| 207 bytes_written = | 207 bytes_written = |
| 208 Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length); | 208 Socket::Write(socket, reinterpret_cast<void*>(buffer), chunk_length); |
| 209 total_bytes_written += bytes_written; | 209 if (bytes_written > 0) total_bytes_written += bytes_written; |
| 210 } while (bytes_written > 0 && total_bytes_written < length); | 210 } while (bytes_written > 0 && total_bytes_written < length); |
| 211 delete[] buffer; | 211 delete[] buffer; |
| 212 } | 212 } |
| 213 if (bytes_written >= 0) { | 213 if (bytes_written >= 0) { |
| 214 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); | 214 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); |
| 215 } else { | 215 } else { |
| 216 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 216 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 217 } | 217 } |
| 218 Dart_ExitScope(); | 218 Dart_ExitScope(); |
| 219 } | 219 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 415 |
| 416 | 416 |
| 417 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { | 417 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { |
| 418 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 418 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 419 } | 419 } |
| 420 | 420 |
| 421 | 421 |
| 422 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 422 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 423 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 423 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 424 } | 424 } |
| OLD | NEW |