| 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 |
| 11 #include "webrtc/base/socket_unittest.h" | 11 #include "webrtc/base/socket_unittest.h" |
| 12 | 12 |
| 13 #include "webrtc/base/arraysize.h" |
| 13 #include "webrtc/base/asyncudpsocket.h" | 14 #include "webrtc/base/asyncudpsocket.h" |
| 14 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
| 15 #include "webrtc/base/nethelpers.h" | 16 #include "webrtc/base/nethelpers.h" |
| 16 #include "webrtc/base/socketserver.h" | 17 #include "webrtc/base/socketserver.h" |
| 17 #include "webrtc/base/testclient.h" | 18 #include "webrtc/base/testclient.h" |
| 18 #include "webrtc/base/testutils.h" | 19 #include "webrtc/base/testutils.h" |
| 19 #include "webrtc/base/thread.h" | 20 #include "webrtc/base/thread.h" |
| 20 | 21 |
| 21 namespace rtc { | 22 namespace rtc { |
| 22 | 23 |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_OPEN)); | 821 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_OPEN)); |
| 821 EXPECT_EQ(client->GetRemoteAddress(), accepted->GetLocalAddress()); | 822 EXPECT_EQ(client->GetRemoteAddress(), accepted->GetLocalAddress()); |
| 822 EXPECT_EQ(accepted->GetRemoteAddress(), client->GetLocalAddress()); | 823 EXPECT_EQ(accepted->GetRemoteAddress(), client->GetLocalAddress()); |
| 823 | 824 |
| 824 // Expect a writable callback from the connect. | 825 // Expect a writable callback from the connect. |
| 825 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout); | 826 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout); |
| 826 | 827 |
| 827 // Fill the socket buffer. | 828 // Fill the socket buffer. |
| 828 char buf[1024 * 16] = {0}; | 829 char buf[1024 * 16] = {0}; |
| 829 int sends = 0; | 830 int sends = 0; |
| 830 while (++sends && accepted->Send(&buf, ARRAY_SIZE(buf)) != -1) {} | 831 while (++sends && accepted->Send(&buf, arraysize(buf)) != -1) {} |
| 831 EXPECT_TRUE(accepted->IsBlocking()); | 832 EXPECT_TRUE(accepted->IsBlocking()); |
| 832 | 833 |
| 833 // Wait until data is available. | 834 // Wait until data is available. |
| 834 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); | 835 EXPECT_TRUE_WAIT(sink.Check(client.get(), testing::SSE_READ), kTimeout); |
| 835 | 836 |
| 836 // Pull data. | 837 // Pull data. |
| 837 for (int i = 0; i < sends; ++i) { | 838 for (int i = 0; i < sends; ++i) { |
| 838 client->Recv(buf, ARRAY_SIZE(buf)); | 839 client->Recv(buf, arraysize(buf)); |
| 839 } | 840 } |
| 840 | 841 |
| 841 // Expect at least one additional writable callback. | 842 // Expect at least one additional writable callback. |
| 842 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout); | 843 EXPECT_TRUE_WAIT(sink.Check(accepted.get(), testing::SSE_WRITE), kTimeout); |
| 843 | 844 |
| 844 // Adding data in response to the writeable callback shouldn't cause infinite | 845 // Adding data in response to the writeable callback shouldn't cause infinite |
| 845 // callbacks. | 846 // callbacks. |
| 846 int extras = 0; | 847 int extras = 0; |
| 847 for (int i = 0; i < 100; ++i) { | 848 for (int i = 0; i < 100; ++i) { |
| 848 accepted->Send(&buf, ARRAY_SIZE(buf)); | 849 accepted->Send(&buf, arraysize(buf)); |
| 849 rtc::Thread::Current()->ProcessMessages(1); | 850 rtc::Thread::Current()->ProcessMessages(1); |
| 850 if (sink.Check(accepted.get(), testing::SSE_WRITE)) { | 851 if (sink.Check(accepted.get(), testing::SSE_WRITE)) { |
| 851 extras++; | 852 extras++; |
| 852 } | 853 } |
| 853 } | 854 } |
| 854 EXPECT_LT(extras, 2); | 855 EXPECT_LT(extras, 2); |
| 855 | 856 |
| 856 // Close down. | 857 // Close down. |
| 857 accepted->Close(); | 858 accepted->Close(); |
| 858 client->Close(); | 859 client->Close(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 ASSERT_EQ(-1, mtu_socket->EstimateMTU(&mtu)); | 1004 ASSERT_EQ(-1, mtu_socket->EstimateMTU(&mtu)); |
| 1004 #else | 1005 #else |
| 1005 // and the behavior seems unpredictable on Linux, | 1006 // and the behavior seems unpredictable on Linux, |
| 1006 // failing on the build machine | 1007 // failing on the build machine |
| 1007 // but succeeding on my Ubiquity instance. | 1008 // but succeeding on my Ubiquity instance. |
| 1008 #endif | 1009 #endif |
| 1009 } | 1010 } |
| 1010 } | 1011 } |
| 1011 | 1012 |
| 1012 } // namespace rtc | 1013 } // namespace rtc |
| OLD | NEW |