mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 04:17:55 +01:00
merge Unix Domain Sockets support and other changes from develop
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "Poco/Net/SocketAddressImpl.h"
|
||||
#include "Poco/Net/SocketDefs.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
@@ -60,11 +61,22 @@ IPv4SocketAddressImpl::IPv4SocketAddressImpl(const void* addr, UInt16 port)
|
||||
{
|
||||
std::memset(&_addr, 0, sizeof(_addr));
|
||||
_addr.sin_family = AF_INET;
|
||||
poco_set_sin_len(&_addr);
|
||||
std::memcpy(&_addr.sin_addr, addr, sizeof(_addr.sin_addr));
|
||||
_addr.sin_port = port;
|
||||
}
|
||||
|
||||
|
||||
std::string IPv4SocketAddressImpl::toString() const
|
||||
{
|
||||
std::string result;
|
||||
result.append(host().toString());
|
||||
result.append(":");
|
||||
NumberFormatter::append(result, ntohs(port()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
|
||||
|
||||
@@ -100,7 +112,59 @@ IPv6SocketAddressImpl::IPv6SocketAddressImpl(const void* addr, UInt16 port, UInt
|
||||
}
|
||||
|
||||
|
||||
std::string IPv6SocketAddressImpl::toString() const
|
||||
{
|
||||
std::string result;
|
||||
result.append("[");
|
||||
result.append(host().toString());
|
||||
result.append("]");
|
||||
result.append(":");
|
||||
NumberFormatter::append(result, ntohs(port()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
|
||||
|
||||
//
|
||||
// LocalSocketAddressImpl
|
||||
//
|
||||
|
||||
|
||||
LocalSocketAddressImpl::LocalSocketAddressImpl(const struct sockaddr_un* addr)
|
||||
{
|
||||
_pAddr = new sockaddr_un;
|
||||
std::memcpy(_pAddr, addr, sizeof(struct sockaddr_un));
|
||||
}
|
||||
|
||||
|
||||
LocalSocketAddressImpl::LocalSocketAddressImpl(const char* path)
|
||||
{
|
||||
_pAddr = new sockaddr_un;
|
||||
poco_set_sun_len(_pAddr, std::strlen(path) + sizeof(struct sockaddr_un) - sizeof(_pAddr->sun_path) + 1);
|
||||
_pAddr->sun_family = AF_UNIX;
|
||||
std::strcpy(_pAddr->sun_path, path);
|
||||
}
|
||||
|
||||
|
||||
LocalSocketAddressImpl::~LocalSocketAddressImpl()
|
||||
{
|
||||
delete _pAddr;
|
||||
}
|
||||
|
||||
|
||||
std::string LocalSocketAddressImpl::toString() const
|
||||
{
|
||||
std::string result(path());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_OS_FAMILY_UNIX
|
||||
|
||||
|
||||
} } } // namespace Poco::Net::Impl
|
||||
|
||||
Reference in New Issue
Block a user