mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-28 00:16:17 +02:00
code blocks
git-svn-id: svn://elaine/murooma/trunk@271 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
2cf7855261
commit
16ef1ae634
53 changed files with 2074 additions and 1759 deletions
|
@ -9,34 +9,34 @@ StreamSession::StreamSession(std::shared_ptr<tcp::socket> _socket) : ServerConne
|
|||
|
||||
void StreamSession::worker()
|
||||
{
|
||||
active_ = true;
|
||||
try
|
||||
{
|
||||
boost::asio::streambuf streambuf;
|
||||
std::ostream stream(&streambuf);
|
||||
for (;;)
|
||||
{
|
||||
shared_ptr<BaseMessage> message(messages.pop());
|
||||
ServerConnection::send(message.get());
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception in thread: " << e.what() << "\n";
|
||||
active_ = false;
|
||||
}
|
||||
active_ = false;
|
||||
active_ = true;
|
||||
try
|
||||
{
|
||||
boost::asio::streambuf streambuf;
|
||||
std::ostream stream(&streambuf);
|
||||
for (;;)
|
||||
{
|
||||
shared_ptr<BaseMessage> message(messages.pop());
|
||||
ServerConnection::send(message.get());
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception in thread: " << e.what() << "\n";
|
||||
active_ = false;
|
||||
}
|
||||
active_ = false;
|
||||
}
|
||||
|
||||
|
||||
void StreamSession::send(shared_ptr<BaseMessage> message)
|
||||
{
|
||||
if (!message)
|
||||
return;
|
||||
if (!message)
|
||||
return;
|
||||
|
||||
while (messages.size() > 100)// chunk->getDuration() > 10000)
|
||||
messages.pop();
|
||||
messages.push(message);
|
||||
while (messages.size() > 100)// chunk->getDuration() > 10000)
|
||||
messages.pop();
|
||||
messages.push(message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,45 +50,45 @@ StreamServer::StreamServer(unsigned short port) : port_(port), headerChunk(NULL)
|
|||
|
||||
void StreamServer::acceptor()
|
||||
{
|
||||
tcp::acceptor a(io_service_, tcp::endpoint(tcp::v4(), port_));
|
||||
for (;;)
|
||||
{
|
||||
socket_ptr sock(new tcp::socket(io_service_));
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
setsockopt(sock->native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
setsockopt(sock->native(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
||||
a.accept(*sock);
|
||||
cout << "StreamServer::New connection: " << sock->remote_endpoint().address().to_string() << "\n";
|
||||
StreamSession* session = new StreamSession(sock);
|
||||
sessions.insert(shared_ptr<StreamSession>(session));
|
||||
session->start();
|
||||
}
|
||||
tcp::acceptor a(io_service_, tcp::endpoint(tcp::v4(), port_));
|
||||
for (;;)
|
||||
{
|
||||
socket_ptr sock(new tcp::socket(io_service_));
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
setsockopt(sock->native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
setsockopt(sock->native(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
||||
a.accept(*sock);
|
||||
cout << "StreamServer::New connection: " << sock->remote_endpoint().address().to_string() << "\n";
|
||||
StreamSession* session = new StreamSession(sock);
|
||||
sessions.insert(shared_ptr<StreamSession>(session));
|
||||
session->start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void StreamServer::send(shared_ptr<BaseMessage> message)
|
||||
{
|
||||
for (std::set<shared_ptr<StreamSession>>::iterator it = sessions.begin(); it != sessions.end(); )
|
||||
{
|
||||
if (!(*it)->active())
|
||||
{
|
||||
cout << "Session inactive. Removing\n";
|
||||
sessions.erase(it++);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
for (std::set<shared_ptr<StreamSession>>::iterator it = sessions.begin(); it != sessions.end(); )
|
||||
{
|
||||
if (!(*it)->active())
|
||||
{
|
||||
cout << "Session inactive. Removing\n";
|
||||
sessions.erase(it++);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
for (auto s : sessions)
|
||||
s->send(message);
|
||||
for (auto s : sessions)
|
||||
s->send(message);
|
||||
}
|
||||
|
||||
|
||||
void StreamServer::start()
|
||||
{
|
||||
acceptThread = new thread(&StreamServer::acceptor, this);
|
||||
acceptThread = new thread(&StreamServer::acceptor, this);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue