From 1ec60225b63e0d1aa138b4253b46777c3c2b9d45 Mon Sep 17 00:00:00 2001 From: Joerg-Christian Boehme Date: Thu, 2 Nov 2017 20:54:38 +0100 Subject: [PATCH] Remove SOO in IPAddress and SocketAddress --- Net/include/Poco/Net/IPAddress.h | 79 ----------------------- Net/include/Poco/Net/IPAddressImpl.h | 7 +-- Net/include/Poco/Net/SocketAddress.h | 80 +----------------------- Net/include/Poco/Net/SocketAddressImpl.h | 7 +-- Net/src/IPAddress.cpp | 6 -- Net/src/SocketAddress.cpp | 2 - 6 files changed, 3 insertions(+), 178 deletions(-) diff --git a/Net/include/Poco/Net/IPAddress.h b/Net/include/Poco/Net/IPAddress.h index c7f1f1a43..7d9cb6fa8 100644 --- a/Net/include/Poco/Net/IPAddress.h +++ b/Net/include/Poco/Net/IPAddress.h @@ -365,11 +365,7 @@ public: private: typedef Poco::Net::Impl::IPAddressImpl Impl; -#ifdef POCO_HAVE_ALIGNMENT - typedef Impl* Ptr; -#else typedef Poco::AutoPtr 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::type AlignerType; - - union - { - char buffer[sz]; - private: - AlignerType aligner; - } - #else // !POCO_ENABLE_CPP11 - #if defined(POCO_HAVE_IPv6) - AlignedCharArrayUnion - #else - AlignedCharArrayUnion - #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(const_cast(_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 diff --git a/Net/include/Poco/Net/IPAddressImpl.h b/Net/include/Poco/Net/IPAddressImpl.h index d8d56f55b..e43d68550 100644 --- a/Net/include/Poco/Net/IPAddressImpl.h +++ b/Net/include/Poco/Net/IPAddressImpl.h @@ -20,9 +20,7 @@ #include "Poco/Net/Net.h" #include "Poco/Net/SocketDefs.h" -#ifndef POCO_HAVE_ALIGNMENT #include "Poco/RefCountedObject.h" -#endif #include @@ -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; diff --git a/Net/include/Poco/Net/SocketAddress.h b/Net/include/Poco/Net/SocketAddress.h index 1d5f03079..b151c4c81 100644 --- a/Net/include/Poco/Net/SocketAddress.h +++ b/Net/include/Poco/Net/SocketAddress.h @@ -195,11 +195,7 @@ protected: private: typedef Poco::Net::Impl::SocketAddressImpl Impl; -#ifdef POCO_HAVE_ALIGNMENT - typedef Impl* Ptr; -#else typedef Poco::AutoPtr 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::type AlignerType; - union - { - char buffer[sz]; - private: - AlignerType aligner; - } - #else // !POCO_ENABLE_CPP11 - #if defined(POCO_HAVE_IPv6) - AlignedCharArrayUnion - #else - AlignedCharArrayUnion - #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(const_cast(_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) diff --git a/Net/include/Poco/Net/SocketAddressImpl.h b/Net/include/Poco/Net/SocketAddressImpl.h index 689a10fc3..27bc4fe69 100644 --- a/Net/include/Poco/Net/SocketAddressImpl.h +++ b/Net/include/Poco/Net/SocketAddressImpl.h @@ -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; diff --git a/Net/src/IPAddress.cpp b/Net/src/IPAddress.cpp index d8b6d470f..fde12a284 100644 --- a/Net/src/IPAddress.cpp +++ b/Net/src/IPAddress.cpp @@ -138,9 +138,7 @@ IPAddress::IPAddress(const std::string& addr, Family family) IPAddress::IPAddress(const void* addr, poco_socklen_t length) -#ifndef POCO_HAVE_ALIGNMENT : _pImpl(0) -#endif { if (length == sizeof(struct in_addr)) newIPv4(addr); @@ -188,9 +186,7 @@ IPAddress::IPAddress(unsigned prefix, Family family) #if defined(_WIN32) IPAddress::IPAddress(const SOCKET_ADDRESS& socket_address) -#ifndef POCO_HAVE_ALIGNMENT : _pImpl(0) -#endif { ADDRESS_FAMILY family = socket_address.lpSockaddr->sa_family; if (family == AF_INET) @@ -221,7 +217,6 @@ IPAddress::IPAddress(const struct sockaddr& sockaddr) IPAddress::~IPAddress() { - destruct(); } @@ -229,7 +224,6 @@ IPAddress& IPAddress::operator = (const IPAddress& addr) { if (&addr != this) { - destruct(); if (addr.family() == IPAddress::IPv4) newIPv4(addr.addr()); #if defined(POCO_HAVE_IPv6) diff --git a/Net/src/SocketAddress.cpp b/Net/src/SocketAddress.cpp index 21f6019ab..0782ca3ee 100644 --- a/Net/src/SocketAddress.cpp +++ b/Net/src/SocketAddress.cpp @@ -168,7 +168,6 @@ SocketAddress::SocketAddress(const struct sockaddr* sockAddr, poco_socklen_t len SocketAddress::~SocketAddress() { - destruct(); } @@ -189,7 +188,6 @@ SocketAddress& SocketAddress::operator = (const SocketAddress& socketAddress) { if (&socketAddress != this) { - destruct(); if (socketAddress.family() == IPv4) newIPv4(reinterpret_cast(socketAddress.addr())); #if defined(POCO_HAVE_IPv6)