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
d52c7e7a
Commit
d52c7e7a
authored
Oct 28, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/httpd: throw C++ exception on init error
parent
c4acccac
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
72 deletions
+35
-72
HttpdInternal.hxx
src/output/plugins/httpd/HttpdInternal.hxx
+5
-16
HttpdOutputPlugin.cxx
src/output/plugins/httpd/HttpdOutputPlugin.cxx
+30
-56
No files found.
src/output/plugins/httpd/HttpdInternal.hxx
View file @
d52c7e7a
...
...
@@ -150,9 +150,13 @@ private:
unsigned
clients_max
;
public
:
HttpdOutput
(
EventLoop
&
_loop
);
HttpdOutput
(
EventLoop
&
_loop
,
const
ConfigBlock
&
block
);
~
HttpdOutput
();
operator
AudioOutput
*
()
{
return
&
base
;
}
#if CLANG_OR_GCC_VERSION(4,7)
constexpr
#endif
...
...
@@ -162,21 +166,6 @@ public:
using
DeferredMonitor
::
GetEventLoop
;
bool
Init
(
const
ConfigBlock
&
block
,
Error
&
error
);
bool
Configure
(
const
ConfigBlock
&
block
,
Error
&
error
);
AudioOutput
*
InitAndConfigure
(
const
ConfigBlock
&
block
,
Error
&
error
)
{
if
(
!
Init
(
block
,
error
))
return
nullptr
;
if
(
!
Configure
(
block
,
error
))
return
nullptr
;
return
&
base
;
}
void
Bind
();
void
Unbind
();
...
...
src/output/plugins/httpd/HttpdOutputPlugin.cxx
View file @
d52c7e7a
...
...
@@ -32,6 +32,7 @@
#include "system/fd_util.h"
#include "IOThread.hxx"
#include "event/Call.hxx"
#include "util/RuntimeError.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/DeleteDisposer.hxx"
...
...
@@ -50,45 +51,12 @@
const
Domain
httpd_output_domain
(
"httpd_output"
);
inline
HttpdOutput
::
HttpdOutput
(
EventLoop
&
_loop
)
HttpdOutput
::
HttpdOutput
(
EventLoop
&
_loop
,
const
ConfigBlock
&
block
)
:
ServerSocket
(
_loop
),
DeferredMonitor
(
_loop
),
base
(
httpd_output_plugin
),
base
(
httpd_output_plugin
,
block
),
encoder
(
nullptr
),
unflushed_input
(
0
),
metadata
(
nullptr
)
{
}
HttpdOutput
::~
HttpdOutput
()
{
if
(
metadata
!=
nullptr
)
metadata
->
Unref
();
delete
prepared_encoder
;
}
inline
void
HttpdOutput
::
Bind
()
{
open
=
false
;
BlockingCall
(
GetEventLoop
(),
[
this
](){
ServerSocket
::
Open
();
});
}
inline
void
HttpdOutput
::
Unbind
()
{
assert
(
!
open
);
BlockingCall
(
GetEventLoop
(),
[
this
](){
ServerSocket
::
Close
();
});
}
inline
bool
HttpdOutput
::
Configure
(
const
ConfigBlock
&
block
,
Error
&
error
)
{
/* read configuration */
name
=
block
.
GetBlockValue
(
"name"
,
"Set name in config"
);
genre
=
block
.
GetBlockValue
(
"genre"
,
"Set genre in config"
);
...
...
@@ -99,11 +67,8 @@ HttpdOutput::Configure(const ConfigBlock &block, Error &error)
const
char
*
encoder_name
=
block
.
GetBlockValue
(
"encoder"
,
"vorbis"
);
const
auto
encoder_plugin
=
encoder_plugin_get
(
encoder_name
);
if
(
encoder_plugin
==
nullptr
)
{
error
.
Format
(
httpd_output_domain
,
"No such encoder: %s"
,
encoder_name
);
return
false
;
}
if
(
encoder_plugin
==
nullptr
)
throw
FormatRuntimeError
(
"No such encoder: %s"
,
encoder_name
);
clients_max
=
block
.
GetBlockValue
(
"max_clients"
,
0u
);
...
...
@@ -123,31 +88,40 @@ HttpdOutput::Configure(const ConfigBlock &block, Error &error)
content_type
=
prepared_encoder
->
GetMimeType
();
if
(
content_type
==
nullptr
)
content_type
=
"application/octet-stream"
;
}
return
true
;
HttpdOutput
::~
HttpdOutput
()
{
if
(
metadata
!=
nullptr
)
metadata
->
Unref
();
delete
prepared_encoder
;
}
inline
bool
HttpdOutput
::
Init
(
const
ConfigBlock
&
block
,
Error
&
error
)
inline
void
HttpdOutput
::
Bind
(
)
{
return
base
.
Configure
(
block
,
error
);
open
=
false
;
BlockingCall
(
GetEventLoop
(),
[
this
](){
ServerSocket
::
Open
();
});
}
static
AudioOutput
*
httpd_output_init
(
const
ConfigBlock
&
block
,
Error
&
error
)
inline
void
HttpdOutput
::
Unbind
(
)
{
HttpdOutput
*
httpd
=
new
HttpdOutput
(
io_thread_get
()
);
assert
(
!
open
);
try
{
AudioOutput
*
result
=
httpd
->
InitAndConfigure
(
block
,
error
);
if
(
result
==
nullptr
)
delete
httpd
;
BlockingCall
(
GetEventLoop
(),
[
this
]()
{
ServerSocket
::
Close
(
);
});
}
return
result
;
}
catch
(
const
std
::
runtime_error
&
e
)
{
delete
httpd
;
throw
;
}
static
AudioOutput
*
httpd_output_init
(
const
ConfigBlock
&
block
,
Error
&
)
{
return
*
new
HttpdOutput
(
io_thread_get
(),
block
);
}
static
void
...
...
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