// Start accepting incoming connections void run() { if(! acceptor_.is_open()) return; do_accept(); }
void handle_accept(sessionPtr newSession, const boost::system::error_code& error) { if (!acceptor_.is_open()) { return; } if (!error) { DEBUG_MSG("Incoming Session accepted"); //Do I need a Lock here? //Critical Section static std::mutex m; std::lock_guard<std::mutex> lock(m); newSession->startSession(); listen(); } else { DEBUG_MSG("Listen_Error"); // //throw ASIOError(Listen_Error); DEBUG_MSG(error.message()); return; } }
static void CloseConnection(tcp::acceptor &_acceptor, tcp::socket &_socket) { log_info(LOG_PREFIX, "disconnecting"); if (_acceptor.is_open()) { _acceptor.close(); } if (_socket.is_open()) { _socket.close(); } }
void worker::do_accept(tcp::acceptor& acceptor, server& srv) { while (acceptor.is_open()) { bs::error_code ec; // get an io service to use for a new client, we pick them via round robin auto& worker = srv.impl()->get_worker(); auto& iosvc = worker.io_service(); auto new_session = std::make_shared<session>(srv, iosvc); acceptor.async_accept(new_session->socket(), bfa::yield[ec]); if (!ec) { worker.add_session(new_session); worker.m_new_session_cv.notify_one(); } } }