File x11vnc-thread-auth.diff of Package x11vnc
Index: x11vnc-0.9.8/x11vnc/screen.c
===================================================================
--- x11vnc-0.9.8.orig/x11vnc/screen.c
+++ x11vnc-0.9.8/x11vnc/screen.c
@@ -3907,8 +3907,40 @@ if (0 && dt > 0.0) fprintf(stderr, "dt:
return msec;
}
/*
+ * Terrible hack for the multithreaded x11vnc ...
+ * But we get the client confused if we start sending stuff in our
+ * main loop prior to it being initialized properly. So wait.
+ * It's polling :-(
+ */
+static void _mt_wait_for_client(void)
+{
+ time_t start = time(0);
+ while (!client_count) {
+ if (first_conn_timeout && time(0) - start > first_conn_timeout)
+ return;
+ usleep(100*1000);
+ }
+ while (1) {
+ rfbClientIteratorPtr iter;
+ rfbClientPtr cl;
+ iter = rfbGetClientIterator(screen);
+ while( (cl = rfbClientIteratorNext(iter)) ) {
+ //ClientData *cd = (ClientData *) cl->clientData;
+ if (cl->state == RFB_NORMAL) {
+ rfbReleaseClientIterator(iter);
+ return;
+ }
+ }
+ rfbReleaseClientIterator(iter);
+ if (first_conn_timeout && time(0) - start > first_conn_timeout)
+ return;
+ usleep(100*1000);
+ }
+}
+
+/*
* main x11vnc loop: polls, checks for events, iterate libvncserver, etc.
*/
void watch_loop(void) {
int cnt = 0, tile_diffs = 0, skip_pe = 0, wait;
@@ -3917,8 +3949,9 @@ void watch_loop(void) {
if (use_threads && !started_rfbRunEventLoop) {
started_rfbRunEventLoop = 1;
rfbRunEventLoop(screen, -1, TRUE);
+ _mt_wait_for_client();
}
while (1) {
char msg[] = "new client: %s taking unixpw client off hold.\n";