void addClntThrdCD::run( void * ) { HAB thab = WinInitialize( 0 ); HMQ hmq = WinCreateMsgQueue( thab , 0 ); // Attempt to create a new socket VSocket *tmpsock; tmpsock = new VSocket; if (tmpsock!=NULL) { // Connect out to the specified host on the VNCviewer listen port // To be really good, we should allow a display number here but // for now we'll just assume we're connecting to display zero tmpsock->Create(); if (tmpsock->Connect(m_host, m_port)) { // Add the new client to this server m_server->AddClient(tmpsock, TRUE, TRUE); } else { // Print up an error message WinMessageBox( HWND_DESKTOP , HWND_DESKTOP , (PSZ)"Failed to connect to listening VNC viewer", (PSZ)"Outgoing Connection", 10001 , MB_ICONEXCLAMATION | MB_OK ); delete tmpsock; } } WinDestroyMsgQueue( hmq ); WinTerminate( thab ); }
// Code to be executed by the thread void *vncSockConnectThread::run_undetached(void * arg) { vnclog.Print(LL_STATE, VNCLOG("started socket connection thread\n")); // Go into a loop, listening for connections on the given socket while (!m_shutdown) { // Accept an incoming connection VSocket *new_socket; if (!m_socket->TryAccept(&new_socket, 100)) break; if (new_socket != NULL) { vnclog.Print(LL_CLIENTS, VNCLOG("accepted connection from %s\n"), new_socket->GetPeerName()); // Successful accept - start the client unauthenticated m_server->AddClient(new_socket, FALSE, FALSE); } } vnclog.Print(LL_STATE, VNCLOG("quitting socket connection thread\n")); return NULL; }