Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Address Alex's issues and use references to avoid temporary construct…

…ors, temporary variables, etc.
  • Loading branch information...
commit fea912af1145bd4e2d057d779d487c8626f8d2b6 1 parent 3388382
@pprindeville authored
View
2  Net/include/Poco/Net/NetworkInterface.h
@@ -155,7 +155,7 @@ class Net_API NetworkInterface
/// Throws NotFoundException if the address family is not
/// configured on the interface.
- void firstAddress(IPAddress& addr, IPAddress::Family family = IPAddress::IPv4) const;
+ const IPAddress& firstAddressNoThrow(IPAddress::Family family) const;
/// Returns the first IP address bound to the interface.
/// If the address family is not configured on the interface,
/// the address returned in addr will be unspecified (wildcard).
View
27 Net/src/NetworkInterface.cpp
@@ -95,7 +95,7 @@ class NetworkInterfaceImpl: public Poco::RefCountedObject
unsigned index() const;
const std::string& name() const;
const std::string& displayName() const;
- void firstAddress(IPAddress& address, IPAddress::Family family) const;
+ const IPAddress& firstAddress(IPAddress::Family family) const;
void addAddress(const AddressTuple& address);
const IPAddress& address(unsigned index) const;
const NetworkInterface::AddressList& addressList() const;
@@ -240,9 +240,7 @@ NetworkInterfaceImpl::~NetworkInterfaceImpl()
bool NetworkInterfaceImpl::supportsIPv4() const
{
- IPAddress addr(IPAddress::IPv4);
-
- firstAddress(addr, IPAddress::IPv4);
+ const IPAddress& addr = firstAddress(IPAddress::IPv4);
return !addr.isWildcard();
}
@@ -251,9 +249,7 @@ bool NetworkInterfaceImpl::supportsIPv4() const
bool NetworkInterfaceImpl::supportsIPv6() const
{
#ifdef POCO_HAVE_IPv6
- IPAddress addr(IPAddress::IPv6);
-
- firstAddress(addr, IPAddress::IPv6);
+ const IPAddress& addr = firstAddress(IPAddress::IPv6);
return !addr.isWildcard();
#else
@@ -280,7 +276,7 @@ inline const std::string& NetworkInterfaceImpl::displayName() const
}
-void NetworkInterfaceImpl::firstAddress(IPAddress& address, IPAddress::Family family) const
+const IPAddress& NetworkInterfaceImpl::firstAddress(IPAddress::Family family) const
{
AddressList::const_iterator it = _addressList.begin();
AddressList::const_iterator end = _addressList.end();
@@ -288,17 +284,13 @@ void NetworkInterfaceImpl::firstAddress(IPAddress& address, IPAddress::Family fa
{
const IPAddress& addr = it->get<NetworkInterface::IP_ADDRESS>();
if (addr.family() == family)
- {
- address = addr;
- return;
- }
+ return addr;
}
// because testing isWildcard() is a lot faster than catching an
// exception... and having an unconfigured interface is hardly
// an 'exceptional' state.
- address = IPAddress(family);
- return;
+ return IPAddress::wildcard(family);
}
@@ -611,18 +603,17 @@ const std::string& NetworkInterface::displayName() const
const IPAddress& NetworkInterface::firstAddress(IPAddress::Family family) const
{
- IPAddress addr(family);
+ const IPAddress& addr = _pImpl->firstAddress(family);
- _pImpl->firstAddress(addr, family);
if (addr.isWildcard())
throw NotFoundException(format("%s family address not found.", (family == IPAddress::IPv4) ? std::string("IPv4") : std::string("IPv6")));
return addr;
}
-void NetworkInterface::firstAddress(IPAddress& addr, IPAddress::Family family) const
+const IPAddress& NetworkInterface::firstAddressNoThrow(IPAddress::Family family) const
{
- _pImpl->firstAddress(addr, family);
+ return _pImpl->firstAddress(family);
}
Please sign in to comment.
Something went wrong with that request. Please try again.