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

IO service reset fix, bind moved to start method

parent 7ab89d38
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -12,8 +12,6 @@ PlainServer::PlainServer(Tango::DeviceImpl* deviceImpl_p,
    Server::Server(deviceImpl_p, configuration_sp)
{
    DEBUG_STREAM << "PlainServer::PlainServer()" << endl;

    startAccept();
}

//==============================================================================
+0 −2
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ SSLServer::SSLServer(Tango::DeviceImpl* deviceImpl_p,
    m_context_sp->use_certificate_chain_file(certificateFile);
    m_context_sp->use_private_key_file(privateKey, boost::asio::ssl::context::pem);
    m_context_sp->use_tmp_dh_file(dHTempFile);

    startAccept();
}

//==============================================================================
+20 −19
Original line number Diff line number Diff line
@@ -25,22 +25,6 @@ Server::Server(Tango::DeviceImpl* deviceImpl_p, Configuration::SP configuration_
    m_work_sp.reset(new boost::asio::io_service::work(*m_ioService_sp));
    m_acceptor_sp.reset(new boost::asio::ip::tcp::acceptor(*m_ioService_sp));

    std::string localHost = m_configuration_sp->getLocalHost();
    unsigned int localPort = m_configuration_sp->getLocalPort();

    INFO_STREAM << "Server::Server() listen 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();

    m_state = Tango::OFF;
    m_status="Disconnected";
}
@@ -52,9 +36,6 @@ Server::~Server()
{
    DEBUG_STREAM << "Server::~Server()" << endl;

    m_state = Tango::OFF;
    m_status="Disconnected";

    m_acceptor_sp->close();

    m_ioService_sp->stop();
@@ -76,6 +57,22 @@ void Server::start()
{
    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_ioService_sp->reset();

    m_threadGroup_sp.reset(new boost::thread_group);

    unsigned int workerNumber = m_configuration_sp->getWorkerNumber();
@@ -84,6 +81,8 @@ void Server::start()

    for(unsigned int i=0; i<workerNumber; ++i)
        m_threadGroup_sp->add_thread(new boost::thread(&WorkerThread::run, worker));

    startAccept();
}

//==============================================================================
@@ -93,6 +92,8 @@ void Server::stop()
{
    DEBUG_STREAM << "Server::stop()" << endl;

    m_acceptor_sp->close();

    m_ioService_sp->stop();

    if(m_threadGroup_sp)