diff options
Diffstat (limited to 'src/Listen.cxx')
-rw-r--r-- | src/Listen.cxx | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/src/Listen.cxx b/src/Listen.cxx index d5c132545..d48d795d1 100644 --- a/src/Listen.cxx +++ b/src/Listen.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 @@ -19,12 +19,10 @@ #include "config.h" #include "Listen.hxx" -#include "Main.hxx" -#include "Instance.hxx" -#include "Client.hxx" -#include "ConfigData.hxx" -#include "ConfigGlobal.hxx" -#include "ConfigOption.hxx" +#include "client/Client.hxx" +#include "config/ConfigData.hxx" +#include "config/ConfigGlobal.hxx" +#include "config/ConfigOption.hxx" #include "event/ServerSocket.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" @@ -43,13 +41,16 @@ static constexpr Domain listen_domain("listen"); #define DEFAULT_PORT 6600 class ClientListener final : public ServerSocket { + Partition &partition; + public: - ClientListener():ServerSocket(*main_loop) {} + ClientListener(EventLoop &_loop, Partition &_partition) + :ServerSocket(_loop), partition(_partition) {} private: virtual void OnAccept(int fd, const sockaddr &address, size_t address_length, int uid) { - client_new(*main_loop, *instance->partition, + client_new(GetEventLoop(), partition, fd, &address, address_length, uid); } }; @@ -76,10 +77,11 @@ listen_add_config_param(unsigned int port, } } +#ifdef ENABLE_SYSTEMD_DAEMON + static bool listen_systemd_activation(Error &error_r) { -#ifdef ENABLE_SYSTEMD_DAEMON int n = sd_listen_fds(true); if (n <= 0) { if (n < 0) @@ -94,29 +96,26 @@ listen_systemd_activation(Error &error_r) return false; return true; -#else - (void)error_r; - return false; -#endif } +#endif + bool -listen_global_init(Error &error) +listen_global_init(EventLoop &loop, Partition &partition, Error &error) { - assert(main_loop != nullptr); - int port = config_get_positive(CONF_PORT, DEFAULT_PORT); const struct config_param *param = - config_get_next_param(CONF_BIND_TO_ADDRESS, nullptr); - bool success; + config_get_param(CONF_BIND_TO_ADDRESS); - listen_socket = new ClientListener(); + listen_socket = new ClientListener(loop, partition); +#ifdef ENABLE_SYSTEMD_DAEMON if (listen_systemd_activation(error)) return true; if (error.IsDefined()) return false; +#endif if (param != nullptr) { /* "bind_to_address" is configured, create listeners @@ -130,16 +129,12 @@ listen_global_init(Error &error) param->line); return false; } - - param = config_get_next_param(CONF_BIND_TO_ADDRESS, - param); - } while (param != nullptr); + } while ((param = param->next) != nullptr); } else { /* no "bind_to_address" configured, bind the configured port on all interfaces */ - success = listen_socket->AddPort(port, error); - if (!success) { + if (!listen_socket->AddPort(port, error)) { delete listen_socket; error.FormatPrefix("Failed to listen on *:%d: ", port); return false; |