"with length too long for a sockaddr_un");
}
- prepFamilyChange(AF_UNIX);
+ if (!external_) {
+ storage_.un.init();
+ }
+ external_ = true;
memcpy(storage_.un.addr, address, addrlen);
updateUnixAddressLength(addrlen);
bool isLoopbackAddress() const;
void reset() {
- prepFamilyChange(AF_UNSPEC);
+ if (external_) {
+ storage_.un.free();
+ }
+ storage_.addr = folly::IPAddress();
+ external_ = false;
}
/**
void updateUnixAddressLength(socklen_t addrlen);
- void prepFamilyChange(sa_family_t newFamily) {
- if (newFamily != AF_UNIX) {
- if (external_) {
- storage_.un.free();
- storage_.addr = folly::IPAddress();
- }
- external_ = false;
- } else {
- if (!external_) {
- storage_.un.init();
- }
- external_ = true;
- }
- }
-
/*
* storage_ contains room for a full IPv4 or IPv6 address, so they can be
* stored inline without a separate allocation on the heap.
addy.reset();
EXPECT_EQ(addy.getFamily(), AF_UNSPEC);
}
+
+TEST(SocketAddress, ResetIPAddress) {
+ SocketAddress addr;
+ addr.setFromIpPort("127.0.0.1", 80);
+ addr.reset();
+ EXPECT_EQ(addr.getFamily(), AF_UNSPEC);
+ EXPECT_FALSE(addr.isInitialized());
+ EXPECT_TRUE(addr.empty());
+
+ addr.setFromIpPort("2620:0:1cfe:face:b00c::3:65535");
+ addr.reset();
+ EXPECT_EQ(addr.getFamily(), AF_UNSPEC);
+ EXPECT_FALSE(addr.isInitialized());
+ EXPECT_TRUE(addr.empty());
+}