Remove SOO in IPAddress and SocketAddress

This commit is contained in:
Joerg-Christian Boehme
2017-11-02 20:54:38 +01:00
parent 5a6009d9a2
commit 1ec60225b6
6 changed files with 3 additions and 178 deletions

View File

@@ -365,11 +365,7 @@ public:
private:
typedef Poco::Net::Impl::IPAddressImpl Impl;
#ifdef POCO_HAVE_ALIGNMENT
typedef Impl* Ptr;
#else
typedef Poco::AutoPtr<Impl> Ptr;
#endif
Ptr pImpl() const;
void newIPv4();
@@ -381,86 +377,35 @@ private:
void newIPv6(const void* hostAddr, Poco::UInt32 scope);
void newIPv6(unsigned prefix);
#endif
void destruct();
#ifdef POCO_HAVE_ALIGNMENT
char* storage();
#ifdef POCO_ENABLE_CPP11
static const unsigned sz = sizeof(Poco::Net::Impl::IPv6AddressImpl);
typedef std::aligned_storage<sz>::type AlignerType;
union
{
char buffer[sz];
private:
AlignerType aligner;
}
#else // !POCO_ENABLE_CPP11
#if defined(POCO_HAVE_IPv6)
AlignedCharArrayUnion <Poco::Net::Impl::IPv6AddressImpl>
#else
AlignedCharArrayUnion <Poco::Net::Impl::IPv4AddressImpl>
#endif
#endif // POCO_ENABLE_CPP11
_memory;
#else // !POCO_HAVE_ALIGNMENT
Ptr _pImpl;
#endif // POCO_HAVE_ALIGNMENT
};
//
// inlines
//
inline void IPAddress::destruct()
{
#ifdef POCO_HAVE_ALIGNMENT
pImpl()->~IPAddressImpl();
#endif
}
inline IPAddress::Ptr IPAddress::pImpl() const
{
#ifdef POCO_HAVE_ALIGNMENT
return reinterpret_cast<Ptr>(const_cast<char *>(_memory.buffer));
#else
if (_pImpl) return _pImpl;
throw NullPointerException("IPaddress implementation pointer is NULL.");
#endif
}
inline void IPAddress::newIPv4()
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv4AddressImpl;
#else
_pImpl = new Poco::Net::Impl::IPv4AddressImpl;
#endif
}
inline void IPAddress::newIPv4(const void* hostAddr)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv4AddressImpl(hostAddr);
#else
_pImpl = new Poco::Net::Impl::IPv4AddressImpl(hostAddr);
#endif
}
inline void IPAddress::newIPv4(unsigned prefix)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv4AddressImpl(prefix);
#else
_pImpl = new Poco::Net::Impl::IPv4AddressImpl(prefix);
#endif
}
@@ -469,55 +414,31 @@ inline void IPAddress::newIPv4(unsigned prefix)
inline void IPAddress::newIPv6()
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv6AddressImpl;
#else
_pImpl = new Poco::Net::Impl::IPv6AddressImpl;
#endif
}
inline void IPAddress::newIPv6(const void* hostAddr)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv6AddressImpl(hostAddr);
#else
_pImpl = new Poco::Net::Impl::IPv6AddressImpl(hostAddr);
#endif
}
inline void IPAddress::newIPv6(const void* hostAddr, Poco::UInt32 scope)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv6AddressImpl(hostAddr, scope);
#else
_pImpl = new Poco::Net::Impl::IPv6AddressImpl(hostAddr, scope);
#endif
}
inline void IPAddress::newIPv6(unsigned prefix)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv6AddressImpl(prefix);
#else
_pImpl = new Poco::Net::Impl::IPv6AddressImpl(prefix);
#endif
}
#endif // POCO_HAVE_IPv6
#ifdef POCO_HAVE_ALIGNMENT
inline char* IPAddress::storage()
{
return _memory.buffer;
}
#endif
} } // namespace Poco::Net

View File

