diff options
Diffstat (limited to '')
30 files changed, 80 insertions, 81 deletions
diff --git a/src/event/BufferedSocket.cxx b/src/event/BufferedSocket.cxx index 939824baa..40aea6618 100644 --- a/src/event/BufferedSocket.cxx +++ b/src/event/BufferedSocket.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,7 +19,7 @@ #include "config.h" #include "BufferedSocket.hxx" -#include "system/SocketError.hxx" +#include "net/SocketError.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" #include "Compiler.h" diff --git a/src/event/BufferedSocket.hxx b/src/event/BufferedSocket.hxx index b1882de2f..1478f82ca 100644 --- a/src/event/BufferedSocket.hxx +++ b/src/event/BufferedSocket.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/Call.cxx b/src/event/Call.cxx index bc16c4e95..216d4a5e8 100644 --- a/src/event/Call.cxx +++ b/src/event/Call.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/Call.hxx b/src/event/Call.hxx index 808965de1..f16337ac3 100644 --- a/src/event/Call.hxx +++ b/src/event/Call.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/DeferredMonitor.cxx b/src/event/DeferredMonitor.cxx index 3e824012f..7d23746de 100644 --- a/src/event/DeferredMonitor.cxx +++ b/src/event/DeferredMonitor.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/DeferredMonitor.hxx b/src/event/DeferredMonitor.hxx index c4aa605fc..2697a7226 100644 --- a/src/event/DeferredMonitor.hxx +++ b/src/event/DeferredMonitor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/FullyBufferedSocket.cxx b/src/event/FullyBufferedSocket.cxx index 457add2b0..ba7f7b455 100644 --- a/src/event/FullyBufferedSocket.cxx +++ b/src/event/FullyBufferedSocket.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,7 +19,7 @@ #include "config.h" #include "FullyBufferedSocket.hxx" -#include "system/SocketError.hxx" +#include "net/SocketError.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" #include "Compiler.h" diff --git a/src/event/FullyBufferedSocket.hxx b/src/event/FullyBufferedSocket.hxx index b03152be2..77b5c4416 100644 --- a/src/event/FullyBufferedSocket.hxx +++ b/src/event/FullyBufferedSocket.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/IdleMonitor.cxx b/src/event/IdleMonitor.cxx index 4af656a22..32b412825 100644 --- a/src/event/IdleMonitor.cxx +++ b/src/event/IdleMonitor.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/IdleMonitor.hxx b/src/event/IdleMonitor.hxx index 8d4d2681a..c7e9e4035 100644 --- a/src/event/IdleMonitor.hxx +++ b/src/event/IdleMonitor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index 1bac7c551..fca1f516f 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index 56804dc81..4001e31a0 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/MultiSocketMonitor.cxx b/src/event/MultiSocketMonitor.cxx index ef77de425..6fc420b8d 100644 --- a/src/event/MultiSocketMonitor.cxx +++ b/src/event/MultiSocketMonitor.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/MultiSocketMonitor.hxx b/src/event/MultiSocketMonitor.hxx index b40ee8caa..eb6f51aa8 100644 --- a/src/event/MultiSocketMonitor.hxx +++ b/src/event/MultiSocketMonitor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/PollGroup.hxx b/src/event/PollGroup.hxx index a2f176860..f376d50ca 100644 --- a/src/event/PollGroup.hxx +++ b/src/event/PollGroup.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/PollGroupEPoll.hxx b/src/event/PollGroupEPoll.hxx index d8edb8a1f..9457823a6 100644 --- a/src/event/PollGroupEPoll.hxx +++ b/src/event/PollGroupEPoll.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/PollGroupPoll.cxx b/src/event/PollGroupPoll.cxx index 402f8616f..b961c3f90 100644 --- a/src/event/PollGroupPoll.cxx +++ b/src/event/PollGroupPoll.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/PollGroupPoll.hxx b/src/event/PollGroupPoll.hxx index f7a3ccb4f..8d73280b4 100644 --- a/src/event/PollGroupPoll.hxx +++ b/src/event/PollGroupPoll.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/PollGroupWinSelect.cxx b/src/event/PollGroupWinSelect.cxx index 26c8abd46..796f699e2 100644 --- a/src/event/PollGroupWinSelect.cxx +++ b/src/event/PollGroupWinSelect.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/PollGroupWinSelect.hxx b/src/event/PollGroupWinSelect.hxx index d01067709..276a602a6 100644 --- a/src/event/PollGroupWinSelect.hxx +++ b/src/event/PollGroupWinSelect.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/PollResultGeneric.hxx b/src/event/PollResultGeneric.hxx index 35daf7f08..3dbeda0e4 100644 --- a/src/event/PollResultGeneric.hxx +++ b/src/event/PollResultGeneric.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/ServerSocket.cxx b/src/event/ServerSocket.cxx index 313f0a6cf..47d692a1c 100644 --- a/src/event/ServerSocket.cxx +++ b/src/event/ServerSocket.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,10 +19,12 @@ #include "config.h" #include "ServerSocket.hxx" -#include "system/SocketUtil.hxx" -#include "system/SocketError.hxx" +#include "net/StaticSocketAddress.hxx" +#include "net/SocketAddress.hxx" +#include "net/SocketUtil.hxx" +#include "net/SocketError.hxx" +#include "net/Resolver.hxx" #include "event/SocketMonitor.hxx" -#include "system/Resolver.hxx" #include "system/fd_util.h" #include "fs/AllocatedPath.hxx" #include "fs/FileSystem.hxx" @@ -52,38 +54,39 @@ #include <netdb.h> #endif -#define DEFAULT_PORT 6600 - class OneServerSocket final : private SocketMonitor { ServerSocket &parent; const unsigned serial; +#ifdef HAVE_UN AllocatedPath path; +#endif - size_t address_length; - struct sockaddr *address; + SocketAddress address; public: OneServerSocket(EventLoop &_loop, ServerSocket &_parent, unsigned _serial, - const struct sockaddr *_address, - size_t _address_length) + SocketAddress _address) :SocketMonitor(_loop), parent(_parent), serial(_serial), +#ifdef HAVE_UN path(AllocatedPath::Null()), - address_length(_address_length), - address((sockaddr *)xmemdup(_address, _address_length)) +#endif + address((sockaddr *)xmemdup(_address.GetAddress(), + _address.GetSize()), + _address.GetSize()) { - assert(_address != nullptr); - assert(_address_length > 0); + assert(!_address.IsNull()); + assert(_address.GetSize() > 0); } OneServerSocket(const OneServerSocket &other) = delete; OneServerSocket &operator=(const OneServerSocket &other) = delete; ~OneServerSocket() { - free(address); + free(const_cast<struct sockaddr *>(address.GetAddress())); if (IsDefined()) Close(); @@ -93,11 +96,13 @@ public: return serial; } +#ifdef HAVE_UN void SetPath(AllocatedPath &&_path) { assert(path.IsNull()); path = std::move(_path); } +#endif bool Open(Error &error); @@ -106,7 +111,7 @@ public: gcc_pure std::string ToString() const { - return sockaddr_to_string(address, address_length); + return sockaddr_to_string(address); } void SetFD(int _fd) { @@ -150,10 +155,10 @@ get_remote_uid(int fd) inline void OneServerSocket::Accept() { - struct sockaddr_storage peer_address; + StaticSocketAddress peer_address; size_t peer_address_length = sizeof(peer_address); int peer_fd = - accept_cloexec_nonblock(Get(), (struct sockaddr*)&peer_address, + accept_cloexec_nonblock(Get(), peer_address, &peer_address_length); if (peer_fd < 0) { const SocketErrorMessage msg; @@ -162,6 +167,8 @@ OneServerSocket::Accept() return; } + peer_address.SetSize(peer_address_length); + if (socket_keepalive(peer_fd)) { const SocketErrorMessage msg; FormatError(server_socket_domain, @@ -169,9 +176,8 @@ OneServerSocket::Accept() (const char *)msg); } - parent.OnAccept(peer_fd, - (const sockaddr &)peer_address, - peer_address_length, get_remote_uid(peer_fd)); + parent.OnAccept(peer_fd, peer_address, + get_remote_uid(peer_fd)); } bool @@ -186,19 +192,21 @@ OneServerSocket::Open(Error &error) { assert(!IsDefined()); - int _fd = socket_bind_listen(address->sa_family, + int _fd = socket_bind_listen(address.GetFamily(), SOCK_STREAM, 0, - address, address_length, 5, + address, 5, error); if (_fd < 0) return false; +#ifdef HAVE_UN /* allow everybody to connect */ if (!path.IsNull()) chmod(path.c_str(), 0666); +#endif - /* register in the GLib main loop */ + /* register in the EventLoop */ SetFD(_fd); @@ -282,10 +290,10 @@ ServerSocket::Close() } OneServerSocket & -ServerSocket::AddAddress(const sockaddr &address, size_t address_length) +ServerSocket::AddAddress(SocketAddress address) { sockets.emplace_back(loop, *this, next_serial, - &address, address_length); + address); return sockets.back(); } @@ -295,17 +303,18 @@ ServerSocket::AddFD(int fd, Error &error) { assert(fd >= 0); - struct sockaddr_storage address; + StaticSocketAddress address; socklen_t address_length = sizeof(address); - if (getsockname(fd, (struct sockaddr *)&address, + if (getsockname(fd, address, &address_length) < 0) { SetSocketError(error); error.AddPrefix("Failed to get socket address: "); return false; } - OneServerSocket &s = AddAddress((const sockaddr &)address, - address_length); + address.SetSize(address_length); + + OneServerSocket &s = AddAddress(address); s.SetFD(fd); return true; @@ -322,7 +331,7 @@ ServerSocket::AddPortIPv4(unsigned port) sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; - AddAddress((const sockaddr &)sin, sizeof(sin)); + AddAddress({(const sockaddr *)&sin, sizeof(sin)}); } #ifdef HAVE_IPV6 @@ -335,7 +344,7 @@ ServerSocket::AddPortIPv6(unsigned port) sin.sin6_port = htons(port); sin.sin6_family = AF_INET6; - AddAddress((const sockaddr &)sin, sizeof(sin)); + AddAddress({(const sockaddr *)&sin, sizeof(sin)}); } /** @@ -394,7 +403,7 @@ ServerSocket::AddHost(const char *hostname, unsigned port, Error &error) return false; for (const struct addrinfo *i = ai; i != nullptr; i = i->ai_next) - AddAddress(*i->ai_addr, i->ai_addrlen); + AddAddress(SocketAddress(i->ai_addr, i->ai_addrlen)); freeaddrinfo(ai); @@ -428,7 +437,7 @@ ServerSocket::AddPath(AllocatedPath &&path, Error &error) 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)); + OneServerSocket &s = AddAddress({(const sockaddr *)&s_un, sizeof(s_un)}); s.SetPath(std::move(path)); return true; diff --git a/src/event/ServerSocket.hxx b/src/event/ServerSocket.hxx index 4c3fd9f1d..ec91dc3fb 100644 --- a/src/event/ServerSocket.hxx +++ b/src/event/ServerSocket.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -24,16 +24,10 @@ #include <stddef.h> -struct sockaddr; +class SocketAddress; class EventLoop; class Error; class AllocatedPath; - -typedef void (*server_socket_callback_t)(int fd, - const struct sockaddr *address, - size_t address_length, int uid, - void *ctx); - class OneServerSocket; /** @@ -57,7 +51,7 @@ public: } private: - OneServerSocket &AddAddress(const sockaddr &address, size_t length); + OneServerSocket &AddAddress(SocketAddress address); /** * Add a listener on a port on all IPv4 interfaces. @@ -78,8 +72,7 @@ public: * Add a listener on a port on all interfaces. * * @param port the TCP port - * @param error_r location to store the error occurring, or nullptr to - * ignore errors + * @param error location to store the error occurring * @return true on success */ bool AddPort(unsigned port, Error &error); @@ -90,8 +83,7 @@ public: * * @param hostname the host name to be resolved * @param port the TCP port - * @param error_r location to store the error occurring, or nullptr to - * ignore errors + * @param error location to store the error occurring * @return true on success */ bool AddHost(const char *hostname, unsigned port, Error &error); @@ -100,8 +92,7 @@ public: * Add a listener on a Unix domain socket. * * @param path the absolute socket path - * @param error_r location to store the error occurring, or nullptr to - * ignore errors + * @param error location to store the error occurring * @return true on success */ bool AddPath(AllocatedPath &&path, Error &error); @@ -117,8 +108,7 @@ public: void Close(); protected: - virtual void OnAccept(int fd, const sockaddr &address, - size_t address_length, int uid) = 0; + virtual void OnAccept(int fd, SocketAddress address, int uid) = 0; }; #endif diff --git a/src/event/SignalMonitor.cxx b/src/event/SignalMonitor.cxx index 2d8fe681f..c9a7085eb 100644 --- a/src/event/SignalMonitor.cxx +++ b/src/event/SignalMonitor.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/SignalMonitor.hxx b/src/event/SignalMonitor.hxx index a41e57ef9..6bed61c66 100644 --- a/src/event/SignalMonitor.hxx +++ b/src/event/SignalMonitor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/SocketMonitor.cxx b/src/event/SocketMonitor.cxx index 69207287d..00e6e6c45 100644 --- a/src/event/SocketMonitor.cxx +++ b/src/event/SocketMonitor.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/SocketMonitor.hxx b/src/event/SocketMonitor.hxx index 56d4273f0..4231e3ec0 100644 --- a/src/event/SocketMonitor.hxx +++ b/src/event/SocketMonitor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/TimeoutMonitor.cxx b/src/event/TimeoutMonitor.cxx index 007e8aa2c..1bda47c5c 100644 --- a/src/event/TimeoutMonitor.cxx +++ b/src/event/TimeoutMonitor.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/TimeoutMonitor.hxx b/src/event/TimeoutMonitor.hxx index 414d48aa6..00289a0db 100644 --- a/src/event/TimeoutMonitor.hxx +++ b/src/event/TimeoutMonitor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/event/WakeFD.hxx b/src/event/WakeFD.hxx index c6222b59c..4b3792111 100644 --- a/src/event/WakeFD.hxx +++ b/src/event/WakeFD.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify |