summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2011-11-15 12:07:43 +0000
committerPierre Ossman <ossman@cendio.se>2011-11-15 12:07:43 +0000
commit3c837139f1872a3d966ca146d4ed6ae9b8f0b722 (patch)
treebe596517545ba1d6e86c1ad0118ec86c26fbfd95 /common
parentc898d9af833212adc2ac5839899d82895976dee9 (diff)
downloadtigervnc-3c837139f1872a3d966ca146d4ed6ae9b8f0b722.tar.gz
tigervnc-3c837139f1872a3d966ca146d4ed6ae9b8f0b722.zip
Add method to query how long since we last wrote something to a fd.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4802 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common')
-rw-r--r--common/rdr/FdOutStream.cxx11
-rw-r--r--common/rdr/FdOutStream.h6
2 files changed, 17 insertions, 0 deletions
diff --git a/common/rdr/FdOutStream.cxx b/common/rdr/FdOutStream.cxx
index a6b85e21..533faa3f 100644
--- a/common/rdr/FdOutStream.cxx
+++ b/common/rdr/FdOutStream.cxx
@@ -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
@@ -44,6 +45,7 @@
#include <rdr/FdOutStream.h>
#include <rdr/Exception.h>
+#include <rfb/util.h>
using namespace rdr;
@@ -56,6 +58,8 @@ FdOutStream::FdOutStream(int fd_, bool blocking_, int timeoutms_, int bufSize_)
{
ptr = start = sentUpTo = new U8[bufSize];
end = start + bufSize;
+
+ gettimeofday(&lastWrite, NULL);
}
FdOutStream::~FdOutStream()
@@ -86,6 +90,11 @@ int FdOutStream::bufferUsage()
return ptr - sentUpTo;
}
+unsigned FdOutStream::getIdleTime()
+{
+ return rfb::msSince(&lastWrite);
+}
+
void FdOutStream::flush()
{
int timeoutms_;
@@ -218,5 +227,7 @@ int FdOutStream::writeWithTimeout(const void* data, int length, int timeoutms)
if (n < 0) throw SystemException("write",errno);
+ gettimeofday(&lastWrite, NULL);
+
return n;
}
diff --git a/common/rdr/FdOutStream.h b/common/rdr/FdOutStream.h
index daa88b24..b7f6cb01 100644
--- a/common/rdr/FdOutStream.h
+++ b/common/rdr/FdOutStream.h
@@ -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
@@ -23,6 +24,8 @@
#ifndef __RDR_FDOUTSTREAM_H__
#define __RDR_FDOUTSTREAM_H__
+#include <sys/time.h>
+
#include <rdr/OutStream.h>
namespace rdr {
@@ -43,6 +46,8 @@ namespace rdr {
int bufferUsage();
+ unsigned getIdleTime();
+
private:
int overrun(int itemSize, int nItems);
int writeWithTimeout(const void* data, int length, int timeoutms);
@@ -53,6 +58,7 @@ namespace rdr {
int offset;
U8* start;
U8* sentUpTo;
+ struct timeval lastWrite;
};
}