| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 V(MojoDataPipe_Create, 3) \ | 27 V(MojoDataPipe_Create, 3) \ |
| 28 V(MojoDataPipe_WriteData, 4) \ | 28 V(MojoDataPipe_WriteData, 4) \ |
| 29 V(MojoDataPipe_BeginWriteData, 3) \ | 29 V(MojoDataPipe_BeginWriteData, 3) \ |
| 30 V(MojoDataPipe_EndWriteData, 2) \ | 30 V(MojoDataPipe_EndWriteData, 2) \ |
| 31 V(MojoDataPipe_ReadData, 4) \ | 31 V(MojoDataPipe_ReadData, 4) \ |
| 32 V(MojoDataPipe_BeginReadData, 3) \ | 32 V(MojoDataPipe_BeginReadData, 3) \ |
| 33 V(MojoDataPipe_EndReadData, 2) \ | 33 V(MojoDataPipe_EndReadData, 2) \ |
| 34 V(MojoMessagePipe_Create, 1) \ | 34 V(MojoMessagePipe_Create, 1) \ |
| 35 V(MojoMessagePipe_Write, 5) \ | 35 V(MojoMessagePipe_Write, 5) \ |
| 36 V(MojoMessagePipe_Read, 5) \ | 36 V(MojoMessagePipe_Read, 5) \ |
| 37 V(MojoMessagePipe_QueryAndRead, 2) \ |
| 37 V(Mojo_GetTimeTicksNow, 0) \ | 38 V(Mojo_GetTimeTicksNow, 0) \ |
| 38 V(MojoHandle_Close, 1) \ | 39 V(MojoHandle_Close, 1) \ |
| 39 V(MojoHandle_Wait, 3) \ | 40 V(MojoHandle_Wait, 3) \ |
| 40 V(MojoHandle_Register, 2) \ | 41 V(MojoHandle_Register, 2) \ |
| 41 V(MojoHandle_WaitMany, 3) \ | 42 V(MojoHandle_WaitMany, 3) \ |
| 42 V(MojoHandleWatcher_GrowStateArrays, 1) \ | 43 V(MojoHandleWatcher_GrowStateArrays, 1) \ |
| 43 V(MojoHandleWatcher_WaitMany, 2) \ | 44 V(MojoHandleWatcher_WaitMany, 2) \ |
| 44 V(MojoHandleWatcher_SendControlData, 4) \ | 45 V(MojoHandleWatcher_SendControlData, 4) \ |
| 45 V(MojoHandleWatcher_RecvControlData, 1) \ | 46 V(MojoHandleWatcher_RecvControlData, 1) \ |
| 46 V(MojoHandleWatcher_SetControlHandle, 1) \ | 47 V(MojoHandleWatcher_SetControlHandle, 1) \ |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 std::vector<uint32_t> signals; | 730 std::vector<uint32_t> signals; |
| 730 std::vector<uint32_t> out_index; | 731 std::vector<uint32_t> out_index; |
| 731 std::vector<MojoHandleSignalsState> out_signals; | 732 std::vector<MojoHandleSignalsState> out_signals; |
| 732 | 733 |
| 733 static MojoWaitManyState* GetInstance(); | 734 static MojoWaitManyState* GetInstance(); |
| 734 | 735 |
| 735 private: | 736 private: |
| 736 DISALLOW_COPY_AND_ASSIGN(MojoWaitManyState); | 737 DISALLOW_COPY_AND_ASSIGN(MojoWaitManyState); |
| 737 }; | 738 }; |
| 738 | 739 |
| 740 void MojoMessagePipe_QueryAndRead(Dart_NativeArguments arguments) { |
| 741 int64_t dart_handle; |
| 742 int64_t flags = 0; |
| 743 CHECK_INTEGER_ARGUMENT(arguments, 0, &dart_handle, Null); |
| 744 CHECK_INTEGER_ARGUMENT(arguments, 1, &flags, Null); |
| 745 |
| 746 // Query the number of bytes and handles available. |
| 747 uint32_t blen = 0; |
| 748 uint32_t hlen = 0; |
| 749 MojoResult res = |
| 750 MojoReadMessage(static_cast<MojoHandle>(dart_handle), nullptr, &blen, |
| 751 nullptr, &hlen, static_cast<MojoReadMessageFlags>(flags)); |
| 752 |
| 753 if ((res != MOJO_RESULT_OK) && (res != MOJO_RESULT_RESOURCE_EXHAUSTED)) { |
| 754 Dart_Handle list = Dart_NewList(3); |
| 755 Dart_ListSetAt(list, 0, Dart_NewInteger(res)); |
| 756 Dart_SetReturnValue(arguments, list); |
| 757 return; |
| 758 } |
| 759 |
| 760 Dart_Handle data = Dart_Null(); |
| 761 if (blen > 0) { |
| 762 data = Dart_NewTypedData(Dart_TypedData_kByteData, blen); |
| 763 } |
| 764 |
| 765 Dart_Handle handles = Dart_Null(); |
| 766 if (hlen > 0) { |
| 767 handles = Dart_NewTypedData(Dart_TypedData_kUint32, hlen); |
| 768 } |
| 769 |
| 770 Dart_TypedData_Type typ; |
| 771 void* bytes = nullptr; |
| 772 intptr_t byte_data_len = 0; |
| 773 if (blen > 0) { |
| 774 Dart_TypedDataAcquireData(data, &typ, &bytes, &byte_data_len); |
| 775 } |
| 776 |
| 777 void* handle_bytes = nullptr; |
| 778 intptr_t handle_bytes_len = 0; |
| 779 if (hlen > 0) { |
| 780 Dart_TypedDataAcquireData(handles, &typ, &handle_bytes, &handle_bytes_len); |
| 781 } |
| 782 |
| 783 res = MojoReadMessage(static_cast<MojoHandle>(dart_handle), bytes, &blen, |
| 784 reinterpret_cast<MojoHandle*>(handle_bytes), &hlen, |
| 785 static_cast<MojoReadMessageFlags>(flags)); |
| 786 |
| 787 if (byte_data_len > 0) { |
| 788 Dart_TypedDataReleaseData(data); |
| 789 } |
| 790 |
| 791 if (handle_bytes_len > 0) { |
| 792 Dart_TypedDataReleaseData(handles); |
| 793 } |
| 794 |
| 795 Dart_Handle list = Dart_NewList(3); |
| 796 Dart_ListSetAt(list, 0, Dart_NewInteger(res)); |
| 797 Dart_ListSetAt(list, 1, data); |
| 798 Dart_ListSetAt(list, 2, handles); |
| 799 Dart_SetReturnValue(arguments, list); |
| 800 } |
| 801 |
| 739 // This global is safe because it is only accessed by the single handle watcher | 802 // This global is safe because it is only accessed by the single handle watcher |
| 740 // isolate. If multiple handle watcher isolates are ever needed, it will need | 803 // isolate. If multiple handle watcher isolates are ever needed, it will need |
| 741 // to be replicated. | 804 // to be replicated. |
| 742 MojoWaitManyState* MojoWaitManyState::GetInstance() { | 805 MojoWaitManyState* MojoWaitManyState::GetInstance() { |
| 743 static MojoWaitManyState* state = new MojoWaitManyState; | 806 static MojoWaitManyState* state = new MojoWaitManyState; |
| 744 return state; | 807 return state; |
| 745 } | 808 } |
| 746 | 809 |
| 747 void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) { | 810 void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) { |
| 748 int64_t new_length; | 811 int64_t new_length; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 mojo_control_handle = control_handle; | 960 mojo_control_handle = control_handle; |
| 898 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); | 961 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); |
| 899 } | 962 } |
| 900 | 963 |
| 901 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { | 964 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { |
| 902 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); | 965 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); |
| 903 } | 966 } |
| 904 | 967 |
| 905 } // namespace dart | 968 } // namespace dart |
| 906 } // namespace mojo | 969 } // namespace mojo |
| OLD | NEW |