mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 08:31:43 +02:00
SF 3538780 SocketAddress needs operator < function
This commit is contained in:
@@ -90,7 +90,7 @@ public:
|
||||
///
|
||||
/// Examples:
|
||||
/// 192.168.1.10:80
|
||||
/// [::FFFF:192.168.1.120]:2040
|
||||
/// [::ffff:192.168.1.120]:2040
|
||||
/// www.appinf.com:8080
|
||||
|
||||
SocketAddress(const SocketAddress& addr);
|
||||
@@ -129,6 +129,7 @@ public:
|
||||
IPAddress::Family family() const;
|
||||
/// Returns the address family of the host's address.
|
||||
|
||||
bool operator < (const SocketAddress& addr) const;
|
||||
bool operator == (const SocketAddress& addr) const;
|
||||
bool operator != (const SocketAddress& addr) const;
|
||||
|
||||
|
@@ -299,6 +299,14 @@ SocketAddress::~SocketAddress()
|
||||
}
|
||||
|
||||
|
||||
bool SocketAddress::operator < (const SocketAddress& addr) const
|
||||
{
|
||||
if (family() < addr.family()) return true;
|
||||
if (host() < addr.host()) return true;
|
||||
return (port() < addr.port());
|
||||
}
|
||||
|
||||
|
||||
SocketAddress& SocketAddress::operator = (const SocketAddress& addr)
|
||||
{
|
||||
if (&addr != this)
|
||||
|
@@ -138,6 +138,20 @@ void SocketAddressTest::testSocketAddress()
|
||||
}
|
||||
|
||||
|
||||
void SocketAddressTest::testSocketRelationals()
|
||||
{
|
||||
SocketAddress sa1("192.168.1.100", 100);
|
||||
SocketAddress sa2("192.168.1.100:100");
|
||||
assert (sa1 == sa2);
|
||||
|
||||
SocketAddress sa3("192.168.1.101", "99");
|
||||
assert (sa2 < sa3);
|
||||
|
||||
SocketAddress sa4("192.168.1.100", "102");
|
||||
assert (sa3 < sa4);
|
||||
}
|
||||
|
||||
|
||||
void SocketAddressTest::testSocketAddress6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
@@ -160,6 +174,7 @@ CppUnit::Test* SocketAddressTest::suite()
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketAddressTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SocketAddressTest, testSocketAddress);
|
||||
CppUnit_addTest(pSuite, SocketAddressTest, testSocketRelationals);
|
||||
CppUnit_addTest(pSuite, SocketAddressTest, testSocketAddress6);
|
||||
|
||||
return pSuite;
|
||||
|
@@ -47,6 +47,7 @@ public:
|
||||
~SocketAddressTest();
|
||||
|
||||
void testSocketAddress();
|
||||
void testSocketRelationals();
|
||||
void testSocketAddress6();
|
||||
|
||||
void setUp();
|
||||
|
Reference in New Issue
Block a user