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) { |
Søren Gjesse
2014/02/18 14:28:00
Can we post a write event instead of this "trick"?
Anders Johnsen
2014/02/19 09:43:03
It's extremely custom how we post such an event. I
| |
244 Dart_SetReturnValue(args, Dart_NewInteger(-bytes_written)); | |
245 } else { | |
246 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | |
247 } | |
242 } else { | 248 } else { |
243 // Extract OSError before we release data, as it may override the error. | 249 // Extract OSError before we release data, as it may override the error. |
244 OSError os_error; | 250 OSError os_error; |
245 Dart_TypedDataReleaseData(buffer_obj); | 251 Dart_TypedDataReleaseData(buffer_obj); |
246 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 252 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
247 } | 253 } |
248 } | 254 } |
249 | 255 |
250 | 256 |
251 void FUNCTION_NAME(Socket_SendTo)(Dart_NativeArguments args) { | 257 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) { | 696 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { |
691 intptr_t socket = 0; | 697 intptr_t socket = 0; |
692 Dart_Handle err = | 698 Dart_Handle err = |
693 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); | 699 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); |
694 if (Dart_IsError(err)) Dart_PropagateError(err); | 700 if (Dart_IsError(err)) Dart_PropagateError(err); |
695 return socket; | 701 return socket; |
696 } | 702 } |
697 | 703 |
698 } // namespace bin | 704 } // namespace bin |
699 } // namespace dart | 705 } // namespace dart |
OLD | NEW |