# HG changeset patch # User Shinji KONO # Date 1312321499 -32400 # Node ID 704e01d2390c18e265e34f124755fe5e50069293 # Parent d4236fd2efe1a6afe74afcbac28a6e4a65c2fab6 fix diff -r d4236fd2efe1 -r 704e01d2390c src/myVncProxy/MyRfbProto.java --- a/src/myVncProxy/MyRfbProto.java Wed Aug 03 04:47:10 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Wed Aug 03 06:44:59 2011 +0900 @@ -57,7 +57,7 @@ byte[] pngBytes; - private MulticastQueue multicastqueue = new MostRecentMultiCast(10); + private MulticastQueue> multicastqueue = new MostRecentMultiCast>(10); private int clients = 0; private Inflater inflater = new Inflater(); @@ -374,27 +374,30 @@ void readSendData(int dataLen) throws IOException, DataFormatException { byte b[] = new byte[dataLen]; readFully(b); - + LinkedListbufs = new LinkedList(); if (b[0]==RfbProto.FramebufferUpdate) { - int encoding = ((b[12]<<8+b[13])<<8+b[14])<<8+b[15]; + int encoding = u32(b,12); if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) { - int len; + int len=0,len0; inflater.setInput(b, 20, b.length-20); do { - byte inf[] = new byte[INFLATE_BUFSIZE+20]; - len = inflater.inflate(inf,20,inf.length-20); - for(int i = 0;i<20;i++) inf[i] = b[i]; - inf[16+0] = (byte) ((len >>> 24) & 0xFF); - inf[16+1] = (byte) ((len >>> 16) & 0xFF); - inf[16+2] = (byte) ((len >>> 8) & 0xFF); - inf[16+3] = (byte) ((len >>> 0) & 0xFF); - multicastqueue.put(inf); - } while (len ==INFLATE_BUFSIZE); + byte buf[] = new byte[INFLATE_BUFSIZE]; + len0 = inflater.inflate(buf); + len += len0; + bufs.addLast(buf); + } while (len0 ==INFLATE_BUFSIZE); + byte [] blen = castIntByte(len0); + bufs.addFirst(blen); + byte inf[] = new byte[16]; + for(int i = 0;i<16;i++) inf[i] = b[i]; + bufs.addFirst(inf); + multicastqueue.put(bufs); is.reset(); - return; + return ; } } - multicastqueue.put(b); + bufs.add(b); + multicastqueue.put(bufs); is.reset(); // It may be compressed. We can inflate here to avoid repeating clients decompressing here, @@ -503,7 +506,9 @@ b[1] = (byte) 0; startCheckTime = System.currentTimeMillis(); System.out.println("startChckTime = "+ startCheckTime); - multicastqueue.put(b); + LinkedListbufs = new LinkedList(); + bufs.add(b); + multicastqueue.put(bufs); } void endSpeedCheck() { @@ -535,7 +540,7 @@ // createBimgFlag = true; // rfb.addSockTmp(newCli); // addSock(newCli); - final Client c = multicastqueue.newClient(); + final Client > c = multicastqueue.newClient(); Runnable sender = new Runnable() { public void run() { @@ -553,26 +558,48 @@ sendInitData(os); for (;;) { - byte[] b = c.poll(); + LinkedList bufs = c.poll(); + byte[] b = bufs.poll(); if (b[0]==RfbProto.FramebufferUpdate) { - int encoding = ((b[12]<<8+b[13])<<8+b[14])<<8+b[15]; + int encoding = u32(b,12); + int clen = u32(bufs.poll(),0); if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) { - byte[] c1 = new byte[INFLATE_BUFSIZE]; - int len=0,len1,clen; - do { - clen = ((b[16]<<8+b[17])<<8+b[18])<<8+b[19]; - deflater.setInput(b,20,clen); - len1 = deflater.deflate(c1); - if (clen==INFLATE_BUFSIZE) b = c.poll(); - len += len1; - } while(clen== INFLATE_BUFSIZE); + LinkedList outs = new LinkedList(); + int len = 0, count = 0; + int len2=0; + int bufSize = bufs.size(); + int bufCount = 0; + for( byte[] b1 : bufs) { + if (++bufCount > bufSize) + deflater.setInput(b1,0,clen); + else + deflater.setInput(b1); + int len1=0; + do { + byte[] c1 = new byte[INFLATE_BUFSIZE]; + len2 = len1; + len1 = deflater.deflate(c1); + if (len1>0) { + outs.addLast(c1); + count ++; + len += len1; + } + } while (len1 > 0); + } byte[] blen = castIntByte(len); - os.write(b,0,16); - os.write(blen,0,4); - os.write(c1,0,len); + outs.addFirst(blen); + outs.addFirst(b); + int i = 0; + for(byte [] out: outs) { + if (i++