void VncClientThread::run() { QMutexLocker locker(&mutex); while (!m_stopped) { // try to connect as long as the server allows locker.relock(); m_passwordError = false; locker.unlock(); rfbClientLog = outputHandler; rfbClientErr = outputHandler; //24bit color dept in 32 bits per pixel = default. Will change colordepth and bpp later if needed cl = rfbGetClient(8, 3, 4); setClientColorDepth(cl, this->colorDepth()); cl->MallocFrameBuffer = newclient; cl->canHandleNewFBSize = true; cl->GetPassword = passwdHandler; cl->GetCredential = credentialHandler; cl->GotFrameBufferUpdate = updatefb; cl->GotXCutText = cuttext; rfbClientSetClientData(cl, 0, this); locker.relock(); cl->serverHost = strdup(m_host.toUtf8().constData()); if (m_port < 0 || !m_port) // port is invalid or empty... m_port = 5900; // fallback: try an often used VNC port if (m_port >= 0 && m_port < 100) // the user most likely used the short form (e.g. :1) m_port += 5900; cl->serverPort = m_port; locker.unlock(); kDebug(5011) << "--------------------- trying init ---------------------"; if (rfbInitClient(cl, 0, 0)) break; else cl = 0; locker.relock(); if (m_passwordError) continue; return; } locker.relock(); kDebug(5011) << "--------------------- Starting main VNC event loop ---------------------"; while (!m_stopped) { locker.unlock(); const int i = WaitForMessage(cl, 500); if (m_stopped || i < 0) { break; } if (i) { if (!HandleRFBServerMessage(cl)) { break; } } locker.relock(); while (!m_eventQueue.isEmpty()) { ClientEvent* clientEvent = m_eventQueue.dequeue(); locker.unlock(); clientEvent->fire(cl); delete clientEvent; locker.relock(); } } m_stopped = true; }
void VncClientThread::run() { QMutexLocker locker(&m_mutex); int passwd_failures = 0; while (!m_stopped) { // try to connect as long as the server allows m_passwordError = false; outputErrorMessageString.clear(); //don't deliver error messages of old instances... rfbClientLog = outputHandler; rfbClientErr = outputHandler; m_cl = rfbGetClient(8, 3, 4); // bitsPerSample, samplesPerPixel, bytesPerPixel m_cl->MallocFrameBuffer = newclient; m_cl->canHandleNewFBSize = true; m_cl->GetPassword = passwdHandler; m_cl->GotFrameBufferUpdate = updatefb; m_cl->GotXCutText = cuttext; rfbClientSetClientData(m_cl, 0, this); m_cl->serverHost = strdup(m_host.toUtf8().constData()); if (m_port < 0 || !m_port) // port is invalid or empty... m_port = 5900; // fallback: try an often used VNC port if (m_port >= 0 && m_port < 100) // the user most likely used the short form (e.g. :1) m_port += 5900; m_cl->serverPort = m_port; m_cl->listenSpecified = rfbBool(m_listen_port > 0); m_cl->listenPort = m_listen_port; kDebug(5011) << "--------------------- trying init ---------------------"; if (rfbInitClient(m_cl, 0, 0)) break; //init failed... if (m_passwordError) { passwd_failures++; if(passwd_failures < 3) continue; //that's ok, try again } //stop connecting m_stopped = true; return; //no cleanup necessary, m_cl was free()d by rfbInitClient() } locker.unlock(); // Main VNC event loop while (!m_stopped) { const int i = WaitForMessage(m_cl, 500); if(m_stopped or i < 0) break; if (i) if (!HandleRFBServerMessage(m_cl)) break; locker.relock(); while (!m_eventQueue.isEmpty()) { ClientEvent* clientEvent = m_eventQueue.dequeue(); clientEvent->fire(m_cl); delete clientEvent; } locker.unlock(); } // Cleanup allocated resources locker.relock(); rfbClientCleanup(m_cl); m_stopped = true; }
void ItalcVncConnection::doConnection() { QMutex sleeperMutex; while( !m_stopped && m_state != Connected ) // try to connect as long as the server allows { m_cl = rfbGetClient( 8, 3, 4 ); m_cl->MallocFrameBuffer = hookNewClient; m_cl->canHandleNewFBSize = true; m_cl->GotFrameBufferUpdate = hookUpdateFB; m_cl->FinishedFrameBufferUpdate = hookFinishFrameBufferUpdate; m_cl->HandleCursorPos = hookHandleCursorPos; m_cl->GotCursorShape = hookCursorShape; m_cl->GotXCutText = hookCutText; rfbClientSetClientData( m_cl, 0, this ); m_mutex.lock(); if( m_port < 0 ) // port is invalid or empty... { m_port = PortOffsetVncServer; } if( m_port >= 0 && m_port < 100 ) { // the user most likely used the short form (e.g. :1) m_port += PortOffsetVncServer; } free( m_cl->serverHost ); m_cl->serverHost = strdup( m_host.toUtf8().constData() ); m_cl->serverPort = m_port; m_mutex.unlock(); emit newClient( m_cl ); int argc; if( rfbInitClient( m_cl, &argc, NULL ) ) { emit connected(); m_state = Connected; if( m_framebufferUpdateInterval < 0 ) { rfbClientSetClientData( m_cl, (void *) 0x555, (void *) 1 ); } } else { // guess reason why connection failed based on the state, // libvncclient left the rfbClient structure if( argc < 0 ) { m_state = HostUnreachable; } else if( argc > 0 ) { m_state = AuthenticationFailed; } else { // failed for an unknown reason m_state = ConnectionFailed; } // do not sleep when already requested to stop if( m_stopped ) { break; } // wait a bit until next connect sleeperMutex.lock(); if( m_framebufferUpdateInterval > 0 ) { m_updateIntervalSleeper.wait( &sleeperMutex, m_framebufferUpdateInterval ); } else { // default: retry every second m_updateIntervalSleeper.wait( &sleeperMutex, 1000 ); } sleeperMutex.unlock(); } } QTime lastFullUpdate = QTime::currentTime(); // Main VNC event loop while( !m_stopped ) { int timeout = 500; if( m_framebufferUpdateInterval < 0 ) { timeout = 100*1000; // 100 ms } const int i = WaitForMessage( m_cl, timeout ); if( i < 0 ) { break; } else if( i ) { // read and process remaining messages many messages as available bool handledOkay = true; while( WaitForMessage( m_cl, 0 ) && handledOkay ) { handledOkay = HandleRFBServerMessage( m_cl ); } if( handledOkay == false ) { break; } } else { /* // work around a bug in UltraVNC on Win7 where it does not handle // incremental updates correctly int msecs = lastFullUpdate.msecsTo( QTime::currentTime() ); if( ( m_framebufferUpdateInterval > 0 && msecs > 10*m_framebufferUpdateInterval ) || ( m_framebufferUpdateInterval == 0 && msecs > 1000 ) ) { SendFramebufferUpdateRequest( m_cl, 0, 0, framebufferSize().width(), framebufferSize().height(), false ); lastFullUpdate = QTime::currentTime(); }*/ } m_mutex.lock(); while( !m_eventQueue.isEmpty() ) { ClientEvent * clientEvent = m_eventQueue.dequeue(); // unlock the queue mutex during the runtime of ClientEvent::fire() m_mutex.unlock(); clientEvent->fire( m_cl ); delete clientEvent; // and lock it again m_mutex.lock(); } m_mutex.unlock(); if( m_framebufferUpdateInterval > 0 && m_stopped == false ) { sleeperMutex.lock(); m_updateIntervalSleeper.wait( &sleeperMutex, m_framebufferUpdateInterval ); sleeperMutex.unlock(); } } if( m_state == Connected && m_cl ) { rfbClientCleanup( m_cl ); } m_state = Disconnected; }
void VncClientThread::run() { QMutexLocker locker(&mutex); while (!m_stopped) { // try to connect as long as the server allows m_passwordError = false; rfbClientLog = outputHandler; rfbClientErr = outputHandler; cl = rfbGetClient(8, 3, 4); cl->MallocFrameBuffer = newclient; cl->canHandleNewFBSize = true; cl->GetPassword = passwdHandler; cl->GotFrameBufferUpdate = updatefb; cl->GotXCutText = cuttext; rfbClientSetClientData(cl, 0, this); cl->serverHost = strdup(m_host.toUtf8().constData()); if (m_port < 0 || !m_port) // port is invalid or empty... m_port = 5900; // fallback: try an often used VNC port if (m_port >= 0 && m_port < 100) // the user most likely used the short form (e.g. :1) m_port += 5900; cl->serverPort = m_port; kDebug(5011) << "--------------------- trying init ---------------------"; if (rfbInitClient(cl, 0, 0)) break; if (m_passwordError) continue; return; } locker.unlock(); // Main VNC event loop while (!m_stopped) { const int i = WaitForMessage(cl, 500); if (i < 0) break; if (i) if (!HandleRFBServerMessage(cl)) break; locker.relock(); while (!m_eventQueue.isEmpty()) { ClientEvent* clientEvent = m_eventQueue.dequeue(); clientEvent->fire(cl); delete clientEvent; } locker.unlock(); } // Cleanup allocated resources locker.relock(); rfbClientCleanup(cl); m_stopped = true; }