mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-14 17:46:45 +02:00
x
git-svn-id: svn://elaine/murooma/trunk@157 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
e03a46d8e2
commit
0a0cb0c48a
1 changed files with 11 additions and 12 deletions
|
@ -15,6 +15,7 @@
|
|||
#include <boost/asio.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <ctime> // localtime
|
||||
#include <sstream> // stringstream
|
||||
#include <iomanip>
|
||||
|
@ -61,18 +62,12 @@ public:
|
|||
for (;;)
|
||||
{
|
||||
shared_ptr<WireChunk> chunk(chunks.pop());
|
||||
boost::system::error_code error;
|
||||
size_t written = 0;
|
||||
do
|
||||
{
|
||||
written += boost::asio::write(*socket_, boost::asio::buffer(chunk.get() + written, sizeof(WireChunk) - written));//, error);
|
||||
}
|
||||
while (written < sizeof(WireChunk));
|
||||
|
||||
if (error == boost::asio::error::eof)
|
||||
break; // Connection closed cleanly by peer.
|
||||
else if (error)
|
||||
throw boost::system::system_error(error); // Some other error.
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
|
@ -102,7 +97,7 @@ private:
|
|||
class Server
|
||||
{
|
||||
public:
|
||||
Server(unsigned short port) : session(NULL), port_(port)
|
||||
Server(unsigned short port) : port_(port)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -114,15 +109,19 @@ public:
|
|||
socket_ptr sock(new tcp::socket(io_service_));
|
||||
a.accept(*sock);
|
||||
cout << "New connection: " << sock->remote_endpoint().address().to_string() << "\n";
|
||||
session = new Session(sock);
|
||||
Session* session = new Session(sock);
|
||||
session->start();
|
||||
sessions.push_back(session);
|
||||
}
|
||||
}
|
||||
|
||||
void send(shared_ptr<WireChunk> chunk)
|
||||
{
|
||||
if (session != 0)
|
||||
session->send(chunk);
|
||||
{
|
||||
for (size_t n=0; n<sessions.size(); ++n)
|
||||
{
|
||||
if (sessions[n] != 0)
|
||||
sessions[n]->send(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
void start()
|
||||
|
@ -136,7 +135,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
Session* session;
|
||||
vector<Session*> sessions;
|
||||
boost::asio::io_service io_service_;
|
||||
unsigned short port_;
|
||||
thread* acceptThread;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue