From ea7ede9838ac51bab0427ecc8b46cc737497a375 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 18 Jun 2018 16:51:53 +0200 Subject: Move version reading/writing out of ConnParams That object is just a container for the current state. Move the I/O to the classes already doing such stuff. --- common/rfb/SConnection.cxx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'common/rfb/SConnection.cxx') diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index efc26acf..846e97e4 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -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); -- cgit v1.2.3