diff options
author | Pierre Ossman <ossman@cendio.se> | 2011-11-07 12:51:34 +0000 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2011-11-07 12:51:34 +0000 |
commit | 2aa4b0c49352472baa6c060371497377350a3d43 (patch) | |
tree | a225e653a1092fe1011a62222edc2ea9133c0b24 | |
parent | 714110ba26fab6c223221ef54a94e8562fa8e335 (diff) | |
download | tigervnc-2aa4b0c49352472baa6c060371497377350a3d43.tar.gz tigervnc-2aa4b0c49352472baa6c060371497377350a3d43.zip |
Timers in RFB still weren't working properly. Do this right and check the next
timer just before the Xorg select() call.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4770 3789f03b-4d11-0410-bbf8-ca57d06f2519
-rw-r--r-- | unix/xserver/hw/vnc/XserverDesktop.cc | 41 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/XserverDesktop.h | 3 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/vncExtInit.cc | 3 |
3 files changed, 32 insertions, 15 deletions
diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index 1a2bd79d..8f50cf9d 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2009-2011 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -509,9 +509,15 @@ void XserverDesktop::add_copied(RegionPtr dst, int dx, int dy) } } -void XserverDesktop::blockHandler(fd_set* fds) +static struct timeval XserverDesktopTimeout; + +void XserverDesktop::blockHandler(fd_set* fds, OSTimePtr timeout) { try { + int nextTimeout; + + // Add all sockets we want read events for, after purging + // any closed sockets. if (listener) FD_SET(listener->getFd(), fds); if (httpListener) @@ -544,18 +550,31 @@ void XserverDesktop::blockHandler(fd_set* fds) } } } + + // Then check when the next timer will expire. + // (this unfortunately also triggers any already expired timers) + nextTimeout = server->checkTimeouts(); + if (nextTimeout > 0) { + // No timeout specified? Or later timeout than we need? + if ((*timeout == NULL) || + ((*timeout)->tv_sec > (nextTimeout/1000)) || + (((*timeout)->tv_sec == (nextTimeout/1000)) && + ((*timeout)->tv_usec > ((nextTimeout%1000)*1000)))) { + XserverDesktopTimeout.tv_sec = nextTimeout/1000; + XserverDesktopTimeout.tv_usec = (nextTimeout%1000)*1000; + *timeout = &XserverDesktopTimeout; + } + } + } catch (rdr::Exception& e) { vlog.error("XserverDesktop::blockHandler: %s",e.str()); } } -static CARD32 dummyTimerCallback(OsTimerPtr timer, CARD32 now, pointer arg) { - return 0; -} - void XserverDesktop::wakeupHandler(fd_set* fds, int nfds) { try { + // First check for file descriptors with something to do if (nfds >= 1) { if (listener) { @@ -603,13 +622,9 @@ void XserverDesktop::wakeupHandler(fd_set* fds, int nfds) inputDevice->PointerSync(); } - int timeout = server->checkTimeouts(); - if (timeout > 0) { - // set a dummy timer just so we are guaranteed be called again next time. - dummyTimer = TimerSet(dummyTimer, 0, timeout, - dummyTimerCallback, 0); - } - + // Then let the timers do some processing. Rescheduling is done in + // blockHandler(). + server->checkTimeouts(); } catch (rdr::Exception& e) { vlog.error("XserverDesktop::wakeupHandler: %s",e.str()); } diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index af365117..fd0773ca 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -1,4 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright 2009-2011 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -70,7 +71,7 @@ public: void add_changed(RegionPtr reg); void add_copied(RegionPtr dst, int dx, int dy); void ignoreHooks(bool b) { ignoreHooks_ = b; } - void blockHandler(fd_set* fds); + void blockHandler(fd_set* fds, OSTimePtr timeout); void wakeupHandler(fd_set* fds, int nfds); void writeBlockHandler(fd_set* fds); void writeWakeupHandler(fd_set* fds, int nfds); diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index baa8fa4e..7d865ed1 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -1,4 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright 2011 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -308,7 +309,7 @@ static void vncBlockHandler(pointer data, OSTimePtr timeout, pointer readmask) for (int scr = 0; scr < screenInfo.numScreens; scr++) if (desktop[scr]) - desktop[scr]->blockHandler(fds); + desktop[scr]->blockHandler(fds, timeout); } static void vncWakeupHandler(pointer data, int nfds, pointer readmask) |