Browse Source

Change idle timeout to timer

Get this timeout in to the timer system as well to make things
simpler and more robust.
tags/v1.9.90
Pierre Ossman 5 years ago
parent
commit
65e08fdc9d
3 changed files with 25 additions and 50 deletions
  1. 23
    38
      common/rfb/VNCSConnectionST.cxx
  2. 2
    6
      common/rfb/VNCSConnectionST.h
  3. 0
    6
      common/rfb/VNCServerST.cxx

+ 23
- 38
common/rfb/VNCSConnectionST.cxx View File

fenceDataLen(0), fenceData(NULL), congestionTimer(this), fenceDataLen(0), fenceData(NULL), congestionTimer(this),
losslessTimer(this), server(server_), updates(false), losslessTimer(this), server(server_), updates(false),
updateRenderedCursor(false), removeRenderedCursor(false), updateRenderedCursor(false), removeRenderedCursor(false),
continuousUpdates(false), encodeManager(this), pointerEventTime(0),
clientHasCursor(false)
continuousUpdates(false), encodeManager(this), idleTimer(this),
pointerEventTime(0), clientHasCursor(false)
{ {
setStreams(&sock->inStream(), &sock->outStream()); setStreams(&sock->inStream(), &sock->outStream());
peerEndpoint.buf = sock->getPeerEndpoint(); peerEndpoint.buf = sock->getPeerEndpoint();


// Configure the socket // Configure the socket
setSocketTimeouts(); setSocketTimeouts();
lastEventTime = time(0);

// Kick off the idle timer
if (rfb::Server::idleTimeout) {
// minimum of 15 seconds while authenticating
if (rfb::Server::idleTimeout < 15)
idleTimer.start(secsToMillis(15));
else
idleTimer.start(secsToMillis(rfb::Server::idleTimeout));
}
} }




} }




int VNCSConnectionST::checkIdleTimeout()
{
int idleTimeout = rfb::Server::idleTimeout;
if (idleTimeout == 0) return 0;
if (state() != RFBSTATE_NORMAL && idleTimeout < 15)
idleTimeout = 15; // minimum of 15 seconds while authenticating
time_t now = time(0);
if (now < lastEventTime) {
// Someone must have set the time backwards. Set lastEventTime so that the
// idleTimeout will count from now.
vlog.info("Time has gone backwards - resetting idle timeout");
lastEventTime = now;
}
int timeLeft = lastEventTime + idleTimeout - now;
if (timeLeft < -60) {
// Our callback is over a minute late - someone must have set the time
// forwards. Set lastEventTime so that the idleTimeout will count from
// now.
vlog.info("Time has gone forwards - resetting idle timeout");
lastEventTime = now;
return secsToMillis(idleTimeout);
}
if (timeLeft <= 0) {
close("Idle timeout");
return 0;
}
return secsToMillis(timeLeft);
}


bool VNCSConnectionST::getComparerState() bool VNCSConnectionST::getComparerState()
{ {
// We interpret a low compression level as an indication that the client // We interpret a low compression level as an indication that the client


void VNCSConnectionST::authSuccess() void VNCSConnectionST::authSuccess()
{ {
lastEventTime = time(0);
if (rfb::Server::idleTimeout)
idleTimer.start(secsToMillis(rfb::Server::idleTimeout));


// - Set the connection parameters appropriately // - Set the connection parameters appropriately
cp.width = server->getPixelBuffer()->width(); cp.width = server->getPixelBuffer()->width();


void VNCSConnectionST::clientInit(bool shared) void VNCSConnectionST::clientInit(bool shared)
{ {
lastEventTime = time(0);
if (rfb::Server::idleTimeout)
idleTimer.start(secsToMillis(rfb::Server::idleTimeout));
if (rfb::Server::alwaysShared || reverseConnection) shared = true; if (rfb::Server::alwaysShared || reverseConnection) shared = true;
if (!accessCheck(AccessNonShared)) shared = true; if (!accessCheck(AccessNonShared)) shared = true;
if (rfb::Server::neverShared) shared = false; if (rfb::Server::neverShared) shared = false;


void VNCSConnectionST::pointerEvent(const Point& pos, int buttonMask) void VNCSConnectionST::pointerEvent(const Point& pos, int buttonMask)
{ {
pointerEventTime = lastEventTime = time(0);
if (rfb::Server::idleTimeout)
idleTimer.start(secsToMillis(rfb::Server::idleTimeout));
pointerEventTime = time(0);
if (!accessCheck(AccessPtrEvents)) return; if (!accessCheck(AccessPtrEvents)) return;
if (!rfb::Server::acceptPointerEvents) return; if (!rfb::Server::acceptPointerEvents) return;
pointerEventPos = pos; pointerEventPos = pos;
void VNCSConnectionST::keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down) { void VNCSConnectionST::keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down) {
rdr::U32 lookup; rdr::U32 lookup;


lastEventTime = time(0);
if (rfb::Server::idleTimeout)
idleTimer.start(secsToMillis(rfb::Server::idleTimeout));
if (!accessCheck(AccessKeyEvents)) return; if (!accessCheck(AccessKeyEvents)) return;
if (!rfb::Server::acceptKeyEvents) return; if (!rfb::Server::acceptKeyEvents) return;


close(e.str()); close(e.str());
} }


if (t == &idleTimer)
close("Idle timeout");

return false; return false;
} }


void VNCSConnectionST::setSocketTimeouts() void VNCSConnectionST::setSocketTimeouts()
{ {
int timeoutms = rfb::Server::clientWaitTimeMillis; int timeoutms = rfb::Server::clientWaitTimeMillis;
soonestTimeout(&timeoutms, secsToMillis(rfb::Server::idleTimeout));
if (timeoutms == 0) if (timeoutms == 0)
timeoutms = -1; timeoutms = -1;
sock->inStream().setTimeout(timeoutms); sock->inStream().setTimeout(timeoutms);

+ 2
- 6
common/rfb/VNCSConnectionST.h View File

void setLEDStateOrClose(unsigned int state); void setLEDStateOrClose(unsigned int state);
void approveConnectionOrClose(bool accept, const char* reason); void approveConnectionOrClose(bool accept, const char* reason);


// checkIdleTimeout() returns the number of milliseconds left until the
// idle timeout expires. If it has expired, the connection is closed and
// zero is returned. Zero is also returned if there is no idle timeout.
int checkIdleTimeout();

// The following methods never throw exceptions // The following methods never throw exceptions


// getComparerState() returns if this client would like the framebuffer // getComparerState() returns if this client would like the framebuffer


std::map<rdr::U32, rdr::U32> pressedKeys; std::map<rdr::U32, rdr::U32> pressedKeys;


time_t lastEventTime;
Timer idleTimer;

time_t pointerEventTime; time_t pointerEventTime;
Point pointerEventPos; Point pointerEventPos;
bool clientHasCursor; bool clientHasCursor;

+ 0
- 6
common/rfb/VNCServerST.cxx View File

int VNCServerST::checkTimeouts() int VNCServerST::checkTimeouts()
{ {
int timeout = 0; int timeout = 0;
std::list<VNCSConnectionST*>::iterator ci, ci_next;


soonestTimeout(&timeout, Timer::checkTimeouts()); soonestTimeout(&timeout, Timer::checkTimeouts());

for (ci=clients.begin();ci!=clients.end();ci=ci_next) {
ci_next = ci; ci_next++;
soonestTimeout(&timeout, (*ci)->checkIdleTimeout());
}
return timeout; return timeout;
} }

Loading…
Cancel
Save