@@ -20,9 +20,7 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h"
#ifndef POCO_HAVE_ALIGNMENT
#include "Poco/RefCountedObject.h"
#endif
#include <vector>
@@ -31,10 +29,7 @@ namespace Net {
namespace Impl {
class IPAddressImpl
#ifndef POCO_HAVE_ALIGNMENT
: public Poco::RefCountedObject
#endif
class IPAddressImpl : public Poco::RefCountedObject
{
public:
typedef AddressFamily::Family Family;

View File

@@ -195,11 +195,7 @@ protected:
private:
typedef Poco::Net::Impl::SocketAddressImpl Impl;
#ifdef POCO_HAVE_ALIGNMENT
typedef Impl* Ptr;
#else
typedef Poco::AutoPtr<Impl> Ptr;
#endif
Ptr pImpl() const;
@@ -217,106 +213,48 @@ private:
void newLocal(const std::string& path);
#endif
void destruct();
#ifdef POCO_HAVE_ALIGNMENT
char* storage();
#ifdef POCO_ENABLE_CPP11
static const unsigned sz = sizeof(Poco::Net::Impl::IPv6SocketAddressImpl);
typedef std::aligned_storage<sz>::type AlignerType;
union
{
char buffer[sz];
private:
AlignerType aligner;
}
#else // !POCO_ENABLE_CPP11
#if defined(POCO_HAVE_IPv6)
AlignedCharArrayUnion <Poco::Net::Impl::IPv6SocketAddressImpl>
#else
AlignedCharArrayUnion <Poco::Net::Impl::IPv4SocketAddressImpl>
#endif
#endif // POCO_ENABLE_CPP11
_memory;
#else // !POCO_HAVE_ALIGNMENT
Ptr _pImpl;
#endif // POCO_HAVE_ALIGNMENT
};
//
// inlines
//
inline void SocketAddress::destruct()
{
#ifdef POCO_HAVE_ALIGNMENT
pImpl()->~SocketAddressImpl();
#endif
}
inline SocketAddress::Ptr SocketAddress::pImpl() const
{
#ifdef POCO_HAVE_ALIGNMENT
return reinterpret_cast<Ptr>(const_cast<char *>(_memory.buffer));
#else
if (_pImpl) return _pImpl;
throw Poco::NullPointerException("Pointer to SocketAddress implementation is NULL.");
#endif
}
inline void SocketAddress::newIPv4()
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv4SocketAddressImpl;
#else
_pImpl = new Poco::Net::Impl::IPv4SocketAddressImpl;
#endif
}
inline void SocketAddress::newIPv4(const sockaddr_in* sockAddr)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv4SocketAddressImpl(sockAddr);
#else
_pImpl = new Poco::Net::Impl::IPv4SocketAddressImpl(sockAddr);
#endif
}
inline void SocketAddress::newIPv4(const IPAddress& hostAddress, Poco::UInt16 portNumber)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv4SocketAddressImpl(hostAddress.addr(), htons(portNumber));
#else
_pImpl = new Poco::Net::Impl::IPv4SocketAddressImpl(hostAddress.addr(), htons(portNumber));
#endif
}
#if defined(POCO_HAVE_IPv6)
inline void SocketAddress::newIPv6(const sockaddr_in6* sockAddr)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv6SocketAddressImpl(sockAddr);
#else
_pImpl = new Poco::Net::Impl::IPv6SocketAddressImpl(sockAddr);
#endif
}
inline void SocketAddress::newIPv6(const IPAddress& hostAddress, Poco::UInt16 portNumber)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::IPv6SocketAddressImpl(hostAddress.addr(), htons(portNumber), hostAddress.scope());
#else
_pImpl = new Poco::Net::Impl::IPv6SocketAddressImpl(hostAddress.addr(), htons(portNumber), hostAddress.scope());
#endif
}
#endif // POCO_HAVE_IPv6
@@ -324,34 +262,18 @@ inline void SocketAddress::newIPv6(const IPAddress& hostAddress, Poco::UInt16 po
#if defined(POCO_OS_FAMILY_UNIX)
inline void SocketAddress::newLocal(const sockaddr_un* sockAddr)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::LocalSocketAddressImpl(sockAddr);
#else
_pImpl = new Poco::Net::Impl::LocalSocketAddressImpl(sockAddr);
#endif
}
inline void SocketAddress::newLocal(const std::string& path)
{
#ifdef POCO_HAVE_ALIGNMENT
new (storage()) Poco::Net::Impl::LocalSocketAddressImpl(path.c_str());
#else
_pImpl = new Poco::Net::Impl::LocalSocketAddressImpl(path.c_str());
#endif
}
#endif // POCO_OS_FAMILY_UNIX
#ifdef POCO_HAVE_ALIGNMENT
inline char* SocketAddress::storage()
{
return _memory.buffer;
}
#endif
inline bool SocketAddress::operator == (const SocketAddress& socketAddress) const
inline bool SocketAddress::operator == (const SocketAddress& socketAddress) const
{
#if defined(POCO_OS_FAMILY_UNIX)
if (family() == UNIX_LOCAL)

View File

@@ -21,9 +21,7 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h"
#include "Poco/Net/IPAddress.h"
#ifndef POCO_HAVE_ALIGNMENT
#include "Poco/RefCountedObject.h"
#endif
namespace Poco {
@@ -31,10 +29,7 @@ namespace Net {
namespace Impl {
class Net_API SocketAddressImpl
#ifndef POCO_HAVE_ALIGNMENT
: public Poco::RefCountedObject
#endif
class Net_API SocketAddressImpl : public Poco::RefCountedObject
{
public:
typedef AddressFamily::Family Family;