Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pick][0.8 to main] | redefine undefined() in EndPoint #686

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion net/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace net {
public:
union {
in6_addr addr = {};
// all data is in network byte order
struct { uint16_t _1, _2, _3, _4, _5, _6; uint8_t a, b, c, d; };
} __attribute__((packed));
// For compatibility, the default constructor is still 0.0.0.0 (IPv4)
Expand Down Expand Up @@ -97,6 +98,8 @@ namespace net {
bool undefined() const {
return mem_equal(V4Any());
}
void reset() { *this = IPAddr(); }
void clear() { reset(); }
// Should ONLY be used for IPv4 address
uint32_t to_nl() const {
assert(is_ipv4());
Expand Down Expand Up @@ -169,7 +172,14 @@ namespace net {
return !operator==(rhs);
}
bool undefined() const {
return addr.undefined();
return addr.undefined() && port == 0;
}
void reset() {
addr.reset();
port = 0;
}
void clear() {
reset();
}
};

Expand Down
2 changes: 1 addition & 1 deletion net/test/test-ipv6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST(ipv6, endpoint) {
c = photon::net::EndPoint("[::1]:8888");
EXPECT_FALSE(c.undefined());
c = photon::net::EndPoint("0.0.0.0:8888");
EXPECT_TRUE(c.undefined());
EXPECT_FALSE(c.undefined());
EXPECT_EQ(8888, c.port);
c = photon::net::EndPoint("::", 8888);
EXPECT_TRUE(!c.undefined());
Expand Down
Loading