summaryrefslogtreecommitdiffstats
path: root/x0vncserver/x0vncserver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'x0vncserver/x0vncserver.cxx')
-rw-r--r--x0vncserver/x0vncserver.cxx33
1 files changed, 24 insertions, 9 deletions
diff --git a/x0vncserver/x0vncserver.cxx b/x0vncserver/x0vncserver.cxx
index b9a44cca..7b8c6609 100644
--- a/x0vncserver/x0vncserver.cxx
+++ b/x0vncserver/x0vncserver.cxx
@@ -401,17 +401,10 @@ int main(int argc, char** argv)
int dynPollingCycle = (int)pollingCycle;
TimeMillis timeSaved, timeNow;
+ fd_set rfds;
+ struct timeval tv;
while (true) {
- fd_set rfds;
- struct timeval tv;
-
- // FIXME: This seems to be wrong.
- tv.tv_sec = 0;
- tv.tv_usec = dynPollingCycle * 1000;
- if (tv.tv_usec > 500000) {
- tv.tv_usec = 500000;
- }
FD_ZERO(&rfds);
FD_SET(listener.getFd(), &rfds);
@@ -419,10 +412,32 @@ int main(int argc, char** argv)
std::list<Socket*> sockets;
server.getSockets(&sockets);
std::list<Socket*>::iterator i;
+ int clients_connected = 0;
for (i = sockets.begin(); i != sockets.end(); i++) {
FD_SET((*i)->getFd(), &rfds);
+ clients_connected++;
}
+ if (clients_connected) {
+ int poll_ms = 20;
+ if (timeNow.update()) {
+ poll_ms = timeNow.diffFrom(timeSaved);
+ }
+ int wait_ms = dynPollingCycle - poll_ms;
+ if (wait_ms < 0) {
+ wait_ms = 0;
+ } else if (wait_ms > 500) {
+ wait_ms = 500;
+ }
+ tv.tv_usec = wait_ms * 1000;
+#ifdef DEBUG
+ fprintf(stderr, "[%d]\t", wait_ms);
+#endif
+ } else {
+ tv.tv_usec = 50000;
+ }
+ tv.tv_sec = 0;
+
int n = select(FD_SETSIZE, &rfds, 0, 0, &tv);
if (n < 0) {
if (errno == EINTR) {