diff options
author | Giandomenico Girardelli <ggirardelli@moog.com> | 2012-10-14 21:26:02 +0200 |
---|---|---|
committer | Johannes Schindelin <johannes.schindelin@gmx.de> | 2012-10-14 21:27:45 +0200 |
commit | b7725a5ce6b6a08f4fb79a1630990ef8370183f6 (patch) | |
tree | a9f5c369b26cf03b2cf21bbd58083faed67a2f9a | |
parent | 55bdab02574e3ac63b7e195e70f3207a88c1e57c (diff) | |
download | libvncserver-gian.zip libvncserver-gian.tar.gz |
Work In Progress (do not push to 'master' in the current form)gian
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
-rw-r--r-- | libvncserver/main.c | 81 | ||||
-rw-r--r-- | rfb/rfb.h | 5 |
2 files changed, 67 insertions, 19 deletions
diff --git a/libvncserver/main.c b/libvncserver/main.c index 4cb18ac..ce3f874 100644 --- a/libvncserver/main.c +++ b/libvncserver/main.c @@ -574,34 +574,55 @@ listenerRun(void *data) socklen_t len; fd_set listen_fds; /* temp file descriptor list for select() */ + struct timeval TimeOut ; //============> GIAN + int ret ; + /* TODO: this thread wont die by restarting the server */ /* TODO: HTTP is not handled */ - while (1) { + while (!screen->AbortTh) // thread still alive =====> GIAN +// while (1) + { client_fd = -1; FD_ZERO(&listen_fds); - if(screen->listenSock >= 0) - FD_SET(screen->listenSock, &listen_fds); - if(screen->listen6Sock >= 0) - FD_SET(screen->listen6Sock, &listen_fds); - if (select(screen->maxFd+1, &listen_fds, NULL, NULL, NULL) == -1) { + if (screen->listenSock >= 0) + FD_SET(screen->listenSock, &listen_fds); + if (screen->listen6Sock >= 0) + FD_SET(screen->listen6Sock, &listen_fds); + + TimeOut.tv_sec = 1 ; // seconds =====> GIAN + TimeOut.tv_usec = 0 ; // nanoseconds =====> GIAN + + if ((ret = select(screen->maxFd+1, &listen_fds, NULL, NULL, &TimeOut)) == -1) // =====> GIAN + { rfbLogPerror("listenerRun: error in select"); return NULL; } + if (!ret) // timeout =====> GIAN + continue ; + + /* + if (select(screen->maxFd+1, &listen_fds, NULL, NULL, NULL) == -1) + { + rfbLogPerror("listenerRun: error in select"); + return NULL; + } */ - /* there is something on the listening sockets, handle new connections */ - len = sizeof (peer); - if (FD_ISSET(screen->listenSock, &listen_fds)) - client_fd = accept(screen->listenSock, (struct sockaddr*)&peer, &len); - else if (FD_ISSET(screen->listen6Sock, &listen_fds)) - client_fd = accept(screen->listen6Sock, (struct sockaddr*)&peer, &len); - - if(client_fd >= 0) - cl = rfbNewClient(screen,client_fd); - if (cl && !cl->onHold ) - rfbStartOnHoldClient(cl); + /* there is something on the listening sockets, handle new connections */ + len = sizeof (peer); + if (FD_ISSET(screen->listenSock, &listen_fds)) + client_fd = accept(screen->listenSock, (struct sockaddr*)&peer, &len) ; + else + if (FD_ISSET(screen->listen6Sock, &listen_fds)) + client_fd = accept(screen->listen6Sock, (struct sockaddr*)&peer, &len); + + if (client_fd >= 0) + cl = rfbNewClient(screen,client_fd); + if (cl && !cl->onHold ) + rfbStartOnHoldClient(cl); } - return(NULL); + screen->AbortTh = 2 ; // Thread closed ========> GIAN + return(NULL) ; } void @@ -1181,6 +1202,7 @@ void rfbRunEventLoop(rfbScreenInfoPtr screen, long usec, rfbBool runInBackground screen->backgroundLoop = TRUE; + screen->AbortTh = 0 ; // allow thread termination ===========> GIAN pthread_create(&listener_thread, NULL, listenerRun, screen); return; #else @@ -1195,3 +1217,26 @@ void rfbRunEventLoop(rfbScreenInfoPtr screen, long usec, rfbBool runInBackground while(rfbIsActive(screen)) rfbProcessEvents(screen,usec); } + +//==============> GIAN +rfbBool rfbRunEventLoopClose(rfbScreenInfoPtr screen) +{ +#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD + int loop ; + + screen->AbortTh = 1 ; // force thread closing + + for (loop=0 ; loop<3 ; loop++) + { + if (screen->AbortTh == 2) + return true ; // Ok + } + sleep(1) ; + } + return false ; // ko + +#else + rfbErr("Can't run in background, because I don't have PThreads!\n"); + return; +#endif +} @@ -389,6 +389,8 @@ typedef struct _rfbScreenInfo SOCKET listen6Sock; int http6Port; SOCKET httpListen6Sock; + + char AbortTh ; // allow thread termination ===========> GIAN } rfbScreenInfo, *rfbScreenInfoPtr; @@ -686,7 +688,7 @@ typedef struct _rfbClientRec { #ifdef LIBVNCSERVER_HAVE_LIBJPEG /* TurboVNC Encoding support (extends TightVNC) */ int turboSubsampLevel; - int turboQualityLevel; /* 1-100 scale */ + int turboQualityLevel; // 1-100 scale #endif #endif @@ -1051,6 +1053,7 @@ extern void rfbRefuseOnHoldClient(rfbClientPtr cl); rfbProcessEvents() returns TRUE if an update was pending. */ extern void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, rfbBool runInBackground); +extern rfbBool rfbRunEventLoopClose(rfbScreenInfoPtr screen) ; //============> GIAN extern rfbBool rfbProcessEvents(rfbScreenInfoPtr screenInfo,long usec); extern rfbBool rfbIsActive(rfbScreenInfoPtr screenInfo); |