Merge pull request #1971 from Bjoe/remove-soo-in-net

Remove SOO in 1.8
This commit is contained in:
Günter Obiltschnig 2017-11-07 14:46:17 +01:00 committed by GitHub
commit 37927faf66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 3 additions and 178 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -138,9 +138,7 @@ IPAddress::IPAddress(const std::string& addr, Family family)
IPAddress::IPAddress(const void* addr, poco_socklen_t length) IPAddress::IPAddress(const void* addr, poco_socklen_t length)
#ifndef POCO_HAVE_ALIGNMENT
: _pImpl(0) : _pImpl(0)
#endif
{ {
if (length == sizeof(struct in_addr)) if (length == sizeof(struct in_addr))
newIPv4(addr); newIPv4(addr);
@ -188,9 +186,7 @@ IPAddress::IPAddress(unsigned prefix, Family family)
#if defined(_WIN32) #if defined(_WIN32)
IPAddress::IPAddress(const SOCKET_ADDRESS& socket_address) IPAddress::IPAddress(const SOCKET_ADDRESS& socket_address)
#ifndef POCO_HAVE_ALIGNMENT
: _pImpl(0) : _pImpl(0)
#endif
{ {
ADDRESS_FAMILY family = socket_address.lpSockaddr->sa_family; ADDRESS_FAMILY family = socket_address.lpSockaddr->sa_family;
if (family == AF_INET) if (family == AF_INET)
@ -221,7 +217,6 @@ IPAddress::IPAddress(const struct sockaddr& sockaddr)
IPAddress::~IPAddress() IPAddress::~IPAddress()
{ {
destruct();
} }
@ -229,7 +224,6 @@ IPAddress& IPAddress::operator = (const IPAddress& addr)
{ {
if (&addr != this) if (&addr != this)
{ {
destruct();
if (addr.family() == IPAddress::IPv4) if (addr.family() == IPAddress::IPv4)
newIPv4(addr.addr()); newIPv4(addr.addr());
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)

View File

@ -168,7 +168,6 @@ SocketAddress::SocketAddress(const struct sockaddr* sockAddr, poco_socklen_t len
SocketAddress::~SocketAddress() SocketAddress::~SocketAddress()
{ {
destruct();
} }
@ -189,7 +188,6 @@ SocketAddress& SocketAddress::operator = (const SocketAddress& socketAddress)
{ {
if (&socketAddress != this) if (&socketAddress != this)
{ {
destruct();
if (socketAddress.family() == IPv4) if (socketAddress.family() == IPv4)
newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr())); newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr()));
#if defined(POCO_HAVE_IPv6) #if defined(POCO_HAVE_IPv6)