void HttpServer::stop() { if (!running_) { return; } running_ = false; stopListeners(); { std::lock_guard<std::mutex> lock(connections_mutex_); for (auto connection : connections_) { connection->markToBeDeleted(); } } while (connection_count_) { std::this_thread::yield(); } pool_->stop(); }
/** * @brief Destructor of the \ref MainWindow. */ MainWindow::~MainWindow() { if(_listener != NULL) { stopListeners(); delete _listener; } delete ui; }
/** * @brief Disconnects the client from the server. * @pre The client have to be connected before to call this method. */ void MainWindow::serverDisconnection() { // cleaning the gui ui->connectionWidget->clean(); ui->rightMenuWidget->clear(); ui->checkerboardwidget->clear(); frame f ; //Advise the opponent if the client is in a game if(strlen(_opponent_player.name) != 0) { qDebug() << "PPPPPPPPPPPPPPPPPPPPP I'm quit the game"; strcpy(f.data_type, OPPONENT_QUIT); memcpy(f.data, &_opponent_player, sizeof(_opponent_player)); write_to_server(_player.socket, &f); } //Advising the server for the disconnection f = make_frame(_local_addr.sin_addr, _local_addr.sin_addr, DISCONNECT, _player.name); write_to_server(_player.socket,&f); //disconnection of the client server_disconnection(_player.socket); stopListeners(); // Stop all listeners threads qDebug() << "Client is disconnected"; // When the client is disconnected, display the connection page ui->stackedWidget->slideInIdx(0, SlidingStackedWidget::TOP2BOTTOM); strcpy(_player.name, ""); _player.color = 0; strcpy(_opponent_player.name, ""); _opponent_player.color = 0; }