mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 23:56:43 +02:00
fixed crash in case of ZeroConf name collision
This commit is contained in:
parent
52b0e92a5c
commit
94ee70d0af
3 changed files with 12 additions and 8 deletions
|
@ -34,12 +34,13 @@ ControlServer::ControlServer(unsigned short port) : port_(port), headerChunk_(NU
|
|||
|
||||
void ControlServer::send(shared_ptr<msg::BaseMessage> message)
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex);
|
||||
std::unique_lock<std::mutex> mlock(mutex_);
|
||||
for (auto it = sessions_.begin(); it != sessions_.end(); )
|
||||
{
|
||||
if (!(*it)->active())
|
||||
{
|
||||
logO << "Session inactive. Removing\n";
|
||||
// don't block: remove ServerSession in a thread
|
||||
auto func = [](shared_ptr<ServerSession> s)->void{s->stop();};
|
||||
std::thread t(func, *it);
|
||||
t.detach();
|
||||
|
@ -74,16 +75,19 @@ void ControlServer::onMessageReceived(ServerSession* connection, const msg::Base
|
|||
}
|
||||
else if (requestMsg.request == kServerSettings)
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex_);
|
||||
serverSettings_->refersTo = requestMsg.id;
|
||||
connection->send(serverSettings_);
|
||||
}
|
||||
else if (requestMsg.request == kSampleFormat)
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex_);
|
||||
sampleFormat_->refersTo = requestMsg.id;
|
||||
connection->send(sampleFormat_);
|
||||
}
|
||||
else if (requestMsg.request == kHeader)
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex_);
|
||||
headerChunk_->refersTo = requestMsg.id;
|
||||
connection->send(headerChunk_);
|
||||
}
|
||||
|
@ -118,7 +122,7 @@ void ControlServer::acceptor()
|
|||
logS(kLogNotice) << "ControlServer::NewConnection: " << sock->remote_endpoint().address().to_string() << endl;
|
||||
ServerSession* session = new ServerSession(this, sock);
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex);
|
||||
std::unique_lock<std::mutex> mlock(mutex_);
|
||||
session->start();
|
||||
sessions_.insert(shared_ptr<ServerSession>(session));
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ void PublishAvahi::create_services(AvahiClient *c) {
|
|||
|
||||
if (!group)
|
||||
{
|
||||
if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) {
|
||||
if (!(group = avahi_entry_group_new(c, entry_group_callback, this))) {
|
||||
logE << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << "\n";
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "serverSession.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include "serverSession.h"
|
||||
#include "common/log.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -69,7 +69,7 @@ void ServerSession::stop()
|
|||
}
|
||||
if (writerThread_)
|
||||
{
|
||||
logD << "joining readerThread\n";
|
||||
logD << "joining writerThread\n";
|
||||
writerThread_->join();
|
||||
delete writerThread_;
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ void ServerSession::reader()
|
|||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
logS(kLogErr) << "Exception: " << e.what() << ", trying to reconnect" << endl;
|
||||
logS(kLogErr) << "Exception in ServerSession::reader(): " << e.what() << endl;
|
||||
}
|
||||
active_ = false;
|
||||
}
|
||||
|
@ -176,9 +176,9 @@ void ServerSession::writer()
|
|||
send(message.get());
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
logE << "Exception in thread: " << e.what() << "\n";
|
||||
logS(kLogErr) << "Exception in ServerSession::writer(): " << e.what() << endl;
|
||||
}
|
||||
active_ = false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue