Mercurial > hg > Members > nobuyasu > tightVNCProxy
diff src/myVncProxy/MyRfbProto.java @ 106:7a7baebdd3cf
minor fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 04 Aug 2011 21:09:17 +0900 |
parents | e166c3cad2b8 |
children | a8b2712de4c5 |
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java Thu Aug 04 19:34:58 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Thu Aug 04 21:09:17 2011 +0900 @@ -508,10 +508,16 @@ while(inputIndex < inputs.size() ) { ByteBuffer b1 = inputs.get(inputIndex++); deflater.setInput(b1.array(),b1.position(),b1.remaining()); + /** + * If we finish() stream and reset() it, Deflater start new gzip stream, this makes continuous zlib reader unhappy. + * if we remove finish(), Deflater.deflate() never flushes its output. The original zlib deflate has flush flag. I'm pretty + * sure this a kind of bug of Java library. + */ if (inputIndex==inputs.size()) deflater.finish(); + int len1 = 0; do { - int len1 = deflater.deflate(c1.array(),c1.position(),c1.remaining()); + len1 = deflater.deflate(c1.array(),c1.position(),c1.remaining()); if (len1>0) { len += len1; c1.position(c1.position()+len1); @@ -520,7 +526,7 @@ c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); } } - } while (!deflater.needsInput()&&!deflater.finished()); + } while (len1 >0 || !deflater.needsInput()); // &&!deflater.finished()); } if (c1.position()!=0) { c1.flip(); outputs.addLast(c1); @@ -586,10 +592,11 @@ if (clicomp) { unzip(inflater, inputs, 0, bufs, INFLATE_BUFSIZE); } else { - Deflater nDeflater = false ? deflater : new Deflater(); + // using new Deflecter every time is incompatible with the protocol, clients have to be modified. + Deflater nDeflater = deflater; // new Deflater(); LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); unzip(inflater, inputs, 0 , out, INFLATE_BUFSIZE); - dump32(inputs); + // dump32(inputs); int len2 = zip(nDeflater, out, 0, bufs); ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip(); bufs.addFirst(blen); @@ -731,19 +738,31 @@ LinkedList<ByteBuffer> in = new LinkedList<ByteBuffer>(); LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); LinkedList<ByteBuffer> out2 = new LinkedList<ByteBuffer>(); + if (false) { for(int i=0;i<10;i++) { in.add(ByteBuffer.wrap("test1".getBytes())); in.add(ByteBuffer.wrap("test2".getBytes())); in.add(ByteBuffer.wrap("test3".getBytes())); in.add(ByteBuffer.wrap("test44".getBytes())); } + } else { + String t = ""; + for(int i=0;i<10;i++) { + t += "test1"; + t += "test2"; + t += "test3"; + t += "test44"; + } + in.add(ByteBuffer.wrap(t.getBytes())); + } + LinkedList<ByteBuffer> in1 = clone(in); Deflater deflater = new Deflater(); zip(deflater,in,0,out); // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend on deflator's state unzip(inflater, out, 0,out2, INFLATE_BUFSIZE); - inflater.reset(); + // inflater.reset(); equalByteBuffers(in1, out2); LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>(); deflater = new Deflater();