Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make wildcard() lightweight.

  • Loading branch information...
commit 33883824e8082d2a01ee5ef9db8a131fd22f4b87 1 parent f654330
@pprindeville authored
Showing with 16 additions and 8 deletions.
  1. +6 −2 Net/include/Poco/Net/IPAddress.h
  2. +10 −6 Net/src/IPAddress.cpp
View
8 Net/include/Poco/Net/IPAddress.h
@@ -370,10 +370,10 @@ class Net_API IPAddress
///
/// Returns false and leaves result unchanged otherwise.
- static IPAddress wildcard(Family family = IPv4);
+ static const IPAddress& wildcard(Family family = IPv4);
/// Returns a wildcard IPv4 or IPv6 address (0.0.0.0).
- static IPAddress broadcast();
+ static const IPAddress& broadcast();
/// Returns a broadcast IPv4 address (255.255.255.255).
enum
@@ -390,6 +390,10 @@ class Net_API IPAddress
protected:
void init(IPAddressImpl* pImpl);
+ static const IPAddress wildcardIPv4;
+ static const IPAddress wildcardIPv6;
+ static const IPAddress broadcastIPv4;
+
private:
IPAddressImpl* _pImpl;
};
View
16 Net/src/IPAddress.cpp
@@ -1243,17 +1243,21 @@ void IPAddress::mask(const IPAddress& mask, const IPAddress& set)
}
-IPAddress IPAddress::wildcard(Family family)
+const IPAddress IPAddress::wildcardIPv4(IPv4);
+const IPAddress IPAddress::wildcardIPv6(IPv6);
+
+const IPAddress& IPAddress::wildcard(Family family)
{
- return IPAddress(family);
+ return ((family == IPv4) ? wildcardIPv4 : wildcardIPv6);
}
-IPAddress IPAddress::broadcast()
+static const struct in_addr bcast = { INADDR_NONE };
+const IPAddress IPAddress::broadcastIPv4(&bcast, sizeof(bcast));
+
+const IPAddress& IPAddress::broadcast()
{
- struct in_addr ia;
- ia.s_addr = INADDR_NONE;
- return IPAddress(&ia, sizeof(ia));
+ return broadcastIPv4;
}
Please sign in to comment.
Something went wrong with that request. Please try again.