Use TQThread in krfb where threads interact with TQt3 instead of direct pthread access

This resolves Bug 1403
pull/1/head
Timothy Pearson 12 years ago
parent 05273794a3
commit 339d5c5986

@ -9,14 +9,20 @@
#
#################################################
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
add_definitions( -DHAVE_PTHREADS -DALLOW24BPP )
##### vncserver (static) ########################
tde_add_library( vncserver STATIC_PIC
tde_add_library( vncserver STATIC_PIC AUTOMOC
SOURCES
main.c rfbserver.c sraRegion.c auth.c sockets.c stats.c corre.c
main.cc rfbserver.c sraRegion.c auth.c sockets.c stats.c corre.c
hextile.c rre.c translate.c cutpaste.c zlib.c tight.c httpd.c
cursor.c font.c draw.c selbox.c d3des.c vncauth.c cargs.c
)

@ -1,8 +1,10 @@
INCLUDES = $(all_includes)
METASOURCES = AUTO
noinst_LTLIBRARIES = libvncserver.la
libvncserver_la_SOURCES = main.c rfbserver.c sraRegion.c auth.c sockets.c \
libvncserver_la_SOURCES = main.cc rfbserver.c sraRegion.c auth.c sockets.c \
stats.c corre.c hextile.c rre.c translate.c cutpaste.c \
zlib.c tight.c httpd.c cursor.c font.c \
draw.c selbox.c d3des.c vncauth.c cargs.c

@ -362,15 +362,15 @@ rfbCursorPtr rfbMakeXCursor(int width,int height,char* cursorString,char* maskSt
cursor->source = (unsigned char*)calloc(w,height);
for(j=0,cp=cursorString;j<height;j++)
for(i=0,bit=0x80;i<width;i++,bit=(bit&1)?0x80:bit>>1,cp++)
if(*cp!=' ') cursor->source[j*w+i/8]|=bit;
if(*cp!=' ') ((char*)(cursor->source))[j*w+i/8]|=bit;
if(maskString) {
cursor->mask = (unsigned char*)calloc(w,height);
for(j=0,cp=maskString;j<height;j++)
for(i=0,bit=0x80;i<width;i++,bit=(bit&1)?0x80:bit>>1,cp++)
if(*cp!=' ') cursor->mask[j*w+i/8]|=bit;
if(*cp!=' ') ((char*)(cursor->mask))[j*w+i/8]|=bit;
} else
cursor->mask = (unsigned char*)rfbMakeMaskForXCursor(width,height,cursor->source);
cursor->mask = (unsigned char*)rfbMakeMaskForXCursor(width,height,(char*)(cursor->source));
return(cursor);
}
@ -403,8 +403,8 @@ void rfbFreeCursor(rfbCursorPtr cursor)
if(cursor) {
if(cursor->richSource)
free(cursor->richSource);
free(cursor->source);
free(cursor->mask);
free((char*)(cursor->source));
free((char*)(cursor->mask));
free(cursor);
}
@ -431,7 +431,7 @@ void MakeXCursorFromRichCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor)
for(j=0;j<cursor->height;j++)
for(i=0,bit=0x80;i<cursor->width;i++,bit=(bit&1)?0x80:bit>>1)
if(memcmp(cursor->richSource+j*width+i*bpp,back,bpp))
cursor->source[j*w+i/8]|=bit;
((char*)(cursor->source))[j*w+i/8]|=bit;
}
void MakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor)

