Chromium Code Reviews| 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 UNREACHABLE(); | |
|
Bill Hesse
2013/04/30 10:50:22
Should we do slightly better error handling here,
Søren Gjesse
2013/04/30 11:28:41
Changed to throw ArgumentError.
| |
| 74 } | |
| 75 int len = SocketAddress::GetAddrLength(raw); | |
| 76 Dart_Handle result = Dart_NewTypedData(kUint8, len); | |
| 77 if (Dart_IsError(result)) { | |
| 78 Dart_Handle error = DartUtils::NewString("Failed to allocate storage."); | |
| 79 Dart_ThrowException(error); | |
| 80 } | |
| 81 Dart_ListSetAsBytes(result, 0, reinterpret_cast<uint8_t *>(&raw), len); | |
| 82 Dart_SetReturnValue(args, result); | |
| 83 Dart_ExitScope(); | |
| 84 } | |
| 85 | |
| 86 | |
| 41 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { | 87 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { |
| 42 Dart_EnterScope(); | 88 Dart_EnterScope(); |
| 43 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); | 89 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); |
| 44 Dart_Handle host_obj = Dart_GetNativeArgument(args, 1); | 90 Dart_Handle host_obj = Dart_GetNativeArgument(args, 1); |
| 45 RawAddr addr; | 91 RawAddr addr; |
| 46 Dart_Handle result = GetSockAddr(host_obj, &addr); | 92 Dart_Handle result = GetSockAddr(host_obj, &addr); |
| 47 int64_t port = 0; | 93 int64_t port = 0; |
| 48 if (!Dart_IsError(result) && | 94 if (!Dart_IsError(result) && |
| 49 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &port)) { | 95 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &port)) { |
| 50 intptr_t socket = Socket::CreateConnect(addr, port); | 96 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); | 575 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 530 } | 576 } |
| 531 | 577 |
| 532 | 578 |
| 533 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 579 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 534 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 580 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 535 } | 581 } |
| 536 | 582 |
| 537 } // namespace bin | 583 } // namespace bin |
| 538 } // namespace dart | 584 } // namespace dart |
| OLD | NEW |