mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 16:48:06 +02:00
gcc alignment and warning suppression
This commit is contained in:
@@ -120,37 +120,45 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
|
|||||||
// MSVC requires special handling here.
|
// MSVC requires special handling here.
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
|
|
||||||
#if __has_feature(cxx_alignas)
|
#ifdef POCO_COMPILER_CLANG
|
||||||
#define POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
|
|
||||||
template <> struct AlignedCharArrayImpl<x> \
|
#if __has_feature(cxx_alignas)
|
||||||
{ \
|
#define POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
|
||||||
char alignas(x) aligned; \
|
template <> struct AlignedCharArrayImpl<x> \
|
||||||
}
|
{ \
|
||||||
|
char alignas(x) aligned; \
|
||||||
|
}
|
||||||
|
#define POCO_HAVE_ALIGNMENT
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(__GNUC__) || defined(__IBM_ATTRIBUTES)
|
#elif defined(__GNUC__) || defined(__IBM_ATTRIBUTES)
|
||||||
|
|
||||||
#define POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
|
#define POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
|
||||||
template <> struct AlignedCharArrayImpl<x> \
|
template <> struct AlignedCharArrayImpl<x> \
|
||||||
{ \
|
{ \
|
||||||
char aligned __attribute__((aligned(x))); \
|
char aligned __attribute__((aligned(x))); \
|
||||||
}
|
}
|
||||||
#else
|
#define POCO_HAVE_ALIGNMENT
|
||||||
# error No supported align as directive.
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(1);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(2);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(4);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(8);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(16);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(32);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(64);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(128);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(512);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(1024);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(2048);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(4096);
|
||||||
|
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(8192);
|
||||||
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(1);
|
#undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(2);
|
#endif // POCO_HAVE_ALIGNMENT
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(4);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(8);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(16);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(32);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(64);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(128);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(512);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(1024);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(2048);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(4096);
|
|
||||||
POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(8192);
|
|
||||||
|
|
||||||
#undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
|
|
||||||
|
|
||||||
#else // _MSC_VER
|
#else // _MSC_VER
|
||||||
|
|
||||||
@@ -180,49 +188,59 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
|
|||||||
// Any larger and MSVC complains.
|
// Any larger and MSVC complains.
|
||||||
#undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
|
#undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
|
||||||
|
|
||||||
|
#define POCO_HAVE_ALIGNMENT
|
||||||
#endif // _MSC_VER
|
#endif // _MSC_VER
|
||||||
|
|
||||||
|
// POCO_HAVE_ALIGNMENT will be defined on the pre-C++11 platforms/compilers where
|
||||||
|
// it can be reliably determined and used. Uncomment the line below to explicitly
|
||||||
|
// disable use of alignment even for those platforms.
|
||||||
|
// #undef POCO_HAVE_ALIGNMENT
|
||||||
|
|
||||||
template <typename T1, typename T2 = char, typename T3 = char, typename T4 = char>
|
|
||||||
union AlignedCharArrayUnion
|
|
||||||
/// This union template exposes a suitably aligned and sized character
|
|
||||||
/// array member which can hold elements of any of up to four types.
|
|
||||||
///
|
|
||||||
/// These types may be arrays, structs, or any other types. The goal is to
|
|
||||||
/// produce a union type containing a character array which, when used, forms
|
|
||||||
/// storage suitable to placement new any of these types over. Support for more
|
|
||||||
/// than four types can be added at the cost of more boiler plate.
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
class AlignerImpl
|
|
||||||
{
|
|
||||||
T1 t1;
|
|
||||||
T2 t2;
|
|
||||||
T3 t3;
|
|
||||||
T4 t4;
|
|
||||||
|
|
||||||
AlignerImpl(); // Never defined or instantiated.
|
|
||||||
};
|
|
||||||
|
|
||||||
union SizerImpl
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
{
|
|
||||||
char arr1[sizeof(T1)];
|
|
||||||
char arr2[sizeof(T2)];
|
|
||||||
char arr3[sizeof(T3)];
|
|
||||||
char arr4[sizeof(T4)];
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
template <typename T1, typename T2 = char, typename T3 = char, typename T4 = char>
|
||||||
char buffer[sizeof(SizerImpl)];
|
union AlignedCharArrayUnion
|
||||||
/// The character array buffer for use by clients.
|
/// This union template exposes a suitably aligned and sized character
|
||||||
|
/// array member which can hold elements of any of up to four types.
|
||||||
///
|
///
|
||||||
/// No other member of this union should be referenced. They exist purely to
|
/// These types may be arrays, structs, or any other types. The goal is to
|
||||||
/// constrain the layout of this character array.
|
/// produce a union type containing a character array which, when used, forms
|
||||||
|
/// storage suitable to placement new any of these types over. Support for more
|
||||||
|
/// than four types can be added at the cost of more boiler plate.
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
class AlignerImpl
|
||||||
|
{
|
||||||
|
T1 t1;
|
||||||
|
T2 t2;
|
||||||
|
T3 t3;
|
||||||
|
T4 t4;
|
||||||
|
|
||||||
|
AlignerImpl(); // Never defined or instantiated.
|
||||||
|
};
|
||||||
|
|
||||||
|
union SizerImpl
|
||||||
|
{
|
||||||
|
char arr1[sizeof(T1)];
|
||||||
|
char arr2[sizeof(T2)];
|
||||||
|
char arr3[sizeof(T3)];
|
||||||
|
char arr4[sizeof(T4)];
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
char buffer[sizeof(SizerImpl)];
|
||||||
|
/// The character array buffer for use by clients.
|
||||||
|
///
|
||||||
|
/// No other member of this union should be referenced. They exist purely to
|
||||||
|
/// constrain the layout of this character array.
|
||||||
|
|
||||||
|
private:
|
||||||
|
Poco::AlignedCharArrayImpl<AlignOf<AlignerImpl>::Alignment> _nonceMember;
|
||||||
|
|
||||||
private:
|
|
||||||
Poco::AlignedCharArrayImpl<AlignOf<AlignerImpl>::Alignment> _nonceMember;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // POCO_HAVE_ALIGNMENT
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
@@ -75,6 +75,29 @@
|
|||||||
#define __THROW
|
#define __THROW
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// GCC diagnostics enable/disable by Patrick Horgan, see
|
||||||
|
// http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
|
||||||
|
// use example: GCC_DIAG_OFF(unused-variable)
|
||||||
|
//
|
||||||
|
#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
|
||||||
|
#define GCC_DIAG_STR(s) #s
|
||||||
|
#define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
|
||||||
|
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
|
||||||
|
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
|
||||||
|
#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
|
||||||
|
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
|
||||||
|
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
|
||||||
|
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
|
||||||
|
#else
|
||||||
|
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
|
||||||
|
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(warning GCC_DIAG_JOINSTR(-W,x))
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GCC_DIAG_OFF(x)
|
||||||
|
#define GCC_DIAG_ON(x)
|
||||||
|
#endif
|
||||||
#endif // __GNUC__
|
#endif // __GNUC__
|
||||||
|
|
||||||
|
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "pcre_config.h"
|
#include "pcre_config.h"
|
||||||
|
GCC_DIAG_OFF(unused-function) // pcre_memmove unused function warning
|
||||||
#include "pcre_internal.h"
|
#include "pcre_internal.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#include "Poco/Bugcheck.h"
|
#include "Poco/Bugcheck.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-but-set-variable)
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1400
|
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||||
#pragma warning(disable:4800)//forcing value to bool 'true' or 'false'
|
#pragma warning(disable:4800)//forcing value to bool 'true' or 'false'
|
||||||
#endif
|
#endif
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "TestPlugin.h"
|
#include "TestPlugin.h"
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
using Poco::ClassLoader;
|
using Poco::ClassLoader;
|
||||||
using Poco::Manifest;
|
using Poco::Manifest;
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
|
|
||||||
class ClassLoaderTest: public CppUnit::TestCase
|
class ClassLoaderTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
|
@@ -51,6 +51,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
using Poco::Bugcheck;
|
using Poco::Bugcheck;
|
||||||
using Poco::Exception;
|
using Poco::Exception;
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#include "Poco/Timespan.h"
|
#include "Poco/Timespan.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
using Poco::Timestamp;
|
using Poco::Timestamp;
|
||||||
using Poco::DateTime;
|
using Poco::DateTime;
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
using Poco::File;
|
using Poco::File;
|
||||||
using Poco::TemporaryFile;
|
using Poco::TemporaryFile;
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
using Poco::HashMap;
|
using Poco::HashMap;
|
||||||
|
|
||||||
|
@@ -37,6 +37,9 @@
|
|||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
using Poco::ListMap;
|
using Poco::ListMap;
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#include "Poco/PatternFormatter.h"
|
#include "Poco/PatternFormatter.h"
|
||||||
#include "Poco/AutoPtr.h"
|
#include "Poco/AutoPtr.h"
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
using Poco::LoggingRegistry;
|
using Poco::LoggingRegistry;
|
||||||
using Poco::Channel;
|
using Poco::Channel;
|
||||||
|
@@ -36,6 +36,8 @@
|
|||||||
#include "Poco/NamedTuple.h"
|
#include "Poco/NamedTuple.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-but-set-variable)
|
||||||
|
|
||||||
using Poco::NamedTuple;
|
using Poco::NamedTuple;
|
||||||
using Poco::Int8;
|
using Poco::Int8;
|
||||||
using Poco::UInt8;
|
using Poco::UInt8;
|
||||||
@@ -52,6 +54,7 @@ using Poco::UInt32;
|
|||||||
using Poco::NotFoundException;
|
using Poco::NotFoundException;
|
||||||
using Poco::InvalidArgumentException;
|
using Poco::InvalidArgumentException;
|
||||||
|
|
||||||
|
|
||||||
NamedTuplesTest::NamedTuplesTest(const std::string& name): CppUnit::TestCase(name)
|
NamedTuplesTest::NamedTuplesTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,9 @@
|
|||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include "Poco/StringTokenizer.h"
|
#include "Poco/StringTokenizer.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
|
|
||||||
using Poco::StringTokenizer;
|
using Poco::StringTokenizer;
|
||||||
using Poco::RangeException;
|
using Poco::RangeException;
|
||||||
|
@@ -37,6 +37,8 @@
|
|||||||
#include "Poco/TypeList.h"
|
#include "Poco/TypeList.h"
|
||||||
#include "Poco/Void.h"
|
#include "Poco/Void.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-but-set-variable)
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# pragma warning(disable:4800) // forcing value to bool 'true' or 'false' on MSVC 71
|
# pragma warning(disable:4800) // forcing value to bool 'true' or 'false' on MSVC 71
|
||||||
#endif
|
#endif
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-variable)
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1400
|
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||||
#pragma warning(disable:4800)//forcing value to bool 'true' or 'false'
|
#pragma warning(disable:4800)//forcing value to bool 'true' or 'false'
|
||||||
#endif
|
#endif
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(unused-but-set-variable)
|
||||||
|
|
||||||
class VarTest: public CppUnit::TestCase
|
class VarTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
|
@@ -43,9 +43,12 @@
|
|||||||
#include "Poco/Net/Net.h"
|
#include "Poco/Net/Net.h"
|
||||||
#include "Poco/Net/SocketDefs.h"
|
#include "Poco/Net/SocketDefs.h"
|
||||||
#include "Poco/Net/IPAddressImpl.h"
|
#include "Poco/Net/IPAddressImpl.h"
|
||||||
|
#include "Poco/AutoPtr.h"
|
||||||
|
#include "Poco/Exception.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#ifdef POCO_ENABLE_CPP11
|
#ifdef POCO_ENABLE_CPP11
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#define POCO_HAVE_ALIGNMENT
|
||||||
#else
|
#else
|
||||||
#include "Poco/Alignment.h"
|
#include "Poco/Alignment.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -389,46 +392,148 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
typedef Poco::Net::Impl::IPAddressImpl Impl;
|
typedef Poco::Net::Impl::IPAddressImpl Impl;
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
typedef Impl* Ptr;
|
typedef Impl* Ptr;
|
||||||
|
#else
|
||||||
|
typedef Poco::AutoPtr<Impl> Ptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
Ptr pImpl() const;
|
Ptr pImpl() const;
|
||||||
|
|
||||||
|
void newIPv4(const void* hostAddr);
|
||||||
|
|
||||||
|
void newIPv6(const void* hostAddr);
|
||||||
|
|
||||||
|
void newIPv6(const void* hostAddr, Poco::UInt32 scope);
|
||||||
|
|
||||||
|
void newIPv4(unsigned prefix);
|
||||||
|
|
||||||
|
void newIPv6(unsigned prefix);
|
||||||
|
|
||||||
|
void newIPv4();
|
||||||
|
|
||||||
|
void newIPv6();
|
||||||
|
|
||||||
void destruct();
|
void destruct();
|
||||||
|
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
char* storage();
|
char* storage();
|
||||||
|
|
||||||
#ifdef POCO_ENABLE_CPP11
|
#ifdef POCO_ENABLE_CPP11
|
||||||
static const unsigned sz = sizeof(Poco::Net::Impl::IPv6AddressImpl);
|
static const unsigned sz = sizeof(Poco::Net::Impl::IPv6AddressImpl);
|
||||||
typedef std::aligned_storage<sz>::type AlignerType;
|
typedef std::aligned_storage<sz>::type AlignerType;
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
char buffer[sz];
|
char buffer[sz];
|
||||||
AlignerType aligner;
|
private:
|
||||||
}
|
AlignerType aligner;
|
||||||
#else // !POCO_ENABLE_CPP11
|
}
|
||||||
AlignedCharArrayUnion <Poco::Net::Impl::IPv6AddressImpl>
|
#else // !POCO_ENABLE_CPP11
|
||||||
#endif // POCO_ENABLE_CPP11
|
AlignedCharArrayUnion <Poco::Net::Impl::IPv6AddressImpl>
|
||||||
_memory;
|
#endif // POCO_ENABLE_CPP11
|
||||||
|
_memory;
|
||||||
|
#else // !POCO_HAVE_ALIGNMENT
|
||||||
|
Ptr _pImpl;
|
||||||
|
#endif // POCO_HAVE_ALIGNMENT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline void IPAddress::destruct()
|
inline void IPAddress::destruct()
|
||||||
{
|
{
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
pImpl()->~IPAddressImpl();
|
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));
|
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(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::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::newIPv4(unsigned prefix)
|
||||||
|
{
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
|
new (storage()) Poco::Net::Impl::IPv4AddressImpl(prefix);
|
||||||
|
#else
|
||||||
|
_pImpl = new Poco::Net::Impl::IPv4AddressImpl(prefix);
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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::newIPv6()
|
||||||
|
{
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
|
new (storage()) Poco::Net::Impl::IPv6AddressImpl;
|
||||||
|
#else
|
||||||
|
_pImpl = new Poco::Net::Impl::IPv6AddressImpl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
inline char* IPAddress::storage()
|
inline char* IPAddress::storage()
|
||||||
{
|
{
|
||||||
return _memory.buffer;
|
return _memory.buffer;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
BinaryWriter& operator << (BinaryWriter& writer, const IPAddress& value);
|
BinaryWriter& operator << (BinaryWriter& writer, const IPAddress& value);
|
||||||
|
@@ -42,6 +42,9 @@
|
|||||||
|
|
||||||
#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"
|
||||||
|
#endif
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
@@ -51,6 +54,9 @@ namespace Impl {
|
|||||||
|
|
||||||
|
|
||||||
class IPAddressImpl
|
class IPAddressImpl
|
||||||
|
#ifndef POCO_HAVE_ALIGNMENT
|
||||||
|
: public Poco::RefCountedObject
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Family
|
enum Family
|
||||||
|
@@ -150,26 +150,45 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
typedef Poco::Net::Impl::SocketAddressImpl Impl;
|
typedef Poco::Net::Impl::SocketAddressImpl Impl;
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
typedef Impl* Ptr;
|
typedef Impl* Ptr;
|
||||||
|
#else
|
||||||
|
typedef Poco::AutoPtr<Impl> Ptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
Ptr pImpl() const;
|
Ptr pImpl() const;
|
||||||
|
|
||||||
|
void newIPv4();
|
||||||
|
|
||||||
|
void newIPv4(const sockaddr_in*);
|
||||||
|
|
||||||
|
void newIPv4(const IPAddress& hostAddress, Poco::UInt16 portNumber);
|
||||||
|
|
||||||
|
void newIPv6(const sockaddr_in6*);
|
||||||
|
|
||||||
|
void newIPv6(const IPAddress& hostAddress, Poco::UInt16 portNumber);
|
||||||
|
|
||||||
void destruct();
|
void destruct();
|
||||||
|
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
char* storage();
|
char* storage();
|
||||||
|
|
||||||
#ifdef POCO_ENABLE_CPP11
|
#ifdef POCO_ENABLE_CPP11
|
||||||
static const unsigned sz = sizeof(Poco::Net::Impl::IPv6SocketAddressImpl);
|
static const unsigned sz = sizeof(Poco::Net::Impl::IPv6SocketAddressImpl);
|
||||||
union
|
typedef std::aligned_storage<sz>::type AlignerType;
|
||||||
{
|
union
|
||||||
std::aligned_storage<sz> a;
|
{
|
||||||
char buffer[sz];
|
char buffer[sz];
|
||||||
}
|
private:
|
||||||
#else // !POCO_ENABLE_CPP11
|
AlignerType aligner;
|
||||||
AlignedCharArrayUnion <Poco::Net::Impl::IPv6SocketAddressImpl,
|
}
|
||||||
Poco::Net::Impl::IPv4SocketAddressImpl>
|
#else // !POCO_ENABLE_CPP11
|
||||||
#endif // POCO_ENABLE_CPP11
|
AlignedCharArrayUnion <Poco::Net::Impl::IPv6SocketAddressImpl>
|
||||||
_memory;
|
#endif // POCO_ENABLE_CPP11
|
||||||
|
_memory;
|
||||||
|
#else // !POCO_HAVE_ALIGNMENT
|
||||||
|
Ptr _pImpl;
|
||||||
|
#endif // POCO_HAVE_ALIGNMENT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -180,19 +199,71 @@ private:
|
|||||||
|
|
||||||
inline void SocketAddress::destruct()
|
inline void SocketAddress::destruct()
|
||||||
{
|
{
|
||||||
|
#ifdef POCO_HAVE_ALIGNMENT
|
||||||
pImpl()->~SocketAddressImpl();
|
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));
|
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 char* SocketAddress::storage()
|
inline void SocketAddress::newIPv4()
|
||||||
{
|
{
|
||||||
return _memory.buffer;
|
#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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -202,6 +273,14 @@ inline IPAddress::Family SocketAddress::family() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
{
|
{
|
||||||
return host() == socketAddress.host() && port() == socketAddress.port();
|
return host() == socketAddress.host() && port() == socketAddress.port();
|
||||||
|
@@ -43,7 +43,9 @@
|
|||||||
#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"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace Net {
|
namespace Net {
|
||||||
@@ -51,6 +53,9 @@ namespace Impl {
|
|||||||
|
|
||||||
|
|
||||||
class Net_API SocketAddressImpl
|
class Net_API SocketAddressImpl
|
||||||
|
#ifndef POCO_HAVE_ALIGNMENT
|
||||||
|
: public Poco::RefCountedObject
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~SocketAddressImpl();
|
virtual ~SocketAddressImpl();
|
||||||
|
@@ -71,7 +71,7 @@ HostEntry DNS::hostByName(const std::string& hostname, unsigned
|
|||||||
#if defined(POCO_HAVE_LIBRESOLV)
|
#if defined(POCO_HAVE_LIBRESOLV)
|
||||||
Poco::ScopedReadRWLock readLock(resolverLock);
|
Poco::ScopedReadRWLock readLock(resolverLock);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(POCO_HAVE_ADDRINFO)
|
#if defined(POCO_HAVE_ADDRINFO)
|
||||||
struct addrinfo* pAI;
|
struct addrinfo* pAI;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
|
@@ -64,26 +64,26 @@ namespace Net {
|
|||||||
|
|
||||||
IPAddress::IPAddress()
|
IPAddress::IPAddress()
|
||||||
{
|
{
|
||||||
new (storage()) IPv4AddressImpl();
|
newIPv4();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IPAddress::IPAddress(const IPAddress& addr)
|
IPAddress::IPAddress(const IPAddress& addr)
|
||||||
{
|
{
|
||||||
if (addr.family() == IPv4)
|
if (addr.family() == IPv4)
|
||||||
new (storage()) IPv4AddressImpl(addr.addr());
|
newIPv4(addr.addr());
|
||||||
else
|
else
|
||||||
new (storage()) IPv6AddressImpl(addr.addr());
|
newIPv6(addr.addr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IPAddress::IPAddress(Family family)
|
IPAddress::IPAddress(Family family)
|
||||||
{
|
{
|
||||||
if (family == IPv4)
|
if (family == IPv4)
|
||||||
new (storage()) IPv4AddressImpl();
|
newIPv4();
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (family == IPv6)
|
else if (family == IPv6)
|
||||||
new (storage()) IPv6AddressImpl();
|
newIPv6();
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
|
throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
|
||||||
@@ -95,14 +95,14 @@ IPAddress::IPAddress(const std::string& addr)
|
|||||||
IPv4AddressImpl empty4 = IPv4AddressImpl();
|
IPv4AddressImpl empty4 = IPv4AddressImpl();
|
||||||
if (addr.empty() || trim(addr) == "0.0.0.0")
|
if (addr.empty() || trim(addr) == "0.0.0.0")
|
||||||
{
|
{
|
||||||
new (storage()) IPv4AddressImpl(empty4.addr());
|
newIPv4(empty4.addr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPv4AddressImpl addr4(IPv4AddressImpl::parse(addr));
|
IPv4AddressImpl addr4(IPv4AddressImpl::parse(addr));
|
||||||
if (addr4 != empty4)
|
if (addr4 != empty4)
|
||||||
{
|
{
|
||||||
new (storage()) IPv4AddressImpl(addr4.addr());
|
newIPv4(addr4.addr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,14 +110,14 @@ IPAddress::IPAddress(const std::string& addr)
|
|||||||
IPv6AddressImpl empty6 = IPv6AddressImpl();
|
IPv6AddressImpl empty6 = IPv6AddressImpl();
|
||||||
if (addr.empty() || trim(addr) == "::")
|
if (addr.empty() || trim(addr) == "::")
|
||||||
{
|
{
|
||||||
new (storage()) IPv6AddressImpl(empty6.addr());
|
newIPv6(empty6.addr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPv6AddressImpl addr6(IPv6AddressImpl::parse(addr));
|
IPv6AddressImpl addr6(IPv6AddressImpl::parse(addr));
|
||||||
if (addr6 != IPv6AddressImpl())
|
if (addr6 != IPv6AddressImpl())
|
||||||
{
|
{
|
||||||
new (storage()) IPv6AddressImpl(addr6.addr());
|
newIPv6(addr6.addr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -131,14 +131,14 @@ IPAddress::IPAddress(const std::string& addr, Family family)
|
|||||||
if (family == IPv4)
|
if (family == IPv4)
|
||||||
{
|
{
|
||||||
IPv4AddressImpl addr4(IPv4AddressImpl::parse(addr));
|
IPv4AddressImpl addr4(IPv4AddressImpl::parse(addr));
|
||||||
new (storage()) IPv4AddressImpl(addr4.addr());
|
newIPv4(addr4.addr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (family == IPv6)
|
else if (family == IPv6)
|
||||||
{
|
{
|
||||||
IPv6AddressImpl addr6(IPv6AddressImpl::parse(addr));
|
IPv6AddressImpl addr6(IPv6AddressImpl::parse(addr));
|
||||||
new (storage()) IPv6AddressImpl(addr6.addr());
|
newIPv6(addr6.addr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -147,12 +147,15 @@ 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)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
if (length == sizeof(struct in_addr))
|
if (length == sizeof(struct in_addr))
|
||||||
new (storage()) IPv4AddressImpl(addr);
|
newIPv4(addr);
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (length == sizeof(struct in6_addr))
|
else if (length == sizeof(struct in6_addr))
|
||||||
new (storage()) IPv6AddressImpl(addr);
|
newIPv6(addr);
|
||||||
#endif
|
#endif
|
||||||
else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()");
|
else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()");
|
||||||
}
|
}
|
||||||
@@ -161,10 +164,10 @@ IPAddress::IPAddress(const void* addr, poco_socklen_t length)
|
|||||||
IPAddress::IPAddress(const void* addr, poco_socklen_t length, Poco::UInt32 scope)
|
IPAddress::IPAddress(const void* addr, poco_socklen_t length, Poco::UInt32 scope)
|
||||||
{
|
{
|
||||||
if (length == sizeof(struct in_addr))
|
if (length == sizeof(struct in_addr))
|
||||||
new (storage()) IPv4AddressImpl(addr);
|
newIPv4(addr);
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (length == sizeof(struct in6_addr))
|
else if (length == sizeof(struct in6_addr))
|
||||||
new (storage()) IPv6AddressImpl(addr, scope);
|
newIPv6(addr, scope);
|
||||||
#endif
|
#endif
|
||||||
else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()");
|
else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()");
|
||||||
}
|
}
|
||||||
@@ -175,13 +178,13 @@ IPAddress::IPAddress(unsigned prefix, Family family)
|
|||||||
if (family == IPv4)
|
if (family == IPv4)
|
||||||
{
|
{
|
||||||
if (prefix <= 32)
|
if (prefix <= 32)
|
||||||
new (storage()) IPv4AddressImpl(prefix);
|
newIPv4(prefix);
|
||||||
}
|
}
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (family == IPv6)
|
else if (family == IPv6)
|
||||||
{
|
{
|
||||||
if (prefix <= 128)
|
if (prefix <= 128)
|
||||||
new (storage()) IPv6AddressImpl(prefix);
|
newIPv6(prefix);
|
||||||
}
|
}
|
||||||
#endif
|
#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()");
|
||||||
@@ -191,13 +194,16 @@ 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)
|
||||||
|
#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)
|
||||||
new (storage()) IPv4AddressImpl(&reinterpret_cast<const struct sockaddr_in*>(socket_address.lpSockaddr)->sin_addr);
|
newIPv4(&reinterpret_cast<const struct sockaddr_in*>(socket_address.lpSockaddr)->sin_addr);
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (family == AF_INET6)
|
else if (family == AF_INET6)
|
||||||
new (storage()) IPv6AddressImpl(&reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_addr,
|
newIPv6(&reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_addr,
|
||||||
reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_scope_id);
|
reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_scope_id);
|
||||||
#endif
|
#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()");
|
||||||
@@ -209,11 +215,11 @@ IPAddress::IPAddress(const struct sockaddr& sockaddr)
|
|||||||
{
|
{
|
||||||
unsigned short family = sockaddr.sa_family;
|
unsigned short family = sockaddr.sa_family;
|
||||||
if (family == AF_INET)
|
if (family == AF_INET)
|
||||||
new (storage()) IPv4AddressImpl(&reinterpret_cast<const struct sockaddr_in*>(&sockaddr)->sin_addr);
|
newIPv4(&reinterpret_cast<const struct sockaddr_in*>(&sockaddr)->sin_addr);
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (family == AF_INET6)
|
else if (family == AF_INET6)
|
||||||
new (storage()) IPv6AddressImpl(&reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_addr,
|
newIPv6(&reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_addr,
|
||||||
reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_scope_id);
|
reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_scope_id);
|
||||||
#endif
|
#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()");
|
||||||
}
|
}
|
||||||
@@ -231,9 +237,9 @@ IPAddress& IPAddress::operator = (const IPAddress& addr)
|
|||||||
{
|
{
|
||||||
destruct();
|
destruct();
|
||||||
if (addr.family() == IPAddress::IPv4)
|
if (addr.family() == IPAddress::IPv4)
|
||||||
new (storage()) IPv4AddressImpl(addr.addr());
|
newIPv4(addr.addr());
|
||||||
else
|
else
|
||||||
new (storage()) IPv6AddressImpl(addr.addr());
|
newIPv6(addr.addr());
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -540,20 +546,19 @@ IPAddress IPAddress::parse(const std::string& addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool IPAddress::tryParse(const std::string& addr, IPAddress& result)
|
bool IPAddress::tryParse(const std::string& addr, IPAddress& result)
|
||||||
{
|
{
|
||||||
IPv4AddressImpl impl4(IPv4AddressImpl::parse(addr));
|
IPv4AddressImpl impl4(IPv4AddressImpl::parse(addr));
|
||||||
if (impl4 != IPv4AddressImpl())
|
if (impl4 != IPv4AddressImpl())
|
||||||
{
|
{
|
||||||
|
result.newIPv4(impl4.addr());
|
||||||
new (result.storage()) IPv4AddressImpl(impl4.addr());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
IPv6AddressImpl impl6(IPv6AddressImpl::parse(addr));
|
IPv6AddressImpl impl6(IPv6AddressImpl::parse(addr));
|
||||||
if (impl6 != IPv6AddressImpl())
|
if (impl6 != IPv6AddressImpl())
|
||||||
{
|
{
|
||||||
new (result.storage()) IPv6AddressImpl(impl6.addr());
|
result.newIPv6(impl6.addr());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -75,7 +75,7 @@ struct AFLT
|
|||||||
|
|
||||||
SocketAddress::SocketAddress()
|
SocketAddress::SocketAddress()
|
||||||
{
|
{
|
||||||
new (storage()) IPv4SocketAddressImpl;
|
newIPv4();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,19 +135,19 @@ SocketAddress::SocketAddress(const std::string& hostAndPort)
|
|||||||
SocketAddress::SocketAddress(const SocketAddress& socketAddress)
|
SocketAddress::SocketAddress(const SocketAddress& socketAddress)
|
||||||
{
|
{
|
||||||
if (socketAddress.family() == IPAddress::IPv4)
|
if (socketAddress.family() == IPAddress::IPv4)
|
||||||
new (storage()) IPv4SocketAddressImpl(reinterpret_cast<const sockaddr_in*>(socketAddress.addr()));
|
newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr()));
|
||||||
else
|
else
|
||||||
new (storage()) IPv6SocketAddressImpl(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr()));
|
newIPv6(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SocketAddress::SocketAddress(const struct sockaddr* sockAddr, poco_socklen_t length)
|
SocketAddress::SocketAddress(const struct sockaddr* sockAddr, poco_socklen_t length)
|
||||||
{
|
{
|
||||||
if (length == sizeof(struct sockaddr_in))
|
if (length == sizeof(struct sockaddr_in))
|
||||||
new (storage()) IPv4SocketAddressImpl(reinterpret_cast<const struct sockaddr_in*>(sockAddr));
|
newIPv4(reinterpret_cast<const struct sockaddr_in*>(sockAddr));
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (length == sizeof(struct sockaddr_in6))
|
else if (length == sizeof(struct sockaddr_in6))
|
||||||
new (storage()) IPv6SocketAddressImpl(reinterpret_cast<const struct sockaddr_in6*>(sockAddr));
|
newIPv6(reinterpret_cast<const struct sockaddr_in6*>(sockAddr));
|
||||||
#endif
|
#endif
|
||||||
else throw Poco::InvalidArgumentException("Invalid address length passed to SocketAddress()");
|
else throw Poco::InvalidArgumentException("Invalid address length passed to SocketAddress()");
|
||||||
}
|
}
|
||||||
@@ -175,9 +175,9 @@ SocketAddress& SocketAddress::operator = (const SocketAddress& socketAddress)
|
|||||||
{
|
{
|
||||||
destruct();
|
destruct();
|
||||||
if (socketAddress.family() == IPAddress::IPv4)
|
if (socketAddress.family() == IPAddress::IPv4)
|
||||||
new (storage()) IPv4SocketAddressImpl(reinterpret_cast<const sockaddr_in*>(socketAddress.addr()));
|
newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr()));
|
||||||
else
|
else
|
||||||
new (storage()) IPv6SocketAddressImpl(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr()));
|
newIPv6(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr()));
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -232,10 +232,10 @@ std::string SocketAddress::toString() const
|
|||||||
void SocketAddress::init(const IPAddress& hostAddress, Poco::UInt16 portNumber)
|
void SocketAddress::init(const IPAddress& hostAddress, Poco::UInt16 portNumber)
|
||||||
{
|
{
|
||||||
if (hostAddress.family() == IPAddress::IPv4)
|
if (hostAddress.family() == IPAddress::IPv4)
|
||||||
new (storage()) IPv4SocketAddressImpl(hostAddress.addr(), htons(portNumber));
|
newIPv4(hostAddress, portNumber);
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6)
|
||||||
else if (hostAddress.family() == IPAddress::IPv6)
|
else if (hostAddress.family() == IPAddress::IPv6)
|
||||||
new (storage()) IPv6SocketAddressImpl(hostAddress.addr(), htons(portNumber), hostAddress.scope());
|
newIPv6(hostAddress, portNumber);
|
||||||
#endif
|
#endif
|
||||||
else throw Poco::NotImplementedException("unsupported IP address family");
|
else throw Poco::NotImplementedException("unsupported IP address family");
|
||||||
}
|
}
|
||||||
|
@@ -104,6 +104,7 @@ void DatagramSocketTest::testBroadcast()
|
|||||||
int n = ss.sendTo("hello", 5, sa);
|
int n = ss.sendTo("hello", 5, sa);
|
||||||
// not all socket implementations fail if broadcast option is not set
|
// not all socket implementations fail if broadcast option is not set
|
||||||
// fail ("broadcast option not set - must throw");
|
// fail ("broadcast option not set - must throw");
|
||||||
|
n = n + 1; // to silence gcc
|
||||||
}
|
}
|
||||||
catch (IOException&)
|
catch (IOException&)
|
||||||
{
|
{
|
||||||
|
@@ -247,7 +247,7 @@ void HTTPClientSessionTest::testKeepAlive()
|
|||||||
assert (response.getChunkedTransferEncoding());
|
assert (response.getChunkedTransferEncoding());
|
||||||
assert (response.getKeepAlive());
|
assert (response.getKeepAlive());
|
||||||
std::ostringstream ostr3;
|
std::ostringstream ostr3;
|
||||||
std::streamsize n = StreamCopier::copyStream(rs3, ostr3);
|
StreamCopier::copyStream(rs3, ostr3);
|
||||||
assert (ostr3.str() == HTTPTestServer::LARGE_BODY);
|
assert (ostr3.str() == HTTPTestServer::LARGE_BODY);
|
||||||
|
|
||||||
request.setMethod(HTTPRequest::HTTP_HEAD);
|
request.setMethod(HTTPRequest::HTTP_HEAD);
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#include "Poco/Net/NetException.h"
|
#include "Poco/Net/NetException.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
GCC_DIAG_OFF(parentheses)
|
||||||
|
|
||||||
using Poco::Net::HTTPResponse;
|
using Poco::Net::HTTPResponse;
|
||||||
using Poco::Net::HTTPMessage;
|
using Poco::Net::HTTPMessage;
|
||||||
|
@@ -78,7 +78,7 @@ namespace
|
|||||||
|
|
||||||
std::istream& istr = request.stream();
|
std::istream& istr = request.stream();
|
||||||
std::ostream& ostr = response.send();
|
std::ostream& ostr = response.send();
|
||||||
std::streamsize n = StreamCopier::copyStream(istr, ostr);
|
StreamCopier::copyStream(istr, ostr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -122,6 +122,7 @@ void HTTPStreamFactoryTest::testError()
|
|||||||
{
|
{
|
||||||
std::istream* pStr = factory.open(uri);
|
std::istream* pStr = factory.open(uri);
|
||||||
fail("not found - must throw");
|
fail("not found - must throw");
|
||||||
|
pStr = pStr + 0; // to silence gcc
|
||||||
}
|
}
|
||||||
catch (HTTPException& exc)
|
catch (HTTPException& exc)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user