Summary:
Add `SocketAddress::makeFromPath(StringPiece)` static member function to
constructor `SocketAddress` from a path to Unix domain socket.
Reviewed By: yfeldblum
Differential Revision:
D5974523
fbshipit-source-id:
b5c1537e67d07d1ef401fea75e35753392eeaf6b
setFromPath(StringPiece{path, length});
}
setFromPath(StringPiece{path, length});
}
+ /**
+ * Construct a SocketAddress from a local unix socket path.
+ *
+ * Raises std::invalid_argument on error.
+ *
+ * @param path The Unix domain socket path.
+ */
+ static SocketAddress makeFromPath(StringPiece path) {
+ SocketAddress addr;
+ addr.setFromPath(path);
+ return addr;
+ }
+
/**
* Initialize this SocketAddress from a socket's peer address.
*
/**
* Initialize this SocketAddress from a socket's peer address.
*
unix3.setFromPath("/bar");
SocketAddress unixAnon;
unixAnon.setFromPath("");
unix3.setFromPath("/bar");
SocketAddress unixAnon;
unixAnon.setFromPath("");
+ auto unix5 = SocketAddress::makeFromPath("/foo");
+ auto unixAnon2 = SocketAddress::makeFromPath("");
+ EXPECT_EQ(unix1, unix5);
EXPECT_EQ(unix1.hash(), unix2.hash());
EXPECT_EQ(unix1.hash(), unix2.hash());
+ EXPECT_EQ(unix1.hash(), unix5.hash());
EXPECT_NE(unix1, unix3);
EXPECT_NE(unix1, unixAnon);
EXPECT_NE(unix1, unix3);
EXPECT_NE(unix1, unixAnon);
+ EXPECT_NE(unix1, unixAnon2);
+ EXPECT_NE(unix5, unix3);
EXPECT_NE(unix2, unixAnon);
EXPECT_NE(unix2, unixAnon);
+ EXPECT_NE(unix2, unixAnon2);
+ EXPECT_NE(unix5, unixAnon);
+ EXPECT_NE(unix5, unixAnon2);
// anonymous addresses aren't equal to any other address,
// including themselves
EXPECT_NE(unixAnon, unixAnon);
// anonymous addresses aren't equal to any other address,
// including themselves
EXPECT_NE(unixAnon, unixAnon);
+ EXPECT_NE(unixAnon2, unixAnon2);
// It isn't strictly required that hashes for different addresses be
// different, but we should have very few collisions. It generally indicates
// It isn't strictly required that hashes for different addresses be
// different, but we should have very few collisions. It generally indicates
EXPECT_NE(unix1.hash(), unix3.hash());
EXPECT_NE(unix1.hash(), unixAnon.hash());
EXPECT_NE(unix3.hash(), unixAnon.hash());
EXPECT_NE(unix1.hash(), unix3.hash());
EXPECT_NE(unix1.hash(), unixAnon.hash());
EXPECT_NE(unix3.hash(), unixAnon.hash());
+ EXPECT_NE(unix1.hash(), unixAnon2.hash());
+ EXPECT_NE(unix3.hash(), unixAnon2.hash());
}
TEST(SocketAddress, IsPrivate) {
}
TEST(SocketAddress, IsPrivate) {