Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: runtime/bin/socket.cc

Issue 76383002: Update InternetAddress (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review commetns Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/socket.h ('k') | runtime/bin/socket_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 case SocketAddress::ADDRESS_ANY_IP_V6: { 66 case SocketAddress::ADDRESS_ANY_IP_V6: {
67 raw.in6.sin6_family = AF_INET6; 67 raw.in6.sin6_family = AF_INET6;
68 raw.in6.sin6_addr = in6addr_any; 68 raw.in6.sin6_addr = in6addr_any;
69 break; 69 break;
70 } 70 }
71 default: 71 default:
72 Dart_Handle error = DartUtils::NewDartArgumentError(""); 72 Dart_Handle error = DartUtils::NewDartArgumentError("");
73 if (Dart_IsError(error)) Dart_PropagateError(error); 73 if (Dart_IsError(error)) Dart_PropagateError(error);
74 Dart_ThrowException(error); 74 Dart_ThrowException(error);
75 } 75 }
76 int len = SocketAddress::GetAddrLength(&raw); 76 Dart_SetReturnValue(args, SocketAddress::ToTypedData(&raw));
77 Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, len);
78 if (Dart_IsError(result)) Dart_PropagateError(result);
79 Dart_ListSetAsBytes(result, 0, reinterpret_cast<uint8_t *>(&raw), len);
80 Dart_SetReturnValue(args, result);
81 } 77 }
82 78
83 79
80 void FUNCTION_NAME(InternetAddress_Parse)(Dart_NativeArguments args) {
81 int64_t type = 0;
82 bool ok = DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &type);
83 ASSERT(ok);
84 USE(ok);
85 const char* address =
86 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
87 ASSERT(address != NULL);
88 RawAddr raw;
89 memset(&raw, 0, sizeof(raw));
90 if (type == SocketAddress::TYPE_IPV4) {
91 raw.addr.sa_family = AF_INET;
92 } else {
93 ASSERT(type == SocketAddress::TYPE_IPV6);
94 raw.addr.sa_family = AF_INET6;
95 }
96 ok = Socket::ParseAddress(type, address, &raw);
97 if (!ok) {
98 Dart_SetReturnValue(args, Dart_Null());
99 } else {
100 Dart_SetReturnValue(args, SocketAddress::ToTypedData(&raw));
101 }
102 }
103
104
84 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { 105 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) {
85 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 106 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
86 Dart_Handle host_obj = Dart_GetNativeArgument(args, 1); 107 Dart_Handle host_obj = Dart_GetNativeArgument(args, 1);
87 RawAddr addr; 108 RawAddr addr;
88 Dart_Handle result = GetSockAddr(host_obj, &addr); 109 Dart_Handle result = GetSockAddr(host_obj, &addr);
89 int64_t port = 0; 110 int64_t port = 0;
90 if (!Dart_IsError(result) && 111 if (!Dart_IsError(result) &&
91 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &port)) { 112 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &port)) {
92 intptr_t socket = Socket::CreateConnect(addr, port); 113 intptr_t socket = Socket::CreateConnect(addr, port);
93 OSError error; 114 OSError error;
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); 537 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id);
517 } 538 }
518 539
519 540
520 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { 541 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) {
521 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); 542 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id);
522 } 543 }
523 544
524 } // namespace bin 545 } // namespace bin
525 } // namespace dart 546 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/socket.h ('k') | runtime/bin/socket_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698