Fix crash during shutdown

In case there are multiple PosixStreams with the same name, the server crashed during shutdown
This commit is contained in:
badaix 2020-01-06 18:50:57 +01:00
parent e12fa3fc7d
commit 062e46060c
4 changed files with 9 additions and 7 deletions

View file

@ -799,10 +799,11 @@ void StreamServer::start()
{ {
try try
{ {
controlServer_.reset(new ControlServer(io_context_, settings_.tcp, settings_.http, this)); controlServer_ = std::make_unique<ControlServer>(io_context_, settings_.tcp, settings_.http, this);
controlServer_->start(); controlServer_->start();
streamManager_.reset(new StreamManager(this, io_context_, settings_.stream.sampleFormat, settings_.stream.codec, settings_.stream.streamChunkMs)); streamManager_ =
std::make_unique<StreamManager>(this, io_context_, settings_.stream.sampleFormat, settings_.stream.codec, settings_.stream.streamChunkMs);
// throw SnapException("xxx"); // throw SnapException("xxx");
for (const auto& streamUri : settings_.stream.pcmStreams) for (const auto& streamUri : settings_.stream.pcmStreams)
{ {

View file

@ -51,7 +51,7 @@ using session_ptr = std::shared_ptr<StreamSession>;
* Receives (via the MessageReceiver interface) and answers messages from the clients * Receives (via the MessageReceiver interface) and answers messages from the clients
* Forwards PCM data to the clients * Forwards PCM data to the clients
*/ */
class StreamServer : public MessageReceiver, ControlMessageReceiver, PcmListener class StreamServer : public MessageReceiver, public ControlMessageReceiver, public PcmListener
{ {
public: public:
StreamServer(boost::asio::io_context& io_context, const ServerSettings& serverSettings); StreamServer(boost::asio::io_context& io_context, const ServerSettings& serverSettings);

View file

@ -68,7 +68,7 @@ void PosixStream::connect()
void PosixStream::do_disconnect() void PosixStream::do_disconnect()
{ {
if (stream_->is_open()) if (stream_ && stream_->is_open())
stream_->close(); stream_->close();
} }

View file

@ -143,14 +143,15 @@ const PcmStreamPtr StreamManager::getStream(const std::string& id)
void StreamManager::start() void StreamManager::start()
{ {
for (auto stream : streams_) for (const auto& stream : streams_)
stream->start(); stream->start();
} }
void StreamManager::stop() void StreamManager::stop()
{ {
for (auto stream : streams_) for (const auto& stream : streams_)
if (stream)
stream->stop(); stream->stop();
} }