Commit e24e1d3f86074889601fa539ca4711a88c1e3fe9

Authored by Arthur Bikmullin
1 parent 4532331d

Fixed MServer incorrect port bug #3

1 1 #include "httpserver.h"
2 2
3   -HttpServer::HttpServer(const QString &documentRoot, QObject* parent)
4   - : QTcpServer(parent), documentRoot(documentRoot)
  3 +HttpServer::HttpServer(const QString &documentRoot, int port, QObject* parent)
  4 + : QTcpServer(parent), documentRoot(documentRoot), port(port)
5 5 {
6 6 }
7 7
... ...
... ... @@ -10,12 +10,14 @@
10 10 class HttpServer : public QTcpServer
11 11 {
12 12 public:
13   - HttpServer(const QString &documentRoot, QObject* parent = 0);
  13 + HttpServer(const QString &documentRoot, int port, QObject* parent = 0);
14 14
15 15 const QString getMimeType(const QString &filename);
16 16
17 17 QString documentRoot;
18 18
  19 + int port;
  20 +
19 21 protected:
20 22 void incomingConnection(qintptr socketDescriptor);
21 23
... ...
... ... @@ -56,11 +56,12 @@ void MainWindow::createHttpServer(QString filename)
56 56 if (!f.exists())
57 57 return;
58 58
  59 + HttpServer *httpServer;
  60 +
59 61 if (!httpServers.contains(f.absolutePath()))
60 62 {
61 63 port = httpServers.empty() ? 8080 : port + 1;
62   -
63   - HttpServer *httpServer = new HttpServer(f.absolutePath(), this);
  64 + httpServer = new HttpServer(f.absolutePath(), port, this);
64 65
65 66 while(!httpServer->listen(QHostAddress::LocalHost, port) && port < 8180)
66 67 port++;
... ... @@ -78,10 +79,11 @@ void MainWindow::createHttpServer(QString filename)
78 79 }
79 80 else
80 81 {
81   - ui->console->appendPlainText("HTTP server active and listening on port " + QString::number(port));
  82 + httpServer = httpServers.value(f.absolutePath());
  83 + ui->console->appendPlainText("HTTP server active and listening on port " + QString::number(httpServer->port));
82 84 }
83 85
84   - QDesktopServices::openUrl(QUrl(QString("http://localhost:%1/%2").arg(QString::number(port), f.fileName())));
  86 + QDesktopServices::openUrl(QUrl(QString("http://localhost:%1/%2").arg(QString::number(httpServer->port), f.fileName())));
85 87 }
86 88
87 89 void MainWindow::receiveMessage(QString filename)
... ...