Mercurial > hg > Members > nobuyasu > tightVNCProxy
changeset 96:f0790bcf000d
fix concurrent modification
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Aug 2011 14:38:30 +0900 |
parents | 285dd4d6dacf |
children | 145506601e0d 0571d955da35 |
files | src/myVncProxy/MyRfbProto.java src/myVncProxy/ProxyVncCanvas.java |
diffstat | 2 files changed, 44 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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<LinkedList<ByteBuffer>> multicastqueue = new MostRecentMultiCast<LinkedList<ByteBuffer>>(10); + // private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MostRecentMultiCast<LinkedList<ByteBuffer>>(10); + private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); 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<ByteBuffer> inputs, LinkedList<ByteBuffer> outputs) throws IOException { + public int zip(Deflater deflater,LinkedList<ByteBuffer> inputs, int inputIndex, LinkedList<ByteBuffer> 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<ByteBuffer> 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<ByteBuffer> outs = new LinkedList<ByteBuffer>(); - 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<ByteBuffer> in1 = clone(in); Deflater deflater = new Deflater(); - zip(deflater, in,out); + zip(deflater,in,0,out); // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend on deflator's state unzip(inflater, out, out2); equalByteBuffers(in1, out2); LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>(); - zip(deflater,out2,out4); + zip(deflater,out2,0,out4); LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>(); unzip(inflater,out4,out5); equalByteBuffers(in1,out5);
--- 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;