| Index: runtime/bin/socket.cc
|
| diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc
|
| index 89e6b00c23d5f78c3e41e194d2162375eac4c658..0213de7cee9a3a93db06b8f39ebab3bca8465e23 100644
|
| --- a/runtime/bin/socket.cc
|
| +++ b/runtime/bin/socket.cc
|
| @@ -486,6 +486,59 @@ static CObject* LookupRequest(const CObjectArray& request) {
|
| }
|
|
|
|
|
| +static CObject* ListAdaptorsRequest(const CObjectArray& request) {
|
| + if (request.Length() == 3 &&
|
| + request[1]->IsBool() &&
|
| + request[2]->IsInt32()) {
|
| + CObjectBool include_localhost(request[1]);
|
| + CObjectInt32 type(request[2]);
|
| + CObject* result = NULL;
|
| + OSError* os_error = NULL;
|
| + SocketAddresses* addresses = Socket::ListAdaptors(
|
| + include_localhost.Value(), type.Value(), &os_error);
|
| + if (addresses != NULL) {
|
| + CObjectArray* array = new CObjectArray(
|
| + CObject::NewArray(addresses->count() + 1));
|
| + array->SetAt(0, new CObjectInt32(CObject::NewInt32(0)));
|
| + for (intptr_t i = 0; i < addresses->count(); i++) {
|
| + AdaptorSocketAddress* addr =
|
| + static_cast<AdaptorSocketAddress*>(addresses->GetAt(i));
|
| + CObjectArray* entry = new CObjectArray(CObject::NewArray(4));
|
| +
|
| + CObjectInt32* type = new CObjectInt32(
|
| + CObject::NewInt32(addr->GetType()));
|
| + entry->SetAt(0, type);
|
| +
|
| + CObjectString* as_string = new CObjectString(CObject::NewString(
|
| + addr->as_string()));
|
| + entry->SetAt(1, as_string);
|
| +
|
| + RawAddr raw = addr->addr();
|
| + CObjectUint8Array* data = new CObjectUint8Array(CObject::NewUint8Array(
|
| + SocketAddress::GetAddrLength(raw)));
|
| + memmove(data->Buffer(),
|
| + reinterpret_cast<void *>(&raw),
|
| + SocketAddress::GetAddrLength(raw));
|
| + entry->SetAt(2, data);
|
| +
|
| + CObjectString* name = new CObjectString(CObject::NewString(
|
| + addr->name()));
|
| + entry->SetAt(3, name);
|
| +
|
| + array->SetAt(i + 1, entry);
|
| + }
|
| + result = array;
|
| + delete addresses;
|
| + } else {
|
| + result = CObject::NewOSError(os_error);
|
| + delete os_error;
|
| + }
|
| + return result;
|
| + }
|
| + return CObject::IllegalArgumentError();
|
| +}
|
| +
|
| +
|
| void SocketService(Dart_Port dest_port_id,
|
| Dart_Port reply_port_id,
|
| Dart_CObject* message) {
|
| @@ -498,6 +551,9 @@ void SocketService(Dart_Port dest_port_id,
|
| case Socket::kLookupRequest:
|
| response = LookupRequest(request);
|
| break;
|
| + case Socket::kListAdaptorsRequest:
|
| + response = ListAdaptorsRequest(request);
|
| + break;
|
| default:
|
| UNREACHABLE();
|
| }
|
|
|