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 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... | |
30 V(MojoDataPipe_Create, 3) \ | 30 V(MojoDataPipe_Create, 3) \ |
31 V(MojoDataPipe_WriteData, 4) \ | 31 V(MojoDataPipe_WriteData, 4) \ |
32 V(MojoDataPipe_BeginWriteData, 3) \ | 32 V(MojoDataPipe_BeginWriteData, 3) \ |
33 V(MojoDataPipe_EndWriteData, 2) \ | 33 V(MojoDataPipe_EndWriteData, 2) \ |
34 V(MojoDataPipe_ReadData, 4) \ | 34 V(MojoDataPipe_ReadData, 4) \ |
35 V(MojoDataPipe_BeginReadData, 3) \ | 35 V(MojoDataPipe_BeginReadData, 3) \ |
36 V(MojoDataPipe_EndReadData, 2) \ | 36 V(MojoDataPipe_EndReadData, 2) \ |
37 V(MojoMessagePipe_Create, 1) \ | 37 V(MojoMessagePipe_Create, 1) \ |
38 V(MojoMessagePipe_Write, 5) \ | 38 V(MojoMessagePipe_Write, 5) \ |
39 V(MojoMessagePipe_Read, 5) \ | 39 V(MojoMessagePipe_Read, 5) \ |
40 V(MojoMessagePipe_QueryAndRead, 5) \ | |
40 V(Mojo_GetTimeTicksNow, 0) \ | 41 V(Mojo_GetTimeTicksNow, 0) \ |
41 V(MojoHandle_Close, 1) \ | 42 V(MojoHandle_Close, 1) \ |
42 V(MojoHandle_Wait, 3) \ | 43 V(MojoHandle_Wait, 3) \ |
43 V(MojoHandle_RegisterFinalizer, 2) \ | 44 V(MojoHandle_RegisterFinalizer, 2) \ |
44 V(MojoHandle_WaitMany, 3) \ | 45 V(MojoHandle_WaitMany, 3) \ |
45 V(MojoHandleWatcher_GrowStateArrays, 1) \ | 46 V(MojoHandleWatcher_GrowStateArrays, 1) \ |
46 V(MojoHandleWatcher_WaitMany, 2) \ | 47 V(MojoHandleWatcher_WaitMany, 2) \ |
47 V(MojoHandleWatcher_SendControlData, 4) \ | 48 V(MojoHandleWatcher_SendControlData, 4) \ |
48 V(MojoHandleWatcher_RecvControlData, 1) \ | 49 V(MojoHandleWatcher_RecvControlData, 1) \ |
49 V(MojoHandleWatcher_SetControlHandle, 1) \ | 50 V(MojoHandleWatcher_SetControlHandle, 1) \ |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 } | 712 } |
712 } | 713 } |
713 | 714 |
714 Dart_Handle list = Dart_NewList(3); | 715 Dart_Handle list = Dart_NewList(3); |
715 Dart_ListSetAt(list, 0, Dart_NewInteger(res)); | 716 Dart_ListSetAt(list, 0, Dart_NewInteger(res)); |
716 Dart_ListSetAt(list, 1, Dart_NewInteger(blen)); | 717 Dart_ListSetAt(list, 1, Dart_NewInteger(blen)); |
717 Dart_ListSetAt(list, 2, Dart_NewInteger(hlen)); | 718 Dart_ListSetAt(list, 2, Dart_NewInteger(hlen)); |
718 Dart_SetReturnValue(arguments, list); | 719 Dart_SetReturnValue(arguments, list); |
719 } | 720 } |
720 | 721 |
722 void MojoMessagePipe_QueryAndRead(Dart_NativeArguments arguments) { | |
723 Dart_Handle err; | |
724 int64_t dart_handle; | |
725 int64_t flags = 0; | |
726 CHECK_INTEGER_ARGUMENT(arguments, 0, &dart_handle, Null); | |
727 CHECK_INTEGER_ARGUMENT(arguments, 1, &flags, Null); | |
728 | |
729 Dart_Handle data = Dart_GetNativeArgument(arguments, 2); | |
730 Dart_Handle handles = Dart_GetNativeArgument(arguments, 3); | |
731 Dart_Handle result = Dart_GetNativeArgument(arguments, 4); | |
732 | |
733 // Query the number of bytes and handles available. | |
734 uint32_t blen = 0; | |
735 uint32_t hlen = 0; | |
736 MojoResult res = | |
737 MojoReadMessage(static_cast<MojoHandle>(dart_handle), nullptr, &blen, | |
738 nullptr, &hlen, static_cast<MojoReadMessageFlags>(flags)); | |
739 | |
740 if ((res != MOJO_RESULT_OK) && (res != MOJO_RESULT_RESOURCE_EXHAUSTED)) { | |
741 Dart_ListSetAt(result, 0, Dart_NewInteger(res)); | |
742 Dart_ListSetAt(result, 1, data); | |
743 Dart_ListSetAt(result, 2, handles); | |
744 Dart_ListSetAt(result, 3, Dart_NewInteger(0)); | |
745 Dart_ListSetAt(result, 4, Dart_NewInteger(0)); | |
746 return; | |
747 } | |
748 | |
749 Dart_TypedData_Type typ; | |
750 void* bytes = nullptr; | |
751 intptr_t bytes_len = 0; | |
752 if ((blen > 0) && Dart_IsNull(data)) { | |
753 data = Dart_NewTypedData(Dart_TypedData_kByteData, blen); | |
Cutch
2015/11/06 21:59:15
Make this external to avoid a copy at every acquir
zra
2015/11/06 23:35:42
Done.
| |
754 } else if (blen > 0) { | |
755 err = Dart_TypedDataAcquireData(data, &typ, &bytes, &bytes_len); | |
756 MOJO_DCHECK(!Dart_IsError(err)); | |
757 err = Dart_TypedDataReleaseData(data); | |
758 MOJO_DCHECK(!Dart_IsError(err)); | |
759 if (static_cast<uintptr_t>(bytes_len) < blen) { | |
760 data = Dart_NewTypedData(Dart_TypedData_kByteData, blen); | |
761 } | |
762 } | |
763 | |
764 void* handle_bytes = nullptr; | |
765 intptr_t handles_len = 0; | |
766 if ((hlen > 0) && Dart_IsNull(handles)) { | |
767 handles = Dart_NewTypedData(Dart_TypedData_kUint32, hlen); | |
Cutch
2015/11/06 21:59:15
Make this external to avoid a copy at every acquir
zra
2015/11/06 23:35:42
Done.
| |
768 } else if (hlen > 0) { | |
769 err = Dart_TypedDataAcquireData(handles, &typ, &handle_bytes, &handles_len); | |
770 MOJO_DCHECK(!Dart_IsError(err)); | |
771 err = Dart_TypedDataReleaseData(handles); | |
772 MOJO_DCHECK(!Dart_IsError(err)); | |
773 if (static_cast<uintptr_t>(handles_len) < hlen) { | |
774 handles = Dart_NewTypedData(Dart_TypedData_kUint32, hlen); | |
775 } | |
776 } | |
777 | |
778 if (blen > 0) { | |
779 err = Dart_TypedDataAcquireData(data, &typ, &bytes, &bytes_len); | |
780 MOJO_DCHECK(!Dart_IsError(err)); | |
781 } | |
782 | |
783 if (hlen > 0) { | |
784 err = Dart_TypedDataAcquireData(handles, &typ, &handle_bytes, &handles_len); | |
785 MOJO_DCHECK(!Dart_IsError(err)); | |
786 } | |
787 | |
788 res = MojoReadMessage(static_cast<MojoHandle>(dart_handle), bytes, &blen, | |
789 reinterpret_cast<MojoHandle*>(handle_bytes), &hlen, | |
790 static_cast<MojoReadMessageFlags>(flags)); | |
791 | |
792 if (blen > 0) { | |
793 err = Dart_TypedDataReleaseData(data); | |
794 MOJO_DCHECK(!Dart_IsError(err)); | |
795 } | |
796 | |
797 if (hlen > 0) { | |
798 err = Dart_TypedDataReleaseData(handles); | |
799 MOJO_DCHECK(!Dart_IsError(err)); | |
800 } | |
801 | |
802 Dart_ListSetAt(result, 0, Dart_NewInteger(res)); | |
803 Dart_ListSetAt(result, 1, data); | |
804 Dart_ListSetAt(result, 2, handles); | |
805 Dart_ListSetAt(result, 3, Dart_NewInteger(blen)); | |
806 Dart_ListSetAt(result, 4, Dart_NewInteger(hlen)); | |
807 } | |
808 | |
721 struct MojoWaitManyState { | 809 struct MojoWaitManyState { |
722 MojoWaitManyState() {} | 810 MojoWaitManyState() {} |
723 | 811 |
724 std::vector<uint32_t> handles; | 812 std::vector<uint32_t> handles; |
725 std::vector<uint32_t> signals; | 813 std::vector<uint32_t> signals; |
726 std::vector<uint32_t> out_index; | 814 std::vector<uint32_t> out_index; |
727 std::vector<MojoHandleSignalsState> out_signals; | 815 std::vector<MojoHandleSignalsState> out_signals; |
728 | 816 |
729 static MojoWaitManyState* GetInstance(); | 817 static MojoWaitManyState* GetInstance(); |
730 | 818 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 mojo_control_handle = control_handle; | 981 mojo_control_handle = control_handle; |
894 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); | 982 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); |
895 } | 983 } |
896 | 984 |
897 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { | 985 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { |
898 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); | 986 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); |
899 } | 987 } |
900 | 988 |
901 } // namespace dart | 989 } // namespace dart |
902 } // namespace mojo | 990 } // namespace mojo |
OLD | NEW |