]> source.dussan.org Git - tigervnc.git/commitdiff
Move version reading/writing out of ConnParams
authorPierre Ossman <ossman@cendio.se>
Mon, 18 Jun 2018 14:51:53 +0000 (16:51 +0200)
committerPierre Ossman <ossman@cendio.se>
Fri, 26 Oct 2018 14:47:49 +0000 (16:47 +0200)
That object is just a container for the current state. Move the I/O
to the classes already doing such stuff.

common/rfb/CConnection.cxx
common/rfb/ConnParams.cxx
common/rfb/ConnParams.h
common/rfb/SConnection.cxx

index fb953775044ae91558f3188ae54f5970de389dc5..7146abc928e647ade3e4812d0a45589d1b599eb8 100644 (file)
@@ -128,13 +128,25 @@ void CConnection::processMsg()
 
 void CConnection::processVersionMsg()
 {
+  char verStr[13];
+  int majorVersion;
+  int minorVersion;
+
   vlog.debug("reading protocol version");
-  bool done;
-  if (!cp.readVersion(is, &done)) {
+
+  if (!is->checkNoWait(12))
+    return;
+
+  is->readBytes(verStr, 12);
+  verStr[12] = '\0';
+
+  if (sscanf(verStr, "RFB %03d.%03d\n",
+             &majorVersion, &minorVersion) != 2) {
     state_ = RFBSTATE_INVALID;
     throw Exception("reading version failed: not an RFB server?");
   }
-  if (!done) return;
+
+  cp.setVersion(majorVersion, minorVersion);
 
   vlog.info("Server supports RFB protocol version %d.%d",
             cp.majorVersion, cp.minorVersion);
@@ -152,7 +164,10 @@ void CConnection::processVersionMsg()
     cp.setVersion(3,8);
   }
 
-  cp.writeVersion(os);
+  sprintf(verStr, "RFB %03d.%03d\n", cp.majorVersion, cp.minorVersion);
+  os->writeBytes(verStr, 12);
+  os->flush();
+
   state_ = RFBSTATE_SECURITY_TYPES;
 
   vlog.info("Using RFB protocol version %d.%d",
index 80b4a5ac4dfbada7e4abdbfb0ee07c1d4890a769..405a99ccfa1c5da902a623d3c92a8132db258ba1 100644 (file)
@@ -18,8 +18,6 @@
  * USA.
  */
 #include <stdio.h>
-#include <rdr/InStream.h>
-#include <rdr/OutStream.h>
 #include <rfb/Exception.h>
 #include <rfb/encodings.h>
 #include <rfb/ledStates.h>
@@ -39,7 +37,7 @@ ConnParams::ConnParams()
     supportsSetDesktopSize(false), supportsFence(false),
     supportsContinuousUpdates(false),
     compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
-    subsampling(subsampleUndefined), name_(0), verStrPos(0),
+    subsampling(subsampleUndefined), name_(0),
     ledState_(ledUnknown)
 {
   setName("");
@@ -52,30 +50,6 @@ ConnParams::~ConnParams()
   delete cursor_;
 }
 
-bool ConnParams::readVersion(rdr::InStream* is, bool* done)
-{
-  if (verStrPos >= 12) return false;
-  while (is->checkNoWait(1) && verStrPos < 12) {
-    verStr[verStrPos++] = is->readU8();
-  }
-
-  if (verStrPos < 12) {
-    *done = false;
-    return true;
-  }
-  *done = true;
-  verStr[12] = 0;
-  return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2);
-}
-
-void ConnParams::writeVersion(rdr::OutStream* os)
-{
-  char str[13];
-  sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion);
-  os->writeBytes(str, 12);
-  os->flush();
-}
-
 void ConnParams::setPF(const PixelFormat& pf)
 {
   pf_ = pf;
index b3222936e0cc76aa87a81acc658ab9667d9c1d27..b56c94074b1f86bc0908c5ca15767245399d1b0f 100644 (file)
@@ -30,8 +30,6 @@
 #include <rfb/PixelFormat.h>
 #include <rfb/ScreenSet.h>
 
-namespace rdr { class InStream; }
-
 namespace rfb {
 
   const int subsampleUndefined = -1;
@@ -47,9 +45,6 @@ namespace rfb {
     ConnParams();
     ~ConnParams();
 
-    bool readVersion(rdr::InStream* is, bool* done);
-    void writeVersion(rdr::OutStream* os);
-
     int majorVersion;
     int minorVersion;
 
@@ -114,8 +109,6 @@ namespace rfb {
     char* name_;
     Cursor* cursor_;
     std::set<rdr::S32> encodings_;
-    char verStr[13];
-    int verStrPos;
     unsigned int ledState_;
   };
 }
index efc26acfe1e00828c0e08027f084ba4d0a3c07f0..846e97e496ca27f9e5c5195b369846235b38d149 100644 (file)
@@ -80,7 +80,12 @@ void SConnection::setStreams(rdr::InStream* is_, rdr::OutStream* os_)
 
 void SConnection::initialiseProtocol()
 {
-  cp.writeVersion(os);
+  char str[13];
+
+  sprintf(str, "RFB %03d.%03d\n", defaultMajorVersion, defaultMinorVersion);
+  os->writeBytes(str, 12);
+  os->flush();
+
   state_ = RFBSTATE_PROTOCOL_VERSION;
 }
 
@@ -104,13 +109,25 @@ void SConnection::processMsg()
 
 void SConnection::processVersionMsg()
 {
+  char verStr[13];
+  int majorVersion;
+  int minorVersion;
+
   vlog.debug("reading protocol version");
-  bool done;
-  if (!cp.readVersion(is, &done)) {
+
+  if (!is->checkNoWait(12))
+    return;
+
+  is->readBytes(verStr, 12);
+  verStr[12] = '\0';
+
+  if (sscanf(verStr, "RFB %03d.%03d\n",
+             &majorVersion, &minorVersion) != 2) {
     state_ = RFBSTATE_INVALID;
     throw Exception("reading version failed: not an RFB client?");
   }
-  if (!done) return;
+
+  cp.setVersion(majorVersion, minorVersion);
 
   vlog.info("Client needs protocol version %d.%d",
             cp.majorVersion, cp.minorVersion);