Commit f7ed76c7 authored by Marco De Marco's avatar Marco De Marco
Browse files

Start listen function added to server class

parent be88747a
Loading
Loading
Loading
Loading
+34 −17
Original line number Diff line number Diff line
@@ -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();

@@ -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;

@@ -102,9 +92,11 @@ void Server::stop()

        m_threadGroup_sp->join_all();
    }

    m_dBManager_sp->disconnect();
}
//==============================================================================
//      Client::readState()
//      Server::readState()
//==============================================================================
Tango::DevState Server::readState()
{
@@ -116,7 +108,7 @@ Tango::DevState Server::readState()
}

//==============================================================================
//      Client::readStatus()
//      Server::readStatus()
//==============================================================================
std::string Server::readStatus()
{
@@ -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()
//==============================================================================
+2 −0
Original line number Diff line number Diff line
@@ -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&);