# HG changeset patch # User Shinji KONO # Date 1312459757 -32400 # Node ID 7a7baebdd3cf57281b03aa1320522da5144d57f2 # Parent e166c3cad2b80ac1a0624afc3571e85fc3fd08d6 minor fix diff -r e166c3cad2b8 -r 7a7baebdd3cf src/myVncProxy/MyRfbProto.java --- 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 out = new LinkedList(); 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 in = new LinkedList(); LinkedList out = new LinkedList(); LinkedList out2 = new LinkedList(); + 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 in1 = clone(in); Deflater deflater = new Deflater(); zip(deflater,in,0,out); // LinkedList 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 out4 = new LinkedList(); deflater = new Deflater();