@ -10,30 +10,41 @@
* see GPL (latest version) for full details
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#ifndef false
#define false 0
#define true -1
#endif
extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#ifndef false
#define false 0
#define true -1
#endif
#include <sys/types.h>
#ifdef __osf__
typedef int socklen_t;
#endif
#ifndef WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#endif
#include <signal.h>
#include <time.h>
}
#include <sys/types.h>
#ifdef __osf__
typedef int socklen_t;
#endif
#ifndef WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#endif
#include <signal.h>
#include <time.h>
#include <ntqobject.h>
#include <ntqvariant.h>
#include <ntqtimer.h>
#include <ntqthread.h>
#include "rfb.h"
#include "sraRegion.h"
extern "C" {
#include "rfb.h"
#include "sraRegion.h"
}
#include "main.h"
/* minimum interval between attempts to send something */
#define PING_MS 10000
@ -47,9 +58,17 @@ int rfbEnableLogging=1;
defined, even if _BYTE_ORDER is not _LITTLE_ENDIAN */
char rfbEndianTest = (_BYTE_ORDER == 1234);
/* from rfbserver.c */
void rfbIncrClientRef(rfbClientPtr cl);
void rfbDecrClientRef(rfbClientPtr cl);
extern "C" {
/* from rfbserver.c */
void rfbIncrClientRef(rfbClientPtr cl);
void rfbDecrClientRef(rfbClientPtr cl);
}
ControlPipeHandlerObject* mControlPipeHandler = NULL;
TQEventLoopThread* mControlPipeHandlerThread = NULL;
OnHoldClientHandlerObject* mOnHoldClientHandler = NULL;
TQEventLoopThread* mOnHoldClientHandlerThread = NULL;
void rfbLogEnable(int enabled) {
rfbEnableLogging=enabled;
@ -339,7 +358,7 @@ listenerRun(void *data)
/* TODO: this thread wont die by restarting the server */
while ((client_fd = accept(rfbScreen->rfbListenSock,
(struct sockaddr*)&peer, &len)) >= 0) {
(struct sockaddr*)&peer, (socklen_t*)(&len))) >= 0) {
cl = rfbNewClient(rfbScreen,client_fd);
len = sizeof(peer);
@ -352,7 +371,12 @@ listenerRun(void *data)
void
rfbStartOnHoldClient(rfbClientPtr cl)
{
pthread_create(&cl->client_thread, NULL, clientInput, (void *)cl);
mOnHoldClientHandlerThread = new TQEventLoopThread();
mOnHoldClientHandler = new OnHoldClientHandlerObject();
mOnHoldClientHandler->d = cl;
mOnHoldClientHandler->moveToThread(mOnHoldClientHandlerThread);
TQTimer::singleShot(0, mOnHoldClientHandler, SLOT(run()));
mOnHoldClientHandlerThread->start();
}
#else
@ -435,7 +459,7 @@ rfbCursorPtr defaultGetCursorPtr(rfbClientPtr cl)
Bool defaultPasswordCheck(rfbClientPtr cl,const char* response,int len)
{
int i;
char *passwd=vncDecryptPasswdFromFile(cl->screen->rfbAuthPasswdData);
char *passwd = vncDecryptPasswdFromFile((char*)(cl->screen->rfbAuthPasswdData));
if(!passwd) {
rfbLog("Couldn't read password file: %s\n",cl->screen->rfbAuthPasswdData);
@ -491,7 +515,7 @@ rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
int width,int height,int bitsPerSample,int samplesPerPixel,
int bytesPerPixel)
{
rfbScreenInfoPtr rfbScreen=malloc(sizeof(rfbScreenInfo));
rfbScreenInfoPtr rfbScreen=(rfbScreenInfoPtr)(malloc(sizeof(rfbScreenInfo)));
rfbPixelFormat* format=&rfbScreen->rfbServerFormat;
INIT_MUTEX(logMutex);
@ -707,23 +731,54 @@ rfbProcessEvents(rfbScreenInfoPtr rfbScreen,long usec)
void rfbRunEventLoop(rfbScreenInfoPtr rfbScreen, long usec, Bool runInBackground)
{
if(runInBackground) {
if (runInBackground) {
#ifdef HAVE_PTHREADS
pthread_t listener_thread;
rfbScreen->backgroundLoop = TRUE;
pthread_create(&listener_thread, NULL, listenerRun, rfbScreen);
return;
rfbScreen->backgroundLoop = TRUE;
mControlPipeHandlerThread = new TQEventLoopThread();
mControlPipeHandler = new ControlPipeHandlerObject();
mControlPipeHandler->d = rfbScreen;
mControlPipeHandler->moveToThread(mControlPipeHandlerThread);
TQTimer::singleShot(0, mControlPipeHandler, SLOT(run()));
mControlPipeHandlerThread->start();
return;
#else
fprintf(stderr,"Can't run in background, because I don't have PThreads!\n");
exit(-1);
fprintf(stderr,"Can't run in background, because I don't have PThreads!\n");
exit(-1);
#endif
}
}
if(usec<0)
usec=rfbScreen->rfbDeferUpdateTime*1000;
if (usec<0) {
usec=rfbScreen->rfbDeferUpdateTime*1000;
}
while (1) {
rfbProcessEvents(rfbScreen,usec);
}
}
ControlPipeHandlerObject::ControlPipeHandlerObject() : TQObject() {
//
}
ControlPipeHandlerObject::~ControlPipeHandlerObject() {
//
}
while(1)
rfbProcessEvents(rfbScreen,usec);
void ControlPipeHandlerObject::run(void) {
listenerRun(d);
}
OnHoldClientHandlerObject::OnHoldClientHandlerObject() : TQObject() {
//
}
OnHoldClientHandlerObject::~OnHoldClientHandlerObject() {
//
}
void OnHoldClientHandlerObject::run(void) {
clientInput(d);
}
#include "main.moc"

@ -0,0 +1,43 @@
/*
* LibVNCServer (C) 2001 Johannes E. Schindelin <Johannes.Schindelin@gmx.de>
* Original OSXvnc (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
* Original Xvnc (C) 1999 AT&T Laboratories Cambridge.
* All Rights Reserved.
*
* see GPL (latest version) for full details
*/
#ifndef _MAIN_H
#define _MAIN_H
class ControlPipeHandlerObject : public TQObject
{
Q_OBJECT
public:
ControlPipeHandlerObject();
~ControlPipeHandlerObject();
public slots:
void run();
public:
rfbScreenInfoPtr d;
};
class OnHoldClientHandlerObject : public TQObject
{
Q_OBJECT
public:
OnHoldClientHandlerObject();
~OnHoldClientHandlerObject();
public slots:
void run();
public:
rfbClientPtr d;
};
#endif // _MAIN_H

@ -154,7 +154,7 @@ typedef unsigned long KeySym;
#define TIMEDWAIT(cond,mutex,t) {struct timeval tv;\
tv.tv_sec = (t) / 1000;\
tv.tv_usec = ((t) % 1000) * 1000;\
pthread_cond_timedwait(&(cond),&(mutex),&tv);}
pthread_cond_timedwait(&(cond),&(mutex),(const timespec*)(&tv));}
#define COND(cond) pthread_cond_t (cond)
#define INIT_COND(cond) pthread_cond_init(&(cond),NULL)
#define TINI_COND(cond) pthread_cond_destroy(&(cond))
@ -725,12 +725,12 @@ extern Bool rfbSendRectEncodingTight(rfbClientPtr cl, int x,int y,int w,int h);
/* cursor.c */
typedef struct rfbCursor {
unsigned char *source; /* points to bits */
unsigned char *mask; /* points to bits */
unsigned short width, height, xhot, yhot; /* metrics */
unsigned short foreRed, foreGreen, foreBlue; /* device-independent colour */
unsigned short backRed, backGreen, backBlue; /* device-independent colour */
unsigned char *richSource; /* source bytes for a rich cursor */
const char *source; /* points to bits */
const char *mask; /* points to bits */
unsigned short width, height, xhot, yhot; /* metrics */
unsigned short foreRed, foreGreen, foreBlue; /* device-independent colour */
unsigned short backRed, backGreen, backBlue; /* device-independent colour */
unsigned char *richSource; /* source bytes for a rich cursor */
} rfbCursor, *rfbCursorPtr;
extern Bool rfbSendCursorShape(rfbClientPtr cl/*, rfbScreenInfoPtr pScreen*/);

Loading…
Cancel
Save