2010-10-05 20:29:41 +02:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2010-10-05 20:29:41 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2013-01-15 21:42:55 +01:00
|
|
|
#include "ServerSocket.hxx"
|
2017-08-11 08:41:58 +02:00
|
|
|
#include "net/IPv4Address.hxx"
|
2015-02-13 21:16:43 +01:00
|
|
|
#include "net/StaticSocketAddress.hxx"
|
2015-07-22 11:05:08 +02:00
|
|
|
#include "net/AllocatedSocketAddress.hxx"
|
2015-02-10 20:30:10 +01:00
|
|
|
#include "net/SocketAddress.hxx"
|
2015-02-10 21:46:23 +01:00
|
|
|
#include "net/SocketUtil.hxx"
|
|
|
|
#include "net/SocketError.hxx"
|
2017-08-10 09:53:09 +02:00
|
|
|
#include "net/UniqueSocketDescriptor.hxx"
|
2015-02-10 21:46:23 +01:00
|
|
|
#include "net/Resolver.hxx"
|
2015-07-22 10:03:36 +02:00
|
|
|
#include "net/ToString.hxx"
|
2013-01-15 22:50:49 +01:00
|
|
|
#include "event/SocketMonitor.hxx"
|
2013-10-19 17:40:56 +02:00
|
|
|
#include "fs/AllocatedPath.hxx"
|
|
|
|
#include "fs/FileSystem.hxx"
|
2016-10-28 10:36:05 +02:00
|
|
|
#include "util/RuntimeError.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Domain.hxx"
|
2016-10-28 10:36:05 +02:00
|
|
|
#include "util/ScopeExit.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "Log.hxx"
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-10-19 17:40:56 +02:00
|
|
|
#include <string>
|
2013-11-28 11:50:54 +01:00
|
|
|
#include <algorithm>
|
2013-10-19 17:40:56 +02:00
|
|
|
|
2010-10-05 20:29:41 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2017-12-12 10:22:20 +01:00
|
|
|
#ifdef _WIN32
|
2010-10-05 20:29:41 +02:00
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#else
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
class OneServerSocket final : private SocketMonitor {
|
2013-01-30 13:20:27 +01:00
|
|
|
ServerSocket &parent;
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-01-15 21:42:55 +01:00
|
|
|
const unsigned serial;
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2015-03-05 08:14:23 +01:00
|
|
|
#ifdef HAVE_UN
|
2013-10-19 17:40:56 +02:00
|
|
|
AllocatedPath path;
|
2015-03-05 08:14:23 +01:00
|
|
|
#endif
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2015-07-22 11:05:08 +02:00
|
|
|
const AllocatedSocketAddress address;
|
2013-01-15 21:42:55 +01:00
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
public:
|
2015-07-22 11:05:08 +02:00
|
|
|
template<typename A>
|
2013-01-30 13:20:27 +01:00
|
|
|
OneServerSocket(EventLoop &_loop, ServerSocket &_parent,
|
2013-01-15 22:50:49 +01:00
|
|
|
unsigned _serial,
|
2015-07-22 11:05:08 +02:00
|
|
|
A &&_address)
|
2013-01-15 22:50:49 +01:00
|
|
|
:SocketMonitor(_loop),
|
|
|
|
parent(_parent), serial(_serial),
|
2015-03-05 08:14:23 +01:00
|
|
|
#ifdef HAVE_UN
|
2018-01-17 12:17:41 +01:00
|
|
|
path(nullptr),
|
2015-03-05 08:14:23 +01:00
|
|
|
#endif
|
2015-07-22 11:05:08 +02:00
|
|
|
address(std::forward<A>(_address))
|
2013-01-15 21:42:55 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OneServerSocket(const OneServerSocket &other) = delete;
|
|
|
|
OneServerSocket &operator=(const OneServerSocket &other) = delete;
|
|
|
|
|
|
|
|
~OneServerSocket() {
|
2014-01-06 18:02:57 +01:00
|
|
|
if (IsDefined())
|
|
|
|
Close();
|
2013-01-15 21:42:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
unsigned GetSerial() const {
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
2015-03-05 08:14:23 +01:00
|
|
|
#ifdef HAVE_UN
|
2013-10-19 17:40:56 +02:00
|
|
|
void SetPath(AllocatedPath &&_path) {
|
|
|
|
assert(path.IsNull());
|
2013-01-30 12:56:23 +01:00
|
|
|
|
2013-10-19 17:40:56 +02:00
|
|
|
path = std::move(_path);
|
2013-01-30 12:56:23 +01:00
|
|
|
}
|
2015-03-05 08:14:23 +01:00
|
|
|
#endif
|
2013-01-30 12:56:23 +01:00
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
void Open();
|
2013-01-15 21:42:55 +01:00
|
|
|
|
2013-02-04 11:44:36 +01:00
|
|
|
using SocketMonitor::IsDefined;
|
2013-01-15 22:50:49 +01:00
|
|
|
using SocketMonitor::Close;
|
2013-01-15 21:42:55 +01:00
|
|
|
|
2013-12-04 08:43:55 +01:00
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
std::string ToString() const noexcept {
|
2015-07-22 10:20:57 +02:00
|
|
|
return ::ToString(address);
|
2013-12-04 08:43:55 +01:00
|
|
|
}
|
2013-01-15 21:42:55 +01:00
|
|
|
|
2017-08-10 18:25:22 +02:00
|
|
|
void SetFD(SocketDescriptor _fd) noexcept {
|
2013-01-15 22:50:49 +01:00
|
|
|
SocketMonitor::Open(_fd);
|
|
|
|
SocketMonitor::ScheduleRead();
|
|
|
|
}
|
2013-01-15 22:53:14 +01:00
|
|
|
|
2017-05-08 14:44:49 +02:00
|
|
|
void Accept() noexcept;
|
2013-01-15 22:50:49 +01:00
|
|
|
|
|
|
|
private:
|
2017-11-10 20:20:07 +01:00
|
|
|
bool OnSocketReady(unsigned flags) noexcept override;
|
2010-10-05 20:29:41 +02:00
|
|
|
};
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
static constexpr Domain server_socket_domain("server_socket");
|
2010-10-05 20:29:41 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
get_remote_uid(int fd)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_STRUCT_UCRED
|
|
|
|
struct ucred cred;
|
|
|
|
socklen_t len = sizeof (cred);
|
|
|
|
|
|
|
|
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
|
2014-11-18 20:53:59 +01:00
|
|
|
return -1;
|
2010-10-05 20:29:41 +02:00
|
|
|
|
|
|
|
return cred.uid;
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_GETPEEREID
|
|
|
|
uid_t euid;
|
|
|
|
gid_t egid;
|
|
|
|
|
|
|
|
if (getpeereid(fd, &euid, &egid) == 0)
|
|
|
|
return euid;
|
|
|
|
#else
|
|
|
|
(void)fd;
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-15 22:53:14 +01:00
|
|
|
inline void
|
2017-05-08 14:44:49 +02:00
|
|
|
OneServerSocket::Accept() noexcept
|
2013-01-15 22:53:14 +01:00
|
|
|
{
|
2015-02-13 21:16:43 +01:00
|
|
|
StaticSocketAddress peer_address;
|
2017-11-10 20:34:45 +01:00
|
|
|
UniqueSocketDescriptor peer_fd(GetSocket().AcceptNonBlock(peer_address));
|
2017-08-10 18:25:22 +02:00
|
|
|
if (!peer_fd.IsDefined()) {
|
2013-01-15 22:53:14 +01:00
|
|
|
const SocketErrorMessage msg;
|
2013-09-27 22:31:24 +02:00
|
|
|
FormatError(server_socket_domain,
|
|
|
|
"accept() failed: %s", (const char *)msg);
|
2013-01-15 22:53:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-10 19:25:02 +02:00
|
|
|
if (!peer_fd.SetKeepAlive()) {
|
2013-01-15 22:53:14 +01:00
|
|
|
const SocketErrorMessage msg;
|
2013-09-27 22:31:24 +02:00
|
|
|
FormatError(server_socket_domain,
|
|
|
|
"Could not set TCP keepalive option: %s",
|
|
|
|
(const char *)msg);
|
2013-01-15 22:53:14 +01:00
|
|
|
}
|
|
|
|
|
2017-08-10 19:13:18 +02:00
|
|
|
parent.OnAccept(std::move(peer_fd), peer_address,
|
2017-08-10 18:25:22 +02:00
|
|
|
get_remote_uid(peer_fd.Get()));
|
2013-01-15 22:53:14 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 10:53:32 +01:00
|
|
|
bool
|
2017-11-10 20:20:07 +01:00
|
|
|
OneServerSocket::OnSocketReady(gcc_unused unsigned flags) noexcept
|
2012-02-13 21:10:36 +01:00
|
|
|
{
|
2013-01-15 22:50:49 +01:00
|
|
|
Accept();
|
2013-01-30 10:53:32 +01:00
|
|
|
return true;
|
2012-02-13 21:10:36 +01:00
|
|
|
}
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
inline void
|
|
|
|
OneServerSocket::Open()
|
2013-01-15 21:42:55 +01:00
|
|
|
{
|
2013-01-15 22:50:49 +01:00
|
|
|
assert(!IsDefined());
|
2013-01-15 21:42:55 +01:00
|
|
|
|
2017-08-10 09:53:09 +02:00
|
|
|
auto _fd = socket_bind_listen(address.GetFamily(),
|
|
|
|
SOCK_STREAM, 0,
|
|
|
|
address, 5);
|
2013-01-15 21:42:55 +01:00
|
|
|
|
2018-08-07 21:30:25 +02:00
|
|
|
/* register in the EventLoop */
|
2013-01-15 21:42:55 +01:00
|
|
|
|
2017-08-10 18:25:22 +02:00
|
|
|
SetFD(_fd.Release());
|
2013-01-15 21:42:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:20:27 +01:00
|
|
|
ServerSocket::ServerSocket(EventLoop &_loop)
|
|
|
|
:loop(_loop), next_serial(1) {}
|
2013-01-30 12:56:23 +01:00
|
|
|
|
|
|
|
/* this is just here to allow the OneServerSocket forward
|
|
|
|
declaration */
|
|
|
|
ServerSocket::~ServerSocket() {}
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
void
|
|
|
|
ServerSocket::Open()
|
2010-10-05 20:29:41 +02:00
|
|
|
{
|
2013-01-30 12:56:23 +01:00
|
|
|
OneServerSocket *good = nullptr, *bad = nullptr;
|
2016-10-28 10:36:05 +02:00
|
|
|
std::exception_ptr last_error;
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
for (auto &i : sockets) {
|
|
|
|
assert(i.GetSerial() > 0);
|
2013-11-04 20:16:28 +01:00
|
|
|
assert(good == nullptr || i.GetSerial() >= good->GetSerial());
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
if (bad != nullptr && i.GetSerial() != bad->GetSerial()) {
|
|
|
|
Close();
|
2016-10-28 10:36:05 +02:00
|
|
|
std::rethrow_exception(last_error);
|
2010-10-05 20:29:41 +02:00
|
|
|
}
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
try {
|
|
|
|
i.Open();
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2013-01-30 12:56:23 +01:00
|
|
|
if (good != nullptr && good->GetSerial() == i.GetSerial()) {
|
2013-12-04 08:43:55 +01:00
|
|
|
const auto address_string = i.ToString();
|
|
|
|
const auto good_string = good->ToString();
|
2017-12-19 10:56:23 +01:00
|
|
|
FormatError(std::current_exception(),
|
2016-10-28 10:36:05 +02:00
|
|
|
"bind to '%s' failed "
|
|
|
|
"(continuing anyway, because "
|
|
|
|
"binding to '%s' succeeded)",
|
|
|
|
address_string.c_str(),
|
|
|
|
good_string.c_str());
|
2013-01-15 21:42:55 +01:00
|
|
|
} else if (bad == nullptr) {
|
|
|
|
bad = &i;
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-12-04 08:43:55 +01:00
|
|
|
const auto address_string = i.ToString();
|
2013-08-10 18:02:44 +02:00
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
try {
|
|
|
|
std::throw_with_nested(FormatRuntimeError("Failed to bind to '%s'",
|
|
|
|
address_string.c_str()));
|
|
|
|
} catch (...) {
|
|
|
|
last_error = std::current_exception();
|
|
|
|
}
|
2013-08-10 18:02:44 +02:00
|
|
|
}
|
|
|
|
|
2010-10-05 20:29:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mark this socket as "good", and clear previous
|
|
|
|
errors */
|
|
|
|
|
2013-01-15 21:42:55 +01:00
|
|
|
good = &i;
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-01-15 21:42:55 +01:00
|
|
|
if (bad != nullptr) {
|
|
|
|
bad = nullptr;
|
2016-10-28 10:36:05 +02:00
|
|
|
last_error = nullptr;
|
2010-10-05 20:29:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-15 21:42:55 +01:00
|
|
|
if (bad != nullptr) {
|
2013-01-30 12:56:23 +01:00
|
|
|
Close();
|
2016-10-28 10:36:05 +02:00
|
|
|
std::rethrow_exception(last_error);
|
2010-10-05 20:29:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-15 21:42:55 +01:00
|
|
|
void
|
2013-01-30 12:56:23 +01:00
|
|
|
ServerSocket::Close()
|
2013-01-15 21:42:55 +01:00
|
|
|
{
|
|
|
|
for (auto &i : sockets)
|
2013-02-04 11:44:36 +01:00
|
|
|
if (i.IsDefined())
|
|
|
|
i.Close();
|
2013-01-15 21:42:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
OneServerSocket &
|
2015-02-10 20:30:10 +01:00
|
|
|
ServerSocket::AddAddress(SocketAddress address)
|
2013-01-15 21:42:55 +01:00
|
|
|
{
|
2013-11-04 20:10:46 +01:00
|
|
|
sockets.emplace_back(loop, *this, next_serial,
|
2015-02-10 20:30:10 +01:00
|
|
|
address);
|
2013-01-15 21:42:55 +01:00
|
|
|
|
2013-11-04 20:10:46 +01:00
|
|
|
return sockets.back();
|
2010-10-05 20:29:41 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 11:05:08 +02:00
|
|
|
OneServerSocket &
|
|
|
|
ServerSocket::AddAddress(AllocatedSocketAddress &&address)
|
|
|
|
{
|
|
|
|
sockets.emplace_back(loop, *this, next_serial,
|
|
|
|
std::move(address));
|
|
|
|
|
|
|
|
return sockets.back();
|
|
|
|
}
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
void
|
2017-08-10 18:25:22 +02:00
|
|
|
ServerSocket::AddFD(int _fd)
|
2012-02-13 20:58:57 +01:00
|
|
|
{
|
2017-08-10 18:25:22 +02:00
|
|
|
assert(_fd >= 0);
|
2012-02-13 20:58:57 +01:00
|
|
|
|
2017-08-10 18:25:22 +02:00
|
|
|
SocketDescriptor fd(_fd);
|
2012-02-13 20:58:57 +01:00
|
|
|
|
2017-08-10 18:25:22 +02:00
|
|
|
StaticSocketAddress address = fd.GetLocalAddress();
|
|
|
|
if (!address.IsDefined())
|
|
|
|
throw MakeSocketError("Failed to get socket address");
|
2015-02-13 21:16:43 +01:00
|
|
|
|
|
|
|
OneServerSocket &s = AddAddress(address);
|
2013-01-15 21:42:55 +01:00
|
|
|
s.SetFD(fd);
|
2012-02-13 20:58:57 +01:00
|
|
|
}
|
|
|
|
|
2010-10-05 20:29:41 +02:00
|
|
|
#ifdef HAVE_TCP
|
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
inline void
|
|
|
|
ServerSocket::AddPortIPv4(unsigned port)
|
2010-10-05 20:29:41 +02:00
|
|
|
{
|
2017-08-11 08:41:58 +02:00
|
|
|
AddAddress(IPv4Address(port));
|
2010-10-05 20:29:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_IPV6
|
2013-11-04 23:36:00 +01:00
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
inline void
|
|
|
|
ServerSocket::AddPortIPv6(unsigned port)
|
2010-10-05 20:29:41 +02:00
|
|
|
{
|
|
|
|
struct sockaddr_in6 sin;
|
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin6_port = htons(port);
|
|
|
|
sin.sin6_family = AF_INET6;
|
|
|
|
|
2015-02-10 20:30:10 +01:00
|
|
|
AddAddress({(const sockaddr *)&sin, sizeof(sin)});
|
2010-10-05 20:29:41 +02:00
|
|
|
}
|
2013-11-04 23:36:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is IPv6 supported by the kernel?
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
static bool
|
2017-05-08 14:44:49 +02:00
|
|
|
SupportsIPv6() noexcept
|
2013-11-04 23:36:00 +01:00
|
|
|
{
|
|
|
|
int fd = socket(AF_INET6, SOCK_STREAM, 0);
|
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-05 20:29:41 +02:00
|
|
|
#endif /* HAVE_IPV6 */
|
|
|
|
|
|
|
|
#endif /* HAVE_TCP */
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
void
|
|
|
|
ServerSocket::AddPort(unsigned port)
|
2010-10-05 20:29:41 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_TCP
|
2016-10-28 10:36:05 +02:00
|
|
|
if (port == 0 || port > 0xffff)
|
|
|
|
throw std::runtime_error("Invalid TCP port");
|
2010-10-05 20:29:41 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_IPV6
|
2013-11-04 23:36:00 +01:00
|
|
|
if (SupportsIPv6())
|
|
|
|
AddPortIPv6(port);
|
2010-10-05 20:29:41 +02:00
|
|
|
#endif
|
2013-01-30 12:56:23 +01:00
|
|
|
AddPortIPv4(port);
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
++next_serial;
|
2010-10-05 20:29:41 +02:00
|
|
|
#else /* HAVE_TCP */
|
|
|
|
(void)port;
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
throw std::runtime_error("TCP support is disabled");
|
2010-10-05 20:29:41 +02:00
|
|
|
#endif /* HAVE_TCP */
|
|
|
|
}
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
void
|
|
|
|
ServerSocket::AddHost(const char *hostname, unsigned port)
|
2010-10-05 20:29:41 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_TCP
|
2011-09-20 20:52:49 +02:00
|
|
|
struct addrinfo *ai = resolve_host_port(hostname, port,
|
2016-10-28 10:36:05 +02:00
|
|
|
AI_PASSIVE, SOCK_STREAM);
|
|
|
|
AtScopeExit(ai) { freeaddrinfo(ai); };
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-01-15 21:42:55 +01:00
|
|
|
for (const struct addrinfo *i = ai; i != nullptr; i = i->ai_next)
|
2015-02-10 20:30:10 +01:00
|
|
|
AddAddress(SocketAddress(i->ai_addr, i->ai_addrlen));
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2013-01-30 12:56:23 +01:00
|
|
|
++next_serial;
|
2010-10-05 20:29:41 +02:00
|
|
|
#else /* HAVE_TCP */
|
|
|
|
(void)hostname;
|
|
|
|
(void)port;
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
throw std::runtime_error("TCP support is disabled");
|
2010-10-05 20:29:41 +02:00
|
|
|
#endif /* HAVE_TCP */
|
|
|
|
}
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
void
|
|
|
|
ServerSocket::AddPath(AllocatedPath &&path)
|
2010-10-05 20:29:41 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_UN
|
2016-08-15 22:25:15 +02:00
|
|
|
unlink(path.c_str());
|
2015-09-29 19:39:06 +02:00
|
|
|
|
2015-07-22 11:01:44 +02:00
|
|
|
AllocatedSocketAddress address;
|
|
|
|
address.SetLocal(path.c_str());
|
2010-10-05 20:29:41 +02:00
|
|
|
|
2015-07-22 11:01:44 +02:00
|
|
|
OneServerSocket &s = AddAddress(std::move(address));
|
2013-10-19 17:40:56 +02:00
|
|
|
s.SetPath(std::move(path));
|
2010-10-05 20:29:41 +02:00
|
|
|
#else /* !HAVE_UN */
|
|
|
|
(void)path;
|
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
throw std::runtime_error("UNIX domain socket support is disabled");
|
2010-10-05 20:29:41 +02:00
|
|
|
#endif /* !HAVE_UN */
|
|
|
|
}
|
|
|
|
|