From 065a43cbb29d4c9acad735e2c86721277574fca7 Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Wed, 29 Jun 2011 20:18:06 +0000 Subject: [PATCH] cleaned up readVersion/writeVersion routines in java client. readVersion wasn't failing when it should have. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4572 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- java/src/com/tigervnc/rfb/CConnection.java | 4 +-- java/src/com/tigervnc/rfb/ConnParams.java | 39 ++++++++++------------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/java/src/com/tigervnc/rfb/CConnection.java b/java/src/com/tigervnc/rfb/CConnection.java index 2a7ecfcc..da4ac6fd 100644 --- a/java/src/com/tigervnc/rfb/CConnection.java +++ b/java/src/com/tigervnc/rfb/CConnection.java @@ -66,12 +66,12 @@ abstract public class CConnection extends CMsgHandler { private void processVersionMsg() { vlog.debug("reading protocol version"); - boolean done = true; + Boolean done = new Boolean(true); if (!cp.readVersion(is, done)) { state_ = RFBSTATE_INVALID; throw new Exception("reading version failed: not an RFB server?"); } - if (!done) return; + if (!done.booleanValue()) return; vlog.info("Server supports RFB protocol version "+cp.majorVersion+"."+ cp.minorVersion); diff --git a/java/src/com/tigervnc/rfb/ConnParams.java b/java/src/com/tigervnc/rfb/ConnParams.java index c5e50d51..70d6114f 100644 --- a/java/src/com/tigervnc/rfb/ConnParams.java +++ b/java/src/com/tigervnc/rfb/ConnParams.java @@ -39,37 +39,32 @@ public class ConnParams { setName(""); } - public boolean readVersion(InStream is, boolean done) { + public boolean readVersion(InStream is, Boolean done) + { if (verStrPos >= 12) return false; - byte[] verStr = new byte[13]; - while (verStrPos < 12) { - verStr[verStrPos++] = (byte)is.readU8(); + verStr = new StringBuilder(13); + while (verStrPos < 12 && is.checkNoWait(1)) { + verStr.insert(verStrPos++,(char)is.readU8()); } if (verStrPos < 12) { - done = false; + done = Boolean.valueOf(false); return true; } - done = true; - verStr[12] = 0; - majorVersion = (verStr[4] - '0') * 100 + (verStr[5] - '0') * 10 + (verStr[6] - '0'); - minorVersion = (verStr[8] - '0') * 100 + (verStr[9] - '0') * 10 + (verStr[10] - '0'); + done = Boolean.valueOf(true); + verStr.insert(12,'0'); verStrPos = 0; - return true; + if (verStr.toString().matches("RFB \\d{3}\\.\\d{3}\\n0")) { + majorVersion = Integer.parseInt(verStr.substring(4,7)); + minorVersion = Integer.parseInt(verStr.substring(8,11)); + return true; + } + return false; } public void writeVersion(OutStream os) { - byte[] b = new byte[12]; - b[0] = (byte)'R'; b[1] = (byte)'F'; b[2] = (byte)'B'; b[3] = (byte)' '; - b[4] = (byte)('0' + (majorVersion / 100) % 10); - b[5] = (byte)('0' + (majorVersion / 10) % 10); - b[6] = (byte)('0' + majorVersion % 10); - b[7] = (byte)'.'; - b[8] = (byte)('0' + (minorVersion / 100) % 10); - b[9] = (byte)('0' + (minorVersion / 10) % 10); - b[10] = (byte)('0' + minorVersion % 10); - b[11] = (byte)'\n'; - os.writeBytes(b, 0, 12); + String str = String.format("RFB %03d.%03d\n", majorVersion, minorVersion); + os.writeBytes(str.getBytes(), 0, 12); os.flush(); } @@ -171,6 +166,6 @@ public class ConnParams { private int nEncodings_; private int[] encodings_; private int currentEncoding_; - private String verStr; + private StringBuilder verStr; private int verStrPos; } -- 2.39.5