summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authordscho <dscho>2001-10-04 11:58:57 +0000
committerdscho <dscho>2001-10-04 11:58:57 +0000
commitbd5fdd670ccae30a31d6b007c312b6d2a1a59cc0 (patch)
tree180753d573f8253e7667a763ef63e8c73e8ef57f /main.c
parent2a683877ecf21311cd05d4d509e3e2e4e43adae6 (diff)
downloadlibtdevnc-bd5fdd670ccae30a31d6b007c312b6d2a1a59cc0.tar.gz
libtdevnc-bd5fdd670ccae30a31d6b007c312b6d2a1a59cc0.zip
fixed 2 pthreads issues, added noXCursor option.
Diffstat (limited to 'main.c')
-rw-r--r--main.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/main.c b/main.c
index 2b6cc25..e7c80fd 100644
--- a/main.c
+++ b/main.c
@@ -34,7 +34,7 @@
#include "sraRegion.h"
#ifdef HAVE_PTHREADS
-pthread_mutex_t logMutex;
+MUTEX(logMutex);
#endif
/*
@@ -48,7 +48,7 @@ rfbLog(char *format, ...)
char buf[256];
time_t log_clock;
- IF_PTHREADS(LOCK(logMutex));
+ LOCK(logMutex);
va_start(args, format);
time(&log_clock);
@@ -59,7 +59,7 @@ rfbLog(char *format, ...)
fflush(stderr);
va_end(args);
- IF_PTHREADS(UNLOCK(logMutex));
+ UNLOCK(logMutex);
}
void rfbLogPerror(char *str)
@@ -116,25 +116,28 @@ clientOutput(void *data)
while (1) {
haveUpdate = false;
- LOCK(cl->updateMutex);
while (!haveUpdate) {
if (cl->sock == -1) {
/* Client has disconnected. */
- UNLOCK(cl->updateMutex);
return NULL;
}
- updateRegion = sraRgnCreateRgn(cl->modifiedRegion);
- haveUpdate = sraRgnAnd(updateRegion,cl->requestedRegion);
- sraRgnDestroy(updateRegion);
+ LOCK(cl->updateMutex);
+ haveUpdate = FB_UPDATE_PENDING(cl);
+ if(!haveUpdate) {
+ updateRegion = sraRgnCreateRgn(cl->modifiedRegion);
+ haveUpdate = sraRgnAnd(updateRegion,cl->requestedRegion);
+ sraRgnDestroy(updateRegion);
+ }
+ UNLOCK(cl->updateMutex);
if (!haveUpdate) {
WAIT(cl->updateCond, cl->updateMutex);
+ UNLOCK(cl->updateMutex); /* we really needn't lock now. */
}
}
/* OK, now, to save bandwidth, wait a little while for more
updates to come along. */
- UNLOCK(cl->updateMutex);
usleep(rfbDeferUpdateTime * 1000);
/* Now, get the region we're going to update, and remove
@@ -143,12 +146,10 @@ clientOutput(void *data)
is updated, we'll be sure to do another update later. */
LOCK(cl->updateMutex);
updateRegion = sraRgnCreateRgn(cl->modifiedRegion);
- sraRgnAnd(updateRegion,cl->requestedRegion);
- sraRgnSubtract(cl->modifiedRegion,updateRegion);
+ UNLOCK(cl->updateMutex);
/* Now actually send the update. */
rfbSendFramebufferUpdate(cl, updateRegion);
- UNLOCK(cl->updateMutex);
sraRgnDestroy(updateRegion);
}
@@ -264,13 +265,14 @@ void
defaultPtrAddEvent(int buttonMask, int x, int y, rfbClientPtr cl)
{
if(x!=cl->screen->cursorX || y!=cl->screen->cursorY) {
- Bool cursorWasDrawn=cl->screen->cursorIsDrawn;
- if(cursorWasDrawn)
+ if(cl->screen->cursorIsDrawn)
rfbUndrawCursor(cl);
- cl->screen->cursorX = x;
- cl->screen->cursorY = y;
- if(cursorWasDrawn)
- rfbDrawCursor(cl);
+ LOCK(cl->screen->cursorMutex);
+ if(!cl->screen->cursorIsDrawn) {
+ cl->screen->cursorX = x;
+ cl->screen->cursorY = y;
+ }
+ UNLOCK(cl->screen->cursorMutex);
}
}
@@ -311,6 +313,8 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv,
rfbScreenInfoPtr rfbScreen=malloc(sizeof(rfbScreenInfo));
rfbPixelFormat* format=&rfbScreen->rfbServerFormat;
+ INIT_MUTEX(logMutex);
+
if(width&3)
fprintf(stderr,"WARNING: Width (%d) is not a multiple of 4. VncViewer has problems with that.\n",width);
@@ -387,7 +391,9 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv,
rfbScreen->dontSendFramebufferUpdate = FALSE;
rfbScreen->cursorX=rfbScreen->cursorY=rfbScreen->underCursorBufferLen=0;
rfbScreen->underCursorBuffer=NULL;
- //INIT_MUTEX(rfbScreen->cursorMutex);
+ rfbScreen->dontConvertRichCursorToXCursor = FALSE;
+ rfbScreen->cursor = &myCursor;
+ INIT_MUTEX(rfbScreen->cursorMutex);
/* proc's and hook's */
@@ -396,7 +402,6 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv,
rfbScreen->ptrAddEvent = defaultPtrAddEvent;
rfbScreen->setXCutText = defaultSetXCutText;
rfbScreen->getCursorPtr = defaultGetCursorPtr;
- rfbScreen->cursor = &myCursor;
rfbScreen->setTranslateFunction = rfbSetTranslateFunction;
rfbScreen->newClientHook = doNothingWithClient;
@@ -421,7 +426,6 @@ void rfbInitServer(rfbScreenInfoPtr rfbScreen)
{
rfbInitSockets(rfbScreen);
httpInitSockets(rfbScreen);
- INIT_MUTEX(logMutex);
}
void
@@ -448,8 +452,6 @@ rfbProcessEvents(rfbScreenInfoPtr rfbScreen,long usec)
void rfbRunEventLoop(rfbScreenInfoPtr rfbScreen, long usec, Bool runInBackground)
{
- rfbInitServer(rfbScreen);
-
if(runInBackground) {
#ifdef HAVE_PTHREADS
pthread_t listener_thread;