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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 } | 228 } |
| 229 | 229 |
| 230 | 230 |
| 231 void FUNCTION_NAME(Socket_GetRemotePeer)(Dart_NativeArguments args) { | 231 void FUNCTION_NAME(Socket_GetRemotePeer)(Dart_NativeArguments args) { |
| 232 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); | 232 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); |
| 233 intptr_t socket = 0; | 233 intptr_t socket = 0; |
| 234 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket); | 234 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket); |
| 235 if (Dart_IsError(err)) Dart_PropagateError(err); | 235 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 236 OSError os_error; | 236 OSError os_error; |
| 237 intptr_t port = 0; | 237 intptr_t port = 0; |
| 238 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); | 238 SocketAddress* addr = Socket::GetRemotePeer(socket, &port); |
| 239 char host[INET6_ADDRSTRLEN]; | 239 if (addr != NULL) { |
| 240 if (Socket::GetRemotePeer(socket, host, &port)) { | |
| 241 Dart_Handle list = Dart_NewList(2); | 240 Dart_Handle list = Dart_NewList(2); |
| 242 Dart_ListSetAt(list, 0, Dart_NewStringFromCString(host)); | 241 |
| 242 Dart_Handle entry = Dart_NewList(3); | |
| 243 Dart_ListSetAt(entry, 0, Dart_NewInteger(addr->GetType())); | |
| 244 Dart_ListSetAt(entry, 1, Dart_NewStringFromCString(addr->as_string())); | |
| 245 | |
| 246 RawAddr raw = addr->addr(); | |
| 247 intptr_t data_length = SocketAddress::GetAddrLength(&raw); | |
| 248 Dart_Handle data = Dart_NewList(data_length); | |
|
Søren Gjesse
2013/11/05 13:14:05
typed data UInt8List?
Anders Johnsen
2013/11/05 13:19:44
Done.
| |
| 249 Dart_ListSetAsBytes(data, 0, reinterpret_cast<uint8_t*>(&raw), data_length); | |
| 250 Dart_ListSetAt(entry, 2, data); | |
| 251 | |
| 252 Dart_ListSetAt(list, 0, entry); | |
| 243 Dart_ListSetAt(list, 1, Dart_NewInteger(port)); | 253 Dart_ListSetAt(list, 1, Dart_NewInteger(port)); |
| 244 Dart_SetReturnValue(args, list); | 254 Dart_SetReturnValue(args, list); |
|
Søren Gjesse
2013/11/05 13:14:05
delete addr?
Anders Johnsen
2013/11/05 13:19:44
Done.
| |
| 245 } else { | 255 } else { |
| 246 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 256 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 247 } | 257 } |
| 248 } | 258 } |
| 249 | 259 |
| 250 | 260 |
| 251 void FUNCTION_NAME(Socket_GetError)(Dart_NativeArguments args) { | 261 void FUNCTION_NAME(Socket_GetError)(Dart_NativeArguments args) { |
| 252 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); | 262 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); |
| 253 intptr_t socket = 0; | 263 intptr_t socket = 0; |
| 254 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket); | 264 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 515 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 506 } | 516 } |
| 507 | 517 |
| 508 | 518 |
| 509 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 519 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 510 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 520 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 511 } | 521 } |
| 512 | 522 |
| 513 } // namespace bin | 523 } // namespace bin |
| 514 } // namespace dart | 524 } // namespace dart |
| OLD | NEW |