Mercurial > hg > Applications > TreeVNC
changeset 182:b3426724667b
fix read send data.
author | oc |
---|---|
date | Mon, 23 Jun 2014 19:30:51 +0900 |
parents | 9c02b5a72bf9 |
children | 6f452c497e0e |
files | src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java |
diffstat | 4 files changed, 32 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Mon Jun 23 17:59:07 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Mon Jun 23 19:30:51 2014 +0900 @@ -40,6 +40,11 @@ if (0 == zippedLength) return; int length = rect.width * rect.height * renderer.getBytesPerPixel(); byte[] bytes = unzip(reader, zippedLength, length, rect.getEncodingType()); + decode1(reader, renderer, rect, bytes, zippedLength); + } + + public void decode1(Reader reader, Renderer renderer, + FramebufferUpdateRectangle rect, byte[] bytes, int zippedLength) throws TransportException { int offset = zippedLength; int maxX = rect.x + rect.width; int maxY = rect.y + rect.height;
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Mon Jun 23 17:59:07 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Mon Jun 23 19:30:51 2014 +0900 @@ -23,20 +23,24 @@ FramebufferUpdateRectangle rect) throws TransportException { int dataLen = getZrleLength(rect, reader); reader.reset(); + byte[] bytes = new byte[dataLen]; // TreeVNC handling - rfb.readSendData(dataLen, reader); + rfb.readSendData(dataLen, reader, bytes); // reader is reseted read again if (rfb.hasViewer()) { reader.reset(); // decode data when it is a client - reader.readBytes(8); + if (!rfb.isRoot()) + reader.readBytes(8); reader.readByte();// message reader.readByte();// padding reader.readUInt16();// numberOfRectangle rect.fill(reader);// fill - Decoder decoder = new ZRLEDecoder(); - if (!rfb.getCuiVersion()) + ZRLEDecoder decoder = new ZRLEDecoder(); + if (rfb.isRoot()) + decoder.decode1(reader, renderer, rect, bytes, dataLen); + else if (!rfb.getCuiVersion()) decoder.decode(reader, renderer, rect); else { reader.readBytes((int) reader.readUInt32());
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Mon Jun 23 17:59:07 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Mon Jun 23 19:30:51 2014 +0900 @@ -44,6 +44,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; import java.util.logging.Logger; import jp.ac.u_ryukyu.treevnc.MyRfbProto; @@ -261,7 +262,8 @@ rfb.getContext().setInitData(initData); repaintController.updateRemoteDesktopName(rfb.getContext()); reader.reset(); - rfb.readSendData(length + 20, reader); // size of UpdateRectangleMessage with initData. + byte[] bytes = new byte[0]; + rfb.readSendData(length + 20, reader, bytes ); // size of UpdateRectangleMessage with initData. short id = (short) rect.x; visible = (id != rfb.getId()); }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Mon Jun 23 17:59:07 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Mon Jun 23 19:30:51 2014 +0900 @@ -451,16 +451,16 @@ * @param inflater * @param inputs * byte data[] - * @param outputs + * @param bytes * byte data[] * @return number of total bytes * @throws IOException */ public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, - int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize) + int inputIndex, byte[] bytes, int bufSize) throws DataFormatException { - int len = 0; - ByteBuffer buf = multicastqueue.allocate(bufSize); + int position = 0; + int limit = bytes.length; while (inputIndex < inputs.size()) { ByteBuffer input = inputs.get(inputIndex++); inflater.setInput(input.array(), input.position(), input.limit()); @@ -468,24 +468,17 @@ // we need this // inflater.end(); but this won't work do { - int len0 = inflater.inflate(buf.array(), buf.position(), - buf.remaining()); + int len0 = inflater.inflate(bytes, position, + limit-position); if (len0 > 0) { - buf.position(buf.position() + len0); - len += len0; - if (buf.remaining() == 0) { - buf.flip(); - outputs.addLast(buf); - buf = multicastqueue.allocate(bufSize); + position += len0; + if (position > limit) { + throw new DataFormatException(); } } } while (!inflater.needsInput()); } - if (buf.position() != 0) { - buf.flip(); - outputs.addLast(buf); - } - return len; + return position; } /** @@ -495,7 +488,7 @@ * @param reader * @throws TransportException */ - public void readSendData(int dataLen, Reader reader) + public void readSendData(int dataLen, Reader reader, byte[] bytes) throws TransportException { LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); ByteBuffer header = multicastqueue.allocate(16); @@ -504,7 +497,9 @@ reader.mark(dataLen+8); // +8 is serialnum reader.readBytes(serial.array(),0,8); serial.limit(8); - } + } else { + reader.mark(dataLen); + } reader.readBytes(header.array(), 0, 16); header.limit(16); if (header.get(0) == FramebufferUpdate) { @@ -528,8 +523,9 @@ Deflater nDeflater = deflater; // new Deflater(); LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); try { - unzip(inflater, inputs, 0, out, INFLATE_BUFSIZE); + unzip(inflater, inputs, 0, bytes, INFLATE_BUFSIZE); // dump32(inputs); + out.add(ByteBuffer.wrap(bytes)); int len2 = zip(nDeflater, out, 0, bufs); ByteBuffer blen = multicastqueue.allocate(4); blen.putInt(len2);