Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
7d16d8c8
Commit
7d16d8c8
authored
Jan 29, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Listen: move ClientListener pointer to struct Partition
parent
1df5c5a7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
49 deletions
+33
-49
Listen.cxx
src/Listen.cxx
+13
-38
Listen.hxx
src/Listen.hxx
+3
-7
Main.cxx
src/Main.cxx
+7
-4
Partition.cxx
src/Partition.cxx
+4
-0
Partition.hxx
src/Partition.hxx
+6
-0
No files found.
src/Listen.cxx
View file @
7d16d8c8
/*
* Copyright 2003-201
7
The Music Player Daemon Project
* Copyright 2003-201
8
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -23,14 +23,9 @@
#include "config/Param.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx"
#include "net/SocketAddress.hxx"
#include "net/UniqueSocketDescriptor.hxx"
#include "event/ServerSocket.hxx"
#include "system/Error.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx"
#include "fs/AllocatedPath.hxx"
#include "Log.hxx"
#include <string.h>
#include <assert.h>
...
...
@@ -39,35 +34,33 @@
#include <systemd/sd-daemon.h>
#endif
static
constexpr
Domain
listen_domain
(
"listen"
);
#define DEFAULT_PORT 6600
static
ClientListener
*
listen_socket
;
int
listen_port
;
/**
* Throws #std::runtime_error on error.
*/
static
void
listen_add_config_param
(
unsigned
int
port
,
listen_add_config_param
(
ClientListener
&
listener
,
unsigned
int
port
,
const
ConfigParam
*
param
)
{
assert
(
param
!=
nullptr
);
if
(
0
==
strcmp
(
param
->
value
.
c_str
(),
"any"
))
{
listen
_socket
->
AddPort
(
port
);
listen
er
.
AddPort
(
port
);
}
else
if
(
param
->
value
[
0
]
==
'/'
||
param
->
value
[
0
]
==
'~'
)
{
listen
_socket
->
AddPath
(
param
->
GetPath
());
listen
er
.
AddPath
(
param
->
GetPath
());
}
else
{
listen
_socket
->
AddHost
(
param
->
value
.
c_str
(),
port
);
listen
er
.
AddHost
(
param
->
value
.
c_str
(),
port
);
}
}
#ifdef ENABLE_SYSTEMD_DAEMON
static
bool
listen_systemd_activation
()
listen_systemd_activation
(
ClientListener
&
listener
)
{
int
n
=
sd_listen_fds
(
true
);
if
(
n
<=
0
)
{
...
...
@@ -78,7 +71,7 @@ listen_systemd_activation()
for
(
int
i
=
SD_LISTEN_FDS_START
,
end
=
SD_LISTEN_FDS_START
+
n
;
i
!=
end
;
++
i
)
listen
_socket
->
AddFD
(
i
);
listen
er
.
AddFD
(
i
);
return
true
;
}
...
...
@@ -86,15 +79,13 @@ listen_systemd_activation()
#endif
void
listen_global_init
(
EventLoop
&
loop
,
Partition
&
partition
)
listen_global_init
(
ClientListener
&
listener
)
{
int
port
=
config_get_positive
(
ConfigOption
::
PORT
,
DEFAULT_PORT
);
const
auto
*
param
=
config_get_param
(
ConfigOption
::
BIND_TO_ADDRESS
);
listen_socket
=
new
ClientListener
(
loop
,
partition
);
#ifdef ENABLE_SYSTEMD_DAEMON
if
(
listen_systemd_activation
())
if
(
listen_systemd_activation
(
listener
))
return
;
#endif
...
...
@@ -104,9 +95,8 @@ listen_global_init(EventLoop &loop, Partition &partition)
do
{
try
{
listen_add_config_param
(
port
,
param
);
listen_add_config_param
(
listener
,
port
,
param
);
}
catch
(...)
{
delete
listen_socket
;
std
::
throw_with_nested
(
FormatRuntimeError
(
"Failed to listen on %s (line %i)"
,
param
->
value
.
c_str
(),
param
->
line
));
...
...
@@ -117,28 +107,13 @@ listen_global_init(EventLoop &loop, Partition &partition)
configured port on all interfaces */
try
{
listen
_socket
->
AddPort
(
port
);
listen
er
.
AddPort
(
port
);
}
catch
(...)
{
delete
listen_socket
;
std
::
throw_with_nested
(
FormatRuntimeError
(
"Failed to listen on *:%d: "
,
port
));
}
}
try
{
listen_socket
->
Open
();
}
catch
(...)
{
delete
listen_socket
;
throw
;
}
listener
.
Open
();
listen_port
=
port
;
}
void
listen_global_finish
(
void
)
{
LogDebug
(
listen_domain
,
"listen_global_finish called"
);
assert
(
listen_socket
!=
nullptr
);
delete
listen_socket
;
}
src/Listen.hxx
View file @
7d16d8c8
/*
* Copyright 2003-201
7
The Music Player Daemon Project
* Copyright 2003-201
8
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -20,15 +20,11 @@
#ifndef MPD_LISTEN_HXX
#define MPD_LISTEN_HXX
class
EventLoop
;
struct
Partition
;
class
ClientListener
;
extern
int
listen_port
;
void
listen_global_init
(
EventLoop
&
loop
,
Partition
&
partition
);
void
listen_global_finish
();
listen_global_init
(
ClientListener
&
listener
);
#endif
src/Main.cxx
View file @
7d16d8c8
...
...
@@ -28,6 +28,7 @@
#include "Mapper.hxx"
#include "Permission.hxx"
#include "Listen.hxx"
#include "client/Listener.hxx"
#include "client/Client.hxx"
#include "client/ClientList.hxx"
#include "command/AllCommands.hxx"
...
...
@@ -442,8 +443,10 @@ Instance::ShutdownDatabase() noexcept
inline
void
Instance
::
BeginShutdownPartitions
()
noexcept
{
for
(
auto
&
partition
:
partitions
)
for
(
auto
&
partition
:
partitions
)
{
partition
.
pc
.
Kill
();
partition
.
listener
.
reset
();
}
}
inline
void
...
...
@@ -548,7 +551,7 @@ try {
initialize_decoder_and_player
(
config
.
replay_gain
);
listen_global_init
(
instance
->
event_loop
,
instance
->
partitions
.
front
()
);
listen_global_init
(
*
instance
->
partitions
.
front
().
listener
);
#ifdef ENABLE_DAEMON
daemonize_set_user
();
...
...
@@ -697,10 +700,10 @@ try {
delete
instance
->
state_file
;
}
ZeroconfDeinit
();
instance
->
BeginShutdownPartitions
();
ZeroconfDeinit
();
listen_global_finish
();
delete
instance
->
client_list
;
#ifdef ENABLE_NEIGHBOR_PLUGINS
...
...
src/Partition.cxx
View file @
7d16d8c8
...
...
@@ -23,6 +23,7 @@
#include "DetachedSong.hxx"
#include "mixer/Volume.hxx"
#include "IdleFlags.hxx"
#include "client/Listener.hxx"
Partition
::
Partition
(
Instance
&
_instance
,
const
char
*
_name
,
...
...
@@ -33,6 +34,7 @@ Partition::Partition(Instance &_instance,
const
ReplayGainConfig
&
replay_gain_config
)
:
instance
(
_instance
),
name
(
_name
),
listener
(
new
ClientListener
(
instance
.
event_loop
,
*
this
)),
global_events
(
instance
.
event_loop
,
BIND_THIS_METHOD
(
OnGlobalEvent
)),
playlist
(
max_length
,
*
this
),
outputs
(
*
this
),
...
...
@@ -42,6 +44,8 @@ Partition::Partition(Instance &_instance,
UpdateEffectiveReplayGainMode
();
}
Partition
::~
Partition
()
noexcept
=
default
;
void
Partition
::
EmitIdle
(
unsigned
mask
)
{
...
...
src/Partition.hxx
View file @
7d16d8c8
...
...
@@ -32,10 +32,12 @@
#include "Compiler.h"
#include <string>
#include <memory>
struct
Instance
;
class
MultipleOutputs
;
class
SongLoader
;
class
ClientListener
;
/**
* A partition of the Music Player Daemon. It is a separate unit with
...
...
@@ -49,6 +51,8 @@ struct Partition final : QueueListener, PlayerListener, MixerListener {
const
std
::
string
name
;
std
::
unique_ptr
<
ClientListener
>
listener
;
MaskMonitor
global_events
;
struct
playlist
playlist
;
...
...
@@ -67,6 +71,8 @@ struct Partition final : QueueListener, PlayerListener, MixerListener {
AudioFormat
configured_audio_format
,
const
ReplayGainConfig
&
replay_gain_config
);
~
Partition
()
noexcept
;
void
EmitGlobalEvent
(
unsigned
mask
)
{
global_events
.
OrMask
(
mask
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment