| 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/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 20 matching lines...) Expand all Loading... |
| 31 uint8_t* data = NULL; | 31 uint8_t* data = NULL; |
| 32 intptr_t len; | 32 intptr_t len; |
| 33 Dart_Handle result = Dart_TypedDataAcquireData( | 33 Dart_Handle result = Dart_TypedDataAcquireData( |
| 34 obj, &data_type, reinterpret_cast<void**>(&data), &len); | 34 obj, &data_type, reinterpret_cast<void**>(&data), &len); |
| 35 if (Dart_IsError(result)) return result; | 35 if (Dart_IsError(result)) return result; |
| 36 memmove(reinterpret_cast<void *>(addr), data, len); | 36 memmove(reinterpret_cast<void *>(addr), data, len); |
| 37 return Dart_Null(); | 37 return Dart_Null(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 void FUNCTION_NAME(InternetAddress_Fixed)(Dart_NativeArguments args) { |
| 42 Dart_EnterScope(); |
| 43 Dart_Handle id_obj = Dart_GetNativeArgument(args, 0); |
| 44 ASSERT(!Dart_IsError(id_obj)); |
| 45 int64_t id = 0; |
| 46 bool ok = DartUtils::GetInt64Value(id_obj, &id); |
| 47 ASSERT(ok); |
| 48 USE(ok); |
| 49 RawAddr raw; |
| 50 memset(&raw, 0, sizeof(raw)); |
| 51 switch (id) { |
| 52 case SocketAddress::ADDRESS_LOOPBACK_IP_V4: { |
| 53 raw.in.sin_family = AF_INET; |
| 54 raw.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); |
| 55 break; |
| 56 } |
| 57 case SocketAddress::ADDRESS_LOOPBACK_IP_V6: { |
| 58 raw.in6.sin6_family = AF_INET6; |
| 59 raw.in6.sin6_addr = in6addr_any; |
| 60 break; |
| 61 } |
| 62 case SocketAddress::ADDRESS_ANY_IP_V4: { |
| 63 raw.in.sin_family = AF_INET; |
| 64 raw.in.sin_addr.s_addr = INADDR_ANY; |
| 65 break; |
| 66 } |
| 67 case SocketAddress::ADDRESS_ANY_IP_V6: { |
| 68 raw.in6.sin6_family = AF_INET6; |
| 69 raw.in6.sin6_addr = in6addr_loopback; |
| 70 break; |
| 71 } |
| 72 default: |
| 73 Dart_Handle error = DartUtils::NewDartArgumentError(""); |
| 74 if (Dart_IsError(error)) Dart_PropagateError(error); |
| 75 Dart_ThrowException(error); |
| 76 } |
| 77 int len = SocketAddress::GetAddrLength(raw); |
| 78 Dart_Handle result = Dart_NewTypedData(kUint8, len); |
| 79 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 80 Dart_ListSetAsBytes(result, 0, reinterpret_cast<uint8_t *>(&raw), len); |
| 81 Dart_SetReturnValue(args, result); |
| 82 Dart_ExitScope(); |
| 83 } |
| 84 |
| 85 |
| 41 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { | 86 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { |
| 42 Dart_EnterScope(); | 87 Dart_EnterScope(); |
| 43 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); | 88 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); |
| 44 Dart_Handle host_obj = Dart_GetNativeArgument(args, 1); | 89 Dart_Handle host_obj = Dart_GetNativeArgument(args, 1); |
| 45 RawAddr addr; | 90 RawAddr addr; |
| 46 Dart_Handle result = GetSockAddr(host_obj, &addr); | 91 Dart_Handle result = GetSockAddr(host_obj, &addr); |
| 47 int64_t port = 0; | 92 int64_t port = 0; |
| 48 if (!Dart_IsError(result) && | 93 if (!Dart_IsError(result) && |
| 49 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &port)) { | 94 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &port)) { |
| 50 intptr_t socket = Socket::CreateConnect(addr, port); | 95 intptr_t socket = Socket::CreateConnect(addr, port); |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 574 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 530 } | 575 } |
| 531 | 576 |
| 532 | 577 |
| 533 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 578 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 534 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 579 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 535 } | 580 } |
| 536 | 581 |
| 537 } // namespace bin | 582 } // namespace bin |
| 538 } // namespace dart | 583 } // namespace dart |
| OLD | NEW |