Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: webrtc/base/socket_unittest.cc

Issue 1944683002: Read recv timestamps from socket (posix only). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Improve test. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 accepted->Close(); 535 accepted->Close();
536 EXPECT_EQ(AsyncSocket::CS_CLOSED, accepted->GetState()); 536 EXPECT_EQ(AsyncSocket::CS_CLOSED, accepted->GetState());
537 537
538 // Expect that the client is notified, and has not yet closed. 538 // Expect that the client is notified, and has not yet closed.
539 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); 539 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout);
540 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_CLOSE)); 540 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_CLOSE));
541 EXPECT_EQ(AsyncSocket::CS_CONNECTED, client->GetState()); 541 EXPECT_EQ(AsyncSocket::CS_CONNECTED, client->GetState());
542 542
543 // Ensure the data can be read. 543 // Ensure the data can be read.
544 char buffer[10]; 544 char buffer[10];
545 EXPECT_EQ(1, client->Recv(buffer, sizeof(buffer))); 545 EXPECT_EQ(1, client->Recv(buffer, sizeof(buffer), nullptr));
546 EXPECT_EQ('a', buffer[0]); 546 EXPECT_EQ('a', buffer[0]);
547 547
548 // Now we should close, but the remote address will remain. 548 // Now we should close, but the remote address will remain.
549 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout); 549 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout);
550 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_CLOSE)); 550 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_CLOSE));
551 EXPECT_FALSE(client->GetRemoteAddress().IsAnyIP()); 551 EXPECT_FALSE(client->GetRemoteAddress().IsAnyIP());
552 552
553 // The closer should not get a close signal. 553 // The closer should not get a close signal.
554 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_CLOSE)); 554 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_CLOSE));
555 EXPECT_TRUE(accepted->GetRemoteAddress().IsNil()); 555 EXPECT_TRUE(accepted->GetRemoteAddress().IsNil());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 // Shouldn't signal when blocked in a thread Send, where process_io is false. 667 // Shouldn't signal when blocked in a thread Send, where process_io is false.
668 std::unique_ptr<Thread> thread(new Thread()); 668 std::unique_ptr<Thread> thread(new Thread());
669 thread->Start(); 669 thread->Start();
670 Sleeper sleeper; 670 Sleeper sleeper;
671 TypedMessageData<AsyncSocket*> data(client.get()); 671 TypedMessageData<AsyncSocket*> data(client.get());
672 thread->Send(&sleeper, 0, &data); 672 thread->Send(&sleeper, 0, &data);
673 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ)); 673 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ));
674 674
675 // But should signal when process_io is true. 675 // But should signal when process_io is true.
676 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout); 676 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout);
677 EXPECT_LT(0, accepted->Recv(buf, 1024)); 677 EXPECT_LT(0, accepted->Recv(buf, 1024, nullptr));
678 } 678 }
679 679
680 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size, 680 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size,
681 ssize_t max_send_size) { 681 ssize_t max_send_size) {
682 testing::StreamSink sink; 682 testing::StreamSink sink;
683 SocketAddress accept_addr; 683 SocketAddress accept_addr;
684 684
685 // Create receiving client. 685 // Create receiving client.
686 std::unique_ptr<AsyncSocket> receiver( 686 std::unique_ptr<AsyncSocket> receiver(
687 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); 687 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 if (!readable) { 757 if (!readable) {
758 // Wait until data is available. 758 // Wait until data is available.
759 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ), 759 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ),
760 kTimeout); 760 kTimeout);
761 readable = true; 761 readable = true;
762 recv_called = false; 762 recv_called = false;
763 } 763 }
764 764
765 // Receive as much as we can get in a single recv call. 765 // Receive as much as we can get in a single recv call.
766 char recved_data[data_size]; 766 char recved_data[data_size];
767 int recved_size = receiver->Recv(recved_data, data_size); 767 int recved_size = receiver->Recv(recved_data, data_size, nullptr);
768 768
769 if (!recv_called) { 769 if (!recv_called) {
770 // The first Recv() after getting readability should succeed and receive 770 // The first Recv() after getting readability should succeed and receive
771 // some data. 771 // some data.
772 // TODO: The following line is disabled due to flakey pulse 772 // TODO: The following line is disabled due to flakey pulse
773 // builds. Re-enable if/when possible. 773 // builds. Re-enable if/when possible.
774 // EXPECT_GT(recved_size, 0); 774 // EXPECT_GT(recved_size, 0);
775 recv_called = true; 775 recv_called = true;
776 } 776 }
777 if (recved_size >= 0) { 777 if (recved_size >= 0) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 char buf[1024 * 16] = {0}; 844 char buf[1024 * 16] = {0};
845 int sends = 0; 845 int sends = 0;
846 while (++sends && accepted->Send(&buf, arraysize(buf)) != -1) {} 846 while (++sends && accepted->Send(&buf, arraysize(buf)) != -1) {}
847 EXPECT_TRUE(accepted->IsBlocking()); 847 EXPECT_TRUE(accepted->IsBlocking());
848 848
849 // Wait until data is available. 849 // Wait until data is available.
850 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); 850 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout);
851 851
852 // Pull data. 852 // Pull data.
853 for (int i = 0; i < sends; ++i) { 853 for (int i = 0; i < sends; ++i) {
854 client->Recv(buf, arraysize(buf)); 854 client->Recv(buf, arraysize(buf), nullptr);
855 } 855 }
856 856
857 // Expect at least one additional writable callback. 857 // Expect at least one additional writable callback.
858 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout); 858 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout);
859 859
860 // Adding data in response to the writeable callback shouldn't cause infinite 860 // Adding data in response to the writeable callback shouldn't cause infinite
861 // callbacks. 861 // callbacks.
862 int extras = 0; 862 int extras = 0;
863 for (int i = 0; i < 100; ++i) { 863 for (int i = 0; i < 100; ++i) {
864 accepted->Send(&buf, arraysize(buf)); 864 accepted->Send(&buf, arraysize(buf));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 ASSERT_EQ(-1, mtu_socket->EstimateMTU(&mtu)); 1018 ASSERT_EQ(-1, mtu_socket->EstimateMTU(&mtu));
1019 #else 1019 #else
1020 // and the behavior seems unpredictable on Linux, 1020 // and the behavior seems unpredictable on Linux,
1021 // failing on the build machine 1021 // failing on the build machine
1022 // but succeeding on my Ubiquity instance. 1022 // but succeeding on my Ubiquity instance.
1023 #endif 1023 #endif
1024 } 1024 }
1025 } 1025 }
1026 1026
1027 } // namespace rtc 1027 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/socket.h ('k') | webrtc/base/socketadapters.h » ('j') | webrtc/base/testclient.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698