| 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } else { | 479 } else { |
| 480 result = CObject::NewOSError(os_error); | 480 result = CObject::NewOSError(os_error); |
| 481 delete os_error; | 481 delete os_error; |
| 482 } | 482 } |
| 483 return result; | 483 return result; |
| 484 } | 484 } |
| 485 return CObject::IllegalArgumentError(); | 485 return CObject::IllegalArgumentError(); |
| 486 } | 486 } |
| 487 | 487 |
| 488 | 488 |
| 489 static CObject* ListAdaptorsRequest(const CObjectArray& request) { |
| 490 if (request.Length() == 3 && |
| 491 request[1]->IsBool() && |
| 492 request[2]->IsInt32()) { |
| 493 CObjectBool include_localhost(request[1]); |
| 494 CObjectInt32 type(request[2]); |
| 495 CObject* result = NULL; |
| 496 OSError* os_error = NULL; |
| 497 SocketAddresses* addresses = Socket::ListAdaptors( |
| 498 include_localhost.Value(), type.Value(), &os_error); |
| 499 if (addresses != NULL) { |
| 500 CObjectArray* array = new CObjectArray( |
| 501 CObject::NewArray(addresses->count() + 1)); |
| 502 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0))); |
| 503 for (intptr_t i = 0; i < addresses->count(); i++) { |
| 504 AdaptorSocketAddress* addr = |
| 505 static_cast<AdaptorSocketAddress*>(addresses->GetAt(i)); |
| 506 CObjectArray* entry = new CObjectArray(CObject::NewArray(4)); |
| 507 |
| 508 CObjectInt32* type = new CObjectInt32( |
| 509 CObject::NewInt32(addr->GetType())); |
| 510 entry->SetAt(0, type); |
| 511 |
| 512 CObjectString* as_string = new CObjectString(CObject::NewString( |
| 513 addr->as_string())); |
| 514 entry->SetAt(1, as_string); |
| 515 |
| 516 RawAddr raw = addr->addr(); |
| 517 CObjectUint8Array* data = new CObjectUint8Array(CObject::NewUint8Array( |
| 518 SocketAddress::GetAddrLength(raw))); |
| 519 memmove(data->Buffer(), |
| 520 reinterpret_cast<void *>(&raw), |
| 521 SocketAddress::GetAddrLength(raw)); |
| 522 entry->SetAt(2, data); |
| 523 |
| 524 CObjectString* name = new CObjectString(CObject::NewString( |
| 525 addr->name())); |
| 526 entry->SetAt(3, name); |
| 527 |
| 528 array->SetAt(i + 1, entry); |
| 529 } |
| 530 result = array; |
| 531 delete addresses; |
| 532 } else { |
| 533 result = CObject::NewOSError(os_error); |
| 534 delete os_error; |
| 535 } |
| 536 return result; |
| 537 } |
| 538 return CObject::IllegalArgumentError(); |
| 539 } |
| 540 |
| 541 |
| 489 void SocketService(Dart_Port dest_port_id, | 542 void SocketService(Dart_Port dest_port_id, |
| 490 Dart_Port reply_port_id, | 543 Dart_Port reply_port_id, |
| 491 Dart_CObject* message) { | 544 Dart_CObject* message) { |
| 492 CObject* response = CObject::IllegalArgumentError(); | 545 CObject* response = CObject::IllegalArgumentError(); |
| 493 CObjectArray request(message); | 546 CObjectArray request(message); |
| 494 if (message->type == Dart_CObject_kArray) { | 547 if (message->type == Dart_CObject_kArray) { |
| 495 if (request.Length() > 1 && request[0]->IsInt32()) { | 548 if (request.Length() > 1 && request[0]->IsInt32()) { |
| 496 CObjectInt32 request_type(request[0]); | 549 CObjectInt32 request_type(request[0]); |
| 497 switch (request_type.Value()) { | 550 switch (request_type.Value()) { |
| 498 case Socket::kLookupRequest: | 551 case Socket::kLookupRequest: |
| 499 response = LookupRequest(request); | 552 response = LookupRequest(request); |
| 500 break; | 553 break; |
| 554 case Socket::kListAdaptorsRequest: |
| 555 response = ListAdaptorsRequest(request); |
| 556 break; |
| 501 default: | 557 default: |
| 502 UNREACHABLE(); | 558 UNREACHABLE(); |
| 503 } | 559 } |
| 504 } | 560 } |
| 505 } | 561 } |
| 506 | 562 |
| 507 Dart_PostCObject(reply_port_id, response->AsApiCObject()); | 563 Dart_PostCObject(reply_port_id, response->AsApiCObject()); |
| 508 } | 564 } |
| 509 | 565 |
| 510 | 566 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 633 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 578 } | 634 } |
| 579 | 635 |
| 580 | 636 |
| 581 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 637 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 582 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 638 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 583 } | 639 } |
| 584 | 640 |
| 585 } // namespace bin | 641 } // namespace bin |
| 586 } // namespace dart | 642 } // namespace dart |
| OLD | NEW |