| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "mojo/edk/embedder/simple_platform_support.h" | 14 #include "mojo/edk/embedder/simple_platform_support.h" |
| 15 #include "mojo/edk/platform/platform_handle_utils_posix.h" | 15 #include "mojo/edk/platform/platform_handle_utils_posix.h" |
| 16 #include "mojo/edk/platform/platform_pipe.h" | 16 #include "mojo/edk/platform/platform_pipe.h" |
| 17 #include "mojo/edk/platform/platform_shared_buffer.h" | 17 #include "mojo/edk/platform/platform_shared_buffer.h" |
| 18 #include "mojo/edk/platform/scoped_platform_handle.h" | 18 #include "mojo/edk/platform/scoped_platform_handle.h" |
| 19 #include "mojo/edk/platform/thread_utils.h" | 19 #include "mojo/edk/platform/thread_utils.h" |
| 20 #include "mojo/edk/system/channel.h" | 20 #include "mojo/edk/system/channel.h" |
| 21 #include "mojo/edk/system/channel_endpoint.h" | 21 #include "mojo/edk/system/channel_endpoint.h" |
| 22 #include "mojo/edk/system/channel_endpoint_id.h" | 22 #include "mojo/edk/system/channel_endpoint_id.h" |
| 23 #include "mojo/edk/system/handle.h" |
| 23 #include "mojo/edk/system/handle_transport.h" | 24 #include "mojo/edk/system/handle_transport.h" |
| 24 #include "mojo/edk/system/incoming_endpoint.h" | 25 #include "mojo/edk/system/incoming_endpoint.h" |
| 25 #include "mojo/edk/system/message_pipe.h" | 26 #include "mojo/edk/system/message_pipe.h" |
| 26 #include "mojo/edk/system/message_pipe_dispatcher.h" | 27 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 27 #include "mojo/edk/system/platform_handle_dispatcher.h" | 28 #include "mojo/edk/system/platform_handle_dispatcher.h" |
| 28 #include "mojo/edk/system/raw_channel.h" | 29 #include "mojo/edk/system/raw_channel.h" |
| 29 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 30 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
| 30 #include "mojo/edk/system/test/scoped_test_dir.h" | 31 #include "mojo/edk/system/test/scoped_test_dir.h" |
| 31 #include "mojo/edk/system/test/test_io_thread.h" | 32 #include "mojo/edk/system/test/test_io_thread.h" |
| 32 #include "mojo/edk/system/test/timeouts.h" | 33 #include "mojo/edk/system/test/timeouts.h" |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 620 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 620 RefPtr<ChannelEndpoint> ep1; | 621 RefPtr<ChannelEndpoint> ep1; |
| 621 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 622 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 622 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 623 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 623 | 624 |
| 624 // We'll try to pass this dispatcher. | 625 // We'll try to pass this dispatcher. |
| 625 auto dispatcher = MessagePipeDispatcher::Create( | 626 auto dispatcher = MessagePipeDispatcher::Create( |
| 626 MessagePipeDispatcher::kDefaultCreateOptions); | 627 MessagePipeDispatcher::kDefaultCreateOptions); |
| 627 auto local_mp = MessagePipe::CreateLocalLocal(); | 628 auto local_mp = MessagePipe::CreateLocalLocal(); |
| 628 dispatcher->Init(local_mp.Clone(), 0); | 629 dispatcher->Init(local_mp.Clone(), 0); |
| 630 Handle handle(std::move(dispatcher), MOJO_HANDLE_RIGHT_TRANSFER | |
| 631 MOJO_HANDLE_RIGHT_READ | |
| 632 MOJO_HANDLE_RIGHT_WRITE); |
| 629 | 633 |
| 630 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 634 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 631 // it later, it might already be readable.) | 635 // it later, it might already be readable.) |
| 632 waiter.Init(); | 636 waiter.Init(); |
| 633 ASSERT_EQ( | 637 ASSERT_EQ( |
| 634 MOJO_RESULT_OK, | 638 MOJO_RESULT_OK, |
| 635 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 639 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 636 | 640 |
| 637 // Write to MP 0, port 0. | 641 // Write to MP 0, port 0. |
| 638 { | 642 { |
| 639 DispatcherTransport transport( | 643 DispatcherTransport transport(test::HandleTryStartTransport(handle)); |
| 640 test::DispatcherTryStartTransport(dispatcher.get())); | |
| 641 EXPECT_TRUE(transport.is_valid()); | 644 EXPECT_TRUE(transport.is_valid()); |
| 642 | 645 |
| 643 std::vector<DispatcherTransport> transports; | 646 std::vector<DispatcherTransport> transports; |
| 644 transports.push_back(transport); | 647 transports.push_back(transport); |
| 645 EXPECT_EQ( | 648 EXPECT_EQ( |
| 646 MOJO_RESULT_OK, | 649 MOJO_RESULT_OK, |
| 647 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 650 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), |
| 648 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 651 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 649 transport.End(); | 652 transport.End(); |
| 650 | 653 |
| 651 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 654 // |handle.dispatcher| should have been closed. This is |DCHECK()|ed when |
| 652 // |dispatcher| is destroyed. | 655 // the |handle.dispatcher| is destroyed. |
| 653 EXPECT_TRUE(dispatcher->HasOneRef()); | 656 EXPECT_TRUE(handle.dispatcher->HasOneRef()); |
| 654 dispatcher = nullptr; | 657 handle.reset(); |
| 655 } | 658 } |
| 656 | 659 |
| 657 // Wait. | 660 // Wait. |
| 658 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 661 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 659 EXPECT_EQ(123u, context); | 662 EXPECT_EQ(123u, context); |
| 660 hss = HandleSignalsState(); | 663 hss = HandleSignalsState(); |
| 661 mp1->RemoveAwakable(1, &waiter, &hss); | 664 mp1->RemoveAwakable(1, &waiter, &hss); |
| 662 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 665 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
| 663 hss.satisfied_signals); | 666 hss.satisfied_signals); |
| 664 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 667 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 static const char kWorld[] = "world!"; | 767 static const char kWorld[] = "world!"; |
| 765 Waiter waiter; | 768 Waiter waiter; |
| 766 HandleSignalsState hss; | 769 HandleSignalsState hss; |
| 767 uint32_t context = 0; | 770 uint32_t context = 0; |
| 768 | 771 |
| 769 // We'll try to pass this dispatcher. | 772 // We'll try to pass this dispatcher. |
| 770 auto dispatcher = MessagePipeDispatcher::Create( | 773 auto dispatcher = MessagePipeDispatcher::Create( |
| 771 MessagePipeDispatcher::kDefaultCreateOptions); | 774 MessagePipeDispatcher::kDefaultCreateOptions); |
| 772 auto local_mp = MessagePipe::CreateLocalLocal(); | 775 auto local_mp = MessagePipe::CreateLocalLocal(); |
| 773 dispatcher->Init(local_mp.Clone(), 0); | 776 dispatcher->Init(local_mp.Clone(), 0); |
| 777 Handle handle(std::move(dispatcher), MOJO_HANDLE_RIGHT_TRANSFER | |
| 778 MOJO_HANDLE_RIGHT_READ | |
| 779 MOJO_HANDLE_RIGHT_WRITE); |
| 774 | 780 |
| 775 hss = local_mp->GetHandleSignalsState(0); | 781 hss = local_mp->GetHandleSignalsState(0); |
| 776 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 782 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
| 777 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 783 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| 778 // Write to the other end (|local_mp|, port 1), and then close it. | 784 // Write to the other end (|local_mp|, port 1), and then close it. |
| 779 EXPECT_EQ( | 785 EXPECT_EQ( |
| 780 MOJO_RESULT_OK, | 786 MOJO_RESULT_OK, |
| 781 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), | 787 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), |
| 782 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 788 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 783 hss = local_mp->GetHandleSignalsState(0); | 789 hss = local_mp->GetHandleSignalsState(0); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 804 | 810 |
| 805 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 811 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 806 // it later, it might already be readable.) | 812 // it later, it might already be readable.) |
| 807 waiter.Init(); | 813 waiter.Init(); |
| 808 ASSERT_EQ( | 814 ASSERT_EQ( |
| 809 MOJO_RESULT_OK, | 815 MOJO_RESULT_OK, |
| 810 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 816 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 811 | 817 |
| 812 // Write to MP 0, port 0. | 818 // Write to MP 0, port 0. |
| 813 { | 819 { |
| 814 DispatcherTransport transport( | 820 DispatcherTransport transport(test::HandleTryStartTransport(handle)); |
| 815 test::DispatcherTryStartTransport(dispatcher.get())); | |
| 816 EXPECT_TRUE(transport.is_valid()); | 821 EXPECT_TRUE(transport.is_valid()); |
| 817 | 822 |
| 818 std::vector<DispatcherTransport> transports; | 823 std::vector<DispatcherTransport> transports; |
| 819 transports.push_back(transport); | 824 transports.push_back(transport); |
| 820 EXPECT_EQ( | 825 EXPECT_EQ( |
| 821 MOJO_RESULT_OK, | 826 MOJO_RESULT_OK, |
| 822 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 827 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), |
| 823 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 828 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 824 transport.End(); | 829 transport.End(); |
| 825 | 830 |
| 826 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 831 // |handle.dispatcher| should have been closed. This is |DCHECK()|ed when |
| 827 // |dispatcher| is destroyed. | 832 // the |handle.dispatcher| is destroyed. |
| 828 EXPECT_TRUE(dispatcher->HasOneRef()); | 833 EXPECT_TRUE(handle.dispatcher->HasOneRef()); |
| 829 dispatcher = nullptr; | 834 handle.reset(); |
| 830 } | 835 } |
| 831 | 836 |
| 832 // Wait. | 837 // Wait. |
| 833 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 838 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 834 EXPECT_EQ(123u, context); | 839 EXPECT_EQ(123u, context); |
| 835 hss = HandleSignalsState(); | 840 hss = HandleSignalsState(); |
| 836 mp1->RemoveAwakable(1, &waiter, &hss); | 841 mp1->RemoveAwakable(1, &waiter, &hss); |
| 837 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 842 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
| 838 hss.satisfied_signals); | 843 hss.satisfied_signals); |
| 839 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 844 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 917 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 913 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 918 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 914 | 919 |
| 915 // We'll try to pass this dispatcher. | 920 // We'll try to pass this dispatcher. |
| 916 MojoResult result = MOJO_RESULT_INTERNAL; | 921 MojoResult result = MOJO_RESULT_INTERNAL; |
| 917 auto dispatcher = SharedBufferDispatcher::Create( | 922 auto dispatcher = SharedBufferDispatcher::Create( |
| 918 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, 100, | 923 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, 100, |
| 919 &result); | 924 &result); |
| 920 EXPECT_EQ(MOJO_RESULT_OK, result); | 925 EXPECT_EQ(MOJO_RESULT_OK, result); |
| 921 ASSERT_TRUE(dispatcher); | 926 ASSERT_TRUE(dispatcher); |
| 927 Handle handle(std::move(dispatcher), |
| 928 MOJO_HANDLE_RIGHT_DUPLICATE | MOJO_HANDLE_RIGHT_TRANSFER | |
| 929 MOJO_HANDLE_RIGHT_READ | MOJO_HANDLE_RIGHT_WRITE); |
| 922 | 930 |
| 923 // Make a mapping. | 931 // Make a mapping. |
| 924 std::unique_ptr<PlatformSharedBufferMapping> mapping0; | 932 std::unique_ptr<PlatformSharedBufferMapping> mapping0; |
| 925 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer( | 933 EXPECT_EQ(MOJO_RESULT_OK, handle.dispatcher->MapBuffer( |
| 926 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); | 934 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); |
| 927 ASSERT_TRUE(mapping0); | 935 ASSERT_TRUE(mapping0); |
| 928 ASSERT_TRUE(mapping0->GetBase()); | 936 ASSERT_TRUE(mapping0->GetBase()); |
| 929 ASSERT_EQ(100u, mapping0->GetLength()); | 937 ASSERT_EQ(100u, mapping0->GetLength()); |
| 930 static_cast<char*>(mapping0->GetBase())[0] = 'A'; | 938 static_cast<char*>(mapping0->GetBase())[0] = 'A'; |
| 931 static_cast<char*>(mapping0->GetBase())[50] = 'B'; | 939 static_cast<char*>(mapping0->GetBase())[50] = 'B'; |
| 932 static_cast<char*>(mapping0->GetBase())[99] = 'C'; | 940 static_cast<char*>(mapping0->GetBase())[99] = 'C'; |
| 933 | 941 |
| 934 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 942 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 935 // it later, it might already be readable.) | 943 // it later, it might already be readable.) |
| 936 waiter.Init(); | 944 waiter.Init(); |
| 937 ASSERT_EQ( | 945 ASSERT_EQ( |
| 938 MOJO_RESULT_OK, | 946 MOJO_RESULT_OK, |
| 939 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 947 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 940 | 948 |
| 941 // Write to MP 0, port 0. | 949 // Write to MP 0, port 0. |
| 942 { | 950 { |
| 943 DispatcherTransport transport( | 951 DispatcherTransport transport(test::HandleTryStartTransport(handle)); |
| 944 test::DispatcherTryStartTransport(dispatcher.get())); | |
| 945 EXPECT_TRUE(transport.is_valid()); | 952 EXPECT_TRUE(transport.is_valid()); |
| 946 | 953 |
| 947 std::vector<DispatcherTransport> transports; | 954 std::vector<DispatcherTransport> transports; |
| 948 transports.push_back(transport); | 955 transports.push_back(transport); |
| 949 EXPECT_EQ( | 956 EXPECT_EQ( |
| 950 MOJO_RESULT_OK, | 957 MOJO_RESULT_OK, |
| 951 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 958 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), |
| 952 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 959 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 953 transport.End(); | 960 transport.End(); |
| 954 | 961 |
| 955 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 962 // |handle.dispatcher| should have been closed. This is |DCHECK()|ed when |
| 956 // |dispatcher| is destroyed. | 963 // the |handle.dispatcher| is destroyed. |
| 957 EXPECT_TRUE(dispatcher->HasOneRef()); | 964 EXPECT_TRUE(handle.dispatcher->HasOneRef()); |
| 958 dispatcher = nullptr; | 965 handle.reset(); |
| 959 } | 966 } |
| 960 | 967 |
| 961 // Wait. | 968 // Wait. |
| 962 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 969 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 963 EXPECT_EQ(123u, context); | 970 EXPECT_EQ(123u, context); |
| 964 hss = HandleSignalsState(); | 971 hss = HandleSignalsState(); |
| 965 mp1->RemoveAwakable(1, &waiter, &hss); | 972 mp1->RemoveAwakable(1, &waiter, &hss); |
| 966 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 973 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
| 967 hss.satisfied_signals); | 974 hss.satisfied_signals); |
| 968 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 975 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 RefPtr<ChannelEndpoint> ep1; | 1040 RefPtr<ChannelEndpoint> ep1; |
| 1034 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 1041 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 1035 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 1042 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 1036 | 1043 |
| 1037 util::ScopedFILE fp(test_dir.CreateFile()); | 1044 util::ScopedFILE fp(test_dir.CreateFile()); |
| 1038 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); | 1045 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); |
| 1039 // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to | 1046 // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to |
| 1040 // be passed. | 1047 // be passed. |
| 1041 auto dispatcher = | 1048 auto dispatcher = |
| 1042 PlatformHandleDispatcher::Create(PlatformHandleFromFILE(std::move(fp))); | 1049 PlatformHandleDispatcher::Create(PlatformHandleFromFILE(std::move(fp))); |
| 1050 // TODO(vtl): Are these the correct rights for a |PlatformHandleDispatcher|? |
| 1051 Handle handle(std::move(dispatcher), MOJO_HANDLE_RIGHT_TRANSFER | |
| 1052 MOJO_HANDLE_RIGHT_READ | |
| 1053 MOJO_HANDLE_RIGHT_WRITE); |
| 1043 | 1054 |
| 1044 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 1055 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 1045 // it later, it might already be readable.) | 1056 // it later, it might already be readable.) |
| 1046 waiter.Init(); | 1057 waiter.Init(); |
| 1047 ASSERT_EQ( | 1058 ASSERT_EQ( |
| 1048 MOJO_RESULT_OK, | 1059 MOJO_RESULT_OK, |
| 1049 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 1060 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 1050 | 1061 |
| 1051 // Write to MP 0, port 0. | 1062 // Write to MP 0, port 0. |
| 1052 { | 1063 { |
| 1053 DispatcherTransport transport( | 1064 DispatcherTransport transport(test::HandleTryStartTransport(handle)); |
| 1054 test::DispatcherTryStartTransport(dispatcher.get())); | |
| 1055 EXPECT_TRUE(transport.is_valid()); | 1065 EXPECT_TRUE(transport.is_valid()); |
| 1056 | 1066 |
| 1057 std::vector<DispatcherTransport> transports; | 1067 std::vector<DispatcherTransport> transports; |
| 1058 transports.push_back(transport); | 1068 transports.push_back(transport); |
| 1059 EXPECT_EQ( | 1069 EXPECT_EQ( |
| 1060 MOJO_RESULT_OK, | 1070 MOJO_RESULT_OK, |
| 1061 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld), | 1071 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld), |
| 1062 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1072 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 1063 transport.End(); | 1073 transport.End(); |
| 1064 | 1074 |
| 1065 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 1075 // |handle.dispatcher| should have been closed. This is |DCHECK()|ed when |
| 1066 // |dispatcher| is destroyed. | 1076 // the |handle.dispatcher| is destroyed. |
| 1067 EXPECT_TRUE(dispatcher->HasOneRef()); | 1077 EXPECT_TRUE(handle.dispatcher->HasOneRef()); |
| 1068 dispatcher = nullptr; | 1078 handle.reset(); |
| 1069 } | 1079 } |
| 1070 | 1080 |
| 1071 // Wait. | 1081 // Wait. |
| 1072 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1082 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 1073 EXPECT_EQ(123u, context); | 1083 EXPECT_EQ(123u, context); |
| 1074 hss = HandleSignalsState(); | 1084 hss = HandleSignalsState(); |
| 1075 mp1->RemoveAwakable(1, &waiter, &hss); | 1085 mp1->RemoveAwakable(1, &waiter, &hss); |
| 1076 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1086 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
| 1077 hss.satisfied_signals); | 1087 hss.satisfied_signals); |
| 1078 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 1088 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 1178 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 1169 RefPtr<ChannelEndpoint> ep1; | 1179 RefPtr<ChannelEndpoint> ep1; |
| 1170 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 1180 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 1171 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 1181 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 1172 | 1182 |
| 1173 // We'll try to pass this dispatcher. | 1183 // We'll try to pass this dispatcher. |
| 1174 auto dispatcher = MessagePipeDispatcher::Create( | 1184 auto dispatcher = MessagePipeDispatcher::Create( |
| 1175 MessagePipeDispatcher::kDefaultCreateOptions); | 1185 MessagePipeDispatcher::kDefaultCreateOptions); |
| 1176 auto local_mp = MessagePipe::CreateLocalLocal(); | 1186 auto local_mp = MessagePipe::CreateLocalLocal(); |
| 1177 dispatcher->Init(local_mp.Clone(), 0); | 1187 dispatcher->Init(local_mp.Clone(), 0); |
| 1188 Handle handle(std::move(dispatcher), MOJO_HANDLE_RIGHT_TRANSFER | |
| 1189 MOJO_HANDLE_RIGHT_READ | |
| 1190 MOJO_HANDLE_RIGHT_WRITE); |
| 1178 | 1191 |
| 1179 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 1192 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 1180 // it later, it might already be readable.) | 1193 // it later, it might already be readable.) |
| 1181 waiter.Init(); | 1194 waiter.Init(); |
| 1182 ASSERT_EQ( | 1195 ASSERT_EQ( |
| 1183 MOJO_RESULT_OK, | 1196 MOJO_RESULT_OK, |
| 1184 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 1197 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 1185 | 1198 |
| 1186 // Write to MP 0, port 0. | 1199 // Write to MP 0, port 0. |
| 1187 { | 1200 { |
| 1188 DispatcherTransport transport( | 1201 DispatcherTransport transport(test::HandleTryStartTransport(handle)); |
| 1189 test::DispatcherTryStartTransport(dispatcher.get())); | |
| 1190 EXPECT_TRUE(transport.is_valid()); | 1202 EXPECT_TRUE(transport.is_valid()); |
| 1191 | 1203 |
| 1192 std::vector<DispatcherTransport> transports; | 1204 std::vector<DispatcherTransport> transports; |
| 1193 transports.push_back(transport); | 1205 transports.push_back(transport); |
| 1194 EXPECT_EQ( | 1206 EXPECT_EQ( |
| 1195 MOJO_RESULT_OK, | 1207 MOJO_RESULT_OK, |
| 1196 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 1208 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), |
| 1197 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1209 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 1198 transport.End(); | 1210 transport.End(); |
| 1199 | 1211 |
| 1200 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 1212 // |handle.dispatcher| should have been closed. This is |DCHECK()|ed when |
| 1201 // |dispatcher| is destroyed. | 1213 // the |handle.dispatcher| is destroyed. |
| 1202 EXPECT_TRUE(dispatcher->HasOneRef()); | 1214 EXPECT_TRUE(handle.dispatcher->HasOneRef()); |
| 1203 dispatcher = nullptr; | 1215 handle.reset(); |
| 1204 } | 1216 } |
| 1205 | 1217 |
| 1206 // Wait. | 1218 // Wait. |
| 1207 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1219 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 1208 EXPECT_EQ(123u, context); | 1220 EXPECT_EQ(123u, context); |
| 1209 hss = HandleSignalsState(); | 1221 hss = HandleSignalsState(); |
| 1210 mp1->RemoveAwakable(1, &waiter, &hss); | 1222 mp1->RemoveAwakable(1, &waiter, &hss); |
| 1211 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1223 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
| 1212 hss.satisfied_signals); | 1224 hss.satisfied_signals); |
| 1213 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 1225 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1226 EXPECT_STREQ(kHello, read_buffer); | 1238 EXPECT_STREQ(kHello, read_buffer); |
| 1227 EXPECT_EQ(1u, read_dispatchers.size()); | 1239 EXPECT_EQ(1u, read_dispatchers.size()); |
| 1228 EXPECT_EQ(1u, read_num_dispatchers); | 1240 EXPECT_EQ(1u, read_num_dispatchers); |
| 1229 ASSERT_TRUE(read_dispatchers[0]); | 1241 ASSERT_TRUE(read_dispatchers[0]); |
| 1230 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | 1242 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); |
| 1231 | 1243 |
| 1232 EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, read_dispatchers[0]->GetType()); | 1244 EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, read_dispatchers[0]->GetType()); |
| 1233 dispatcher = RefPtr<MessagePipeDispatcher>( | 1245 dispatcher = RefPtr<MessagePipeDispatcher>( |
| 1234 static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get())); | 1246 static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get())); |
| 1235 read_dispatchers.clear(); | 1247 read_dispatchers.clear(); |
| 1248 // TODO(vtl): We should really get |handle| from |ReadMessage()|. |
| 1249 handle = Handle(std::move(dispatcher), MOJO_HANDLE_RIGHT_TRANSFER | |
| 1250 MOJO_HANDLE_RIGHT_READ | |
| 1251 MOJO_HANDLE_RIGHT_WRITE); |
| 1236 | 1252 |
| 1237 // Now pass it back. | 1253 // Now pass it back. |
| 1238 | 1254 |
| 1239 // Prepare to wait on MP 0, port 0. (Add the waiter now. Otherwise, if we do | 1255 // Prepare to wait on MP 0, port 0. (Add the waiter now. Otherwise, if we do |
| 1240 // it later, it might already be readable.) | 1256 // it later, it might already be readable.) |
| 1241 waiter.Init(); | 1257 waiter.Init(); |
| 1242 ASSERT_EQ( | 1258 ASSERT_EQ( |
| 1243 MOJO_RESULT_OK, | 1259 MOJO_RESULT_OK, |
| 1244 mp0->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); | 1260 mp0->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); |
| 1245 | 1261 |
| 1246 // Write to MP 1, port 1. | 1262 // Write to MP 1, port 1. |
| 1247 { | 1263 { |
| 1248 DispatcherTransport transport( | 1264 DispatcherTransport transport(test::HandleTryStartTransport(handle)); |
| 1249 test::DispatcherTryStartTransport(dispatcher.get())); | |
| 1250 EXPECT_TRUE(transport.is_valid()); | 1265 EXPECT_TRUE(transport.is_valid()); |
| 1251 | 1266 |
| 1252 std::vector<DispatcherTransport> transports; | 1267 std::vector<DispatcherTransport> transports; |
| 1253 transports.push_back(transport); | 1268 transports.push_back(transport); |
| 1254 EXPECT_EQ( | 1269 EXPECT_EQ( |
| 1255 MOJO_RESULT_OK, | 1270 MOJO_RESULT_OK, |
| 1256 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), | 1271 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), |
| 1257 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1272 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 1258 transport.End(); | 1273 transport.End(); |
| 1259 | 1274 |
| 1260 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 1275 // |handle.dispatcher| should have been closed. This is |DCHECK()|ed when |
| 1261 // |dispatcher| is destroyed. | 1276 // the |handle.dispatcher| is destroyed. |
| 1262 EXPECT_TRUE(dispatcher->HasOneRef()); | 1277 EXPECT_TRUE(handle.dispatcher->HasOneRef()); |
| 1263 dispatcher = nullptr; | 1278 handle.reset(); |
| 1264 } | 1279 } |
| 1265 | 1280 |
| 1266 // Wait. | 1281 // Wait. |
| 1267 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1282 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 1268 EXPECT_EQ(456u, context); | 1283 EXPECT_EQ(456u, context); |
| 1269 hss = HandleSignalsState(); | 1284 hss = HandleSignalsState(); |
| 1270 mp0->RemoveAwakable(0, &waiter, &hss); | 1285 mp0->RemoveAwakable(0, &waiter, &hss); |
| 1271 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1286 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
| 1272 hss.satisfied_signals); | 1287 hss.satisfied_signals); |
| 1273 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 1288 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 mp0->Close(0); | 1375 mp0->Close(0); |
| 1361 mp1->Close(1); | 1376 mp1->Close(1); |
| 1362 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1377 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 1363 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1378 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
| 1364 local_mp->Close(1); | 1379 local_mp->Close(1); |
| 1365 } | 1380 } |
| 1366 | 1381 |
| 1367 } // namespace | 1382 } // namespace |
| 1368 } // namespace system | 1383 } // namespace system |
| 1369 } // namespace mojo | 1384 } // namespace mojo |
| OLD | NEW |