Don't attempt to use "network binder" for sockets bound to "ANY" IP.
BUG=NONE Review-Url: https://codereview.webrtc.org/2701253002 Cr-Commit-Position: refs/heads/master@{#16760}
This commit is contained in:
parent
e352dbe6d5
commit
9ffa13ff5d
@ -194,7 +194,7 @@ int PhysicalSocket::Bind(const SocketAddress& bind_addr) {
|
||||
// If a network binder is available, use it to bind a socket to an interface
|
||||
// instead of bind(), since this is more reliable on an OS with a weak host
|
||||
// model.
|
||||
if (ss_->network_binder()) {
|
||||
if (ss_->network_binder() && !bind_addr.IsAnyIP()) {
|
||||
NetworkBindingResult result =
|
||||
ss_->network_binder()->BindSocketToNetwork(s_, bind_addr.ipaddr());
|
||||
if (result == NetworkBindingResult::SUCCESS) {
|
||||
|
||||
@ -89,13 +89,17 @@ class FakePhysicalSocketServer : public PhysicalSocketServer {
|
||||
class FakeNetworkBinder : public NetworkBinderInterface {
|
||||
public:
|
||||
NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override {
|
||||
++num_binds_;
|
||||
return result_;
|
||||
}
|
||||
|
||||
void set_result(NetworkBindingResult result) { result_ = result; }
|
||||
|
||||
int num_binds() { return num_binds_; }
|
||||
|
||||
private:
|
||||
NetworkBindingResult result_ = NetworkBindingResult::SUCCESS;
|
||||
int num_binds_ = 0;
|
||||
};
|
||||
|
||||
class PhysicalSocketTest : public SocketTest {
|
||||
@ -441,6 +445,18 @@ TEST_F(PhysicalSocketTest,
|
||||
server_->set_network_binder(nullptr);
|
||||
}
|
||||
|
||||
// Network binder shouldn't be used if the socket is bound to the "any" IP.
|
||||
TEST_F(PhysicalSocketTest,
|
||||
NetworkBinderIsNotUsedForAnyIp) {
|
||||
FakeNetworkBinder fake_network_binder;
|
||||
server_->set_network_binder(&fake_network_binder);
|
||||
std::unique_ptr<AsyncSocket> socket(
|
||||
server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM));
|
||||
EXPECT_EQ(0, socket->Bind(SocketAddress("0.0.0.0", 0)));
|
||||
EXPECT_EQ(0, fake_network_binder.num_binds());
|
||||
server_->set_network_binder(nullptr);
|
||||
}
|
||||
|
||||
// For a loopback interface, failures to bind to the interface should be
|
||||
// tolerated.
|
||||
TEST_F(PhysicalSocketTest,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user