aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/ServerSocket.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/event/ServerSocket.cxx')
-rw-r--r--src/event/ServerSocket.cxx46
1 files changed, 19 insertions, 27 deletions
diff --git a/src/event/ServerSocket.cxx b/src/event/ServerSocket.cxx
index 781d29181..c465c15c8 100644
--- a/src/event/ServerSocket.cxx
+++ b/src/event/ServerSocket.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -31,13 +31,13 @@
#include "system/fd_util.h"
#include "fs/AllocatedPath.hxx"
#include "fs/FileSystem.hxx"
+#include "util/Alloc.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
-#include <glib.h>
-
#include <string>
+#include <algorithm>
#include <sys/types.h>
#include <sys/stat.h>
@@ -78,7 +78,7 @@ public:
parent(_parent), serial(_serial),
path(AllocatedPath::Null()),
address_length(_address_length),
- address((sockaddr *)g_memdup(_address, _address_length))
+ address((sockaddr *)xmemdup(_address, _address_length))
{
assert(_address != nullptr);
assert(_address_length > 0);
@@ -88,7 +88,10 @@ public:
OneServerSocket &operator=(const OneServerSocket &other) = delete;
~OneServerSocket() {
- g_free(address);
+ free(address);
+
+ if (IsDefined())
+ Close();
}
unsigned GetSerial() const {
@@ -106,7 +109,10 @@ public:
using SocketMonitor::IsDefined;
using SocketMonitor::Close;
- char *ToString() const;
+ gcc_pure
+ std::string ToString() const {
+ return sockaddr_to_string(address, address_length);
+ }
void SetFD(int _fd) {
SocketMonitor::Open(_fd);
@@ -121,18 +127,6 @@ private:
static constexpr Domain server_socket_domain("server_socket");
-/**
- * Wraper for sockaddr_to_string() which never fails.
- */
-char *
-OneServerSocket::ToString() const
-{
- char *p = sockaddr_to_string(address, address_length, IgnoreError());
- if (p == nullptr)
- p = g_strdup("[unknown]");
- return p;
-}
-
static int
get_remote_uid(int fd)
{
@@ -242,23 +236,21 @@ ServerSocket::Open(Error &error)
Error error2;
if (!i.Open(error2)) {
if (good != nullptr && good->GetSerial() == i.GetSerial()) {
- char *address_string = i.ToString();
- char *good_string = good->ToString();
+ const auto address_string = i.ToString();
+ const auto good_string = good->ToString();
FormatWarning(server_socket_domain,
"bind to '%s' failed: %s "
"(continuing anyway, because "
"binding to '%s' succeeded)",
- address_string, error2.GetMessage(),
- good_string);
- g_free(address_string);
- g_free(good_string);
+ address_string.c_str(),
+ error2.GetMessage(),
+ good_string.c_str());
} else if (bad == nullptr) {
bad = &i;
- char *address_string = i.ToString();
+ const auto address_string = i.ToString();
error2.FormatPrefix("Failed to bind to '%s': ",
- address_string);
- g_free(address_string);
+ address_string.c_str());
last_error = std::move(error2);
}