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