mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-18 03:26:15 +02:00
abc
git-svn-id: svn://elaine/murooma/trunk@283 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
001bfa6aba
commit
7467141a14
3 changed files with 47 additions and 2 deletions
|
@ -20,6 +20,7 @@ void ControlServer::send(shared_ptr<BaseMessage> message)
|
|||
if (!(*it)->active())
|
||||
{
|
||||
cout << "Session inactive. Removing\n";
|
||||
(*it)->stop();
|
||||
sessions.erase(it++);
|
||||
}
|
||||
else
|
||||
|
@ -92,8 +93,8 @@ void ControlServer::acceptor()
|
|||
ServerSession* session = new ServerSession(this, sock);
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex);
|
||||
sessions.insert(shared_ptr<ServerSession>(session));
|
||||
session->start();
|
||||
sessions.insert(shared_ptr<ServerSession>(session));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@ ServerSession::ServerSession(MessageReceiver* _receiver, std::shared_ptr<tcp::so
|
|||
}
|
||||
|
||||
|
||||
ServerSession::~ServerSession()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
void ServerSession::start()
|
||||
{
|
||||
active_ = true;
|
||||
|
@ -24,13 +30,49 @@ void ServerSession::start()
|
|||
}
|
||||
|
||||
|
||||
void ServerSession::stop()
|
||||
{
|
||||
active_ = false;
|
||||
try
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
if (socket)
|
||||
{
|
||||
socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
|
||||
if (ec) cout << "Error in socket shutdown: " << ec << "\n";
|
||||
socket->close(ec);
|
||||
if (ec) cout << "Error in socket close: " << ec << "\n";
|
||||
}
|
||||
if (readerThread)
|
||||
{
|
||||
cout << "joining readerThread\n";
|
||||
readerThread->join();
|
||||
delete readerThread;
|
||||
}
|
||||
if (writerThread)
|
||||
{
|
||||
cout << "joining readerThread\n";
|
||||
writerThread->join();
|
||||
delete writerThread;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
readerThread = NULL;
|
||||
writerThread = NULL;
|
||||
cout << "ServerSession stopped\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ServerSession::socketRead(void* _to, size_t _bytes)
|
||||
{
|
||||
size_t read = 0;
|
||||
do
|
||||
{
|
||||
boost::system::error_code error;
|
||||
read += socket->read_some(boost::asio::buffer((char*)_to + read, _bytes - read), error);
|
||||
read += socket->read_some(boost::asio::buffer((char*)_to + read, _bytes - read));
|
||||
}
|
||||
while (read < _bytes);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,9 @@ class ServerSession
|
|||
{
|
||||
public:
|
||||
ServerSession(MessageReceiver* _receiver, std::shared_ptr<tcp::socket> _socket);
|
||||
~ServerSession();
|
||||
void start();
|
||||
void stop();
|
||||
bool send(BaseMessage* message);
|
||||
void add(std::shared_ptr<BaseMessage> message);
|
||||
virtual bool connected()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue