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

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: rebase 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
« no previous file with comments | « webrtc/base/socket_unittest.h ('k') | webrtc/base/socketadapters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 void SocketTest::TestGetSetOptionsIPv4() { 178 void SocketTest::TestGetSetOptionsIPv4() {
179 GetSetOptionsInternal(kIPv4Loopback); 179 GetSetOptionsInternal(kIPv4Loopback);
180 } 180 }
181 181
182 void SocketTest::TestGetSetOptionsIPv6() { 182 void SocketTest::TestGetSetOptionsIPv6() {
183 MAYBE_SKIP_IPV6; 183 MAYBE_SKIP_IPV6;
184 GetSetOptionsInternal(kIPv6Loopback); 184 GetSetOptionsInternal(kIPv6Loopback);
185 } 185 }
186 186
187 void SocketTest::TestSocketRecvTimestamp() {
188 SocketRecvTimestamp(kIPv4Loopback);
189 }
190
187 // For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC 191 // For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC
188 // values on Windows, but an empty address of the same family on Linux/MacOS X. 192 // values on Windows, but an empty address of the same family on Linux/MacOS X.
189 bool IsUnspecOrEmptyIP(const IPAddress& address) { 193 bool IsUnspecOrEmptyIP(const IPAddress& address) {
190 #if !defined(WEBRTC_WIN) 194 #if !defined(WEBRTC_WIN)
191 return IPIsAny(address); 195 return IPIsAny(address);
192 #else 196 #else
193 return address.family() == AF_UNSPEC; 197 return address.family() == AF_UNSPEC;
194 #endif 198 #endif
195 } 199 }
196 200
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 accepted->Close(); 538 accepted->Close();
535 EXPECT_EQ(AsyncSocket::CS_CLOSED, accepted->GetState()); 539 EXPECT_EQ(AsyncSocket::CS_CLOSED, accepted->GetState());
536 540
537 // Expect that the client is notified, and has not yet closed. 541 // Expect that the client is notified, and has not yet closed.
538 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); 542 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout);
539 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_CLOSE)); 543 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_CLOSE));
540 EXPECT_EQ(AsyncSocket::CS_CONNECTED, client->GetState()); 544 EXPECT_EQ(AsyncSocket::CS_CONNECTED, client->GetState());
541 545
542 // Ensure the data can be read. 546 // Ensure the data can be read.
543 char buffer[10]; 547 char buffer[10];
544 EXPECT_EQ(1, client->Recv(buffer, sizeof(buffer))); 548 EXPECT_EQ(1, client->Recv(buffer, sizeof(buffer), nullptr));
545 EXPECT_EQ('a', buffer[0]); 549 EXPECT_EQ('a', buffer[0]);
546 550
547 // Now we should close, but the remote address will remain. 551 // Now we should close, but the remote address will remain.
548 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout); 552 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout);
549 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_CLOSE)); 553 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_CLOSE));
550 EXPECT_FALSE(client->GetRemoteAddress().IsAnyIP()); 554 EXPECT_FALSE(client->GetRemoteAddress().IsAnyIP());
551 555
552 // The closer should not get a close signal. 556 // The closer should not get a close signal.
553 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_CLOSE)); 557 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_CLOSE));
554 EXPECT_TRUE(accepted->GetRemoteAddress().IsNil()); 558 EXPECT_TRUE(accepted->GetRemoteAddress().IsNil());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 // Shouldn't signal when blocked in a thread Send, where process_io is false. 670 // Shouldn't signal when blocked in a thread Send, where process_io is false.
667 std::unique_ptr<Thread> thread(new Thread()); 671 std::unique_ptr<Thread> thread(new Thread());
668 thread->Start(); 672 thread->Start();
669 Sleeper sleeper; 673 Sleeper sleeper;
670 TypedMessageData<AsyncSocket*> data(client.get()); 674 TypedMessageData<AsyncSocket*> data(client.get());
671 thread->Send(&sleeper, 0, &data); 675 thread->Send(&sleeper, 0, &data);
672 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ)); 676 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ));
673 677
674 // But should signal when process_io is true. 678 // But should signal when process_io is true.
675 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout); 679 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout);
676 EXPECT_LT(0, accepted->Recv(buf, 1024)); 680 EXPECT_LT(0, accepted->Recv(buf, 1024, nullptr));
677 } 681 }
678 682
679 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size, 683 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size,
680 ssize_t max_send_size) { 684 ssize_t max_send_size) {
681 testing::StreamSink sink; 685 testing::StreamSink sink;
682 SocketAddress accept_addr; 686 SocketAddress accept_addr;
683 687
684 // Create receiving client. 688 // Create receiving client.
685 std::unique_ptr<AsyncSocket> receiver( 689 std::unique_ptr<AsyncSocket> receiver(
686 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); 690 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 if (!readable) { 760 if (!readable) {
757 // Wait until data is available. 761 // Wait until data is available.
758 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ), 762 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ),
759 kTimeout); 763 kTimeout);
760 readable = true; 764 readable = true;
761 recv_called = false; 765 recv_called = false;
762 } 766 }
763 767
764 // Receive as much as we can get in a single recv call. 768 // Receive as much as we can get in a single recv call.
765 char recved_data[data_size]; 769 char recved_data[data_size];
766 int recved_size = receiver->Recv(recved_data, data_size); 770 int recved_size = receiver->Recv(recved_data, data_size, nullptr);
767 771
768 if (!recv_called) { 772 if (!recv_called) {
769 // The first Recv() after getting readability should succeed and receive 773 // The first Recv() after getting readability should succeed and receive
770 // some data. 774 // some data.
771 // TODO: The following line is disabled due to flakey pulse 775 // TODO: The following line is disabled due to flakey pulse
772 // builds. Re-enable if/when possible. 776 // builds. Re-enable if/when possible.
773 // EXPECT_GT(recved_size, 0); 777 // EXPECT_GT(recved_size, 0);
774 recv_called = true; 778 recv_called = true;
775 } 779 }
776 if (recved_size >= 0) { 780 if (recved_size >= 0) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 char buf[1024 * 16] = {0}; 847 char buf[1024 * 16] = {0};
844 int sends = 0; 848 int sends = 0;
845 while (++sends && accepted->Send(&buf, arraysize(buf)) != -1) {} 849 while (++sends && accepted->Send(&buf, arraysize(buf)) != -1) {}
846 EXPECT_TRUE(accepted->IsBlocking()); 850 EXPECT_TRUE(accepted->IsBlocking());
847 851
848 // Wait until data is available. 852 // Wait until data is available.
849 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); 853 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout);
850 854
851 // Pull data. 855 // Pull data.
852 for (int i = 0; i < sends; ++i) { 856 for (int i = 0; i < sends; ++i) {
853 client->Recv(buf, arraysize(buf)); 857 client->Recv(buf, arraysize(buf), nullptr);
854 } 858 }
855 859
856 // Expect at least one additional writable callback. 860 // Expect at least one additional writable callback.
857 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout); 861 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout);
858 862
859 // Adding data in response to the writeable callback shouldn't cause infinite 863 // Adding data in response to the writeable callback shouldn't cause infinite
860 // callbacks. 864 // callbacks.
861 int extras = 0; 865 int extras = 0;
862 for (int i = 0; i < 100; ++i) { 866 for (int i = 0; i < 100; ++i) {
863 accepted->Send(&buf, arraysize(buf)); 867 accepted->Send(&buf, arraysize(buf));
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 // except on WEBRTC_MAC && !WEBRTC_IOS, where it's not yet implemented 1020 // except on WEBRTC_MAC && !WEBRTC_IOS, where it's not yet implemented
1017 ASSERT_EQ(-1, mtu_socket->EstimateMTU(&mtu)); 1021 ASSERT_EQ(-1, mtu_socket->EstimateMTU(&mtu));
1018 #else 1022 #else
1019 // and the behavior seems unpredictable on Linux, 1023 // and the behavior seems unpredictable on Linux,
1020 // failing on the build machine 1024 // failing on the build machine
1021 // but succeeding on my Ubiquity instance. 1025 // but succeeding on my Ubiquity instance.
1022 #endif 1026 #endif
1023 } 1027 }
1024 } 1028 }
1025 1029
1030 void SocketTest::SocketRecvTimestamp(const IPAddress& loopback) {
1031 std::unique_ptr<Socket> socket(
1032 ss_->CreateSocket(loopback.family(), SOCK_DGRAM));
1033 EXPECT_EQ(0, socket->Bind(SocketAddress(loopback, 0)));
1034 SocketAddress address = socket->GetLocalAddress();
1035
1036 socket->SendTo("foo", 3, address);
1037 int64_t timestamp;
1038 char buffer[3];
1039 socket->RecvFrom(buffer, 3, nullptr, &timestamp);
1040 EXPECT_GT(timestamp, -1);
1041 int64_t prev_timestamp = timestamp;
1042
1043 const int64_t kTimeBetweenPacketsMs = 10;
1044 Thread::SleepMs(kTimeBetweenPacketsMs);
1045
1046 socket->SendTo("bar", 3, address);
1047 socket->RecvFrom(buffer, 3, nullptr, &timestamp);
1048 EXPECT_NEAR(timestamp, prev_timestamp + kTimeBetweenPacketsMs * 1000, 2000);
1049 }
1050
1026 } // namespace rtc 1051 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/socket_unittest.h ('k') | webrtc/base/socketadapters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698