| 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* ReverseLookupRequest(const CObjectArray& request) { |
| 490 if (request.Length() == 2 && |
| 491 request[1]->IsTypedData()) { |
| 492 CObjectUint8Array addr_object(request[1]); |
| 493 RawAddr addr; |
| 494 memmove(reinterpret_cast<void *>(&addr), |
| 495 addr_object.Buffer(), |
| 496 addr_object.Length()); |
| 497 OSError* os_error = NULL; |
| 498 const intptr_t kMaxHostLength = 1025; |
| 499 char host[kMaxHostLength]; |
| 500 if (Socket::ReverseLookup(addr, host, kMaxHostLength, &os_error)) { |
| 501 return new CObjectString(CObject::NewString(host)); |
| 502 } else { |
| 503 CObject* result = CObject::NewOSError(os_error); |
| 504 delete os_error; |
| 505 return result; |
| 506 } |
| 507 } |
| 508 return CObject::IllegalArgumentError(); |
| 509 } |
| 510 |
| 511 |
| 512 |
| 489 static CObject* ListInterfacesRequest(const CObjectArray& request) { | 513 static CObject* ListInterfacesRequest(const CObjectArray& request) { |
| 490 if (request.Length() == 2 && | 514 if (request.Length() == 2 && |
| 491 request[1]->IsInt32()) { | 515 request[1]->IsInt32()) { |
| 492 CObjectInt32 type(request[1]); | 516 CObjectInt32 type(request[1]); |
| 493 CObject* result = NULL; | 517 CObject* result = NULL; |
| 494 OSError* os_error = NULL; | 518 OSError* os_error = NULL; |
| 495 AddressList<InterfaceSocketAddress>* addresses = Socket::ListInterfaces( | 519 AddressList<InterfaceSocketAddress>* addresses = Socket::ListInterfaces( |
| 496 type.Value(), &os_error); | 520 type.Value(), &os_error); |
| 497 if (addresses != NULL) { | 521 if (addresses != NULL) { |
| 498 CObjectArray* array = new CObjectArray( | 522 CObjectArray* array = new CObjectArray( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 if (message->type == Dart_CObject_kArray) { | 569 if (message->type == Dart_CObject_kArray) { |
| 546 if (request.Length() > 1 && request[0]->IsInt32()) { | 570 if (request.Length() > 1 && request[0]->IsInt32()) { |
| 547 CObjectInt32 request_type(request[0]); | 571 CObjectInt32 request_type(request[0]); |
| 548 switch (request_type.Value()) { | 572 switch (request_type.Value()) { |
| 549 case Socket::kLookupRequest: | 573 case Socket::kLookupRequest: |
| 550 response = LookupRequest(request); | 574 response = LookupRequest(request); |
| 551 break; | 575 break; |
| 552 case Socket::kListInterfacesRequest: | 576 case Socket::kListInterfacesRequest: |
| 553 response = ListInterfacesRequest(request); | 577 response = ListInterfacesRequest(request); |
| 554 break; | 578 break; |
| 579 case Socket::kReverseLookupRequest: |
| 580 response = ReverseLookupRequest(request); |
| 581 break; |
| 555 default: | 582 default: |
| 556 UNREACHABLE(); | 583 UNREACHABLE(); |
| 557 } | 584 } |
| 558 } | 585 } |
| 559 } | 586 } |
| 560 | 587 |
| 561 Dart_PostCObject(reply_port_id, response->AsApiCObject()); | 588 Dart_PostCObject(reply_port_id, response->AsApiCObject()); |
| 562 } | 589 } |
| 563 | 590 |
| 564 | 591 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 658 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 632 } | 659 } |
| 633 | 660 |
| 634 | 661 |
| 635 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { | 662 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { |
| 636 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); | 663 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); |
| 637 } | 664 } |
| 638 | 665 |
| 639 } // namespace bin | 666 } // namespace bin |
| 640 } // namespace dart | 667 } // namespace dart |
| OLD | NEW |