mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 02:18:04 +01:00
merge Unix Domain Sockets support and other changes from develop
This commit is contained in:
@@ -33,13 +33,25 @@ using Poco::UInt16;
|
||||
using Poco::UInt32;
|
||||
using Poco::Net::Impl::IPAddressImpl;
|
||||
using Poco::Net::Impl::IPv4AddressImpl;
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
using Poco::Net::Impl::IPv6AddressImpl;
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
#if !defined(_MSC_VER) || defined(__STDC__)
|
||||
// Go home MSVC, you're drunk...
|
||||
// See http://stackoverflow.com/questions/5899857/multiple-definition-error-for-static-const-class-members
|
||||
const IPAddress::Family IPAddress::IPv4;
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
const IPAddress::Family IPAddress::IPv6;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
IPAddress::IPAddress()
|
||||
{
|
||||
newIPv4();
|
||||
@@ -50,8 +62,10 @@ IPAddress::IPAddress(const IPAddress& addr)
|
||||
{
|
||||
if (addr.family() == IPv4)
|
||||
newIPv4(addr.addr());
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
else
|
||||
newIPv6(addr.addr(), addr.scope());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +77,7 @@ IPAddress::IPAddress(Family family)
|
||||
else if (family == IPv6)
|
||||
newIPv6();
|
||||
#endif
|
||||
else
|
||||
throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
|
||||
else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
|
||||
}
|
||||
|
||||
|
||||
@@ -219,8 +232,12 @@ IPAddress& IPAddress::operator = (const IPAddress& addr)
|
||||
destruct();
|
||||
if (addr.family() == IPAddress::IPv4)
|
||||
newIPv4(addr.addr());
|
||||
else
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
else if (addr.family() == IPAddress::IPv6)
|
||||
newIPv6(addr.addr(), addr.scope());
|
||||
#endif
|
||||
else
|
||||
throw Poco::InvalidArgumentException("Invalid or unsupported address family");
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -228,7 +245,7 @@ IPAddress& IPAddress::operator = (const IPAddress& addr)
|
||||
|
||||
IPAddress::Family IPAddress::family() const
|
||||
{
|
||||
return static_cast<IPAddress::Family>(pImpl()->family());
|
||||
return pImpl()->family();
|
||||
}
|
||||
|
||||
|
||||
@@ -561,19 +578,30 @@ IPAddress IPAddress::broadcast()
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& operator << (BinaryWriter& writer, const IPAddress& value)
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
Poco::BinaryWriter& operator << (Poco::BinaryWriter& writer, const Poco::Net::IPAddress& value)
|
||||
{
|
||||
writer.stream().write((const char*) value.addr(), value.length());
|
||||
writer << static_cast<Poco::UInt8>(value.length());
|
||||
writer.writeRaw(reinterpret_cast<const char*>(value.addr()), value.length());
|
||||
return writer;
|
||||
}
|
||||
|
||||
BinaryReader& operator >> (BinaryReader& reader, IPAddress& value)
|
||||
|
||||
Poco::BinaryReader& operator >> (Poco::BinaryReader& reader, Poco::Net::IPAddress& value)
|
||||
{
|
||||
char buf[sizeof(struct in6_addr)];
|
||||
reader.stream().read(buf, value.length());
|
||||
value = IPAddress(buf, value.length());
|
||||
Poco::UInt8 length;
|
||||
reader >> length;
|
||||
reader.readRaw(buf, length);
|
||||
value = Poco::Net::IPAddress(buf, length);
|
||||
return reader;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
std::ostream& operator << (std::ostream& ostr, const Poco::Net::IPAddress& addr)
|
||||
{
|
||||
ostr << addr.toString();
|
||||
return ostr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user