| 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "bin/socket.h" | 7 #include "bin/socket.h" |
| 8 | 8 |
| 9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
| 10 #include "bin/io_buffer.h" | 10 #include "bin/io_buffer.h" |
| 11 #include "bin/isolate_data.h" | 11 #include "bin/isolate_data.h" |
| 12 #include "bin/lockers.h" | 12 #include "bin/lockers.h" |
| 13 #include "bin/thread.h" | 13 #include "bin/thread.h" |
| 14 #include "bin/utils.h" | 14 #include "bin/utils.h" |
| 15 | 15 |
| 16 #include "include/dart_api.h" | 16 #include "include/dart_api.h" |
| 17 | 17 |
| 18 #include "platform/globals.h" | 18 #include "platform/globals.h" |
| 19 #include "platform/utils.h" | 19 #include "platform/utils.h" |
| 20 | 20 |
| 21 namespace dart { | 21 namespace dart { |
| 22 namespace bin { | 22 namespace bin { |
| 23 | 23 |
| 24 static const int kSocketIdNativeField = 0; | 24 static const int kSocketIdNativeField = 0; |
| 25 | 25 |
| 26 ListeningSocketRegistry *globalTcpListeningSocketRegistry = NULL; | 26 ListeningSocketRegistry *globalTcpListeningSocketRegistry = NULL; |
| 27 | 27 |
| 28 bool short_socket_read = false; |
| 29 |
| 30 bool short_socket_write = false; |
| 31 |
| 28 void ListeningSocketRegistry::Initialize() { | 32 void ListeningSocketRegistry::Initialize() { |
| 29 ASSERT(globalTcpListeningSocketRegistry == NULL); | 33 ASSERT(globalTcpListeningSocketRegistry == NULL); |
| 30 globalTcpListeningSocketRegistry = new ListeningSocketRegistry(); | 34 globalTcpListeningSocketRegistry = new ListeningSocketRegistry(); |
| 31 } | 35 } |
| 32 | 36 |
| 33 | 37 |
| 34 ListeningSocketRegistry *ListeningSocketRegistry::Instance() { | 38 ListeningSocketRegistry *ListeningSocketRegistry::Instance() { |
| 35 return globalTcpListeningSocketRegistry; | 39 return globalTcpListeningSocketRegistry; |
| 36 } | 40 } |
| 37 | 41 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 Dart_SetReturnValue(args, Dart_NewInteger(available)); | 333 Dart_SetReturnValue(args, Dart_NewInteger(available)); |
| 330 } else { | 334 } else { |
| 331 // Available failed. Mark socket as having data, to trigger a future read | 335 // Available failed. Mark socket as having data, to trigger a future read |
| 332 // event where the actual error can be reported. | 336 // event where the actual error can be reported. |
| 333 Dart_SetReturnValue(args, Dart_NewInteger(1)); | 337 Dart_SetReturnValue(args, Dart_NewInteger(1)); |
| 334 } | 338 } |
| 335 } | 339 } |
| 336 | 340 |
| 337 | 341 |
| 338 void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) { | 342 void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) { |
| 339 static bool short_socket_reads = Dart_IsVMFlagSet("short_socket_read"); | |
| 340 intptr_t socket = | 343 intptr_t socket = |
| 341 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 344 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 342 int64_t length = 0; | 345 int64_t length = 0; |
| 343 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) { | 346 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) { |
| 344 if (short_socket_reads) { | 347 if (short_socket_read) { |
| 345 length = (length + 1) / 2; | 348 length = (length + 1) / 2; |
| 346 } | 349 } |
| 347 uint8_t* buffer = NULL; | 350 uint8_t* buffer = NULL; |
| 348 Dart_Handle result = IOBuffer::Allocate(length, &buffer); | 351 Dart_Handle result = IOBuffer::Allocate(length, &buffer); |
| 349 if (Dart_IsError(result)) { | 352 if (Dart_IsError(result)) { |
| 350 Dart_PropagateError(result); | 353 Dart_PropagateError(result); |
| 351 } | 354 } |
| 352 ASSERT(buffer != NULL); | 355 ASSERT(buffer != NULL); |
| 353 intptr_t bytes_read = Socket::Read(socket, buffer, length); | 356 intptr_t bytes_read = Socket::Read(socket, buffer, length); |
| 354 if (bytes_read == length) { | 357 if (bytes_read == length) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 Dart_Handle result = | 448 Dart_Handle result = |
| 446 Dart_Invoke(io_lib, | 449 Dart_Invoke(io_lib, |
| 447 DartUtils::NewString("_makeDatagram"), | 450 DartUtils::NewString("_makeDatagram"), |
| 448 kNumArgs, | 451 kNumArgs, |
| 449 dart_args); | 452 dart_args); |
| 450 Dart_SetReturnValue(args, result); | 453 Dart_SetReturnValue(args, result); |
| 451 } | 454 } |
| 452 | 455 |
| 453 | 456 |
| 454 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { | 457 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { |
| 455 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); | |
| 456 intptr_t socket = | 458 intptr_t socket = |
| 457 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 459 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 458 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 460 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 459 ASSERT(Dart_IsList(buffer_obj)); | 461 ASSERT(Dart_IsList(buffer_obj)); |
| 460 intptr_t offset = | 462 intptr_t offset = |
| 461 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); | 463 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
| 462 intptr_t length = | 464 intptr_t length = |
| 463 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); | 465 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); |
| 464 bool short_write = false; | 466 bool short_write = false; |
| 465 if (short_socket_writes) { | 467 if (short_socket_write) { |
| 466 if (length > 1) { | 468 if (length > 1) { |
| 467 short_write = true; | 469 short_write = true; |
| 468 } | 470 } |
| 469 length = (length + 1) / 2; | 471 length = (length + 1) / 2; |
| 470 } | 472 } |
| 471 Dart_TypedData_Type type; | 473 Dart_TypedData_Type type; |
| 472 uint8_t* buffer = NULL; | 474 uint8_t* buffer = NULL; |
| 473 intptr_t len; | 475 intptr_t len; |
| 474 Dart_Handle result = Dart_TypedDataAcquireData( | 476 Dart_Handle result = Dart_TypedDataAcquireData( |
| 475 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); | 477 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 if (Dart_IsError(err)) { | 947 if (Dart_IsError(err)) { |
| 946 Dart_PropagateError(err); | 948 Dart_PropagateError(err); |
| 947 } | 949 } |
| 948 return socket; | 950 return socket; |
| 949 } | 951 } |
| 950 | 952 |
| 951 } // namespace bin | 953 } // namespace bin |
| 952 } // namespace dart | 954 } // namespace dart |
| 953 | 955 |
| 954 #endif // !defined(DART_IO_DISABLED) | 956 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |