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);
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",
* USA.
*/
#include <stdio.h>
-#include <rdr/InStream.h>
-#include <rdr/OutStream.h>
#include <rfb/Exception.h>
#include <rfb/encodings.h>
#include <rfb/ledStates.h>
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("");
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;
#include <rfb/PixelFormat.h>
#include <rfb/ScreenSet.h>
-namespace rdr { class InStream; }
-
namespace rfb {
const int subsampleUndefined = -1;
ConnParams();
~ConnParams();
- bool readVersion(rdr::InStream* is, bool* done);
- void writeVersion(rdr::OutStream* os);
-
int majorVersion;
int minorVersion;
char* name_;
Cursor* cursor_;
std::set<rdr::S32> encodings_;
- char verStr[13];
- int verStrPos;
unsigned int ledState_;
};
}
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;
}
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);