summaryrefslogtreecommitdiffstats
path: root/sockets.c
diff options
context:
space:
mode:
authordscho <dscho>2001-09-29 19:51:17 +0000
committerdscho <dscho>2001-09-29 19:51:17 +0000
commit08ed0461c7abca36fd6a6b0abf7ae466a2e8435a (patch)
tree36a9db4d83034048feaae920a071a670e6f5bcda /sockets.c
parent641012310eebe3a129c8a1939c3f8c9cd645ef50 (diff)
downloadlibtdevnc-08ed0461c7abca36fd6a6b0abf7ae466a2e8435a.tar.gz
libtdevnc-08ed0461c7abca36fd6a6b0abf7ae466a2e8435a.zip
finally fixed pthreads
Diffstat (limited to 'sockets.c')
-rw-r--r--sockets.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/sockets.c b/sockets.c
index 9721110..145236b 100644
--- a/sockets.c
+++ b/sockets.c
@@ -141,7 +141,8 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
char buf[6];
const int one = 1;
int sock;
- rfbClientPtr cl;
+ rfbClientIteratorPtr i;
+ rfbClientPtr cl,cl_next;
if (!rfbScreen->inetdInitDone && rfbScreen->inetdSock != -1) {
rfbNewClientConnection(rfbScreen,rfbScreen->inetdSock);
@@ -232,10 +233,33 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
return;
}
- for (cl = rfbScreen->rfbClientHead; cl; cl=cl->next) {
- if (FD_ISSET(cl->sock, &fds) && FD_ISSET(cl->sock, &(rfbScreen->allFds))) {
- rfbProcessClientMessage(cl);
- }
+ /* I know that this is horrible. But we have the following problem:
+ inside this loop, the IO functions access the clients via the
+ iterator.
+ So we have to lock rfbClientListMutex to fetch a reliable
+ rfbClientHead. Remember, a client can just go away in a multithreaded
+ environment. So we have to lock the next client before working with
+ the current.
+ */
+ i = rfbGetClientIterator(rfbScreen);
+ cl = rfbClientIteratorNext(i);
+ if(cl) {
+#ifdef HAVE_PTHREADS
+ //pthread_mutex_lock(&cl->updateMutex);
+#endif
+ }
+ rfbReleaseClientIterator(i);
+
+ while(cl) {
+ cl_next = cl->next;
+#ifdef HAVE_PTHREADS
+ //pthread_mutex_unlock(&cl->updateMutex);
+ //if(cl_next)
+ //pthread_mutex_lock(&cl_next->updateMutex);
+#endif
+ if (FD_ISSET(cl->sock, &fds) && FD_ISSET(cl->sock, &(rfbScreen->allFds)))
+ rfbProcessClientMessage(cl);
+ cl=cl_next;
}
}
@@ -257,8 +281,8 @@ rfbCloseClient(cl)
close(cl->sock);
cl->sock = -1;
pthread_cond_signal(&cl->updateCond);
- pthread_mutex_lock(&cl->updateMutex);
- rfbClientConnectionGone(cl);
+ //pthread_mutex_lock(&cl->updateMutex);
+ //rfbClientConnectionGone(cl);
pthread_mutex_unlock(&cl->updateMutex);
}