Loading src/Server.cpp +34 −17 Original line number Diff line number Diff line Loading @@ -53,23 +53,11 @@ Server::~Server() //============================================================================== // Server::start() //============================================================================== void Server::start() void Server::start() //@todo: handle exceptions { DEBUG_STREAM << "Server::start()" << endl; std::string localHost = m_configuration_sp->getLocalHost(); unsigned int localPort = m_configuration_sp->getLocalPort(); boost::asio::ip::tcp::resolver::query query(localHost, boost::lexical_cast<std::string>(localPort)); boost::asio::ip::tcp::resolver resolver(*m_ioService_sp); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); m_acceptor_sp->open(endpoint.protocol()); m_acceptor_sp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); m_acceptor_sp->bind(endpoint); m_acceptor_sp->listen(); m_dBManager_sp->connect(); m_ioService_sp->reset(); Loading @@ -82,13 +70,15 @@ void Server::start() for(unsigned int i=0; i<workerNumber; ++i) m_threadGroup_sp->add_thread(new boost::thread(&WorkerThread::run, worker)); startListen(); startAccept(); } //============================================================================== // Server::stop() //============================================================================== void Server::stop() void Server::stop() //@todo: handle exceptions { DEBUG_STREAM << "Server::stop()" << endl; Loading @@ -102,9 +92,11 @@ void Server::stop() m_threadGroup_sp->join_all(); } m_dBManager_sp->disconnect(); } //============================================================================== // Client::readState() // Server::readState() //============================================================================== Tango::DevState Server::readState() { Loading @@ -116,7 +108,7 @@ Tango::DevState Server::readState() } //============================================================================== // Client::readStatus() // Server::readStatus() //============================================================================== std::string Server::readStatus() { Loading @@ -127,6 +119,31 @@ std::string Server::readStatus() return m_status; } //============================================================================== // Server::readStatus() //============================================================================== void Server::startListen() //@todo: handle exceptions { DEBUG_STREAM << "Server::startListen()" << endl; std::string localHost = m_configuration_sp->getLocalHost(); unsigned int localPort = m_configuration_sp->getLocalPort(); INFO_STREAM << "Server::startListen() listening on " << localHost << ":" << localPort << endl; boost::asio::ip::tcp::resolver::query query(localHost, boost::lexical_cast<std::string>(localPort)); boost::asio::ip::tcp::resolver resolver(*m_ioService_sp); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); m_acceptor_sp->open(endpoint.protocol()); m_acceptor_sp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); m_acceptor_sp->bind(endpoint); m_acceptor_sp->listen(); } //============================================================================== // Server::handleAccept() //============================================================================== Loading src/Server.h +2 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,8 @@ protected: //------------------------------------------------------------------------------ // [Protected] Incoming connection methods //------------------------------------------------------------------------------ virtual void startListen(); virtual void startAccept() = 0; virtual void handleAccept(Session::SP, const boost::system::error_code&); Loading Loading
src/Server.cpp +34 −17 Original line number Diff line number Diff line Loading @@ -53,23 +53,11 @@ Server::~Server() //============================================================================== // Server::start() //============================================================================== void Server::start() void Server::start() //@todo: handle exceptions { DEBUG_STREAM << "Server::start()" << endl; std::string localHost = m_configuration_sp->getLocalHost(); unsigned int localPort = m_configuration_sp->getLocalPort(); boost::asio::ip::tcp::resolver::query query(localHost, boost::lexical_cast<std::string>(localPort)); boost::asio::ip::tcp::resolver resolver(*m_ioService_sp); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); m_acceptor_sp->open(endpoint.protocol()); m_acceptor_sp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); m_acceptor_sp->bind(endpoint); m_acceptor_sp->listen(); m_dBManager_sp->connect(); m_ioService_sp->reset(); Loading @@ -82,13 +70,15 @@ void Server::start() for(unsigned int i=0; i<workerNumber; ++i) m_threadGroup_sp->add_thread(new boost::thread(&WorkerThread::run, worker)); startListen(); startAccept(); } //============================================================================== // Server::stop() //============================================================================== void Server::stop() void Server::stop() //@todo: handle exceptions { DEBUG_STREAM << "Server::stop()" << endl; Loading @@ -102,9 +92,11 @@ void Server::stop() m_threadGroup_sp->join_all(); } m_dBManager_sp->disconnect(); } //============================================================================== // Client::readState() // Server::readState() //============================================================================== Tango::DevState Server::readState() { Loading @@ -116,7 +108,7 @@ Tango::DevState Server::readState() } //============================================================================== // Client::readStatus() // Server::readStatus() //============================================================================== std::string Server::readStatus() { Loading @@ -127,6 +119,31 @@ std::string Server::readStatus() return m_status; } //============================================================================== // Server::readStatus() //============================================================================== void Server::startListen() //@todo: handle exceptions { DEBUG_STREAM << "Server::startListen()" << endl; std::string localHost = m_configuration_sp->getLocalHost(); unsigned int localPort = m_configuration_sp->getLocalPort(); INFO_STREAM << "Server::startListen() listening on " << localHost << ":" << localPort << endl; boost::asio::ip::tcp::resolver::query query(localHost, boost::lexical_cast<std::string>(localPort)); boost::asio::ip::tcp::resolver resolver(*m_ioService_sp); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); m_acceptor_sp->open(endpoint.protocol()); m_acceptor_sp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); m_acceptor_sp->bind(endpoint); m_acceptor_sp->listen(); } //============================================================================== // Server::handleAccept() //============================================================================== Loading
src/Server.h +2 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,8 @@ protected: //------------------------------------------------------------------------------ // [Protected] Incoming connection methods //------------------------------------------------------------------------------ virtual void startListen(); virtual void startAccept() = 0; virtual void handleAccept(Session::SP, const boost::system::error_code&); Loading