diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-11-24 02:26:53 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-11-24 02:26:53 -0600 |
commit | 8dd45350dba5c170e64ebef33773ed88795d42c3 (patch) | |
tree | 09bbbdc785abbb3e84225f41508aff631696cde0 /krfb/libvncserver | |
parent | a59a189a8b8ac84741975d749c6f82f3acca5362 (diff) | |
download | tdenetwork-8dd45350dba5c170e64ebef33773ed88795d42c3.tar.gz tdenetwork-8dd45350dba5c170e64ebef33773ed88795d42c3.zip |
Fix improper thread support in krfb
This relates to bug 1583
Diffstat (limited to 'krfb/libvncserver')
-rw-r--r-- | krfb/libvncserver/main.cc | 54 | ||||
-rw-r--r-- | krfb/libvncserver/main.h | 15 |
2 files changed, 65 insertions, 4 deletions
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 |