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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 TypedMessageData<AsyncSocket*> data(client.get()); | 674 TypedMessageData<AsyncSocket*> data(client.get()); |
675 thread->Send(RTC_FROM_HERE, &sleeper, 0, &data); | 675 thread->Send(RTC_FROM_HERE, &sleeper, 0, &data); |
676 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ)); | 676 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ)); |
677 | 677 |
678 // But should signal when process_io is true. | 678 // But should signal when process_io is true. |
679 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout); | 679 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout); |
680 EXPECT_LT(0, accepted->Recv(buf, 1024, nullptr)); | 680 EXPECT_LT(0, accepted->Recv(buf, 1024, nullptr)); |
681 } | 681 } |
682 | 682 |
683 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size, | 683 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size, |
684 ssize_t max_send_size) { | 684 ptrdiff_t max_send_size) { |
685 testing::StreamSink sink; | 685 testing::StreamSink sink; |
686 SocketAddress accept_addr; | 686 SocketAddress accept_addr; |
687 | 687 |
688 // Create receiving client. | 688 // Create receiving client. |
689 std::unique_ptr<AsyncSocket> receiver( | 689 std::unique_ptr<AsyncSocket> receiver( |
690 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); | 690 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); |
691 sink.Monitor(receiver.get()); | 691 sink.Monitor(receiver.get()); |
692 | 692 |
693 // Create server and listen. | 693 // Create server and listen. |
694 std::unique_ptr<AsyncSocket> server( | 694 std::unique_ptr<AsyncSocket> server( |
(...skipping 17 matching lines...) Expand all Loading... |
712 EXPECT_EQ(receiver->GetRemoteAddress(), sender->GetLocalAddress()); | 712 EXPECT_EQ(receiver->GetRemoteAddress(), sender->GetLocalAddress()); |
713 EXPECT_EQ(sender->GetRemoteAddress(), receiver->GetLocalAddress()); | 713 EXPECT_EQ(sender->GetRemoteAddress(), receiver->GetLocalAddress()); |
714 | 714 |
715 // Create test data. | 715 // Create test data. |
716 rtc::Buffer send_buffer(0, data_size); | 716 rtc::Buffer send_buffer(0, data_size); |
717 rtc::Buffer recv_buffer(0, data_size); | 717 rtc::Buffer recv_buffer(0, data_size); |
718 for (size_t i = 0; i < data_size; ++i) { | 718 for (size_t i = 0; i < data_size; ++i) { |
719 char ch = static_cast<char>(i % 256); | 719 char ch = static_cast<char>(i % 256); |
720 send_buffer.AppendData(&ch, sizeof(ch)); | 720 send_buffer.AppendData(&ch, sizeof(ch)); |
721 } | 721 } |
| 722 rtc::Buffer recved_data(0, data_size); |
722 | 723 |
723 // Send and receive a bunch of data. | 724 // Send and receive a bunch of data. |
724 size_t sent_size = 0; | 725 size_t sent_size = 0; |
725 bool writable = true; | 726 bool writable = true; |
726 bool send_called = false; | 727 bool send_called = false; |
727 bool readable = false; | 728 bool readable = false; |
728 bool recv_called = false; | 729 bool recv_called = false; |
729 while (recv_buffer.size() < send_buffer.size()) { | 730 while (recv_buffer.size() < send_buffer.size()) { |
730 // Send as much as we can while we're cleared to send. | 731 // Send as much as we can while we're cleared to send. |
731 while (writable && sent_size < send_buffer.size()) { | 732 while (writable && sent_size < send_buffer.size()) { |
732 int unsent_size = static_cast<int>(send_buffer.size() - sent_size); | 733 int unsent_size = static_cast<int>(send_buffer.size() - sent_size); |
733 int sent = sender->Send(send_buffer.data() + sent_size, unsent_size); | 734 int sent = sender->Send(send_buffer.data() + sent_size, unsent_size); |
734 if (!send_called) { | 735 if (!send_called) { |
735 // The first Send() after connecting or getting writability should | 736 // The first Send() after connecting or getting writability should |
736 // succeed and send some data. | 737 // succeed and send some data. |
737 EXPECT_GT(sent, 0); | 738 EXPECT_GT(sent, 0); |
738 send_called = true; | 739 send_called = true; |
739 } | 740 } |
740 if (sent >= 0) { | 741 if (sent >= 0) { |
741 EXPECT_LE(sent, unsent_size); | 742 EXPECT_LE(sent, unsent_size); |
742 sent_size += sent; | 743 sent_size += sent; |
743 if (max_send_size >= 0) { | 744 if (max_send_size >= 0) { |
744 EXPECT_LE(static_cast<ssize_t>(sent), max_send_size); | 745 EXPECT_LE(static_cast<ptrdiff_t>(sent), max_send_size); |
745 if (sent < unsent_size) { | 746 if (sent < unsent_size) { |
746 // If max_send_size is limiting the amount to send per call such | 747 // If max_send_size is limiting the amount to send per call such |
747 // that the sent amount is less than the unsent amount, we simulate | 748 // that the sent amount is less than the unsent amount, we simulate |
748 // that the socket is no longer writable. | 749 // that the socket is no longer writable. |
749 writable = false; | 750 writable = false; |
750 } | 751 } |
751 } | 752 } |
752 } else { | 753 } else { |
753 ASSERT_TRUE(sender->IsBlocking()); | 754 ASSERT_TRUE(sender->IsBlocking()); |
754 writable = false; | 755 writable = false; |
755 } | 756 } |
756 } | 757 } |
757 | 758 |
758 // Read all the sent data. | 759 // Read all the sent data. |
759 while (recv_buffer.size() < sent_size) { | 760 while (recv_buffer.size() < sent_size) { |
760 if (!readable) { | 761 if (!readable) { |
761 // Wait until data is available. | 762 // Wait until data is available. |
762 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ), | 763 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ), |
763 kTimeout); | 764 kTimeout); |
764 readable = true; | 765 readable = true; |
765 recv_called = false; | 766 recv_called = false; |
766 } | 767 } |
767 | 768 |
768 // Receive as much as we can get in a single recv call. | 769 // Receive as much as we can get in a single recv call. |
769 char recved_data[data_size]; | 770 int recved_size = receiver->Recv(recved_data.data(), data_size, nullptr); |
770 int recved_size = receiver->Recv(recved_data, data_size, nullptr); | |
771 | 771 |
772 if (!recv_called) { | 772 if (!recv_called) { |
773 // The first Recv() after getting readability should succeed and receive | 773 // The first Recv() after getting readability should succeed and receive |
774 // some data. | 774 // some data. |
775 // TODO: The following line is disabled due to flakey pulse | 775 // TODO: The following line is disabled due to flakey pulse |
776 // builds. Re-enable if/when possible. | 776 // builds. Re-enable if/when possible. |
777 // EXPECT_GT(recved_size, 0); | 777 // EXPECT_GT(recved_size, 0); |
778 recv_called = true; | 778 recv_called = true; |
779 } | 779 } |
780 if (recved_size >= 0) { | 780 if (recved_size >= 0) { |
781 EXPECT_LE(static_cast<size_t>(recved_size), | 781 EXPECT_LE(static_cast<size_t>(recved_size), |
782 sent_size - recv_buffer.size()); | 782 sent_size - recv_buffer.size()); |
783 recv_buffer.AppendData(recved_data, recved_size); | 783 recv_buffer.AppendData(recved_data.data(), recved_size); |
784 } else { | 784 } else { |
785 ASSERT_TRUE(receiver->IsBlocking()); | 785 ASSERT_TRUE(receiver->IsBlocking()); |
786 readable = false; | 786 readable = false; |
787 } | 787 } |
788 } | 788 } |
789 | 789 |
790 // Once all that we've sent has been received, expect to be able to send | 790 // Once all that we've sent has been received, expect to be able to send |
791 // again. | 791 // again. |
792 if (!writable) { | 792 if (!writable) { |
793 EXPECT_TRUE_WAIT(sink.Check(sender.get(), testing::SSE_WRITE), | 793 ASSERT_TRUE_WAIT(sink.Check(sender.get(), testing::SSE_WRITE), |
794 kTimeout); | 794 kTimeout); |
795 writable = true; | 795 writable = true; |
796 send_called = false; | 796 send_called = false; |
797 } | 797 } |
798 } | 798 } |
799 | 799 |
800 // The received data matches the sent data. | 800 // The received data matches the sent data. |
801 EXPECT_EQ(data_size, sent_size); | 801 EXPECT_EQ(data_size, sent_size); |
802 EXPECT_EQ(data_size, recv_buffer.size()); | 802 EXPECT_EQ(data_size, recv_buffer.size()); |
803 EXPECT_EQ(recv_buffer, send_buffer); | 803 EXPECT_EQ(recv_buffer, send_buffer); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 | 1042 |
1043 const int64_t kTimeBetweenPacketsMs = 10; | 1043 const int64_t kTimeBetweenPacketsMs = 10; |
1044 Thread::SleepMs(kTimeBetweenPacketsMs); | 1044 Thread::SleepMs(kTimeBetweenPacketsMs); |
1045 | 1045 |
1046 socket->SendTo("bar", 3, address); | 1046 socket->SendTo("bar", 3, address); |
1047 socket->RecvFrom(buffer, 3, nullptr, ×tamp); | 1047 socket->RecvFrom(buffer, 3, nullptr, ×tamp); |
1048 EXPECT_NEAR(timestamp, prev_timestamp + kTimeBetweenPacketsMs * 1000, 2000); | 1048 EXPECT_NEAR(timestamp, prev_timestamp + kTimeBetweenPacketsMs * 1000, 2000); |
1049 } | 1049 } |
1050 | 1050 |
1051 } // namespace rtc | 1051 } // namespace rtc |
OLD | NEW |