summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordscho <dscho>2006-02-28 19:33:34 +0000
committerdscho <dscho>2006-02-28 19:33:34 +0000
commitf52cfa651b99540b8c9a2d251c350cd1cc775aee (patch)
tree58b7066c545273989cc606682da619df84918ecf
parent79310af7e7a289d2baf1bdc295daefdcc76ecc0e (diff)
downloadlibtdevnc-f52cfa651b99540b8c9a2d251c350cd1cc775aee.tar.gz
libtdevnc-f52cfa651b99540b8c9a2d251c350cd1cc775aee.zip
add handleEventsEagerly flag (Thanks, Donald)
-rw-r--r--AUTHORS2
-rw-r--r--ChangeLog4
-rw-r--r--libvncserver/main.c2
-rwxr-xr-xlibvncserver/sockets.c168
-rw-r--r--rfb/rfb.h5
5 files changed, 97 insertions, 84 deletions
diff --git a/AUTHORS b/AUTHORS
index 8d572c5..9698253 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -28,7 +28,7 @@ email!): Akira Hatakeyama, Karl J. Runge, Justin "Zippy" Dearing,
Oliver Mihatsch, Greg Sternberg, Werner Hofer, Giampiero Giancipoli,
Glenn Mabutt, Paul Kreiner, Erik Kunze, Mike Frysinger, Martin Waitz,
Mark McLoughlin, Paul Fox, Juan Jose Costello, Andre Leiadella,
-Alberto Lusiani, Malvina Mazin, Dave Stuart.
+Alberto Lusiani, Malvina Mazin, Dave Stuart, Rohit Kumar, and Donald Dugger.
Probably I forgot quite a few people sending a patch here and there, which
really made a difference. Without those, some obscure bugs still would
diff --git a/ChangeLog b/ChangeLog
index a1678ce..9c29744 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-02-28 Donald Dugger <donald.d.dugger@intel.com>
+ * rfb.h, sockets.c, main.c: add a flag to handle all pending
+ input events instead of one at a time.
+
2006-02-24 Karl Runge <runge@karlrunge.com>
* x11vnc: -unixpw and -stunnel options. Add clipboard input
to per-client input controls.
diff --git a/libvncserver/main.c b/libvncserver/main.c
index a46b3bc..093f81d 100644
--- a/libvncserver/main.c
+++ b/libvncserver/main.c
@@ -796,6 +796,8 @@ rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
screen->deferUpdateTime=5;
screen->maxRectsPerUpdate=50;
+ screen->handleEventsEagerly = FALSE;
+
if(!rfbProcessArguments(screen,argc,argv)) {
free(screen);
return NULL;
diff --git a/libvncserver/sockets.c b/libvncserver/sockets.c
index fb61fcd..a4c6cad 100755
--- a/libvncserver/sockets.c
+++ b/libvncserver/sockets.c
@@ -213,7 +213,7 @@ void rfbShutdownSockets(rfbScreenInfoPtr rfbScreen)
* rfbProcessClientMessage, etc).
*/
-void
+int
rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
{
int nfds;
@@ -232,108 +232,112 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
rfbScreen->inetdInitDone = TRUE;
}
- memcpy((char *)&fds, (char *)&(rfbScreen->allFds), sizeof(fd_set));
- tv.tv_sec = 0;
- tv.tv_usec = usec;
- nfds = select(rfbScreen->maxFd + 1, &fds, NULL, NULL /* &fds */, &tv);
- if (nfds == 0) {
- return;
- }
- if (nfds < 0) {
+ do {
+ memcpy((char *)&fds, (char *)&(rfbScreen->allFds), sizeof(fd_set));
+ tv.tv_sec = 0;
+ tv.tv_usec = usec;
+ nfds = select(rfbScreen->maxFd + 1, &fds, NULL, NULL /* &fds */, &tv);
+ if (nfds == 0) {
+ return 0;
+ }
+ if (nfds < 0) {
#ifdef WIN32
- errno = WSAGetLastError();
+ errno = WSAGetLastError();
#endif
- if (errno != EINTR)
+ if (errno != EINTR)
rfbLogPerror("rfbCheckFds: select");
- return;
- }
+ return 0;
+ }
- if (rfbScreen->listenSock != -1 && FD_ISSET(rfbScreen->listenSock, &fds)) {
+ if (rfbScreen->listenSock != -1 && FD_ISSET(rfbScreen->listenSock, &fds)) {
- if ((sock = accept(rfbScreen->listenSock,
- (struct sockaddr *)&addr, &addrlen)) < 0) {
- rfbLogPerror("rfbCheckFds: accept");
- return;
- }
+ if ((sock = accept(rfbScreen->listenSock,
+ (struct sockaddr *)&addr, &addrlen)) < 0) {
+ rfbLogPerror("rfbCheckFds: accept");
+ return 0;
+ }
#ifndef WIN32
- if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
- rfbLogPerror("rfbCheckFds: fcntl");
- closesocket(sock);
- return;
- }
+ if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
+ rfbLogPerror("rfbCheckFds: fcntl");
+ closesocket(sock);
+ return 0;
+ }
#endif
- if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
- (char *)&one, sizeof(one)) < 0) {
- rfbLogPerror("rfbCheckFds: setsockopt");
- closesocket(sock);
- return;
- }
+ if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
+ (char *)&one, sizeof(one)) < 0) {
+ rfbLogPerror("rfbCheckFds: setsockopt");
+ closesocket(sock);
+ return 0;
+ }
#ifdef USE_LIBWRAP
- if(!hosts_ctl("vnc",STRING_UNKNOWN,inet_ntoa(addr.sin_addr),
- STRING_UNKNOWN)) {
- rfbLog("Rejected connection from client %s\n",
- inet_ntoa(addr.sin_addr));
- closesocket(sock);
- return;
- }
+ if(!hosts_ctl("vnc",STRING_UNKNOWN,inet_ntoa(addr.sin_addr),
+ STRING_UNKNOWN)) {
+ rfbLog("Rejected connection from client %s\n",
+ inet_ntoa(addr.sin_addr));
+ closesocket(sock);
+ return 0;
+ }
#endif
- rfbLog("Got connection from client %s\n", inet_ntoa(addr.sin_addr));
+ rfbLog("Got connection from client %s\n", inet_ntoa(addr.sin_addr));
- rfbNewClient(rfbScreen,sock);
-
- FD_CLR(rfbScreen->listenSock, &fds);
- if (--nfds == 0)
- return;
- }
+ rfbNewClient(rfbScreen,sock);
+
+ FD_CLR(rfbScreen->listenSock, &fds);
+ if (--nfds == 0)
+ return 0;
+ }
- if ((rfbScreen->udpSock != -1) && FD_ISSET(rfbScreen->udpSock, &fds)) {
- if(!rfbScreen->udpClient)
- rfbNewUDPClient(rfbScreen);
- if (recvfrom(rfbScreen->udpSock, buf, 1, MSG_PEEK,
- (struct sockaddr *)&addr, &addrlen) < 0) {
- rfbLogPerror("rfbCheckFds: UDP: recvfrom");
- rfbDisconnectUDPSock(rfbScreen);
- rfbScreen->udpSockConnected = FALSE;
- } else {
- if (!rfbScreen->udpSockConnected ||
- (memcmp(&addr, &rfbScreen->udpRemoteAddr, addrlen) != 0))
- {
- /* new remote end */
- rfbLog("rfbCheckFds: UDP: got connection\n");
-
- memcpy(&rfbScreen->udpRemoteAddr, &addr, addrlen);
- rfbScreen->udpSockConnected = TRUE;
-
- if (connect(rfbScreen->udpSock,
- (struct sockaddr *)&addr, addrlen) < 0) {
- rfbLogPerror("rfbCheckFds: UDP: connect");
- rfbDisconnectUDPSock(rfbScreen);
- return;
+ if ((rfbScreen->udpSock != -1) && FD_ISSET(rfbScreen->udpSock, &fds)) {
+ if(!rfbScreen->udpClient)
+ rfbNewUDPClient(rfbScreen);
+ if (recvfrom(rfbScreen->udpSock, buf, 1, MSG_PEEK,
+ (struct sockaddr *)&addr, &addrlen) < 0) {
+ rfbLogPerror("rfbCheckFds: UDP: recvfrom");
+ rfbDisconnectUDPSock(rfbScreen);
+ rfbScreen->udpSockConnected = FALSE;
+ } else {
+ if (!rfbScreen->udpSockConnected ||
+ (memcmp(&addr, &rfbScreen->udpRemoteAddr, addrlen) != 0))
+ {
+ /* new remote end */
+ rfbLog("rfbCheckFds: UDP: got connection\n");
+
+ memcpy(&rfbScreen->udpRemoteAddr, &addr, addrlen);
+ rfbScreen->udpSockConnected = TRUE;
+
+ if (connect(rfbScreen->udpSock,
+ (struct sockaddr *)&addr, addrlen) < 0) {
+ rfbLogPerror("rfbCheckFds: UDP: connect");
+ rfbDisconnectUDPSock(rfbScreen);
+ return 0;
+ }
+
+ rfbNewUDPConnection(rfbScreen,rfbScreen->udpSock);
}
- rfbNewUDPConnection(rfbScreen,rfbScreen->udpSock);
+ rfbProcessUDPInput(rfbScreen);
}
- rfbProcessUDPInput(rfbScreen);
+ FD_CLR(rfbScreen->udpSock, &fds);
+ if (--nfds == 0)
+ return 0;
}
- FD_CLR(rfbScreen->udpSock, &fds);
- if (--nfds == 0)
- return;
- }
-
- i = rfbGetClientIterator(rfbScreen);
- while((cl = rfbClientIteratorNext(i))) {
- if (cl->onHold)
- continue;
- if (FD_ISSET(cl->sock, &fds) && FD_ISSET(cl->sock, &(rfbScreen->allFds)))
- rfbProcessClientMessage(cl);
- }
- rfbReleaseClientIterator(i);
+ i = rfbGetClientIterator(rfbScreen);
+ while((cl = rfbClientIteratorNext(i))) {
+ if (cl->onHold)
+ continue;
+ if (FD_ISSET(cl->sock, &fds) &&
+ FD_ISSET(cl->sock, &(rfbScreen->allFds)))
+ rfbProcessClientMessage(cl);
+ }
+ rfbReleaseClientIterator(i);
+ } while(rfbScreen->handleEventsEagerly);
+ return 1;
}
diff --git a/rfb/rfb.h b/rfb/rfb.h
index aee6b45..cf4665b 100644
--- a/rfb/rfb.h
+++ b/rfb/rfb.h
@@ -310,6 +310,9 @@ typedef struct _rfbScreenInfo
in_addr_t listenInterface;
int deferPtrUpdateTime;
+
+ /* handle as many input events as possible (default off) */
+ rfbBool handleEventsEagerly;
} rfbScreenInfo, *rfbScreenInfoPtr;
@@ -563,7 +566,7 @@ extern void rfbCloseClient(rfbClientPtr cl);
extern int rfbReadExact(rfbClientPtr cl, char *buf, int len);
extern int rfbReadExactTimeout(rfbClientPtr cl, char *buf, int len,int timeout);
extern int rfbWriteExact(rfbClientPtr cl, const char *buf, int len);
-extern void rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec);
+extern int rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec);
extern int rfbConnect(rfbScreenInfoPtr rfbScreen, char* host, int port);
extern int rfbConnectToTcpAddr(char* host, int port);
extern int rfbListenOnTCPPort(int port, in_addr_t iface);