Commit 0d40904d authored by dscho's avatar dscho

rfbCheckFds now returns the number of processed events

parent f52cfa65
...@@ -226,6 +226,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -226,6 +226,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
int sock; int sock;
rfbClientIteratorPtr i; rfbClientIteratorPtr i;
rfbClientPtr cl; rfbClientPtr cl;
int result = 0;
if (!rfbScreen->inetdInitDone && rfbScreen->inetdSock != -1) { if (!rfbScreen->inetdInitDone && rfbScreen->inetdSock != -1) {
rfbNewClientConnection(rfbScreen,rfbScreen->inetdSock); rfbNewClientConnection(rfbScreen,rfbScreen->inetdSock);
...@@ -238,7 +239,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -238,7 +239,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
tv.tv_usec = usec; tv.tv_usec = usec;
nfds = select(rfbScreen->maxFd + 1, &fds, NULL, NULL /* &fds */, &tv); nfds = select(rfbScreen->maxFd + 1, &fds, NULL, NULL /* &fds */, &tv);
if (nfds == 0) { if (nfds == 0) {
return 0; return result;
} }
if (nfds < 0) { if (nfds < 0) {
#ifdef WIN32 #ifdef WIN32
...@@ -246,22 +247,24 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -246,22 +247,24 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
#endif #endif
if (errno != EINTR) if (errno != EINTR)
rfbLogPerror("rfbCheckFds: select"); rfbLogPerror("rfbCheckFds: select");
return 0; return -1;
} }
result += nfds;
if (rfbScreen->listenSock != -1 && FD_ISSET(rfbScreen->listenSock, &fds)) { if (rfbScreen->listenSock != -1 && FD_ISSET(rfbScreen->listenSock, &fds)) {
if ((sock = accept(rfbScreen->listenSock, if ((sock = accept(rfbScreen->listenSock,
(struct sockaddr *)&addr, &addrlen)) < 0) { (struct sockaddr *)&addr, &addrlen)) < 0) {
rfbLogPerror("rfbCheckFds: accept"); rfbLogPerror("rfbCheckFds: accept");
return 0; return -1;
} }
#ifndef WIN32 #ifndef WIN32
if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
rfbLogPerror("rfbCheckFds: fcntl"); rfbLogPerror("rfbCheckFds: fcntl");
closesocket(sock); closesocket(sock);
return 0; return -1;
} }
#endif #endif
...@@ -269,7 +272,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -269,7 +272,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
(char *)&one, sizeof(one)) < 0) { (char *)&one, sizeof(one)) < 0) {
rfbLogPerror("rfbCheckFds: setsockopt"); rfbLogPerror("rfbCheckFds: setsockopt");
closesocket(sock); closesocket(sock);
return 0; return -1;
} }
#ifdef USE_LIBWRAP #ifdef USE_LIBWRAP
...@@ -278,7 +281,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -278,7 +281,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
rfbLog("Rejected connection from client %s\n", rfbLog("Rejected connection from client %s\n",
inet_ntoa(addr.sin_addr)); inet_ntoa(addr.sin_addr));
closesocket(sock); closesocket(sock);
return 0; return -1;
} }
#endif #endif
...@@ -288,7 +291,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -288,7 +291,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
FD_CLR(rfbScreen->listenSock, &fds); FD_CLR(rfbScreen->listenSock, &fds);
if (--nfds == 0) if (--nfds == 0)
return 0; return result;
} }
if ((rfbScreen->udpSock != -1) && FD_ISSET(rfbScreen->udpSock, &fds)) { if ((rfbScreen->udpSock != -1) && FD_ISSET(rfbScreen->udpSock, &fds)) {
...@@ -313,7 +316,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -313,7 +316,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
(struct sockaddr *)&addr, addrlen) < 0) { (struct sockaddr *)&addr, addrlen) < 0) {
rfbLogPerror("rfbCheckFds: UDP: connect"); rfbLogPerror("rfbCheckFds: UDP: connect");
rfbDisconnectUDPSock(rfbScreen); rfbDisconnectUDPSock(rfbScreen);
return 0; return -1;
} }
rfbNewUDPConnection(rfbScreen,rfbScreen->udpSock); rfbNewUDPConnection(rfbScreen,rfbScreen->udpSock);
...@@ -324,7 +327,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -324,7 +327,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
FD_CLR(rfbScreen->udpSock, &fds); FD_CLR(rfbScreen->udpSock, &fds);
if (--nfds == 0) if (--nfds == 0)
return 0; return result;
} }
i = rfbGetClientIterator(rfbScreen); i = rfbGetClientIterator(rfbScreen);
...@@ -337,7 +340,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -337,7 +340,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
} }
rfbReleaseClientIterator(i); rfbReleaseClientIterator(i);
} while(rfbScreen->handleEventsEagerly); } while(rfbScreen->handleEventsEagerly);
return 1; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment