disconnect now closes listening connections
authorChristian Pulvermacher <christian@hazel.(none)>
Wed, 13 Oct 2010 20:25:18 +0000 (22:25 +0200)
committerChristian Pulvermacher <christian@hazel.(none)>
Wed, 13 Oct 2010 20:25:18 +0000 (22:25 +0200)
libvnc/libvncclient/listen.c
src/connectdialog.cpp
src/vncclientthread.cpp
src/vncview.cpp
vnc.pro

index 9f9c779..fa63b93 100644 (file)
@@ -63,7 +63,7 @@ listenForIncomingConnections(rfbClient* client)
   rfbClientLog("Command line errors are not reported until "
          "a connection comes in.\n");
 
-  while (TRUE) {
+  while (client->listenSpecified) {
 
     /* reap any zombies */
     int status, pid;
@@ -75,7 +75,12 @@ listenForIncomingConnections(rfbClient* client)
 
     FD_SET(listenSocket, &fds);
 
-    select(FD_SETSIZE, &fds, NULL, NULL, NULL);
+       //100ms
+    struct timeval timeout;
+    timeout.tv_sec=0;
+    timeout.tv_usec=100000;
+
+    select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
 
     if (FD_ISSET(listenSocket, &fds)) {
       client->sock = AcceptTcpConnection(listenSocket);
@@ -87,29 +92,12 @@ listenForIncomingConnections(rfbClient* client)
        //modified to accept only a single connection
        //if something goes wrong, we can always create another listening socket
        rfbClientLog("Accepted connection.\n");
-       close(listenSocket);
-       return;
+       break;
 
-//      /* Now fork off a new process to deal with it... */
-//
-//      switch (fork()) {
-//
-//      case -1: 
-//     rfbClientErr("fork\n"); 
-//     return;
-//
-//      case 0:
-//     /* child - return to caller */
-//     close(listenSocket);
-//     return;
-//
-//      default:
-//     /* parent - go round and listen again */
-//     close(client->sock); 
-//     break;
-//      }
-    }
+       }
   }
+
+  close(listenSocket);
 #endif
 }
 
index dec578b..65efcb8 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include "connectdialog.h"
+#include "rfb/rfbclient.h"
 
 
 ConnectDialog::ConnectDialog(QWidget *parent):
@@ -134,8 +135,9 @@ void ConnectDialog::accept()
 
        QSettings settings;
        if(!hosts.itemIcon(hosts.currentIndex()).isNull()) {
-               int listen_port = settings.value("listen_port", 5500).toInt();
+               int listen_port = settings.value("listen_port", LISTEN_PORT_OFFSET).toInt();
 
+#if QT_VERSION >= 0x040500
                //ask user if listen_port is correct
                bool ok;
                listen_port = QInputDialog::getInt(this,
@@ -143,6 +145,9 @@ void ConnectDialog::accept()
                        tr("Listen on Port:"),
                        listen_port, 1, 65535, //value, min, max
                        1, &ok);
+#else
+               bool ok = true;
+#endif
                if(ok) {
                        settings.setValue("listen_port", listen_port);
                        emit connectToHost("", quality, listen_port);
index e215b3d..ac71844 100644 (file)
@@ -159,6 +159,7 @@ VncClientThread::VncClientThread(QObject *parent)
         : QThread(parent)
         , frameBuffer(0)
 {
+       outputErrorMessageString.clear(); //don't deliver error messages of old instances...
     QMutexLocker locker(&mutex);
     m_stopped = false;
 
@@ -243,15 +244,20 @@ void VncClientThread::emitGotCut(const QString &text)
 
 void VncClientThread::stop()
 {
-    QMutexLocker locker(&mutex);
+       if(m_stopped)
+               return;
 
-    m_stopped = true;
+       //also abort listening for connections, should be safe without locking
+       if(listen_port)
+               cl->listenSpecified = false;
+
+       QMutexLocker locker(&mutex);
+       m_stopped = true;
 }
 
 void VncClientThread::run()
 {
     QMutexLocker locker(&mutex);
-       bool clean = false;
 
     int passwd_failures = 0;
     while (!m_stopped) { // try to connect as long as the server allows
@@ -293,11 +299,13 @@ void VncClientThread::run()
                        passwd_failures++;
                        if(passwd_failures > 2) {
                                m_stopped = true;
-                               clean = true; //rfbInitClient cleans up after itself upon failure
+                               return;
                        }
                        continue;
                }
 
+               //clean, just exit
+               m_stopped = true;
         return;
     }
 
@@ -326,8 +334,7 @@ void VncClientThread::run()
 
     // Cleanup allocated resources
     locker.relock();
-       if(!clean)
-               rfbClientCleanup(cl);
+       rfbClientCleanup(cl);
     m_stopped = true;
 }
 
index c0f6f16..5ba10fa 100644 (file)
@@ -237,7 +237,8 @@ void VncView::requestPassword()
        QHBoxLayout layout1;
        QVBoxLayout layout2;
        layout2.addWidget(&passwordbox);
-       layout2.addWidget(&save_password);
+       if(!m_host.isEmpty()) //don't save incomming connections
+               layout2.addWidget(&save_password);
        layout1.addLayout(&layout2);
        layout1.addWidget(&ok_button);
        dialog.setLayout(&layout1);
@@ -245,7 +246,7 @@ void VncView::requestPassword()
        if(dialog.exec()) { //dialog accepted
                password = passwordbox.text();
 
-               if(save_password.isChecked()) {
+               if(!m_host.isEmpty() and save_password.isChecked()) {
                        kDebug(5011) << "Saving password for host '" << m_host << "'";
 
                        settings.setValue(QString("%1/password").arg(m_host), password);
@@ -260,8 +261,6 @@ void VncView::requestPassword()
 
 void VncView::outputErrorMessage(const QString &message)
 {
-    kDebug(5011) << message;
-
     if (message == "INTERNAL:APPLE_VNC_COMPATIBILTY") {
         setCursor(localDotCursor());
         m_forceLocalCursor = true;
diff --git a/vnc.pro b/vnc.pro
index 86b3688..9f62098 100644 (file)
--- a/vnc.pro
+++ b/vnc.pro
@@ -2,7 +2,7 @@ TEMPLATE = app
 TARGET = presencevnc-bin
 LIBS += -Llibvnc/libvncclient/.libs -lvncclient
 DEFINES += QTONLY
-CONFIG += silent release
+CONFIG += silent debug
 
 maemo5 {
        QT += maemo5