# HG changeset patch # User Shinji KONO # Date 1312349910 -32400 # Node ID f0790bcf000db80ff8735cf20e2a4c30b0d6fb1d # Parent 285dd4d6dacf733e364fb285935695f7829f3fb3 fix concurrent modification diff -r 285dd4d6dacf -r f0790bcf000d src/myVncProxy/MyRfbProto.java --- a/src/myVncProxy/MyRfbProto.java Wed Aug 03 13:17:14 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Wed Aug 03 14:38:30 2011 +0900 @@ -64,7 +64,8 @@ byte[] pngBytes; - private MulticastQueue> multicastqueue = new MostRecentMultiCast>(10); + // private MulticastQueue> multicastqueue = new MostRecentMultiCast>(10); + private MulticastQueue> multicastqueue = new MulticastQueue>(); private int clients = 0; private Inflater inflater = new Inflater(); @@ -527,16 +528,17 @@ * @param deflater * @param inputs * byte data[] + * @param inputIndex * @param outputs * byte data[] * @return byte length in last byte array * @throws IOException */ - public int zip(Deflater deflater,LinkedList inputs, LinkedList outputs) throws IOException { + public int zip(Deflater deflater,LinkedList inputs, int inputIndex, LinkedList outputs) throws IOException { int len1=0,len = 0; deflater.reset(); - while(inputs.size()>0) { - ByteBuffer b1 = inputs.poll(); + while(inputIndex < inputs.size()) { + ByteBuffer b1 = inputs.get(inputIndex++); deflater.setInput(b1.array(),b1.position(),b1.limit()); if (inputs.size()==0) { deflater.finish(); @@ -568,8 +570,9 @@ throws DataFormatException { int len=0,len0; // inflater.reset(); + int inputIndex = 0; do { - ByteBuffer input = inputs.poll(); + ByteBuffer input = inputs.get(inputIndex++); inflater.setInput(input.array(),0,input.limit()); do { ByteBuffer buf = ByteBuffer.allocate(INFLATE_BUFSIZE); @@ -580,7 +583,7 @@ outputs.addLast(buf); } } while (len0>0); - } while (!inputs.isEmpty()); + } while (inputIndex < inputs.size()) ; return len; } @@ -641,14 +644,38 @@ readClientInit(is); sendInitData(os); + Runnable reader = new Runnable() { + public void run() { + byte b[] = new byte[4096]; + for(;;) { + try { + int c = is.read(b); + if (c<=0) throw new IOException(); + System.out.println("client read "+c); + } catch (IOException e) { + try { + os.close(); + is.close(); + } catch (IOException e1) { + } + return; + } + } + } + }; + new Thread(reader).start(); + for (;;) { LinkedList bufs = c.poll(); - ByteBuffer header = bufs.poll(); + int inputIndex = 0; + ByteBuffer header = bufs.get(inputIndex++); + if (header==null) continue; if (header.get(0)==RfbProto.FramebufferUpdate) { + System.out.println("client "+ clients); int encoding = header.getInt(12); if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) { LinkedList outs = new LinkedList(); - int len2 = zip(deflater, bufs, outs); + int len2 = zip(deflater, bufs, inputIndex, outs); ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip(); outs.addFirst(blen); outs.addFirst(header); @@ -661,12 +688,17 @@ continue; } os.write(header.array(),header.position(),header.limit()); - for(ByteBuffer b : bufs) { + while(inputIndex < bufs.size()) { + ByteBuffer b = bufs.get(inputIndex++); os.write(b.array(), b.position(), b.limit()); } os.flush(); } } catch (IOException e) { + try { + os.close(); + } catch (IOException e1) { + } /* if socket closed cliList.remove(newCli); */ } } @@ -693,12 +725,12 @@ LinkedList in1 = clone(in); Deflater deflater = new Deflater(); - zip(deflater, in,out); + zip(deflater,in,0,out); // LinkedList out3 = clone(out); zipped result is depend on deflator's state unzip(inflater, out, out2); equalByteBuffers(in1, out2); LinkedList out4 = new LinkedList(); - zip(deflater,out2,out4); + zip(deflater,out2,0,out4); LinkedList out5 = new LinkedList(); unzip(inflater,out4,out5); equalByteBuffers(in1,out5); diff -r 285dd4d6dacf -r f0790bcf000d src/myVncProxy/ProxyVncCanvas.java --- a/src/myVncProxy/ProxyVncCanvas.java Wed Aug 03 13:17:14 2011 +0900 +++ b/src/myVncProxy/ProxyVncCanvas.java Wed Aug 03 14:38:30 2011 +0900 @@ -79,6 +79,7 @@ // True if we process keyboard and mouse events. boolean inputEnabled; + private int b = 0; @@ -505,7 +506,6 @@ fullUpdateNeeded = true; } */ - // Request framebuffer update if needed. int w = rfb.framebufferWidth; int h = rfb.framebufferHeight;