From f96ec75eec9fee80ce3815909406ef18021c3d1f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 30 Dec 2009 09:46:06 +0000 Subject: [PATCH] - Improve Web UI settings so that the HTTP server is reconstructed only when necessary --- src/bittorrent.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 04186bd4f..75da224bb 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -504,17 +504,23 @@ void Bittorrent::configureSession() { } bool Bittorrent::initWebUi(QString username, QString password, int port) { - if(httpServer) - httpServer->close(); - else + if(httpServer) { + if(httpServer->serverPort() != port) { + httpServer->close(); + } + } else { httpServer = new HttpServer(this, 3000, this); + } httpServer->setAuthorization(username, password); - bool success = httpServer->listen(QHostAddress::Any, port); - if (success) - qDebug("Web UI listening on port %d", port); - else - addConsoleMessage(tr("Web User Interface Error - Unable to bind Web UI to port %1").arg(port), QColor("red")); - return success; + bool success = true; + if(!httpServer->isListening()) { + success = httpServer->listen(QHostAddress::Any, port); + if (success) + qDebug("Web UI listening on port %d", port); + else + addConsoleMessage(tr("Web User Interface Error - Unable to bind Web UI to port %1").arg(port), QColor("red")); + } + return success; } void Bittorrent::takeETASamples() {