Commit df5f9f4a authored by Max Kellermann's avatar Max Kellermann

Listen: add Partition reference

parent d9466cad
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
#include "config.h" #include "config.h"
#include "Listen.hxx" #include "Listen.hxx"
#include "Main.hxx"
#include "Instance.hxx"
#include "client/Client.hxx" #include "client/Client.hxx"
#include "config/ConfigData.hxx" #include "config/ConfigData.hxx"
#include "config/ConfigGlobal.hxx" #include "config/ConfigGlobal.hxx"
...@@ -43,13 +41,16 @@ static constexpr Domain listen_domain("listen"); ...@@ -43,13 +41,16 @@ static constexpr Domain listen_domain("listen");
#define DEFAULT_PORT 6600 #define DEFAULT_PORT 6600
class ClientListener final : public ServerSocket { class ClientListener final : public ServerSocket {
Partition &partition;
public: public:
ClientListener(EventLoop &_loop):ServerSocket(_loop) {} ClientListener(EventLoop &_loop, Partition &_partition)
:ServerSocket(_loop), partition(_partition) {}
private: private:
virtual void OnAccept(int fd, const sockaddr &address, virtual void OnAccept(int fd, const sockaddr &address,
size_t address_length, int uid) { size_t address_length, int uid) {
client_new(GetEventLoop(), *instance->partition, client_new(GetEventLoop(), partition,
fd, &address, address_length, uid); fd, &address, address_length, uid);
} }
}; };
...@@ -101,14 +102,14 @@ listen_systemd_activation(Error &error_r) ...@@ -101,14 +102,14 @@ listen_systemd_activation(Error &error_r)
} }
bool bool
listen_global_init(EventLoop &loop, Error &error) listen_global_init(EventLoop &loop, Partition &partition, Error &error)
{ {
int port = config_get_positive(CONF_PORT, DEFAULT_PORT); int port = config_get_positive(CONF_PORT, DEFAULT_PORT);
const struct config_param *param = const struct config_param *param =
config_get_next_param(CONF_BIND_TO_ADDRESS, nullptr); config_get_next_param(CONF_BIND_TO_ADDRESS, nullptr);
bool success; bool success;
listen_socket = new ClientListener(loop); listen_socket = new ClientListener(loop, partition);
if (listen_systemd_activation(error)) if (listen_systemd_activation(error))
return true; return true;
......
...@@ -22,11 +22,12 @@ ...@@ -22,11 +22,12 @@
class EventLoop; class EventLoop;
class Error; class Error;
struct Partition;
extern int listen_port; extern int listen_port;
bool bool
listen_global_init(EventLoop &loop, Error &error); listen_global_init(EventLoop &loop, Partition &partition, Error &error);
void listen_global_finish(void); void listen_global_finish(void);
......
...@@ -432,7 +432,8 @@ int mpd_main(int argc, char *argv[]) ...@@ -432,7 +432,8 @@ int mpd_main(int argc, char *argv[])
const unsigned max_clients = config_get_positive(CONF_MAX_CONN, 10); const unsigned max_clients = config_get_positive(CONF_MAX_CONN, 10);
instance->client_list = new ClientList(max_clients); instance->client_list = new ClientList(max_clients);
if (!listen_global_init(*instance->event_loop, error)) { if (!listen_global_init(*instance->event_loop, *instance->partition,
error)) {
LogError(error); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment