allways write exceptions to log
[anytun.git] / src / syncServer.cpp
blobe39a11eba0ac75308451ec792a6690d0bea6cee4
1 #include "syncServer.h"
3 //using asio::ip::tcp;
5 SyncServer::SyncServer(boost::asio::io_service& io_service, SyncTcpConnection::proto::endpoint tcp_endpoint )
6 : acceptor_(io_service, tcp_endpoint)
8 start_accept();
11 void SyncServer::start_accept()
13 Lock lock(mutex_);
14 SyncTcpConnection::pointer new_connection =
15 SyncTcpConnection::create(acceptor_.io_service());
16 conns_.push_back(new_connection);
18 acceptor_.async_accept(new_connection->socket(),
19 boost::bind(&SyncServer::handle_accept, this, new_connection,
20 boost::asio::placeholders::error));
23 void SyncServer::send(std::string message)
25 Lock lock(mutex_);
26 for(std::list<SyncTcpConnection::pointer>::iterator it = conns_.begin() ;it != conns_.end(); ++it) {
27 (*it)->Send(message);
31 void SyncServer::handle_accept(SyncTcpConnection::pointer new_connection,
32 const boost::system::error_code& error)
34 if (!error)
36 new_connection->onConnect=onConnect;
37 new_connection->start();
38 start_accept();