| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 void SocketTest::TestSingleFlowControlCallbackIPv6() { | 150 void SocketTest::TestSingleFlowControlCallbackIPv6() { |
| 151 MAYBE_SKIP_IPV6; | 151 MAYBE_SKIP_IPV6; |
| 152 SingleFlowControlCallbackInternal(kIPv6Loopback); | 152 SingleFlowControlCallbackInternal(kIPv6Loopback); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void SocketTest::TestUdpIPv4() { | 155 void SocketTest::TestUdpIPv4() { |
| 156 UdpInternal(kIPv4Loopback); | 156 UdpInternal(kIPv4Loopback); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void SocketTest::TestUdpIpv4Interval() { |
| 160 SendUdpInterval(kIPv4Loopback, 5000); |
| 161 } |
| 162 |
| 159 void SocketTest::TestUdpIPv6() { | 163 void SocketTest::TestUdpIPv6() { |
| 160 MAYBE_SKIP_IPV6; | 164 MAYBE_SKIP_IPV6; |
| 161 UdpInternal(kIPv6Loopback); | 165 UdpInternal(kIPv6Loopback); |
| 162 } | 166 } |
| 163 | 167 |
| 168 void SocketTest::TestUdpIpv6Interval() { |
| 169 MAYBE_SKIP_IPV6; |
| 170 SendUdpInterval(kIPv6Loopback, 5000); |
| 171 } |
| 172 |
| 164 void SocketTest::TestUdpReadyToSendIPv4() { | 173 void SocketTest::TestUdpReadyToSendIPv4() { |
| 165 #if !defined(WEBRTC_MAC) | 174 #if !defined(WEBRTC_MAC) |
| 166 // TODO(ronghuawu): Enable this test on mac/ios. | 175 // TODO(ronghuawu): Enable this test on mac/ios. |
| 167 UdpReadyToSend(kIPv4Loopback); | 176 UdpReadyToSend(kIPv4Loopback); |
| 168 #endif | 177 #endif |
| 169 } | 178 } |
| 170 | 179 |
| 171 void SocketTest::TestUdpReadyToSendIPv6() { | 180 void SocketTest::TestUdpReadyToSendIPv6() { |
| 172 #if defined(WEBRTC_WIN) | 181 #if defined(WEBRTC_WIN) |
| 173 // TODO(ronghuawu): Enable this test (currently flakey) on mac and linux. | 182 // TODO(ronghuawu): Enable this test (currently flakey) on mac and linux. |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 accepted->Close(); | 544 accepted->Close(); |
| 536 EXPECT_EQ(AsyncSocket::CS_CLOSED, accepted->GetState()); | 545 EXPECT_EQ(AsyncSocket::CS_CLOSED, accepted->GetState()); |
| 537 | 546 |
| 538 // Expect that the client is notified, and has not yet closed. | 547 // Expect that the client is notified, and has not yet closed. |
| 539 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); | 548 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); |
| 540 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_CLOSE)); | 549 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_CLOSE)); |
| 541 EXPECT_EQ(AsyncSocket::CS_CONNECTED, client->GetState()); | 550 EXPECT_EQ(AsyncSocket::CS_CONNECTED, client->GetState()); |
| 542 | 551 |
| 543 // Ensure the data can be read. | 552 // Ensure the data can be read. |
| 544 char buffer[10]; | 553 char buffer[10]; |
| 545 EXPECT_EQ(1, client->Recv(buffer, sizeof(buffer))); | 554 EXPECT_EQ(1, client->Recv(buffer, sizeof(buffer), nullptr)); |
| 546 EXPECT_EQ('a', buffer[0]); | 555 EXPECT_EQ('a', buffer[0]); |
| 547 | 556 |
| 548 // Now we should close, but the remote address will remain. | 557 // Now we should close, but the remote address will remain. |
| 549 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout); | 558 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout); |
| 550 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_CLOSE)); | 559 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_CLOSE)); |
| 551 EXPECT_FALSE(client->GetRemoteAddress().IsAnyIP()); | 560 EXPECT_FALSE(client->GetRemoteAddress().IsAnyIP()); |
| 552 | 561 |
| 553 // The closer should not get a close signal. | 562 // The closer should not get a close signal. |
| 554 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_CLOSE)); | 563 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_CLOSE)); |
| 555 EXPECT_TRUE(accepted->GetRemoteAddress().IsNil()); | 564 EXPECT_TRUE(accepted->GetRemoteAddress().IsNil()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 // Shouldn't signal when blocked in a thread Send, where process_io is false. | 676 // Shouldn't signal when blocked in a thread Send, where process_io is false. |
| 668 std::unique_ptr<Thread> thread(new Thread()); | 677 std::unique_ptr<Thread> thread(new Thread()); |
| 669 thread->Start(); | 678 thread->Start(); |
| 670 Sleeper sleeper; | 679 Sleeper sleeper; |
| 671 TypedMessageData<AsyncSocket*> data(client.get()); | 680 TypedMessageData<AsyncSocket*> data(client.get()); |
| 672 thread->Send(&sleeper, 0, &data); | 681 thread->Send(&sleeper, 0, &data); |
| 673 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ)); | 682 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ)); |
| 674 | 683 |
| 675 // But should signal when process_io is true. | 684 // But should signal when process_io is true. |
| 676 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout); | 685 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout); |
| 677 EXPECT_LT(0, accepted->Recv(buf, 1024)); | 686 EXPECT_LT(0, accepted->Recv(buf, 1024, nullptr)); |
| 678 } | 687 } |
| 679 | 688 |
| 680 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size, | 689 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size, |
| 681 ssize_t max_send_size) { | 690 ssize_t max_send_size) { |
| 682 testing::StreamSink sink; | 691 testing::StreamSink sink; |
| 683 SocketAddress accept_addr; | 692 SocketAddress accept_addr; |
| 684 | 693 |
| 685 // Create receiving client. | 694 // Create receiving client. |
| 686 std::unique_ptr<AsyncSocket> receiver( | 695 std::unique_ptr<AsyncSocket> receiver( |
| 687 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); | 696 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 if (!readable) { | 766 if (!readable) { |
| 758 // Wait until data is available. | 767 // Wait until data is available. |
| 759 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ), | 768 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ), |
| 760 kTimeout); | 769 kTimeout); |
| 761 readable = true; | 770 readable = true; |
| 762 recv_called = false; | 771 recv_called = false; |
| 763 } | 772 } |
| 764 | 773 |
| 765 // Receive as much as we can get in a single recv call. | 774 // Receive as much as we can get in a single recv call. |
| 766 char recved_data[data_size]; | 775 char recved_data[data_size]; |
| 767 int recved_size = receiver->Recv(recved_data, data_size); | 776 int recved_size = receiver->Recv(recved_data, data_size, nullptr); |
| 768 | 777 |
| 769 if (!recv_called) { | 778 if (!recv_called) { |
| 770 // The first Recv() after getting readability should succeed and receive | 779 // The first Recv() after getting readability should succeed and receive |
| 771 // some data. | 780 // some data. |
| 772 // TODO: The following line is disabled due to flakey pulse | 781 // TODO: The following line is disabled due to flakey pulse |
| 773 // builds. Re-enable if/when possible. | 782 // builds. Re-enable if/when possible. |
| 774 // EXPECT_GT(recved_size, 0); | 783 // EXPECT_GT(recved_size, 0); |
| 775 recv_called = true; | 784 recv_called = true; |
| 776 } | 785 } |
| 777 if (recved_size >= 0) { | 786 if (recved_size >= 0) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 char buf[1024 * 16] = {0}; | 853 char buf[1024 * 16] = {0}; |
| 845 int sends = 0; | 854 int sends = 0; |
| 846 while (++sends && accepted->Send(&buf, arraysize(buf)) != -1) {} | 855 while (++sends && accepted->Send(&buf, arraysize(buf)) != -1) {} |
| 847 EXPECT_TRUE(accepted->IsBlocking()); | 856 EXPECT_TRUE(accepted->IsBlocking()); |
| 848 | 857 |
| 849 // Wait until data is available. | 858 // Wait until data is available. |
| 850 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); | 859 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); |
| 851 | 860 |
| 852 // Pull data. | 861 // Pull data. |
| 853 for (int i = 0; i < sends; ++i) { | 862 for (int i = 0; i < sends; ++i) { |
| 854 client->Recv(buf, arraysize(buf)); | 863 client->Recv(buf, arraysize(buf), nullptr); |
| 855 } | 864 } |
| 856 | 865 |
| 857 // Expect at least one additional writable callback. | 866 // Expect at least one additional writable callback. |
| 858 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout); | 867 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout); |
| 859 | 868 |
| 860 // Adding data in response to the writeable callback shouldn't cause infinite | 869 // Adding data in response to the writeable callback shouldn't cause infinite |
| 861 // callbacks. | 870 // callbacks. |
| 862 int extras = 0; | 871 int extras = 0; |
| 863 for (int i = 0; i < 100; ++i) { | 872 for (int i = 0; i < 100; ++i) { |
| 864 accepted->Send(&buf, arraysize(buf)); | 873 accepted->Send(&buf, arraysize(buf)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 | 922 |
| 914 SocketAddress addr5; | 923 SocketAddress addr5; |
| 915 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, addr4)); | 924 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, addr4)); |
| 916 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &addr5)); | 925 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &addr5)); |
| 917 EXPECT_EQ(addr5, addr1); | 926 EXPECT_EQ(addr5, addr1); |
| 918 | 927 |
| 919 addr2 = addr4; | 928 addr2 = addr4; |
| 920 } | 929 } |
| 921 } | 930 } |
| 922 | 931 |
| 932 void SocketTest::SendUdpInterval(const IPAddress& loopback, |
| 933 int64_t time_interval_ms) { |
| 934 SocketAddress empty = EmptySocketAddressWithFamily(loopback.family()); |
| 935 AsyncSocket* socket = ss_->CreateAsyncSocket(loopback.family(), SOCK_DGRAM); |
| 936 EXPECT_EQ(AsyncSocket::CS_CLOSED, socket->GetState()); |
| 937 EXPECT_EQ(0, socket->Bind(SocketAddress(loopback, 0))); |
| 938 SocketAddress address = socket->GetLocalAddress(); |
| 939 delete socket; |
| 940 |
| 941 // Test send/receive behavior. |
| 942 std::unique_ptr<TestClient> client1( |
| 943 new TestClient(AsyncUDPSocket::Create(ss_, address))); |
| 944 |
| 945 int64_t start_ms = rtc::TimeMillis(); |
| 946 while (rtc::TimeMillis() - start_ms < time_interval_ms) { |
| 947 EXPECT_EQ(3, client1->SendTo("foo", 3, address)); |
| 948 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, nullptr)); |
| 949 } |
| 950 } |
| 951 |
| 923 void SocketTest::UdpReadyToSend(const IPAddress& loopback) { | 952 void SocketTest::UdpReadyToSend(const IPAddress& loopback) { |
| 924 SocketAddress empty = EmptySocketAddressWithFamily(loopback.family()); | 953 SocketAddress empty = EmptySocketAddressWithFamily(loopback.family()); |
| 925 // RFC 5737 - The blocks 192.0.2.0/24 (TEST-NET-1) ... are provided for use in | 954 // RFC 5737 - The blocks 192.0.2.0/24 (TEST-NET-1) ... are provided for use in |
| 926 // documentation. | 955 // documentation. |
| 927 // RFC 3849 - 2001:DB8::/32 as a documentation-only prefix. | 956 // RFC 3849 - 2001:DB8::/32 as a documentation-only prefix. |
| 928 std::string dest = (loopback.family() == AF_INET6) ? | 957 std::string dest = (loopback.family() == AF_INET6) ? |
| 929 "2001:db8::1" : "192.0.2.0"; | 958 "2001:db8::1" : "192.0.2.0"; |
| 930 SocketAddress test_addr(dest, 2345); | 959 SocketAddress test_addr(dest, 2345); |
| 931 | 960 |
| 932 // Test send | 961 // Test send |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 ASSERT_EQ(-1, mtu_socket->EstimateMTU(&mtu)); | 1047 ASSERT_EQ(-1, mtu_socket->EstimateMTU(&mtu)); |
| 1019 #else | 1048 #else |
| 1020 // and the behavior seems unpredictable on Linux, | 1049 // and the behavior seems unpredictable on Linux, |
| 1021 // failing on the build machine | 1050 // failing on the build machine |
| 1022 // but succeeding on my Ubiquity instance. | 1051 // but succeeding on my Ubiquity instance. |
| 1023 #endif | 1052 #endif |
| 1024 } | 1053 } |
| 1025 } | 1054 } |
| 1026 | 1055 |
| 1027 } // namespace rtc | 1056 } // namespace rtc |
| OLD | NEW |