OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 PhysicalSocketTest* GetTest() const { return test_; } | 83 PhysicalSocketTest* GetTest() const { return test_; } |
84 | 84 |
85 private: | 85 private: |
86 PhysicalSocketTest* test_; | 86 PhysicalSocketTest* test_; |
87 }; | 87 }; |
88 | 88 |
89 class FakeNetworkBinder : public NetworkBinderInterface { | 89 class FakeNetworkBinder : public NetworkBinderInterface { |
90 public: | 90 public: |
91 NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override { | 91 NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override { |
| 92 ++num_binds_; |
92 return result_; | 93 return result_; |
93 } | 94 } |
94 | 95 |
95 void set_result(NetworkBindingResult result) { result_ = result; } | 96 void set_result(NetworkBindingResult result) { result_ = result; } |
96 | 97 |
| 98 int num_binds() { return num_binds_; } |
| 99 |
97 private: | 100 private: |
98 NetworkBindingResult result_ = NetworkBindingResult::SUCCESS; | 101 NetworkBindingResult result_ = NetworkBindingResult::SUCCESS; |
| 102 int num_binds_ = 0; |
99 }; | 103 }; |
100 | 104 |
101 class PhysicalSocketTest : public SocketTest { | 105 class PhysicalSocketTest : public SocketTest { |
102 public: | 106 public: |
103 // Set flag to simluate failures when calling "::accept" on a AsyncSocket. | 107 // Set flag to simluate failures when calling "::accept" on a AsyncSocket. |
104 void SetFailAccept(bool fail) { fail_accept_ = fail; } | 108 void SetFailAccept(bool fail) { fail_accept_ = fail; } |
105 bool FailAccept() const { return fail_accept_; } | 109 bool FailAccept() const { return fail_accept_; } |
106 | 110 |
107 // Maximum size to ::send to a socket. Set to < 0 to disable limiting. | 111 // Maximum size to ::send to a socket. Set to < 0 to disable limiting. |
108 void SetMaxSendSize(int max_size) { max_send_size_ = max_size; } | 112 void SetMaxSendSize(int max_size) { max_send_size_ = max_size; } |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 BindFailsIfNetworkBinderFailsForNonLoopbackInterface) { | 438 BindFailsIfNetworkBinderFailsForNonLoopbackInterface) { |
435 FakeNetworkBinder fake_network_binder; | 439 FakeNetworkBinder fake_network_binder; |
436 server_->set_network_binder(&fake_network_binder); | 440 server_->set_network_binder(&fake_network_binder); |
437 std::unique_ptr<AsyncSocket> socket( | 441 std::unique_ptr<AsyncSocket> socket( |
438 server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); | 442 server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); |
439 fake_network_binder.set_result(NetworkBindingResult::FAILURE); | 443 fake_network_binder.set_result(NetworkBindingResult::FAILURE); |
440 EXPECT_EQ(-1, socket->Bind(SocketAddress("192.168.0.1", 0))); | 444 EXPECT_EQ(-1, socket->Bind(SocketAddress("192.168.0.1", 0))); |
441 server_->set_network_binder(nullptr); | 445 server_->set_network_binder(nullptr); |
442 } | 446 } |
443 | 447 |
| 448 // Network binder shouldn't be used if the socket is bound to the "any" IP. |
| 449 TEST_F(PhysicalSocketTest, |
| 450 NetworkBinderIsNotUsedForAnyIp) { |
| 451 FakeNetworkBinder fake_network_binder; |
| 452 server_->set_network_binder(&fake_network_binder); |
| 453 std::unique_ptr<AsyncSocket> socket( |
| 454 server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); |
| 455 EXPECT_EQ(0, socket->Bind(SocketAddress("0.0.0.0", 0))); |
| 456 EXPECT_EQ(0, fake_network_binder.num_binds()); |
| 457 server_->set_network_binder(nullptr); |
| 458 } |
| 459 |
444 // For a loopback interface, failures to bind to the interface should be | 460 // For a loopback interface, failures to bind to the interface should be |
445 // tolerated. | 461 // tolerated. |
446 TEST_F(PhysicalSocketTest, | 462 TEST_F(PhysicalSocketTest, |
447 BindSucceedsIfNetworkBinderFailsForLoopbackInterface) { | 463 BindSucceedsIfNetworkBinderFailsForLoopbackInterface) { |
448 FakeNetworkBinder fake_network_binder; | 464 FakeNetworkBinder fake_network_binder; |
449 server_->set_network_binder(&fake_network_binder); | 465 server_->set_network_binder(&fake_network_binder); |
450 std::unique_ptr<AsyncSocket> socket( | 466 std::unique_ptr<AsyncSocket> socket( |
451 server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); | 467 server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); |
452 fake_network_binder.set_result(NetworkBindingResult::FAILURE); | 468 fake_network_binder.set_result(NetworkBindingResult::FAILURE); |
453 EXPECT_EQ(0, socket->Bind(SocketAddress(kIPv4Loopback, 0))); | 469 EXPECT_EQ(0, socket->Bind(SocketAddress(kIPv4Loopback, 0))); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 thread->Start(runnable.get()); | 587 thread->Start(runnable.get()); |
572 EXPECT_TRUE(ss_->Wait(1500, true)); | 588 EXPECT_TRUE(ss_->Wait(1500, true)); |
573 EXPECT_TRUE(ExpectSignal(SIGTERM)); | 589 EXPECT_TRUE(ExpectSignal(SIGTERM)); |
574 EXPECT_EQ(Thread::Current(), signaled_thread_); | 590 EXPECT_EQ(Thread::Current(), signaled_thread_); |
575 EXPECT_TRUE(ExpectNone()); | 591 EXPECT_TRUE(ExpectNone()); |
576 } | 592 } |
577 | 593 |
578 #endif | 594 #endif |
579 | 595 |
580 } // namespace rtc | 596 } // namespace rtc |
OLD | NEW |