event/ServerSocket: use AllocatedSocketAddress to build local socket address

This commit is contained in:
Max Kellermann 2015-07-22 11:01:44 +02:00
parent fdeec0307e
commit cbb595ba83

View File

@ -429,21 +429,12 @@ bool
ServerSocket::AddPath(AllocatedPath &&path, Error &error) ServerSocket::AddPath(AllocatedPath &&path, Error &error)
{ {
#ifdef HAVE_UN #ifdef HAVE_UN
struct sockaddr_un s_un; (void)error;
const size_t path_length = path.length(); AllocatedSocketAddress address;
if (path_length >= sizeof(s_un.sun_path)) { address.SetLocal(path.c_str());
error.Set(server_socket_domain,
"UNIX socket path is too long");
return false;
}
RemoveFile(path); OneServerSocket &s = AddAddress(std::move(address));
s_un.sun_family = AF_UNIX;
memcpy(s_un.sun_path, path.c_str(), path_length + 1);
OneServerSocket &s = AddAddress({(const sockaddr *)&s_un, sizeof(s_un)});
s.SetPath(std::move(path)); s.SetPath(std::move(path));
return true; return true;