SocketAddress: constructor taking single string now also accepts a local socket path on UNIX platforms

This commit is contained in:
Guenter Obiltschnig 2015-09-16 09:26:30 +02:00
parent 5bde0dae76
commit 86f2094d09
3 changed files with 16 additions and 0 deletions

View File

@ -91,6 +91,10 @@ public:
/// 192.168.1.10:80
/// [::ffff:192.168.1.120]:2040
/// www.appinf.com:8080
///
/// On POSIX platforms supporting UNIX_LOCAL sockets, hostAndPort
/// can also be the absolute path of a local socket, starting with a
/// slash, e.g. "/tmp/local.socket".
SocketAddress(Family family, const std::string& addr);
/// Creates a SocketAddress of the given family from a

View File

@ -285,6 +285,14 @@ void SocketAddress::init(const std::string& hostAndPort)
std::string port;
std::string::const_iterator it = hostAndPort.begin();
std::string::const_iterator end = hostAndPort.end();
#if defined(POCO_OS_FAMILY_UNIX)
if (*it == '/')
{
newLocal(hostAndPort);
return;
}
#endif
if (*it == '[')
{
++it;

View File

@ -170,6 +170,10 @@ void SocketAddressTest::testSocketAddressUnixLocal()
SocketAddress sa3(SocketAddress::UNIX_LOCAL, "/tmp/sock1");
assert (sa1 == sa3);
assert (!(sa1 < sa3));
SocketAddress sa4("/tmp/sock1");
assert (sa1 == sa4);
assert (sa4.toString() == "/tmp/sock1");
#endif
}