mirror of
				https://github.com/pocoproject/poco.git
				synced 2025-10-27 19:10:20 +01:00 
			
		
		
		
	clean build with POCO_NET_NO_IPv6, add test for Unix domain sockets
This commit is contained in:
		| @@ -374,21 +374,15 @@ private: | ||||
| #endif | ||||
|  | ||||
| 	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 newIPv4(const void* hostAddr); | ||||
| 	void newIPv4(unsigned prefix); | ||||
| #if defined(POCO_HAVE_IPv6) | ||||
| 	void newIPv6(); | ||||
|  | ||||
| 	void newIPv6(const void* hostAddr); | ||||
| 	void newIPv6(const void* hostAddr, Poco::UInt32 scope); | ||||
| 	void newIPv6(unsigned prefix); | ||||
| #endif | ||||
| 	void destruct(); | ||||
|  | ||||
| #ifdef POCO_HAVE_ALIGNMENT | ||||
| @@ -405,7 +399,11 @@ private: | ||||
| 			AlignerType aligner; | ||||
| 		} | ||||
| 	#else // !POCO_ENABLE_CPP11 | ||||
| 		AlignedCharArrayUnion <Poco::Net::Impl::IPv6AddressImpl> | ||||
| 		#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 | ||||
| @@ -438,6 +436,16 @@ inline IPAddress::Ptr IPAddress::pImpl() const | ||||
| } | ||||
|  | ||||
|  | ||||
| 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 | ||||
| @@ -448,6 +456,29 @@ inline void IPAddress::newIPv4(const void* hostAddr) | ||||
| } | ||||
|  | ||||
|  | ||||
| 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 | ||||
| } | ||||
|  | ||||
|  | ||||
| #if defined(POCO_HAVE_IPv6) | ||||
|  | ||||
|  | ||||
| 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 | ||||
| @@ -468,16 +499,6 @@ inline void IPAddress::newIPv6(const void* hostAddr, Poco::UInt32 scope) | ||||
| } | ||||
|  | ||||
|  | ||||
| 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 | ||||
| @@ -488,24 +509,7 @@ inline void IPAddress::newIPv6(unsigned prefix) | ||||
| } | ||||
|  | ||||
|  | ||||
| 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 | ||||
| } | ||||
| #endif // POCO_HAVE_IPv6 | ||||
|  | ||||
|  | ||||
| #ifdef POCO_HAVE_ALIGNMENT | ||||
|   | ||||
| @@ -124,6 +124,9 @@ private: | ||||
| }; | ||||
|  | ||||
|  | ||||
| #if defined(POCO_HAVE_IPv6) | ||||
|  | ||||
|  | ||||
| // | ||||
| // IPv6AddressImpl | ||||
| // | ||||
| @@ -174,6 +177,9 @@ private: | ||||
| }; | ||||
|  | ||||
|  | ||||
| #endif // POCO_HAVE_IPv6 | ||||
|  | ||||
|  | ||||
| } } } // namespace Poco::Net::Impl | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -139,7 +139,9 @@ public: | ||||
| 	enum | ||||
| 	{ | ||||
| 		MAX_ADDRESS_LENGTH =  | ||||
| #if defined(POCO_HAVE_IPv6) | ||||
| #if defined(POCO_OS_FAMILY_UNIX) | ||||
| 			sizeof(struct sockaddr_un) | ||||
| #elif defined(POCO_HAVE_IPv6) | ||||
| 			sizeof(struct sockaddr_in6) | ||||
| #else | ||||
| 			sizeof(struct sockaddr_in) | ||||
|   | ||||
| @@ -35,7 +35,9 @@ 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 { | ||||
| @@ -58,8 +60,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 | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -71,8 +75,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()"); | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -227,8 +230,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; | ||||
| } | ||||
| @@ -236,7 +243,7 @@ IPAddress& IPAddress::operator = (const IPAddress& addr) | ||||
|  | ||||
| IPAddress::Family IPAddress::family() const | ||||
| { | ||||
| 	return static_cast<IPAddress::Family>(pImpl()->family()); | ||||
| 	return pImpl()->family(); | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -96,9 +96,13 @@ void ServerSocket::bind6(const SocketAddress& address, bool reuseAddress, bool i | ||||
|  | ||||
| void ServerSocket::bind6(Poco::UInt16 port, bool reuseAddress, bool ipV6Only) | ||||
| { | ||||
| #if defined(POCO_HAVE_IPv6) | ||||
| 	IPAddress wildcardAddr(IPAddress::IPv6); | ||||
| 	SocketAddress address(wildcardAddr, port); | ||||
| 	impl()->bind6(address, reuseAddress, ipV6Only); | ||||
| #else | ||||
| 	throw Poco::NotImplementedException("No IPv6 support available"); | ||||
| #endif // POCO_HAVE_IPv6 | ||||
| } | ||||
|  | ||||
| 	 | ||||
|   | ||||
| @@ -32,6 +32,16 @@ EchoServer::EchoServer(): | ||||
| } | ||||
|  | ||||
|  | ||||
| EchoServer::EchoServer(const Poco::Net::SocketAddress& address): | ||||
| 	_socket(address), | ||||
| 	_thread("EchoServer"), | ||||
| 	_stop(false) | ||||
| { | ||||
| 	_thread.start(*this); | ||||
| 	_ready.wait(); | ||||
| } | ||||
|  | ||||
|  | ||||
| EchoServer::~EchoServer() | ||||
| { | ||||
| 	_stop = true; | ||||
|   | ||||
| @@ -29,6 +29,9 @@ public: | ||||
| 	EchoServer(); | ||||
| 		/// Creates the EchoServer. | ||||
|  | ||||
| 	EchoServer(const Poco::Net::SocketAddress& address); | ||||
| 		/// Creates the EchoServer using the given address. | ||||
|  | ||||
| 	~EchoServer(); | ||||
| 		/// Destroys the EchoServer. | ||||
|  | ||||
|   | ||||
| @@ -23,6 +23,7 @@ | ||||
| #include "Poco/Buffer.h" | ||||
| #include "Poco/FIFOBuffer.h" | ||||
| #include "Poco/Delegate.h" | ||||
| #include "Poco/File.h" | ||||
| #include <iostream> | ||||
|  | ||||
|  | ||||
| @@ -501,6 +502,28 @@ void SocketTest::testSelect3() | ||||
| } | ||||
|  | ||||
|  | ||||
| void SocketTest::testEchoUnixLocal() | ||||
| { | ||||
| #if defined(POCO_OS_FAMILY_UNIX) | ||||
| 	Poco::File socketFile("/tmp/SocketTest.sock"); | ||||
| 	if (socketFile.exists()) socketFile.remove(); | ||||
| 	SocketAddress localAddr(SocketAddress::UNIX_LOCAL, socketFile.path()); | ||||
| 	EchoServer echoServer(localAddr); | ||||
| 	StreamSocket ss(SocketAddress::UNIX_LOCAL); | ||||
| 	ss.connect(localAddr); | ||||
| 	int n = ss.sendBytes("hello", 5); | ||||
| 	assert (n == 5); | ||||
| 	char buffer[256]; | ||||
| 	n = ss.receiveBytes(buffer, sizeof(buffer)); | ||||
| 	assert (n == 5); | ||||
| 	assert (std::string(buffer, n) == "hello"); | ||||
| 	ss.close(); | ||||
| 	socketFile.remove(); | ||||
| #endif | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| void SocketTest::onReadable(bool& b) | ||||
| { | ||||
| 	if (b) ++_notToReadable; | ||||
| @@ -549,6 +572,7 @@ CppUnit::Test* SocketTest::suite() | ||||
| 	CppUnit_addTest(pSuite, SocketTest, testSelect); | ||||
| 	CppUnit_addTest(pSuite, SocketTest, testSelect2); | ||||
| 	CppUnit_addTest(pSuite, SocketTest, testSelect3); | ||||
| 	CppUnit_addTest(pSuite, SocketTest, testEchoUnixLocal); | ||||
|  | ||||
| 	return pSuite; | ||||
| } | ||||
|   | ||||
| @@ -42,6 +42,7 @@ public: | ||||
| 	void testSelect(); | ||||
| 	void testSelect2(); | ||||
| 	void testSelect3(); | ||||
| 	void testEchoUnixLocal(); | ||||
|  | ||||
| 	void setUp(); | ||||
| 	void tearDown(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Guenter Obiltschnig
					Guenter Obiltschnig