void LibEventServerWithTakeover::start() { if (m_server_ssl) { // Set a flag to prevent parent class from trying to listen to ssl // before the old server releases the port m_accept_sock_ssl = -2; } LibEventServer::start(); if (m_took_over) { Logger::Info("takeover: requesting shutdown of satellites"); // Use AFDT to synchronously shut down the old server's satellites // so we can take their ports using accept. The main server will be // stopped asynchronously. uint8_t shutdown_request[3] = P_VERSION C_TERM_REQ; uint8_t shutdown_response[3] = {0,0,0}; uint32_t response_len = sizeof(shutdown_response); int should_not_receive_fd; afdt_error_t err = AFDT_ERROR_T_INIT; // TODO(dreiss): Make this timeout configurable. // We can aford to wait a long time here, since we've already started // the dispatcher for this server. We want to give the old server // plenty of time to shut down all of its satellite servers. struct timeval timeout = { 10 , 0 }; int ret = afdt_sync_client( m_transfer_fname.c_str(), shutdown_request, sizeof(shutdown_request) - 1, shutdown_response, &response_len, &should_not_receive_fd, &timeout, &err); if (ret < 0) { fd_transfer_error_hander(&err, nullptr); Logger::Warning("Failed to shut-down old server with AFDT."); // The higher-level start logic will try *very* hard to recover from this. } String resp((const char*)shutdown_response, response_len, CopyString); if (resp != P_VERSION C_TERM_OK) { Logger::Error( "Old server could not shut down: " "response = '%s'", StringUtil::CEncode(resp, null_string).data()); } else { Logger::Info("takeover: old satellites have shut down"); } } if (m_server_ssl) { if (getAcceptSocketSSL() != 0) { Logger::Error("Fail to listen on ssl port %d", m_port_ssl); throw FailedToListenException(m_address, m_port_ssl); } Logger::Info("Listen on ssl port %d",m_port_ssl); } setupFdServer(); }
void LibEventServer::start() { if (getStatus() == RunStatus::RUNNING) return; if (getAcceptSocket() != 0) { throw FailedToListenException(m_address, m_port); } if (m_server_ssl != nullptr) { if (getAcceptSocketSSL() != 0) { Logger::Error("Fail to listen on ssl port %d", m_port_ssl); throw FailedToListenException(m_address, m_port_ssl); } Logger::Info("Listen on ssl port %d",m_port_ssl); } setStatus(RunStatus::RUNNING); m_dispatcher.start(); m_dispatcherThread.start(); }
void LibEventServer::start() { if (getStatus() == RunStatus::RUNNING) return; if (getAcceptSocket() != 0) { throw FailedToListenException(m_address, m_port); } if (m_server_ssl != nullptr && m_accept_sock_ssl != -2) { // m_accept_sock_ssl here serves as a flag to indicate whether it is // called from subclass (LibEventServerWithTakeover). If it is (==-2) // we delay the getAcceptSocketSSL(); if (getAcceptSocketSSL() != 0) { Logger::Error("Fail to listen on ssl port %d", m_port_ssl); throw FailedToListenException(m_address, m_port_ssl); } Logger::Info("Listen on ssl port %d",m_port_ssl); } setStatus(RunStatus::RUNNING); m_dispatcher.start(); m_dispatcherThread.start(); }