Ejemplo n.º 1
0
 void ServerImpl::stop() {
     boost::unique_lock<boost::mutex> lock(m_runControl);
     if (m_everStarted) {
         m_run.signalAndWaitForShutdown();
         m_thread.join();
         m_thread = boost::thread();
     } else {
         m_orderedDestruction();
     }
 }
Ejemplo n.º 2
0
    void ServerImpl::start() {
        boost::unique_lock<boost::mutex> lock(m_runControl);
        if (!m_ctx || !m_conn) {
            throw std::logic_error("Cannot start server - context or "
                                   "connection destroyed (probably attempting "
                                   "to restart a stopped server)");
        }
        m_running = true;

        // Use a lambda to run the loop.
        m_thread = boost::thread([&] {
            bool keepRunning = true;
            ::util::LoopGuard guard(m_run);
            do {
                keepRunning = this->loop();
            } while (keepRunning);
            m_orderedDestruction();
            m_running = false;
        });
        m_run.signalAndWaitForStart();
    }