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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { | 217 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { |
218 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); | 218 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); |
219 intptr_t socket = | 219 intptr_t socket = |
220 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 220 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
221 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 221 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
222 ASSERT(Dart_IsList(buffer_obj)); | 222 ASSERT(Dart_IsList(buffer_obj)); |
223 intptr_t offset = | 223 intptr_t offset = |
224 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); | 224 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
225 intptr_t length = | 225 intptr_t length = |
226 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); | 226 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); |
| 227 bool short_write = false; |
227 if (short_socket_writes) { | 228 if (short_socket_writes) { |
| 229 if (length > 1) short_write = true; |
228 length = (length + 1) / 2; | 230 length = (length + 1) / 2; |
229 } | 231 } |
230 Dart_TypedData_Type type; | 232 Dart_TypedData_Type type; |
231 uint8_t* buffer = NULL; | 233 uint8_t* buffer = NULL; |
232 intptr_t len; | 234 intptr_t len; |
233 Dart_Handle result = Dart_TypedDataAcquireData( | 235 Dart_Handle result = Dart_TypedDataAcquireData( |
234 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); | 236 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); |
235 if (Dart_IsError(result)) Dart_PropagateError(result); | 237 if (Dart_IsError(result)) Dart_PropagateError(result); |
236 ASSERT((offset + length) <= len); | 238 ASSERT((offset + length) <= len); |
237 buffer += offset; | 239 buffer += offset; |
238 intptr_t bytes_written = Socket::Write(socket, buffer, length); | 240 intptr_t bytes_written = Socket::Write(socket, buffer, length); |
239 if (bytes_written >= 0) { | 241 if (bytes_written >= 0) { |
240 Dart_TypedDataReleaseData(buffer_obj); | 242 Dart_TypedDataReleaseData(buffer_obj); |
241 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 243 if (short_write) { |
| 244 // If the write was forced 'short', indicate by returning the negative |
| 245 // number of bytes. A forced short write may not trigger a write event. |
| 246 Dart_SetReturnValue(args, Dart_NewInteger(-bytes_written)); |
| 247 } else { |
| 248 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 249 } |
242 } else { | 250 } else { |
243 // Extract OSError before we release data, as it may override the error. | 251 // Extract OSError before we release data, as it may override the error. |
244 OSError os_error; | 252 OSError os_error; |
245 Dart_TypedDataReleaseData(buffer_obj); | 253 Dart_TypedDataReleaseData(buffer_obj); |
246 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 254 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
247 } | 255 } |
248 } | 256 } |
249 | 257 |
250 | 258 |
251 void FUNCTION_NAME(Socket_SendTo)(Dart_NativeArguments args) { | 259 void FUNCTION_NAME(Socket_SendTo)(Dart_NativeArguments args) { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { | 698 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { |
691 intptr_t socket = 0; | 699 intptr_t socket = 0; |
692 Dart_Handle err = | 700 Dart_Handle err = |
693 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); | 701 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); |
694 if (Dart_IsError(err)) Dart_PropagateError(err); | 702 if (Dart_IsError(err)) Dart_PropagateError(err); |
695 return socket; | 703 return socket; |
696 } | 704 } |
697 | 705 |
698 } // namespace bin | 706 } // namespace bin |
699 } // namespace dart | 707 } // namespace dart |
OLD | NEW |