aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-07-22 11:05:08 +0200
committerMax Kellermann <max@duempel.org>2015-07-22 11:05:08 +0200
commitfdeec0307e4bcc841d74e994ebf767bc013a3544 (patch)
tree071771446ed9e39166f2612e5a6650c3011139d9 /src
parentf084bbbf357b83f9fc10b088a4750497016bdd9e (diff)
downloadmpd-fdeec0307e4bcc841d74e994ebf767bc013a3544.tar.gz
mpd-fdeec0307e4bcc841d74e994ebf767bc013a3544.tar.xz
mpd-fdeec0307e4bcc841d74e994ebf767bc013a3544.zip
event/ServerSocket: use AllocatedSocketAddress for OneServerSocket::address
Manages memory automatically.
Diffstat (limited to 'src')
-rw-r--r--src/event/ServerSocket.cxx23
-rw-r--r--src/event/ServerSocket.hxx2
2 files changed, 16 insertions, 9 deletions
diff --git a/src/event/ServerSocket.cxx b/src/event/ServerSocket.cxx
index 552efb0a3..b1cffcfda 100644
--- a/src/event/ServerSocket.cxx
+++ b/src/event/ServerSocket.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "ServerSocket.hxx"
#include "net/StaticSocketAddress.hxx"
+#include "net/AllocatedSocketAddress.hxx"
#include "net/SocketAddress.hxx"
#include "net/SocketUtil.hxx"
#include "net/SocketError.hxx"
@@ -64,31 +65,26 @@ class OneServerSocket final : private SocketMonitor {
AllocatedPath path;
#endif
- SocketAddress address;
+ const AllocatedSocketAddress address;
public:
+ template<typename A>
OneServerSocket(EventLoop &_loop, ServerSocket &_parent,
unsigned _serial,
- SocketAddress _address)
+ A &&_address)
:SocketMonitor(_loop),
parent(_parent), serial(_serial),
#ifdef HAVE_UN
path(AllocatedPath::Null()),
#endif
- address((sockaddr *)xmemdup(_address.GetAddress(),
- _address.GetSize()),
- _address.GetSize())
+ address(std::forward<A>(_address))
{
- assert(!_address.IsNull());
- assert(_address.GetSize() > 0);
}
OneServerSocket(const OneServerSocket &other) = delete;
OneServerSocket &operator=(const OneServerSocket &other) = delete;
~OneServerSocket() {
- free(const_cast<struct sockaddr *>(address.GetAddress()));
-
if (IsDefined())
Close();
}
@@ -299,6 +295,15 @@ ServerSocket::AddAddress(SocketAddress address)
return sockets.back();
}
+OneServerSocket &
+ServerSocket::AddAddress(AllocatedSocketAddress &&address)
+{
+ sockets.emplace_back(loop, *this, next_serial,
+ std::move(address));
+
+ return sockets.back();
+}
+
bool
ServerSocket::AddFD(int fd, Error &error)
{
diff --git a/src/event/ServerSocket.hxx b/src/event/ServerSocket.hxx
index ec91dc3fb..a59ac3f2a 100644
--- a/src/event/ServerSocket.hxx
+++ b/src/event/ServerSocket.hxx
@@ -25,6 +25,7 @@
#include <stddef.h>
class SocketAddress;
+class AllocatedSocketAddress;
class EventLoop;
class Error;
class AllocatedPath;
@@ -52,6 +53,7 @@ public:
private:
OneServerSocket &AddAddress(SocketAddress address);
+ OneServerSocket &AddAddress(AllocatedSocketAddress &&address);
/**
* Add a listener on a port on all IPv4 interfaces.