]> source.dussan.org Git - tigervnc.git/commitdiff
Provide dummy output for dummy client connections
authorPierre Ossman <ossman@cendio.se>
Thu, 27 Feb 2020 11:43:05 +0000 (12:43 +0100)
committerPierre Ossman <ossman@cendio.se>
Thu, 27 Feb 2020 11:43:05 +0000 (12:43 +0100)
The CConnection base class wants to be able to write things these days,
so we need to provide it a place to do so.

tests/perf/decperf.cxx
tests/perf/encperf.cxx

index df5214f280ada47f30cbd3058e1723464e36d13b..a6a5089971b9e6b2640095c80159af84a9bacde0 100644 (file)
 
 #include <rdr/Exception.h>
 #include <rdr/FileInStream.h>
+#include <rdr/OutStream.h>
 
 #include <rfb/CConnection.h>
 #include <rfb/CMsgReader.h>
+#include <rfb/CMsgWriter.h>
 #include <rfb/PixelBuffer.h>
 #include <rfb/PixelFormat.h>
 
 // FIXME: Files are always in this format
 static const rfb::PixelFormat filePF(32, 24, false, true, 255, 255, 255, 0, 8, 16);
 
+class DummyOutStream : public rdr::OutStream {
+public:
+  DummyOutStream();
+
+  virtual size_t length();
+  virtual void flush();
+
+private:
+  virtual size_t overrun(size_t itemSize, size_t nItems);
+
+  int offset;
+  rdr::U8 buf[131072];
+};
+
 class CConn : public rfb::CConnection {
 public:
   CConn(const char *filename);
@@ -61,24 +77,55 @@ public:
 
 protected:
   rdr::FileInStream *in;
+  DummyOutStream *out;
 };
 
+DummyOutStream::DummyOutStream()
+{
+  offset = 0;
+  ptr = buf;
+  end = buf + sizeof(buf);
+}
+
+size_t DummyOutStream::length()
+{
+  flush();
+  return offset;
+}
+
+void DummyOutStream::flush()
+{
+  offset += ptr - buf;
+  ptr = buf;
+}
+
+size_t DummyOutStream::overrun(size_t itemSize, size_t nItems)
+{
+  flush();
+  if (itemSize * nItems > (size_t)(end - ptr))
+    nItems = (end - ptr) / itemSize;
+  return nItems;
+}
+
 CConn::CConn(const char *filename)
 {
   cpuTime = 0.0;
 
   in = new rdr::FileInStream(filename);
-  setStreams(in, NULL);
+  out = new DummyOutStream;
+  setStreams(in, out);
 
   // Need to skip the initial handshake
   setState(RFBSTATE_INITIALISATION);
   // That also means that the reader and writer weren't setup
   setReader(new rfb::CMsgReader(this, in));
+  setWriter(new rfb::CMsgWriter(&server, out));
 }
 
 CConn::~CConn()
 {
   delete in;
+  delete out;
 }
 
 void CConn::initDone()
index 171564d1a28ed1b1f4483bb6ddc9f33c54005e9f..286a8d7b85c84d9a78df839c57b848900b00a61e 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <rfb/CConnection.h>
 #include <rfb/CMsgReader.h>
+#include <rfb/CMsgWriter.h>
 #include <rfb/UpdateTracker.h>
 
 #include <rfb/EncodeManager.h>
@@ -104,6 +105,7 @@ public:
 
 protected:
   rdr::FileInStream *in;
+  DummyOutStream *out;
   rfb::SimpleUpdateTracker updates;
   class SConn *sc;
 };
@@ -167,12 +169,14 @@ CConn::CConn(const char *filename)
   encodeTime = 0.0;
 
   in = new rdr::FileInStream(filename);
-  setStreams(in, NULL);
+  out = new DummyOutStream;
+  setStreams(in, out);
 
   // Need to skip the initial handshake and ServerInit
   setState(RFBSTATE_NORMAL);
   // That also means that the reader and writer weren't setup
   setReader(new rfb::CMsgReader(this, in));
+  setWriter(new rfb::CMsgWriter(&server, out));
   // Nor the frame buffer size and format
   rfb::PixelFormat pf;
   pf.parse(format);
@@ -188,6 +192,7 @@ CConn::~CConn()
 {
   delete sc;
   delete in;
+  delete out;
 }
 
 void CConn::getStats(double& ratio, unsigned long long& bytes,