From 8dd45350dba5c170e64ebef33773ed88795d42c3 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 24 Nov 2013 02:26:53 -0600 Subject: Fix improper thread support in krfb This relates to bug 1583 --- krfb/libvncserver/main.cc | 54 +++++++++++++++++++++++++++++++++++++++++++---- krfb/libvncserver/main.h | 15 +++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) (limited to 'krfb/libvncserver') diff --git a/krfb/libvncserver/main.cc b/krfb/libvncserver/main.cc index 51cfaa5d..6ecea30d 100644 --- a/krfb/libvncserver/main.cc +++ b/krfb/libvncserver/main.cc @@ -314,8 +314,14 @@ static void * clientInput(void *data) { rfbClientPtr cl = (rfbClientPtr)data; - pthread_t output_thread; - pthread_create(&output_thread, NULL, clientOutput, (void *)cl); + + /* Start output thread */ + TQEventLoopThread* clientOutputHandlerThread = new TQEventLoopThread(); + ClientOutputHandlerObject* clientOutputHandler = new ClientOutputHandlerObject(); + clientOutputHandler->d = cl; + clientOutputHandler->moveToThread(clientOutputHandlerThread); + TQTimer::singleShot(0, clientOutputHandler, SLOT(run())); + clientOutputHandlerThread->start(); while (1) { rfbProcessClientMessage(cl); @@ -325,11 +331,15 @@ clientInput(void *data) } } - /* Get rid of the output thread. */ + /* Get rid of the output thread */ LOCK(cl->updateMutex); TSIGNAL(cl->updateCond); UNLOCK(cl->updateMutex); - IF_PTHREADS(pthread_join(output_thread, NULL)); + clientOutputHandlerThread->wait(); + delete clientOutputHandlerThread; + clientOutputHandlerThread = NULL; + delete clientOutputHandler; + clientOutputHandler = NULL; rfbClientConnectionGone(cl); @@ -652,6 +662,21 @@ void rfbScreenCleanup(rfbScreenInfoPtr rfbScreen) } rfbReleaseClientIterator(i); + if (mOnHoldClientHandlerThread) { + mOnHoldClientHandlerThread->exit(); + delete mOnHoldClientHandlerThread; + mOnHoldClientHandlerThread = NULL; + delete mOnHoldClientHandler; + mOnHoldClientHandler = NULL; + } + if (mControlPipeHandlerThread) { + mControlPipeHandlerThread->exit(); + delete mControlPipeHandlerThread; + mControlPipeHandlerThread = NULL; + delete mControlPipeHandler; + mControlPipeHandler = NULL; + } + /* TODO: hang up on all clients and free all reserved memory */ #define FREE_IF(x) if(rfbScreen->x) free(rfbScreen->x) FREE_IF(colourMap.data.bytes); @@ -767,6 +792,9 @@ ControlPipeHandlerObject::~ControlPipeHandlerObject() { void ControlPipeHandlerObject::run(void) { listenerRun(d); + + // Terminate thread + TQThread::exit(); } OnHoldClientHandlerObject::OnHoldClientHandlerObject() : TQObject() { @@ -779,6 +807,24 @@ OnHoldClientHandlerObject::~OnHoldClientHandlerObject() { void OnHoldClientHandlerObject::run(void) { clientInput(d); + + // Terminate thread + TQThread::exit(); +} + +ClientOutputHandlerObject::ClientOutputHandlerObject() : TQObject() { + // +} + +ClientOutputHandlerObject::~ClientOutputHandlerObject() { + // +} + +void ClientOutputHandlerObject::run(void) { + clientOutput(d); + + // Terminate thread + TQThread::exit(); } #include "main.moc" \ No newline at end of file diff --git a/krfb/libvncserver/main.h b/krfb/libvncserver/main.h index f662a212..ad6aec5f 100644 --- a/krfb/libvncserver/main.h +++ b/krfb/libvncserver/main.h @@ -40,4 +40,19 @@ class OnHoldClientHandlerObject : public TQObject rfbClientPtr d; }; +class ClientOutputHandlerObject : public TQObject +{ + Q_OBJECT + + public: + ClientOutputHandlerObject(); + ~ClientOutputHandlerObject(); + + public slots: + void run(); + + public: + rfbClientPtr d; +}; + #endif // _MAIN_H \ No newline at end of file -- cgit v1.2.1