explicitly listening on IPv4 even if IPv6 is available
authorMarcus Eggenberger <egs@quassel-irc.org>
Fri, 5 Sep 2008 15:11:19 +0000 (17:11 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Fri, 5 Sep 2008 15:11:19 +0000 (17:11 +0200)
src/core/core.cpp
src/core/core.h

index 4a5a64e..01b341c 100644 (file)
@@ -85,7 +85,8 @@ void Core::init() {
     }
   }
 
     }
   }
 
-  connect(&server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
+  connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
+  connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
   if(!startListening(cs.port())) exit(1); // TODO make this less brutal
 }
 
   if(!startListening(cs.port())) exit(1); // TODO make this less brutal
 }
 
@@ -343,31 +344,33 @@ QHash<BufferId, MsgId> Core::bufferLastSeenMsgIds(UserId user) {
 bool Core::startListening(uint port) {
   bool success = false;
 
 bool Core::startListening(uint port) {
   bool success = false;
 
-  // let's see if ipv6 is available
-  success = server.listen(QHostAddress::AnyIPv6, port);
-
-  if(!success && server.serverError() == QAbstractSocket::UnsupportedSocketOperationError) {
-    // fall back to v4
-    success = server.listen(QHostAddress::Any, port);
+  if(_server.listen(QHostAddress::Any, port)) {
+    quInfo() << "Listening for GUI clients on IPv6 port" << _server.serverPort() << "using protocol version" << Global::protocolVersion;
+    success = true;
+  }
+  if(_v6server.listen(QHostAddress::AnyIPv6, port)) {
+    quInfo() << "Listening for GUI clients on IPv4 port" << _v6server.serverPort() << "using protocol version" << Global::protocolVersion;
+    success = true;
   }
 
   if(!success) {
   }
 
   if(!success) {
-    quError() << qPrintable(QString("Could not open GUI client port %1: %2").arg(port).arg(server.errorString()));
-  } else {
-    quInfo() << "Listening for GUI clients on port" << server.serverPort() << "using protocol version" << Global::protocolVersion;
+    quError() << qPrintable(QString("Could not open GUI client port %1: %2").arg(port).arg(_server.errorString()));
   }
   
   return success;
 }
 
 void Core::stopListening() {
   }
   
   return success;
 }
 
 void Core::stopListening() {
-  server.close();
+  _server.close();
+  _v6server.close();
   quInfo() << "No longer listening for GUI clients.";
 }
 
 void Core::incomingConnection() {
   quInfo() << "No longer listening for GUI clients.";
 }
 
 void Core::incomingConnection() {
-  while(server.hasPendingConnections()) {
-    QTcpSocket *socket = server.nextPendingConnection();
+  QTcpServer *server = qobject_cast<QTcpServer *>(sender());
+  Q_ASSERT(server);
+  while(server->hasPendingConnections()) {
+    QTcpSocket *socket = server->nextPendingConnection();
     connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
     connect(socket, SIGNAL(readyRead()), this, SLOT(clientHasData()));
     connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
     connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
     connect(socket, SIGNAL(readyRead()), this, SLOT(clientHasData()));
     connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
@@ -376,8 +379,9 @@ void Core::incomingConnection() {
     blocksizes.insert(socket, (quint32)0);
     quInfo() << qPrintable(tr("Client connected from"))  << qPrintable(socket->peerAddress().toString());
 
     blocksizes.insert(socket, (quint32)0);
     quInfo() << qPrintable(tr("Client connected from"))  << qPrintable(socket->peerAddress().toString());
 
-    if (!configured) {
-      server.close();
+    if(!configured) {
+      _server.close();
+      _v6server.close();
       quDebug() << "Closing server for basic setup.";
     }
   }
       quDebug() << "Closing server for basic setup.";
     }
   }
@@ -434,7 +438,7 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) {
       .arg(updays).arg(uphours,2,10,QChar('0')).arg(upmins,2,10,QChar('0')).arg(startTime().toString(Qt::TextDate));
 
 #ifdef HAVE_SSL
       .arg(updays).arg(uphours,2,10,QChar('0')).arg(upmins,2,10,QChar('0')).arg(startTime().toString(Qt::TextDate));
 
 #ifdef HAVE_SSL
-    SslServer *sslServer = qobject_cast<SslServer *>(&server);
+    SslServer *sslServer = qobject_cast<SslServer *>(&_server);
     QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
     bool supportSsl = (bool)sslServer && (bool)sslSocket && sslServer->certIsValid();
 #else
     QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
     bool supportSsl = (bool)sslServer && (bool)sslSocket && sslServer->certIsValid();
 #else
index fdcc291..eddaf7f 100644 (file)
@@ -328,9 +328,9 @@ class Core : public QObject {
     QTimer _storageSyncTimer;
 
 #ifdef HAVE_SSL  
     QTimer _storageSyncTimer;
 
 #ifdef HAVE_SSL  
-    SslServer server;
+  SslServer _server, _v6server;
 #else
 #else
-    QTcpServer server;
+  QTcpServer _server, _v6server;
 #endif  
 
     QHash<QTcpSocket *, quint32> blocksizes;
 #endif  
 
     QHash<QTcpSocket *, quint32> blocksizes;